You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SqlHelperImpl.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright (c) 2021 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.impl;
  14. import java.io.IOException;
  15. import java.sql.Blob;
  16. import java.sql.Clob;
  17. import java.sql.SQLException;
  18. import java.sql.Types;
  19. /**
  20. * Implementation of SqlHelperImpl which works with the java.sql modules
  21. * classes. This class is used if the java.sql module is enabled in the
  22. * application.
  23. *
  24. * @author James Ahlborn
  25. */
  26. public class SqlHelperImpl extends SqlHelper {
  27. public SqlHelperImpl() {}
  28. @Override
  29. public boolean isBlob(Object value) {
  30. return (value instanceof Blob);
  31. }
  32. @Override
  33. public byte[] getBlobBytes(Object value) throws IOException {
  34. try {
  35. Blob b = (Blob)value;
  36. // note, start pos is 1-based
  37. return b.getBytes(1L, (int)b.length());
  38. } catch(SQLException e) {
  39. throw new IOException(e.getMessage(), e);
  40. }
  41. }
  42. @Override
  43. public boolean isClob(Object value) {
  44. return (value instanceof Clob);
  45. }
  46. @Override
  47. public CharSequence getClobString(Object value) throws IOException {
  48. try {
  49. Clob c = (Clob)value;
  50. // note, start pos is 1-based
  51. return c.getSubString(1L, (int)c.length());
  52. } catch(SQLException e) {
  53. throw new IOException(e.getMessage(), e);
  54. }
  55. }
  56. @Override
  57. public Integer getNewSqlType(String typeName) throws Exception {
  58. java.lang.reflect.Field sqlTypeField = Types.class.getField(typeName);
  59. return (Integer)sqlTypeField.get(null);
  60. }
  61. }