Java Code Examples for java.sql.Types#ARRAY
The following examples show how to use
java.sql.Types#ARRAY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcTypeUtil.java From flink with Apache License 2.0 | 5 votes |
public static int typeInformationToSqlType(TypeInformation<?> type) { if (TYPE_MAPPING.containsKey(type)) { return TYPE_MAPPING.get(type); } else if (type instanceof ObjectArrayTypeInfo || type instanceof PrimitiveArrayTypeInfo) { return Types.ARRAY; } else { throw new IllegalArgumentException("Unsupported type: " + type); } }
Example 2
Source File: TypesTranslator.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
/** * This does not return null * @throws com.foundationdb.server.error.UnsupportedColumnDataTypeException if an appropriate TClass can't be found * @throws com.foundationdb.server.error.UnsupportedDataTypeException if an appropriate TClass can't be found */ public TClass typeClassForJDBCType(int jdbcType, String schemaName, String tableName, String columnName) { switch (jdbcType) { case Types.BLOB: return AkBlob.INSTANCE; case Types.BOOLEAN: return AkBool.INSTANCE; case Types.ARRAY: case Types.DATALINK: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.NULL: case Types.OTHER: case Types.REF: case Types.ROWID: case Types.STRUCT: default: if (columnName != null) { throw new UnsupportedColumnDataTypeException(schemaName, tableName, columnName, jdbcTypeName(jdbcType)); } else { throw new UnsupportedDataTypeException(jdbcTypeName(jdbcType)); } } }
Example 3
Source File: PgServer.java From Lealone-Plugins with Apache License 2.0 | 5 votes |
/** * Convert the SQL type to a PostgreSQL type * * @param type the SQL type * @return the PostgreSQL type */ public static int convertType(final int type) { switch (type) { case Types.BOOLEAN: return PG_TYPE_BOOL; case Types.VARCHAR: return PG_TYPE_VARCHAR; case Types.CLOB: return PG_TYPE_TEXT; case Types.CHAR: return PG_TYPE_BPCHAR; case Types.SMALLINT: return PG_TYPE_INT2; case Types.INTEGER: return PG_TYPE_INT4; case Types.BIGINT: return PG_TYPE_INT8; case Types.DECIMAL: return PG_TYPE_NUMERIC; case Types.REAL: return PG_TYPE_FLOAT4; case Types.DOUBLE: return PG_TYPE_FLOAT8; case Types.TIME: return PG_TYPE_TIME; case Types.DATE: return PG_TYPE_DATE; case Types.TIMESTAMP: return PG_TYPE_TIMESTAMP_NO_TMZONE; case Types.VARBINARY: return PG_TYPE_BYTEA; case Types.BLOB: return PG_TYPE_OID; case Types.ARRAY: return PG_TYPE_TEXTARRAY; default: return PG_TYPE_UNKNOWN; } }
Example 4
Source File: ArgumentTypePreparedStatementSetter.java From java-technology-stack with MIT License | 5 votes |
@Override public void setValues(PreparedStatement ps) throws SQLException { int parameterPosition = 1; if (this.args != null && this.argTypes != null) { for (int i = 0; i < this.args.length; i++) { Object arg = this.args[i]; if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) { Collection<?> entries = (Collection<?>) arg; for (Object entry : entries) { if (entry instanceof Object[]) { Object[] valueArray = ((Object[]) entry); for (Object argValue : valueArray) { doSetValue(ps, parameterPosition, this.argTypes[i], argValue); parameterPosition++; } } else { doSetValue(ps, parameterPosition, this.argTypes[i], entry); parameterPosition++; } } } else { doSetValue(ps, parameterPosition, this.argTypes[i], arg); parameterPosition++; } } } }
Example 5
Source File: Heading.java From sql4es with Apache License 2.0 | 5 votes |
public static int getTypeIdForObject(Object c) { if (c instanceof Long) return Types.BIGINT; if (c instanceof Boolean) return Types.BOOLEAN; if (c instanceof Character) return Types.CHAR; if (c instanceof Timestamp) return Types.TIMESTAMP; if (c instanceof java.sql.Date) return Types.DATE; if (c instanceof java.util.Date) return Types.DATE; if (c instanceof Double) return Types.DOUBLE; if (c instanceof Integer) return Types.INTEGER; if (c instanceof BigDecimal) return Types.NUMERIC; if (c instanceof Short) return Types.SMALLINT; if (c instanceof Float) return Types.FLOAT; if (c instanceof String) return Types.VARCHAR; if (c instanceof Time) return Types.TIME; if (c instanceof Byte) return Types.TINYINT; if (c instanceof Byte[]) return Types.VARBINARY; if(c instanceof Object[]) return Types.JAVA_OBJECT; if(c instanceof Object) return Types.JAVA_OBJECT; if (c instanceof Array) return Types.ARRAY; else return Types.OTHER; }
Example 6
Source File: DataViewUtils.java From netbeans with Apache License 2.0 | 5 votes |
public static boolean isPrecisionRequired(int jdbcType) { switch (jdbcType) { case Types.BIGINT: case Types.BOOLEAN: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: case Types.FLOAT: case Types.REAL: case Types.DOUBLE: case Types.DATE: case Types.TIMESTAMP: case Types.JAVA_OBJECT: case Types.LONGVARCHAR: case Types.LONGVARBINARY: case Types.BLOB: case Types.CLOB: case Types.ARRAY: case Types.STRUCT: case Types.DISTINCT: case Types.REF: case Types.DATALINK: return false; default: return true; } }
Example 7
Source File: DBTypeSelector.java From evosql with Apache License 2.0 | 4 votes |
/** * Instantiates an instance of an appropriate DBType subclass. * * @param dataType The Java SQL type. * @param length The length of the type. Does not apply to all types. * @return An instance of an appropriate DBType subclass. */ public DBType create(int dataType, int length) { switch (dataType) { // Floating-point numbers case Types.DOUBLE: return new DBDouble(); case Types.REAL: return new DBDouble("REAL"); case Types.DECIMAL: return new DBDouble("DECIMAL"); // Integer numbers case Types.INTEGER: return new DBInteger(); case Types.SMALLINT: return new DBInteger("SMALLINT"); case Types.TINYINT: return new DBInteger("TINYINT"); // HSQLDB doesn't support tinyint case Types.BIGINT: return new DBInteger(); // we don't need bigint in our evaluations // Strings case Types.VARCHAR: return new DBString(length); case Types.NVARCHAR: return new DBString(length, "NVARCHAR"); case Types.LONGVARCHAR: return new DBString(EvoSQLConfiguration.MAX_STRING_LENGTH, "LONGVARCHAR"); case Types.LONGNVARCHAR: return new DBString(EvoSQLConfiguration.MAX_STRING_LENGTH, "LONGNVARCHAR"); case Types.CHAR: return new DBString(length, "CHAR(" + length + ")"); case Types.NCHAR: return new DBString(length, "NCHAR"); // Boolean values case Types.BIT: return new DBBoolean("BIT"); // HSQLDB doesn't support bit case Types.BOOLEAN: return new DBBoolean("BOOLEAN"); // Dates and times case Types.DATE: return new DBDate(); case Types.TIME: return new DBTime(); case Types.TIMESTAMP: return new DBDateTime("TIMESTAMP"); case Types.NUMERIC: return new DBDouble("NUMERIC(18, 6)"); //FIXME: hotfix for erpnext schema // Other types case Types.ARRAY: throw new UnsupportedOperationException("The ARRAY data type is currently not supported by EvoSQL."); default: throw new UnsupportedOperationException("This database type is not currently supported: " + dataType); } }
Example 8
Source File: PIntegerArray.java From phoenix with Apache License 2.0 | 4 votes |
@Override public int getResultSetSqlType() { return Types.ARRAY; }
Example 9
Source File: AvaticaSite.java From calcite-avatica with Apache License 2.0 | 4 votes |
/** Similar logic to {@link #setObject}. */ public static Object get(Cursor.Accessor accessor, int targetSqlType, Calendar localCalendar) throws SQLException { switch (targetSqlType) { case Types.CLOB: case Types.DATALINK: case Types.NCLOB: case Types.REF: case Types.SQLXML: throw notImplemented(); case Types.STRUCT: return accessor.getStruct(); case Types.ARRAY: return accessor.getArray(); case Types.BIGINT: final long aLong = accessor.getLong(); if (aLong == 0 && accessor.wasNull()) { return null; } return aLong; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: return accessor.getBytes(); case Types.BIT: case Types.BOOLEAN: final boolean aBoolean = accessor.getBoolean(); if (!aBoolean && accessor.wasNull()) { return null; } return aBoolean; case Types.BLOB: return accessor.getBlob(); case Types.DATE: return accessor.getDate(localCalendar); case Types.DECIMAL: case Types.NUMERIC: return accessor.getBigDecimal(); case Types.DISTINCT: throw notImplemented(); case Types.DOUBLE: case Types.FLOAT: // yes really; SQL FLOAT is up to 8 bytes final double aDouble = accessor.getDouble(); if (aDouble == 0 && accessor.wasNull()) { return null; } return aDouble; case Types.INTEGER: final int anInt = accessor.getInt(); if (anInt == 0 && accessor.wasNull()) { return null; } return anInt; case Types.JAVA_OBJECT: case Types.OTHER: return accessor.getObject(); case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.VARCHAR: case Types.CHAR: case Types.NCHAR: return accessor.getString(); case Types.REAL: final float aFloat = accessor.getFloat(); if (aFloat == 0 && accessor.wasNull()) { return null; } return aFloat; case Types.ROWID: throw notImplemented(); case Types.SMALLINT: final short aShort = accessor.getShort(); if (aShort == 0 && accessor.wasNull()) { return null; } return aShort; case Types.TIME: return accessor.getTime(localCalendar); case Types.TIMESTAMP: return accessor.getTimestamp(localCalendar); case Types.TINYINT: final byte aByte = accessor.getByte(); if (aByte == 0 && accessor.wasNull()) { return null; } return aByte; default: throw notImplemented(); } }
Example 10
Source File: SqlTypeToClass.java From DataDefender with Apache License 2.0 | 4 votes |
public Class getTypeFrom(int type) { switch (type) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: return String.class; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return Byte[].class; case Types.NUMERIC: case Types.DECIMAL: return BigDecimal.class; case Types.BIT: return Boolean.class; case Types.TINYINT: case Types.SMALLINT: return Short.class; case Types.INTEGER: return Integer.class; case Types.BIGINT: return Long.class; case Types.REAL: return Float.class; case Types.FLOAT: case Types.DOUBLE: return Double.class; case Types.DATE: return Date.class; case Types.TIME: return Time.class; case Types.TIMESTAMP: return Timestamp.class; case Types.BLOB: return Blob.class; case Types.CLOB: return Clob.class; case Types.ARRAY: return Array.class; case Types.NULL: return null; default: throw new IllegalArgumentException("Unsupported or unknown type"); } }
Example 11
Source File: QuicksqlServerResultSet.java From Quicksql with MIT License | 4 votes |
private static Object getValue(ResultSet resultSet, int type, int j, Calendar calendar) throws SQLException { switch (type) { case Types.BIGINT: final long aLong = resultSet.getLong(j + 1); return aLong == 0 && resultSet.wasNull() ? null : aLong; case Types.INTEGER: final int anInt = resultSet.getInt(j + 1); return anInt == 0 && resultSet.wasNull() ? null : anInt; case Types.SMALLINT: final short aShort = resultSet.getShort(j + 1); return aShort == 0 && resultSet.wasNull() ? null : aShort; case Types.TINYINT: final byte aByte = resultSet.getByte(j + 1); return aByte == 0 && resultSet.wasNull() ? null : aByte; case Types.DOUBLE: case Types.FLOAT: final double aDouble = resultSet.getDouble(j + 1); return aDouble == 0D && resultSet.wasNull() ? null : aDouble; case Types.REAL: final float aFloat = resultSet.getFloat(j + 1); return aFloat == 0D && resultSet.wasNull() ? null : aFloat; case Types.DATE: final Date aDate = resultSet.getDate(j + 1, calendar); return aDate == null ? null : (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY); case Types.TIME: final Time aTime = resultSet.getTime(j + 1, calendar); return aTime == null ? null : (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY); case Types.TIMESTAMP: final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar); return aTimestamp == null ? null : aTimestamp.getTime(); case Types.ARRAY: final Array array = resultSet.getArray(j + 1); if (null == array) { return null; } try { // Recursively extracts an Array using its ResultSet-representation return extractUsingResultSet(array, calendar); } catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) { // Not every database might implement Array.getResultSet(). This call // assumes a non-nested array (depends on the db if that's a valid assumption) return extractUsingArray(array, calendar); } case Types.STRUCT: Struct struct = resultSet.getObject(j + 1, Struct.class); Object[] attrs = struct.getAttributes(); List<Object> list = new ArrayList<>(attrs.length); for (Object o : attrs) { list.add(o); } return list; default: return resultSet.getObject(j + 1); } }
Example 12
Source File: Converters.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Get {@link GFXDType} for given JDBC {@link Types}. */ public static GFXDType getThriftSQLType(int jdbcType) { switch (jdbcType) { case Types.ARRAY: return GFXDType.ARRAY; case Types.BIGINT: return GFXDType.BIGINT; case Types.BINARY: return GFXDType.BINARY; case Types.BIT: return GFXDType.BOOLEAN; case Types.BLOB: return GFXDType.BLOB; case Types.BOOLEAN: return GFXDType.BOOLEAN; case Types.CHAR: return GFXDType.CHAR; case Types.CLOB: return GFXDType.CLOB; case Types.DATALINK: return GFXDType.DATALINK; case Types.DATE: return GFXDType.DATE; case Types.DECIMAL: return GFXDType.DECIMAL; case Types.DISTINCT: return GFXDType.DISTINCT; case Types.DOUBLE: return GFXDType.DOUBLE; case Types.FLOAT: return GFXDType.FLOAT; case Types.INTEGER: return GFXDType.INTEGER; case Types.JAVA_OBJECT: return GFXDType.JAVA_OBJECT; case TYPE_JSON_OBJECT: return GFXDType.JSON_OBJECT; case Types.LONGNVARCHAR: return GFXDType.LONGNVARCHAR; case Types.LONGVARBINARY: return GFXDType.LONGVARBINARY; case Types.LONGVARCHAR: return GFXDType.LONGVARCHAR; case Types.NCHAR: return GFXDType.NCHAR; case Types.NCLOB: return GFXDType.NCLOB; case Types.NULL: return GFXDType.NULLTYPE; case Types.NUMERIC: return GFXDType.DECIMAL; case Types.NVARCHAR: return GFXDType.NVARCHAR; case Types.OTHER: return GFXDType.OTHER; case TYPE_PDX_OBJECT: return GFXDType.PDX_OBJECT; case Types.REAL: return GFXDType.REAL; case Types.REF: return GFXDType.REF; case Types.ROWID: return GFXDType.ROWID; case Types.SMALLINT: return GFXDType.SMALLINT; case Types.SQLXML: return GFXDType.SQLXML; case Types.STRUCT: return GFXDType.STRUCT; case Types.TIME: return GFXDType.TIME; case Types.TIMESTAMP: return GFXDType.TIMESTAMP; case Types.TINYINT: return GFXDType.TINYINT; case Types.VARBINARY: return GFXDType.VARBINARY; case Types.VARCHAR: return GFXDType.VARCHAR; default: return GFXDType.OTHER; } }
Example 13
Source File: PVarcharArray.java From phoenix with Apache License 2.0 | 4 votes |
@Override public int getResultSetSqlType() { return Types.ARRAY; }
Example 14
Source File: Converters.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Get {@link GFXDType} for given JDBC {@link Types}. */ public static GFXDType getThriftSQLType(int jdbcType) { switch (jdbcType) { case Types.ARRAY: return GFXDType.ARRAY; case Types.BIGINT: return GFXDType.BIGINT; case Types.BINARY: return GFXDType.BINARY; case Types.BIT: return GFXDType.BOOLEAN; case Types.BLOB: return GFXDType.BLOB; case Types.BOOLEAN: return GFXDType.BOOLEAN; case Types.CHAR: return GFXDType.CHAR; case Types.CLOB: return GFXDType.CLOB; case Types.DATALINK: return GFXDType.DATALINK; case Types.DATE: return GFXDType.DATE; case Types.DECIMAL: return GFXDType.DECIMAL; case Types.DISTINCT: return GFXDType.DISTINCT; case Types.DOUBLE: return GFXDType.DOUBLE; case Types.FLOAT: return GFXDType.FLOAT; case Types.INTEGER: return GFXDType.INTEGER; case Types.JAVA_OBJECT: return GFXDType.JAVA_OBJECT; case TYPE_JSON_OBJECT: return GFXDType.JSON_OBJECT; case Types.LONGNVARCHAR: return GFXDType.LONGNVARCHAR; case Types.LONGVARBINARY: return GFXDType.LONGVARBINARY; case Types.LONGVARCHAR: return GFXDType.LONGVARCHAR; case Types.NCHAR: return GFXDType.NCHAR; case Types.NCLOB: return GFXDType.NCLOB; case Types.NULL: return GFXDType.NULLTYPE; case Types.NUMERIC: return GFXDType.DECIMAL; case Types.NVARCHAR: return GFXDType.NVARCHAR; case Types.OTHER: return GFXDType.OTHER; case TYPE_PDX_OBJECT: return GFXDType.PDX_OBJECT; case Types.REAL: return GFXDType.REAL; case Types.REF: return GFXDType.REF; case Types.ROWID: return GFXDType.ROWID; case Types.SMALLINT: return GFXDType.SMALLINT; case Types.SQLXML: return GFXDType.SQLXML; case Types.STRUCT: return GFXDType.STRUCT; case Types.TIME: return GFXDType.TIME; case Types.TIMESTAMP: return GFXDType.TIMESTAMP; case Types.TINYINT: return GFXDType.TINYINT; case Types.VARBINARY: return GFXDType.VARBINARY; case Types.VARCHAR: return GFXDType.VARCHAR; default: return GFXDType.OTHER; } }
Example 15
Source File: SQLTableModel.java From nordpos with GNU General Public License v3.0 | 4 votes |
/** Creates a new instance of SQLTableModel */ public SQLTableModel(DataField[] df) { m_aRows = new ArrayList(); m_df = df; m_classes = new Datas[df.length]; for (int i = 0; i < df.length; i++) { switch (df[i].Type) { case Types.INTEGER: case Types.BIGINT: case Types.SMALLINT: case Types.TINYINT: m_classes[i] = Datas.INT; break; case Types.BIT: case Types.BOOLEAN: m_classes[i] = Datas.BOOLEAN; break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: m_classes[i] = Datas.DOUBLE; break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: m_classes[i] = Datas.STRING; break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: m_classes[i] = Datas.TIMESTAMP; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: m_classes[i] = Datas.BYTES; break; case Types.ARRAY: case Types.DATALINK: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.NULL: case Types.OTHER: case Types.REF: case Types.STRUCT: default: m_classes[i] = Datas.OBJECT; break; } } }
Example 16
Source File: PBooleanArray.java From phoenix with Apache License 2.0 | 4 votes |
@Override public int getResultSetSqlType() { return Types.ARRAY; }
Example 17
Source File: AvaticaSite.java From calcite-avatica with Apache License 2.0 | 4 votes |
public void setObject(Object x, int targetSqlType) { if (x == null || Types.NULL == targetSqlType) { setNull(targetSqlType); return; } switch (targetSqlType) { case Types.CLOB: case Types.DATALINK: case Types.NCLOB: case Types.OTHER: case Types.REF: case Types.SQLXML: case Types.STRUCT: throw notImplemented(); case Types.ARRAY: setArray(toArray(x)); break; case Types.BIGINT: setLong(toLong(x)); break; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: setBytes(toBytes(x)); break; case Types.BIT: case Types.BOOLEAN: setBoolean(toBoolean(x)); break; case Types.BLOB: if (x instanceof Blob) { setBlob((Blob) x); break; } else if (x instanceof InputStream) { setBlob((InputStream) x); } throw unsupportedCast(x.getClass(), Blob.class); case Types.DATE: setDate(toDate(x), calendar); break; case Types.DECIMAL: case Types.NUMERIC: setBigDecimal(toBigDecimal(x)); break; case Types.DISTINCT: throw notImplemented(); case Types.DOUBLE: case Types.FLOAT: // yes really; SQL FLOAT is up to 8 bytes setDouble(toDouble(x)); break; case Types.INTEGER: setInt(toInt(x)); break; case Types.JAVA_OBJECT: setObject(x); break; case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.VARCHAR: case Types.CHAR: case Types.NCHAR: setString(toString(x)); break; case Types.REAL: setFloat(toFloat(x)); break; case Types.ROWID: if (x instanceof RowId) { setRowId((RowId) x); break; } throw unsupportedCast(x.getClass(), RowId.class); case Types.SMALLINT: setShort(toShort(x)); break; case Types.TIME: setTime(toTime(x), calendar); break; case Types.TIMESTAMP: setTimestamp(toTimestamp(x), calendar); break; case Types.TINYINT: setByte(toByte(x)); break; default: throw notImplemented(); } }
Example 18
Source File: ColumnInfo.java From presto with Apache License 2.0 | 4 votes |
private static int getType(ClientTypeSignature type) { switch (type.getRawType()) { case "array": return Types.ARRAY; case "boolean": return Types.BOOLEAN; case "bigint": return Types.BIGINT; case "integer": return Types.INTEGER; case "smallint": return Types.SMALLINT; case "tinyint": return Types.TINYINT; case "real": return Types.REAL; case "double": return Types.DOUBLE; case "varchar": return Types.VARCHAR; case "char": return Types.CHAR; case "varbinary": return Types.VARBINARY; case "time": return Types.TIME; case "time with time zone": return Types.TIME; case "timestamp": return Types.TIMESTAMP; case "timestamp with time zone": return Types.TIMESTAMP; case "date": return Types.DATE; case "decimal": return Types.DECIMAL; case "unknown": return Types.NULL; default: return Types.JAVA_OBJECT; } }
Example 19
Source File: JdbcTypeHelper.java From SimpleFlatMapper with MIT License | 4 votes |
public static Class<?> toJavaType(int sqlType, Type propertyType) { switch (sqlType) { case Types.ARRAY: return Array.class; case Types.CHAR: case Types.VARCHAR: case Types.LONGNVARCHAR: return String.class; case Types.NUMERIC: case Types.DECIMAL: return BigDecimal.class; case Types.BIT: return boolean.class; case Types.TINYINT: return byte.class; case Types.SMALLINT: return short.class; case Types.INTEGER: return int.class; case Types.BIGINT: return long.class; case Types.REAL: return float.class; case Types.FLOAT: case Types.DOUBLE: return double.class; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return byte[].class; case Types.DATE: return Date.class; case Types.TIME: return Time.class; case Types.TIMESTAMP: return Timestamp.class; case Types.CLOB: return Clob.class; case Types.BLOB: return Blob.class; case Types.STRUCT: return Struct.class; case Types.REF: return Ref.class; //IFJAVA8_START case Types.TIME_WITH_TIMEZONE: return OffsetTime.class; case Types.TIMESTAMP_WITH_TIMEZONE: return OffsetDateTime.class; //IFJAVA8_END } Class<?> defaultSqlType = javaTypeToSqlType.get(TypeHelper.toClass(propertyType).getName()); if (defaultSqlType != null) { return defaultSqlType; } return Object.class; }
Example 20
Source File: PostgreSqlClient.java From presto with Apache License 2.0 | 4 votes |
@Override public Optional<ColumnMapping> toPrestoType(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle) { String jdbcTypeName = typeHandle.getJdbcTypeName() .orElseThrow(() -> new PrestoException(JDBC_ERROR, "Type name is missing: " + typeHandle)); Optional<ColumnMapping> mapping = getForcedMappingToVarchar(typeHandle); if (mapping.isPresent()) { return mapping; } switch (jdbcTypeName) { case "money": return Optional.of(moneyColumnMapping()); case "uuid": return Optional.of(uuidColumnMapping()); case "jsonb": case "json": return Optional.of(jsonColumnMapping()); case "timestamptz": // PostgreSQL's "timestamp with time zone" is reported as Types.TIMESTAMP rather than Types.TIMESTAMP_WITH_TIMEZONE return Optional.of(timestampWithTimeZoneColumnMapping()); case "hstore": return Optional.of(hstoreColumnMapping(session)); } if (typeHandle.getJdbcType() == Types.VARCHAR && !jdbcTypeName.equals("varchar")) { // This can be e.g. an ENUM return Optional.of(typedVarcharColumnMapping(jdbcTypeName)); } if (typeHandle.getJdbcType() == Types.TIME) { return Optional.of(timeColumnMapping(session)); } if (typeHandle.getJdbcType() == Types.TIMESTAMP) { return Optional.of(ColumnMapping.longMapping( TIMESTAMP, timestampReadFunction(session), timestampWriteFunction(session))); } if (typeHandle.getJdbcType() == Types.NUMERIC && getDecimalRounding(session) == ALLOW_OVERFLOW) { if (typeHandle.getColumnSize() == 131089) { // decimal type with unspecified scale - up to 131072 digits before the decimal point; up to 16383 digits after the decimal point) // 131089 = SELECT LENGTH(pow(10::numeric,131071)::varchar); 131071 = 2^17-1 (org.postgresql.jdbc.TypeInfoCache#getDisplaySize) return Optional.of(decimalColumnMapping(createDecimalType(Decimals.MAX_PRECISION, getDecimalDefaultScale(session)), getDecimalRoundingMode(session))); } int precision = typeHandle.getColumnSize(); if (precision > Decimals.MAX_PRECISION) { int scale = min(typeHandle.getDecimalDigits(), getDecimalDefaultScale(session)); return Optional.of(decimalColumnMapping(createDecimalType(Decimals.MAX_PRECISION, scale), getDecimalRoundingMode(session))); } } if (typeHandle.getJdbcType() == Types.ARRAY) { ArrayMapping arrayMapping = getArrayMapping(session); if (arrayMapping == DISABLED) { return Optional.empty(); } // resolve and map base array element type JdbcTypeHandle baseElementTypeHandle = getArrayElementTypeHandle(connection, typeHandle); String baseElementTypeName = baseElementTypeHandle.getJdbcTypeName() .orElseThrow(() -> new PrestoException(JDBC_ERROR, "Element type name is missing: " + baseElementTypeHandle)); if (baseElementTypeHandle.getJdbcType() == Types.VARBINARY) { // PostgreSQL jdbc driver doesn't currently support array of varbinary (bytea[]) // https://github.com/pgjdbc/pgjdbc/pull/1184 return Optional.empty(); } Optional<ColumnMapping> baseElementMapping = toPrestoType(session, connection, baseElementTypeHandle); if (arrayMapping == AS_ARRAY) { if (typeHandle.getArrayDimensions().isEmpty()) { return Optional.empty(); } return baseElementMapping .map(elementMapping -> { ArrayType prestoArrayType = new ArrayType(elementMapping.getType()); ColumnMapping arrayColumnMapping = arrayColumnMapping(session, prestoArrayType, elementMapping, baseElementTypeName); int arrayDimensions = typeHandle.getArrayDimensions().get(); for (int i = 1; i < arrayDimensions; i++) { prestoArrayType = new ArrayType(prestoArrayType); arrayColumnMapping = arrayColumnMapping(session, prestoArrayType, arrayColumnMapping, baseElementTypeName); } return arrayColumnMapping; }); } if (arrayMapping == AS_JSON) { return baseElementMapping .map(elementMapping -> arrayAsJsonColumnMapping(session, elementMapping)); } throw new IllegalStateException("Unsupported array mapping type: " + arrayMapping); } // TODO support PostgreSQL's TIME WITH TIME ZONE explicitly, otherwise predicate pushdown for these types may be incorrect return super.toPrestoType(session, connection, typeHandle); }