OmniSciDB  4201147b46
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HeavyAIType.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 
17 package ai.heavy.jdbc;
18 
19 import java.sql.DatabaseMetaData;
20 
21 import ai.heavy.thrift.server.TDatumType;
22 
23 class HeavyAIType {
24  protected String typeName; // String => Type name
25  protected int dataType; // int => SQL data type from java.sql.Types
26  protected int precision; // int => maximum precision
27  protected String
28  literalPrefix; // String => prefix used to quote a literal (may be null)
29  protected String
30  literalSuffix; // String => suffix used to quote a literal (may be null)
31  protected String
32  createParams; // String => parameters used in creating the type (may be null)
33  protected short nullable; // short => can you use NULL for this type.
34  // typeNoNulls - does not allow NULL values
35  // typeNullable - allows NULL values
36  // typeNullableUnknown - nullability unknown
37  protected boolean caseSensitive; // boolean=> is it case sensitive.
38  protected short searchable; // short => can you use "WHERE" based on this type:
39  // typePredNone - No support
40  // typePredChar - Only supported with WHERE .. LIKE
41  // typePredBasic - Supported except for WHERE .. LIKE
42  // typeSearchable - Supported for all WHERE ..
43  protected boolean unsignedAttribute; // boolean => is it unsigned.
44  protected boolean fixedPrecScale; // boolean => can it be a money value.
45  protected boolean
46  autoIncrement; // boolean => can it be used for an auto-increment value.
47  protected String
48  localTypeName; // String => localized version of type name (may be null)
49  protected short minimumScale; // short => minimum scale supported
50  protected short maximumScale; // short => maximum scale supported
51  protected int SqlDataType; // int => unused
52  protected int SqlDatetimeSub; // int => unused
53  protected int numPrecRadix; // int => usually 2 or 10
54 
55  void HeavyAIType(String tn, int dt) {
56  typeName = tn;
57  dataType = dt;
58  precision = 10;
59  literalPrefix = null;
60  literalSuffix = null;
61  createParams = null;
62  nullable = DatabaseMetaData.typeNullable;
63  caseSensitive = true;
64  searchable = DatabaseMetaData.typeSearchable;
65  unsignedAttribute = false;
66  fixedPrecScale = false;
67  autoIncrement = false;
68  localTypeName = tn;
69  minimumScale = 1;
70  maximumScale = 20;
71  SqlDataType = 0;
72  SqlDatetimeSub = 0;
73  numPrecRadix = 10;
74  }
75 
76  static int toJava(TDatumType type) {
77  switch (type) {
78  case TINYINT:
79  return java.sql.Types.TINYINT;
80  case SMALLINT:
81  return java.sql.Types.SMALLINT;
82  case INT:
83  return java.sql.Types.INTEGER;
84  case BIGINT:
85  return java.sql.Types.BIGINT;
86  case FLOAT:
87  return java.sql.Types.FLOAT;
88  case DECIMAL:
89  return java.sql.Types.DECIMAL;
90  case DOUBLE:
91  return java.sql.Types.DOUBLE;
92  case STR:
93  return java.sql.Types.VARCHAR;
94  case TIME:
95  return java.sql.Types.TIME;
96  case TIMESTAMP:
97  return java.sql.Types.TIMESTAMP;
98  case DATE:
99  return java.sql.Types.DATE;
100  case BOOL:
101  return java.sql.Types.BOOLEAN;
102  case POINT:
103  case POLYGON:
104  case MULTIPOLYGON:
105  case LINESTRING:
106  return java.sql.Types.OTHER;
107  default:
108  throw new AssertionError(type.name());
109  }
110  }
111 }
static int toJava(TDatumType type)
void HeavyAIType(String tn, int dt)