AbstractResultSet.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package org.elasticsearch.jdbc;
  2. import java.sql.ResultSet;
  3. import java.sql.SQLException;
  4. import java.sql.SQLWarning;
  5. import java.sql.Statement;
  6. public abstract class AbstractResultSet extends AbstractFeatureNotSupportedResultSet {
  7. protected boolean isClosed = false;
  8. protected Statement statement;
  9. public AbstractResultSet(Statement statement) {
  10. this.statement = statement;
  11. }
  12. @Override
  13. public void close() throws SQLException {
  14. isClosed = true;
  15. }
  16. @Override
  17. public boolean isClosed() throws SQLException {
  18. return isClosed;
  19. }
  20. @Override
  21. public int findColumn(String columnLabel) throws SQLException {
  22. //aways return first col
  23. return 1;
  24. }
  25. @Override
  26. public boolean wasNull() throws SQLException {
  27. return false;
  28. }
  29. @Override
  30. public SQLWarning getWarnings() throws SQLException {
  31. return null;
  32. }
  33. @Override
  34. public void clearWarnings() throws SQLException {
  35. // ignore
  36. }
  37. @Override
  38. public int getFetchDirection() throws SQLException {
  39. return ResultSet.FETCH_FORWARD;
  40. }
  41. @Override
  42. public int getType() throws SQLException {
  43. return ResultSet.TYPE_FORWARD_ONLY;
  44. }
  45. @Override
  46. public int getConcurrency() throws SQLException {
  47. return ResultSet.CONCUR_READ_ONLY;
  48. }
  49. @Override
  50. public Statement getStatement() throws SQLException {
  51. return statement;
  52. }
  53. @Override
  54. public int getHoldability() throws SQLException {
  55. return ResultSet.CLOSE_CURSORS_AT_COMMIT;
  56. }
  57. @Override
  58. public Object getObject(int columnIndex) throws SQLException {
  59. return getString(columnIndex);
  60. }
  61. @Override
  62. public Object getObject(String columnLabel) throws SQLException {
  63. return getString(columnLabel);
  64. }
  65. @Override
  66. @SuppressWarnings("unchecked")
  67. public final <T> T unwrap(final Class<T> iface) throws SQLException {
  68. if (isWrapperFor(iface)) {
  69. return (T) this;
  70. }
  71. throw new SQLException(String.format("[%s] cannot be unwrapped as [%s]", getClass().getName(), iface.getName()));
  72. }
  73. @Override
  74. public final boolean isWrapperFor(final Class<?> iface) throws SQLException {
  75. return iface.isInstance(this);
  76. }
  77. }