ElasticResultSetMetaData.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package org.es.jdbc.api;
  2. import java.sql.ResultSetMetaData;
  3. import java.sql.SQLException;
  4. import java.sql.Types;
  5. public class ElasticResultSetMetaData implements ResultSetMetaData {
  6. protected static final String JSON_DATA_COL_NAME = "__INDEX_DOCS__";
  7. @Override
  8. public int getColumnCount() throws SQLException {
  9. return 1;
  10. }
  11. @Override
  12. public boolean isAutoIncrement(int column) throws SQLException {
  13. return true;
  14. }
  15. @Override
  16. public boolean isCaseSensitive(int column) throws SQLException {
  17. return true;
  18. }
  19. @Override
  20. public boolean isSearchable(int column) throws SQLException {
  21. return false;
  22. }
  23. @Override
  24. public boolean isCurrency(int column) throws SQLException {
  25. return false;
  26. }
  27. @Override
  28. public int isNullable(int column) throws SQLException {
  29. return columnNoNulls;
  30. }
  31. @Override
  32. public boolean isSigned(int column) throws SQLException {
  33. return false;
  34. }
  35. @Override
  36. public int getColumnDisplaySize(int column) throws SQLException {
  37. return 0;
  38. }
  39. @Override
  40. public String getColumnLabel(int column) throws SQLException {
  41. return JSON_DATA_COL_NAME;
  42. }
  43. @Override
  44. public String getColumnName(int column) throws SQLException {
  45. return JSON_DATA_COL_NAME;
  46. }
  47. @Override
  48. public String getSchemaName(int column) throws SQLException {
  49. return null;
  50. }
  51. @Override
  52. public int getPrecision(int column) throws SQLException {
  53. return 0;
  54. }
  55. @Override
  56. public int getScale(int column) throws SQLException {
  57. return 0;
  58. }
  59. @Override
  60. public String getTableName(int column) throws SQLException {
  61. return null;
  62. }
  63. @Override
  64. public String getCatalogName(int column) throws SQLException {
  65. return null;
  66. }
  67. @Override
  68. public int getColumnType(int column) throws SQLException {
  69. return Types.VARCHAR;
  70. }
  71. @Override
  72. public String getColumnTypeName(int column) throws SQLException {
  73. return "String";
  74. }
  75. @Override
  76. public boolean isReadOnly(int column) throws SQLException {
  77. return true;
  78. }
  79. @Override
  80. public boolean isWritable(int column) throws SQLException {
  81. return false;
  82. }
  83. @Override
  84. public boolean isDefinitelyWritable(int column) throws SQLException {
  85. return false;
  86. }
  87. @Override
  88. public String getColumnClassName(int column) throws SQLException {
  89. return String.class.toString();
  90. }
  91. @Override
  92. @SuppressWarnings("unchecked")
  93. public final <T> T unwrap(final Class<T> iface) throws SQLException {
  94. if (isWrapperFor(iface)) {
  95. return (T) this;
  96. }
  97. throw new SQLException(String.format("[%s] cannot be unwrapped as [%s]", getClass().getName(), iface.getName()));
  98. }
  99. @Override
  100. public final boolean isWrapperFor(final Class<?> iface) throws SQLException {
  101. return iface.isInstance(this);
  102. }
  103. }