AbstractResultSet.java 2.2 KB

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