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