OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HeavyAIResultSetMetaData.java
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package ai.heavy.jdbc;
17 
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 
21 import java.sql.DatabaseMetaData;
22 import java.sql.ResultSetMetaData;
23 import java.sql.SQLException;
24 
25 import ai.heavy.thrift.server.TDatumType;
26 import ai.heavy.thrift.server.TQueryResult;
27 
28 class HeavyAIResultSetMetaData implements ResultSetMetaData {
29  final static Logger logger = LoggerFactory.getLogger(HeavyAIResultSetMetaData.class);
30  final TQueryResult sqlResult;
31  final String sql;
32 
33  public HeavyAIResultSetMetaData(TQueryResult sqlResult, String sql) {
34  this.sqlResult = sqlResult;
35  this.sql = sql;
36  }
37 
38  @Override
39  public int getColumnCount() throws SQLException { // logger.debug("Entered "+ sql );
40  return sqlResult.row_set.row_desc.size();
41  }
42 
43  @Override
44  public boolean isAutoIncrement(int column)
45  throws SQLException { // logger.debug("Entered "+ sql );
46  // logger.debug("returning false");
47  return false;
48  }
49 
50  @Override
51  public boolean isCaseSensitive(int column)
52  throws SQLException { // logger.debug("Entered "+ sql );
53  return true;
54  }
55 
56  @Override
57  public boolean isSearchable(int column)
58  throws SQLException { // logger.debug("Entered "+ sql );
59  return false;
60  }
61 
62  @Override
63  public boolean isCurrency(int column)
64  throws SQLException { // logger.debug("Entered "+ sql );
65  return false;
66  }
67 
68  @Override
69  public int isNullable(int column)
70  throws SQLException { // logger.debug("Entered "+ sql );
71  return sqlResult.row_set.row_desc.get(column - 1).col_type.nullable
72  ? DatabaseMetaData.columnNullable
73  : DatabaseMetaData.columnNoNulls;
74  }
75 
76  @Override
77  public boolean isSigned(int column)
78  throws SQLException { // logger.debug("Entered "+ sql );
79  return true;
80  }
81 
82  @Override
83  public int getColumnDisplaySize(int column)
84  throws SQLException { // logger.debug("Entered "+ sql );
85  return 100;
86  }
87 
88  @Override
89  public String getColumnLabel(int column)
90  throws SQLException { // logger.debug("Entered "+ sql );
91  // logger.debug("ColumnLabel is "+ sqlResult.row_set.row_desc.get(column
92  // -1).col_name);
93  return sqlResult.row_set.row_desc.get(column - 1).col_name;
94  }
95 
96  @Override
97  public String getColumnName(int column)
98  throws SQLException { // logger.debug("Entered "+ sql );
99  return sqlResult.row_set.row_desc.get(column - 1).getCol_name();
100  }
101 
102  @Override
103  public String getSchemaName(int column)
104  throws SQLException { // logger.debug("Entered "+ sql );
105  return null;
106  }
107 
108  @Override
109  public int getPrecision(int column)
110  throws SQLException { // logger.debug("Entered "+ sql );
111  return sqlResult.row_set.row_desc.get(column - 1).col_type.precision;
112  }
113 
114  @Override
115  public int getScale(int column) throws SQLException { // logger.debug("Entered "+ sql );
116  return sqlResult.row_set.row_desc.get(column - 1).col_type.scale;
117  }
118 
119  @Override
120  public String getTableName(int column)
121  throws SQLException { // logger.debug("Entered "+ sql );
122  return "tableName??";
123  }
124 
125  @Override
126  public String getCatalogName(int column)
127  throws SQLException { // logger.debug("Entered "+ sql );
128  return null;
129  }
130 
131  @Override
132  public int getColumnType(int column)
133  throws SQLException { // logger.debug("Entered "+ sql );
134  TDatumType type = sqlResult.row_set.row_desc.get(column - 1).col_type.type;
135 
136  return HeavyAIType.toJava(type);
137  }
138 
139  @Override
140  public String getColumnTypeName(int column)
141  throws SQLException { // logger.debug("Entered "+ sql );
142  return sqlResult.row_set.row_desc.get(column - 1).col_type.type.name();
143  }
144 
145  @Override
146  public boolean isReadOnly(int column)
147  throws SQLException { // logger.debug("Entered "+ sql );
148  return true;
149  }
150 
151  @Override
152  public boolean isWritable(int column)
153  throws SQLException { // logger.debug("Entered "+ sql );
154  return false;
155  }
156 
157  @Override
158  public boolean isDefinitelyWritable(int column)
159  throws SQLException { // logger.debug("Entered "+ sql );
160  return false;
161  }
162 
163  @Override
164  public String getColumnClassName(int column)
165  throws SQLException { // logger.debug("Entered "+ sql );
166  throw new UnsupportedOperationException("Not supported yet,"
167  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
168  + " class:" + new Throwable().getStackTrace()[0].getClassName()
169  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
170  }
171 
172  @Override
173  public <T> T unwrap(Class<T> iface)
174  throws SQLException { // logger.debug("Entered "+ sql );
175  throw new UnsupportedOperationException("Not supported yet,"
176  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
177  + " class:" + new Throwable().getStackTrace()[0].getClassName()
178  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
179  }
180 
181  @Override
182  public boolean isWrapperFor(Class<?> iface)
183  throws SQLException { // logger.debug("Entered "+ sql );
184  throw new UnsupportedOperationException("Not supported yet,"
185  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
186  + " class:" + new Throwable().getStackTrace()[0].getClassName()
187  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
188  }
189 }
static int toJava(TDatumType type)
HeavyAIResultSetMetaData(TQueryResult sqlResult, String sql)