AbstractConnection.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package org.elasticsearch.jdbc;
  2. import java.sql.*;
  3. import java.util.Properties;
  4. public abstract class AbstractConnection extends AbstractFeatureNotSupportedConnection {
  5. private boolean closed = false;
  6. private int transactionIsolation;
  7. protected String url;
  8. protected Properties info;
  9. public AbstractConnection(String url, Properties info) {
  10. this.url = url;
  11. this.info = info;
  12. }
  13. @Override
  14. @SuppressWarnings("unchecked")
  15. public final <T> T unwrap(final Class<T> iface) throws SQLException {
  16. if (isWrapperFor(iface)) {
  17. return (T) this;
  18. }
  19. throw new SQLException(String.format("[%s] cannot be unwrapped as [%s]", getClass().getName(), iface.getName()));
  20. }
  21. @Override
  22. public final boolean isWrapperFor(final Class<?> iface) throws SQLException {
  23. return iface.isInstance(this);
  24. }
  25. @Override
  26. public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
  27. return createStatement();
  28. }
  29. @Override
  30. public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
  31. return prepareStatement(sql);
  32. }
  33. @Override
  34. public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
  35. return prepareStatement(sql);
  36. }
  37. @Override
  38. public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
  39. return prepareStatement(sql);
  40. }
  41. @Override
  42. public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
  43. return prepareStatement(sql);
  44. }
  45. @Override
  46. public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
  47. return prepareStatement(sql);
  48. }
  49. @Override
  50. public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
  51. return createStatement();
  52. }
  53. @Override
  54. public boolean getAutoCommit() throws SQLException {
  55. return false;
  56. }
  57. @Override
  58. public void setTransactionIsolation(int level) throws SQLException {
  59. this.transactionIsolation = level;
  60. }
  61. @Override
  62. public int getTransactionIsolation() throws SQLException {
  63. return transactionIsolation;
  64. }
  65. @Override
  66. public boolean isReadOnly() throws SQLException {
  67. return true;
  68. }
  69. @Override
  70. public void close() throws SQLException {
  71. closed = true;
  72. }
  73. @Override
  74. public boolean isClosed() throws SQLException {
  75. return closed;
  76. }
  77. @Override
  78. public void setReadOnly(boolean readOnly) throws SQLException {
  79. // ignore
  80. }
  81. @Override
  82. public void commit() throws SQLException {
  83. // ignore
  84. }
  85. @Override
  86. public void rollback() throws SQLException {
  87. // ignore
  88. }
  89. @Override
  90. public void setAutoCommit(boolean autoCommit) throws SQLException {
  91. // ignore
  92. }
  93. @Override
  94. public SQLWarning getWarnings() throws SQLException {
  95. return null;
  96. }
  97. @Override
  98. public void clearWarnings() throws SQLException {
  99. // ignore
  100. }
  101. @Override
  102. public final int getHoldability() throws SQLException {
  103. return ResultSet.HOLD_CURSORS_OVER_COMMIT;
  104. }
  105. @Override
  106. public final void setHoldability(final int holdability) throws SQLException {
  107. // ignore
  108. }
  109. }