OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OmniSciResultSetMetaData.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 com.omnisci.jdbc;
17 
18 import com.mapd.thrift.server.TDatumType;
19 import com.mapd.thrift.server.TQueryResult;
20 
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 
24 import java.sql.DatabaseMetaData;
25 import java.sql.ResultSetMetaData;
26 import java.sql.SQLException;
27 
32 class OmniSciResultSetMetaData implements ResultSetMetaData {
33  final static Logger logger = LoggerFactory.getLogger(OmniSciResultSetMetaData.class);
34  final TQueryResult sqlResult;
35  final String sql;
36 
37  public OmniSciResultSetMetaData(TQueryResult sqlResult, String sql) {
38  this.sqlResult = sqlResult;
39  this.sql = sql;
40  }
41 
42  @Override
43  public int getColumnCount() throws SQLException { // logger.debug("Entered "+ sql );
44  return sqlResult.row_set.row_desc.size();
45  }
46 
47  @Override
48  public boolean isAutoIncrement(int column)
49  throws SQLException { // logger.debug("Entered "+ sql );
50  // logger.debug("returning false");
51  return false;
52  }
53 
54  @Override
55  public boolean isCaseSensitive(int column)
56  throws SQLException { // logger.debug("Entered "+ sql );
57  return true;
58  }
59 
60  @Override
61  public boolean isSearchable(int column)
62  throws SQLException { // logger.debug("Entered "+ sql );
63  return false;
64  }
65 
66  @Override
67  public boolean isCurrency(int column)
68  throws SQLException { // logger.debug("Entered "+ sql );
69  return false;
70  }
71 
72  @Override
73  public int isNullable(int column)
74  throws SQLException { // logger.debug("Entered "+ sql );
75  return sqlResult.row_set.row_desc.get(column - 1).col_type.nullable
76  ? DatabaseMetaData.columnNullable
77  : DatabaseMetaData.columnNoNulls;
78  }
79 
80  @Override
81  public boolean isSigned(int column)
82  throws SQLException { // logger.debug("Entered "+ sql );
83  return true;
84  }
85 
86  @Override
87  public int getColumnDisplaySize(int column)
88  throws SQLException { // logger.debug("Entered "+ sql );
89  return 100;
90  }
91 
92  @Override
93  public String getColumnLabel(int column)
94  throws SQLException { // logger.debug("Entered "+ sql );
95  // logger.debug("ColumnLabel is "+ sqlResult.row_set.row_desc.get(column
96  // -1).col_name);
97  return sqlResult.row_set.row_desc.get(column - 1).col_name;
98  }
99 
100  @Override
101  public String getColumnName(int column)
102  throws SQLException { // logger.debug("Entered "+ sql );
103  return sqlResult.row_set.row_desc.get(column - 1).getCol_name();
104  }
105 
106  @Override
107  public String getSchemaName(int column)
108  throws SQLException { // logger.debug("Entered "+ sql );
109  return null;
110  }
111 
112  @Override
113  public int getPrecision(int column)
114  throws SQLException { // logger.debug("Entered "+ sql );
115  return sqlResult.row_set.row_desc.get(column - 1).col_type.precision;
116  }
117 
118  @Override
119  public int getScale(int column) throws SQLException { // logger.debug("Entered "+ sql );
120  return sqlResult.row_set.row_desc.get(column - 1).col_type.scale;
121  }
122 
123  @Override
124  public String getTableName(int column)
125  throws SQLException { // logger.debug("Entered "+ sql );
126  return "tableName??";
127  }
128 
129  @Override
130  public String getCatalogName(int column)
131  throws SQLException { // logger.debug("Entered "+ sql );
132  return null;
133  }
134 
135  @Override
136  public int getColumnType(int column)
137  throws SQLException { // logger.debug("Entered "+ sql );
138  TDatumType type = sqlResult.row_set.row_desc.get(column - 1).col_type.type;
139 
140  return OmniSciType.toJava(type);
141  }
142 
143  @Override
144  public String getColumnTypeName(int column)
145  throws SQLException { // logger.debug("Entered "+ sql );
146  return sqlResult.row_set.row_desc.get(column - 1).col_type.type.name();
147  }
148 
149  @Override
150  public boolean isReadOnly(int column)
151  throws SQLException { // logger.debug("Entered "+ sql );
152  return true;
153  }
154 
155  @Override
156  public boolean isWritable(int column)
157  throws SQLException { // logger.debug("Entered "+ sql );
158  return false;
159  }
160 
161  @Override
162  public boolean isDefinitelyWritable(int column)
163  throws SQLException { // logger.debug("Entered "+ sql );
164  return false;
165  }
166 
167  @Override
168  public String getColumnClassName(int column)
169  throws SQLException { // logger.debug("Entered "+ sql );
170  throw new UnsupportedOperationException("Not supported yet,"
171  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
172  + " class:" + new Throwable().getStackTrace()[0].getClassName()
173  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
174  }
175 
176  @Override
177  public <T> T unwrap(Class<T> iface)
178  throws SQLException { // logger.debug("Entered "+ sql );
179  throw new UnsupportedOperationException("Not supported yet,"
180  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
181  + " class:" + new Throwable().getStackTrace()[0].getClassName()
182  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
183  }
184 
185  @Override
186  public boolean isWrapperFor(Class<?> iface)
187  throws SQLException { // logger.debug("Entered "+ sql );
188  throw new UnsupportedOperationException("Not supported yet,"
189  + " line:" + new Throwable().getStackTrace()[0].getLineNumber()
190  + " class:" + new Throwable().getStackTrace()[0].getClassName()
191  + " method:" + new Throwable().getStackTrace()[0].getMethodName());
192  }
193 }
OmniSciResultSetMetaData(TQueryResult sqlResult, String sql)
static int toJava(TDatumType type)