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.

SqlHelper.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /**
  16. * Helper class to isolate the java.sql module interactions from the core of
  17. * jackcess (in java 9+ environments). If the module is enabled (indicating
  18. * that the application is already using sql constructs), then jackcess will
  19. * seamlessly interact with sql types. If the module is not enabled
  20. * (indicating that the application is not using any sql constructs), then
  21. * jackcess will not require the module in order to function otherwise
  22. * normally.
  23. *
  24. * This base class is the "fallback" class if the java.sql module is not
  25. * available.
  26. *
  27. * @author James Ahlborn
  28. */
  29. public class SqlHelper {
  30. public static final SqlHelper INSTANCE = loadInstance();
  31. public SqlHelper() {}
  32. public boolean isBlob(Object value) {
  33. return false;
  34. }
  35. public byte[] getBlobBytes(Object value) throws IOException {
  36. throw new UnsupportedOperationException();
  37. }
  38. public boolean isClob(Object value) {
  39. return false;
  40. }
  41. public CharSequence getClobString(Object value) throws IOException {
  42. throw new UnsupportedOperationException();
  43. }
  44. public Integer getNewSqlType(String typeName) throws Exception {
  45. throw new UnsupportedOperationException();
  46. }
  47. private static final SqlHelper loadInstance() {
  48. // attempt to load the implementation of this class which works with
  49. // java.sql classes. if that fails, use this fallback instance instead.
  50. try {
  51. return (SqlHelper)
  52. Class.forName("com.healthmarketscience.jackcess.impl.SqlHelperImpl")
  53. .newInstance();
  54. } catch(Throwable ignored) {}
  55. return new SqlHelper();
  56. }
  57. }