Java Code Examples for java.sql.Types#NVARCHAR

The following examples show how to use java.sql.Types#NVARCHAR . 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: DB297Dialect.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
	// See HHH-12753
	// It seems that DB2's JDBC 4.0 support as of 9.5 does not support the N-variant methods like
	// NClob or NString.  Therefore here we overwrite the sql type descriptors to use the non-N variants
	// which are supported.
	switch ( sqlCode ) {
		case Types.NCHAR:
			return CharTypeDescriptor.INSTANCE;

		case Types.NCLOB:
			if ( useInputStreamToInsertBlob() ) {
				return ClobTypeDescriptor.STREAM_BINDING;
			}
			else {
				return ClobTypeDescriptor.CLOB_BINDING;
			}

		case Types.NVARCHAR:
			return VarcharTypeDescriptor.INSTANCE;

		default:
			return super.getSqlTypeDescriptorOverride( sqlCode );
	}
}
 
Example 2
Source File: DB2ColumnMetadataReader.java    From virtual-schemas with MIT License 6 votes vote down vote up
@Override
public DataType mapJdbcType(final JdbcTypeDescription jdbcTypeDescription) {
    final int size = jdbcTypeDescription.getPrecisionOrSize();
    switch (jdbcTypeDescription.getJdbcType()) {
    case Types.CLOB:
    case Types.OTHER:
        return DataType.createVarChar(DataType.MAX_EXASOL_VARCHAR_SIZE, DataType.ExaCharset.UTF8);
    case Types.TIMESTAMP:
        return DataType.createVarChar(32, DataType.ExaCharset.UTF8);
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.LONGVARCHAR:
    case Types.CHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
        return getLiteralDataType(size);
    case Types.BINARY:
        return DataType.createChar(size * 2, DataType.ExaCharset.ASCII);
    case Types.VARBINARY:
        return DataType.createVarChar(size * 2, DataType.ExaCharset.ASCII);
    default:
        return super.mapJdbcType(jdbcTypeDescription);
    }
}
 
Example 3
Source File: CloudSpannerResultSetMetaData.java    From spanner-jdbc with MIT License 6 votes vote down vote up
@Override
public int getColumnDisplaySize(int column) throws SQLException {
  int colType = getColumnType(column);
  switch (colType) {
    case Types.ARRAY:
      return 50;
    case Types.BOOLEAN:
      return 5;
    case Types.BINARY:
      return 50;
    case Types.DATE:
      return 10;
    case Types.DOUBLE:
      return 14;
    case Types.BIGINT:
      return 10;
    case Types.NVARCHAR:
      int length = getPrecision(column);
      return length == 0 ? 50 : length;
    case Types.TIMESTAMP:
      return 16;
    default:
      return 10;
  }
}
 
Example 4
Source File: DB2ColumnMetadataReaderTest.java    From virtual-schemas with MIT License 5 votes vote down vote up
@ValueSource(ints = { Types.VARCHAR, Types.NVARCHAR, Types.LONGNVARCHAR, Types.CHAR, Types.NCHAR,
        Types.LONGNVARCHAR })
@ParameterizedTest
void testMapJdbcVarcharSizeLesserThanExasolMaxVarcharSize(final int type) {
    final JdbcTypeDescription jdbcTypeDescription = new JdbcTypeDescription(type, 0, 10, 0, "");
    assertThat(this.db2ColumnMetadataReader.mapJdbcType(jdbcTypeDescription),
            equalTo(DataType.createVarChar(10, DataType.ExaCharset.UTF8)));
}
 
Example 5
Source File: DBTablePrinter.java    From salesforce-jdbc with MIT License 5 votes vote down vote up
/**
 * Takes a generic SQL type and returns the category this type
 * belongs to. Types are categorized according to print formatting
 * needs:
 * <p>
 * Integers should not be truncated so column widths should
 * be adjusted without a column width limit. Text columns should be
 * left justified and can be truncated to a max. column width etc...</p>
 * <p>
 * See also: <a target="_blank"
 * href="http://docs.oracle.com/javase/8/docs/api/java/sql/Types.html">
 * java.sql.Types</a>
 *
 * @param type Generic SQL type
 * @return The category this type belongs to
 */
private static int whichCategory(int type) {
    switch (type) {
        case Types.BIGINT:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return CATEGORY_INTEGER;

        case Types.REAL:
        case Types.DOUBLE:
        case Types.DECIMAL:
            return CATEGORY_DOUBLE;

        case Types.DATE:
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
            return CATEGORY_DATETIME;

        case Types.BOOLEAN:
            return CATEGORY_BOOLEAN;

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CHAR:
        case Types.NCHAR:
            return CATEGORY_STRING;

        default:
            return CATEGORY_OTHER;
    }
}
 
Example 6
Source File: RowSetMetaDataTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
    return new Object[][]{
        {Types.CHAR, "java.lang.String"},
        {Types.NCHAR, "java.lang.String"},
        {Types.VARCHAR, "java.lang.String"},
        {Types.NVARCHAR, "java.lang.String"},
        {Types.LONGVARCHAR, "java.lang.String"},
        {Types.LONGNVARCHAR, "java.lang.String"},
        {Types.NUMERIC, "java.math.BigDecimal"},
        {Types.DECIMAL, "java.math.BigDecimal"},
        {Types.BIT, "java.lang.Boolean"},
        {Types.TINYINT, "java.lang.Byte"},
        {Types.SMALLINT, "java.lang.Short"},
        {Types.INTEGER, "java.lang.Integer"},
        {Types.FLOAT, "java.lang.Double"},
        {Types.DOUBLE, "java.lang.Double"},
        {Types.BINARY, "byte[]"},
        {Types.VARBINARY, "byte[]"},
        {Types.LONGVARBINARY, "byte[]"},
        {Types.DATE, "java.sql.Date"},
        {Types.TIME, "java.sql.Time"},
        {Types.TIMESTAMP, "java.sql.Timestamp"},
        {Types.CLOB, "java.sql.Clob"},
        {Types.BLOB, "java.sql.Blob"}

    };

}
 
Example 7
Source File: ConnManager.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if a column is char or a char-variant type.
 * @return true if column type is CHAR, VARCHAR, LONGVARCHAR
 * or their N version. These are used to store strings.
 */
public boolean isCharColumn(int columnType) {
  return (columnType == Types.VARCHAR)
      || (columnType == Types.NVARCHAR)
      || (columnType == Types.CHAR)
      || (columnType == Types.NCHAR)
      || (columnType == Types.LONGVARCHAR)
      || (columnType == Types.LONGNVARCHAR);
}
 
Example 8
Source File: RowSetMetaDataTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
    return new Object[][]{
        {Types.CHAR, "java.lang.String"},
        {Types.NCHAR, "java.lang.String"},
        {Types.VARCHAR, "java.lang.String"},
        {Types.NVARCHAR, "java.lang.String"},
        {Types.LONGVARCHAR, "java.lang.String"},
        {Types.LONGNVARCHAR, "java.lang.String"},
        {Types.NUMERIC, "java.math.BigDecimal"},
        {Types.DECIMAL, "java.math.BigDecimal"},
        {Types.BIT, "java.lang.Boolean"},
        {Types.TINYINT, "java.lang.Byte"},
        {Types.SMALLINT, "java.lang.Short"},
        {Types.INTEGER, "java.lang.Integer"},
        {Types.FLOAT, "java.lang.Double"},
        {Types.DOUBLE, "java.lang.Double"},
        {Types.BINARY, "byte[]"},
        {Types.VARBINARY, "byte[]"},
        {Types.LONGVARBINARY, "byte[]"},
        {Types.DATE, "java.sql.Date"},
        {Types.TIME, "java.sql.Time"},
        {Types.TIMESTAMP, "java.sql.Timestamp"},
        {Types.CLOB, "java.sql.Clob"},
        {Types.BLOB, "java.sql.Blob"}

    };

}
 
Example 9
Source File: Backup.java    From Jantent with MIT License 5 votes vote down vote up
public String getSQLValue(Table table, Row row, int index) {
	Column column = table.getColumns().get(index);
	int type = column.getDataType();
	if (row.get(index) == null) {
		return "null";
	} else {
		switch (type) {
		case Types.CHAR:
		case Types.VARCHAR:
		case Types.LONGNVARCHAR:
		case Types.NCHAR:
		case Types.NVARCHAR:
		case Types.LONGVARCHAR:
			return "\"" + row.getString(index) + "\"";

		case Types.DATE:
			return "\"" +  DATE_FORMAT.format(row.getDate(index)) + "\"";
			
		case Types.TIME:
			return "\"" + TIME_FORMAT.format(row.getDate(index)) + "\"";
			
		case Types.TIMESTAMP:
			return "\"" + DATE_TIME_FORMAT.format(row.getDate(index)) + "\"";

		default:
			return row.getString(index);
		}

	}
}
 
Example 10
Source File: CloudSpannerDatabaseMetaData.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern,
    String columnNamePattern) throws SQLException {
  String sql =
      "SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, "
          + "CASE " + "	WHEN SPANNER_TYPE = 'ARRAY' THEN " + Types.ARRAY + " "
          + "	WHEN SPANNER_TYPE = 'BOOL' THEN " + Types.BOOLEAN + " "
          + "	WHEN SPANNER_TYPE = 'BYTES' THEN " + Types.BINARY + " "
          + "	WHEN SPANNER_TYPE = 'DATE' THEN " + Types.DATE + " "
          + "	WHEN SPANNER_TYPE = 'FLOAT64' THEN " + Types.DOUBLE + " "
          + "	WHEN SPANNER_TYPE = 'INT64' THEN " + Types.BIGINT + " "
          + "	WHEN SPANNER_TYPE = 'STRING' THEN " + Types.NVARCHAR + " "
          + "	WHEN SPANNER_TYPE = 'STRUCT' THEN " + Types.STRUCT + " "
          + "	WHEN SPANNER_TYPE = 'TIMESTAMP' THEN " + Types.TIMESTAMP + " "
          + "END AS DATA_TYPE, "
          + "0 AS COLUMN_SIZE, NULL AS DECIMAL_DIGITS, 0 AS NUM_PREC_RADIX, 'USAGE_UNKNOWN' AS COLUMN_USAGE, NULL AS REMARKS, 0 AS CHAR_OCTET_LENGTH, IS_NULLABLE "
          + FROM_COLUMNS_STATEMENT_WITHOUT_RESULTS;

  sql = sql + getCatalogSchemaTableWhereClause("T", catalog, schemaPattern, tableNamePattern);
  if (columnNamePattern != null)
    sql = sql + "AND UPPER(COLUMN_NAME) LIKE ? ";
  sql = sql + "ORDER BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION ";

  CloudSpannerPreparedStatement statement =
      prepareStatement(sql, catalog, schemaPattern, tableNamePattern, columnNamePattern);
  return statement.executeQuery();
}
 
Example 11
Source File: CloudSpannerParameterMetaData.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public int getParameterType(int param) throws SQLException {
  Integer type = statement.getParameterStore().getType(param);
  if (type != null)
    return type.intValue();

  Object value = statement.getParameterStore().getParameter(param);
  if (value == null) {
    return Types.OTHER;
  } else if (Boolean.class.isAssignableFrom(value.getClass())) {
    return Types.BOOLEAN;
  } else if (Byte.class.isAssignableFrom(value.getClass())) {
    return Types.TINYINT;
  } else if (Short.class.isAssignableFrom(value.getClass())) {
    return Types.SMALLINT;
  } else if (Integer.class.isAssignableFrom(value.getClass())) {
    return Types.INTEGER;
  } else if (Long.class.isAssignableFrom(value.getClass())) {
    return Types.BIGINT;
  } else if (Float.class.isAssignableFrom(value.getClass())) {
    return Types.FLOAT;
  } else if (Double.class.isAssignableFrom(value.getClass())) {
    return Types.DOUBLE;
  } else if (BigDecimal.class.isAssignableFrom(value.getClass())) {
    return Types.DECIMAL;
  } else if (Date.class.isAssignableFrom(value.getClass())) {
    return Types.DATE;
  } else if (Timestamp.class.isAssignableFrom(value.getClass())) {
    return Types.TIMESTAMP;
  } else if (Time.class.isAssignableFrom(value.getClass())) {
    return Types.TIME;
  } else if (String.class.isAssignableFrom(value.getClass())) {
    return Types.NVARCHAR;
  } else if (byte[].class.isAssignableFrom(value.getClass())) {
    return Types.BINARY;
  } else {
    return Types.OTHER;
  }
}
 
Example 12
Source File: MysqlDefs.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
public static int javaTypeMysql(int javaType) {

		switch (javaType) {
		case Types.NUMERIC:
			return MysqlDefs.FIELD_TYPE_DECIMAL;

		case Types.DECIMAL:
			return MysqlDefs.FIELD_TYPE_NEW_DECIMAL;

		case Types.TINYINT:
			return MysqlDefs.FIELD_TYPE_TINY;

		case Types.SMALLINT:
			return MysqlDefs.FIELD_TYPE_SHORT;

		case Types.INTEGER:
			return MysqlDefs.FIELD_TYPE_LONG;

		case Types.REAL:
			return MysqlDefs.FIELD_TYPE_FLOAT;

		case Types.DOUBLE:
			return MysqlDefs.FIELD_TYPE_DOUBLE;

		case Types.NULL:
			return MysqlDefs.FIELD_TYPE_NULL;

		case Types.TIMESTAMP:
			return MysqlDefs.FIELD_TYPE_TIMESTAMP;

		case Types.BIGINT:
			return MysqlDefs.FIELD_TYPE_LONGLONG;

		case Types.DATE:
			return MysqlDefs.FIELD_TYPE_DATE;

		case Types.TIME:
			return MysqlDefs.FIELD_TYPE_TIME;

		case Types.VARBINARY:
			return MysqlDefs.FIELD_TYPE_TINY_BLOB;

		case Types.LONGVARBINARY:
			return MysqlDefs.FIELD_TYPE_BLOB;
            //对应sqlserver的image类型
            case 27:
                return MysqlDefs.FIELD_TYPE_BLOB;

		case Types.VARCHAR:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;

		case Types.CHAR:
			return MysqlDefs.FIELD_TYPE_STRING;

		case Types.BINARY:
			return MysqlDefs.FIELD_TYPE_GEOMETRY;

		case Types.BIT:
			return MysqlDefs.FIELD_TYPE_BIT;
		case Types.CLOB:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;
		case Types.BLOB:
			return MysqlDefs.FIELD_TYPE_BLOB;

		//修改by     [email protected]
		// 当jdbc连接非mysql的数据库时,需要把对应类型映射为mysql的类型,否则应用端会出错
			case Types.NVARCHAR:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;
			case Types.NCHAR:
				return MysqlDefs.FIELD_TYPE_STRING;
			case Types.NCLOB:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;
			case Types.LONGNVARCHAR:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;

		default:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;   //其他未知类型返回字符类型
		//	return Types.VARCHAR;
		}

	}
 
Example 13
Source File: Converters.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * 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 14
Source File: CloudSpannerResultSetMetaData.java    From spanner-jdbc with MIT License 4 votes vote down vote up
@Override
public boolean isCaseSensitive(int column) throws SQLException {
  int type = getColumnType(column);
  return type == Types.NVARCHAR || type == Types.BINARY;
}
 
Example 15
Source File: JDBCConnection.java    From dbtransfer with GNU Lesser General Public License v2.1 4 votes vote down vote up
public List<ForeignKeyDefinition> getForeignKeyList(Name table) throws Exception
    {
        DatabaseMetaData rsmd = connection.getMetaData();
        System.out.println( "getting FKs: " + connection.getCatalog() + "/" + dbSchema + "/" + table.originalName + "/" );
        ResultSet rs = rsmd.getImportedKeys( catalog, dbSchema, helper.outputName( table.originalName ) );
        List<ForeignKeyDefinition> list = new LinkedList<ForeignKeyDefinition>();
        Map<String,ForeignKeyDefinition> fks = new HashMap<String, ForeignKeyDefinition>();
        while( rs.next() )
        {
            String fkName = rs.getString( 12 );
//System.out.println( "FK : " + fkName );
            ForeignKeyDefinition fk = fks.get( fkName );
            if( fk == null )
            {
                    fk = new ForeignKeyDefinition( fkName, table );
                    fks.put( fkName, fk );
            }
            ColumnDefinition col = new ColumnDefinition();
            col.referencedTable = new Name( rs.getString( 3 ) );
            col.referencedColumn = new Name( rs.getString( 4 ) );
            col.name = new Name( rs.getString( 8 ) );
            ResultSet rsC = rsmd.getColumns( catalog, dbSchema, helper.outputName( table.originalName ), col.name.originalName );
            if( rsC.next() )
            {
                col.sqlTypeName = rsC.getString( 6 );
                if( rsC.getInt( 5 ) == Types.CHAR
                                || rsC.getInt( 5 ) == Types.LONGVARCHAR
                                || rsC.getInt( 5 ) == Types.VARCHAR
                                || rsC.getInt( 5 ) == Types.NCHAR
                                || rsC.getInt( 5 ) == Types.LONGNVARCHAR
                                || rsC.getInt( 5 ) == Types.NVARCHAR )
                {
                        col.sqlSize = rsC.getInt( 7 );
                }
                col.defaultValue = rsC.getString( 13 );
                col.isNotNull = "NO".equals( rsC.getString( 18 ).trim() );
                rsC.close();
            }
            else
            {
                new Exception( "Can't find column for fk - " + fk.name + "/ col " + col.name ).printStackTrace();
            }
            fk.columns.add( col );
            list.add( fk );
        }
        rs.close();
        return list;
    }
 
Example 16
Source File: ResultSetRecordSet.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static RecordFieldType getFieldType(final int sqlType, final String valueClassName) {
    switch (sqlType) {
        case Types.BIGINT:
        case Types.ROWID:
            return RecordFieldType.LONG;
        case Types.BIT:
        case Types.BOOLEAN:
            return RecordFieldType.BOOLEAN;
        case Types.CHAR:
            return RecordFieldType.CHAR;
        case Types.DATE:
            return RecordFieldType.DATE;
        case Types.NUMERIC:
        case Types.DECIMAL:
            return RecordFieldType.DECIMAL;
        case Types.DOUBLE:
        case Types.REAL:
            return RecordFieldType.DOUBLE;
        case Types.FLOAT:
            return RecordFieldType.FLOAT;
        case Types.INTEGER:
            return RecordFieldType.INT;
        case Types.SMALLINT:
            return RecordFieldType.SHORT;
        case Types.TINYINT:
            return RecordFieldType.BYTE;
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NULL:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            return RecordFieldType.STRING;
        case Types.OTHER:
        case Types.JAVA_OBJECT:
            if (STRING_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.STRING;
            }
            if (INT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.INT;
            }
            if (LONG_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.LONG;
            }
            if (DATE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DATE;
            }
            if (FLOAT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.FLOAT;
            }
            if (DOUBLE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DOUBLE;
            }
            if (BIGDECIMAL_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DECIMAL;
            }

            return RecordFieldType.RECORD;
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
            return RecordFieldType.TIME;
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
        case -101: // Oracle's TIMESTAMP WITH TIME ZONE
        case -102: // Oracle's TIMESTAMP WITH LOCAL TIME ZONE
            return RecordFieldType.TIMESTAMP;
    }

    return RecordFieldType.STRING;
}
 
Example 17
Source File: ValueBinderExpressionVisitorAdapter.java    From spanner-jdbc with MIT License 4 votes vote down vote up
private R setNullValue(Integer sqlType) {
  if (sqlType == null) {
    return binder.to((String) null);
  }
  switch (sqlType) {
    case Types.BIGINT:
      return binder.to((Long) null);
    case Types.BINARY:
      return binder.to((ByteArray) null);
    case Types.BLOB:
      return binder.to((ByteArray) null);
    case Types.BOOLEAN:
      return binder.to((Boolean) null);
    case Types.CHAR:
      return binder.to((String) null);
    case Types.CLOB:
      return binder.to((String) null);
    case Types.DATE:
      return binder.to((com.google.cloud.Date) null);
    case Types.DECIMAL:
      return binder.to((Double) null);
    case Types.DOUBLE:
      return binder.to((Double) null);
    case Types.FLOAT:
      return binder.to((Double) null);
    case Types.INTEGER:
      return binder.to((Long) null);
    case Types.LONGNVARCHAR:
      return binder.to((String) null);
    case Types.LONGVARBINARY:
      return binder.to((ByteArray) null);
    case Types.LONGVARCHAR:
      return binder.to((String) null);
    case Types.NCHAR:
      return binder.to((String) null);
    case Types.NCLOB:
      return binder.to((String) null);
    case Types.NUMERIC:
      return binder.to((Double) null);
    case Types.NVARCHAR:
      return binder.to((String) null);
    case Types.REAL:
      return binder.to((Double) null);
    case Types.SMALLINT:
      return binder.to((Long) null);
    case Types.SQLXML:
      return binder.to((String) null);
    case Types.TIME:
      return binder.to((com.google.cloud.Timestamp) null);
    case Types.TIMESTAMP:
      return binder.to((com.google.cloud.Timestamp) null);
    case Types.TINYINT:
      return binder.to((Long) null);
    case Types.VARBINARY:
      return binder.to((ByteArray) null);
    case Types.VARCHAR:
      return binder.to((String) null);
    default:
      throw new IllegalArgumentException("Unsupported sql type for setting to null: " + sqlType);
  }
}
 
Example 18
Source File: Encoders.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Encoding encodingFor(TInstance type) {
    TClass tclass = TInstance.tClass(type);
    if (tclass == null)
        return null;
    int jdbcType = tclass.jdbcType();
    switch (jdbcType) {
    case Types.DECIMAL:
    case Types.NUMERIC:
        return DecimalEncoder.INSTANCE;

    case Types.BIGINT:
        if (tclass.isUnsigned())
            return UBigIntEncoder.INSTANCE;
        /* else falls through */
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BOOLEAN:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return LongEncoder.INSTANCE;

    case Types.FLOAT:
    case Types.REAL:
        return FloatEncoder.INSTANCE;
    case Types.DOUBLE:
        return DoubleEncoder.INSTANCE;

    case Types.BINARY:
    case Types.BIT:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        return VarBinaryEncoder.INSTANCE;

    case Types.CHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.VARCHAR:
    case Types.LONGNVARCHAR:
    case Types.LONGVARCHAR:
    case Types.CLOB:
        return charEncoding(StringAttribute.charsetName(type));

    default:
        if (tclass == AkGUID.INSTANCE) {
            return GuidEncoder.INSTANCE;
        }
        return null;
    }
}
 
Example 19
Source File: AttributeSetup.java    From celerio with Apache License 2.0 4 votes vote down vote up
private MappedType getRawMappedType() {
    switch (attribute.getJdbcType().getJdbcType()) {
        case Types.ARRAY:
            return M_ARRAY;
        case Types.BIGINT:
            return M_LONG;
        case Types.BINARY:
            return M_BYTES;
        case Types.BIT:
        case Types.BOOLEAN:
            return M_BOOLEAN;
        case Types.BLOB:
            return M_BLOB;
        case Types.CLOB:
        case Types.NCLOB:
        case Types.SQLXML:
            return M_CLOB;
        case Types.DATALINK:
            return M_URL;
        case Types.DATE:
            return M_UTILDATE;
        case Types.DISTINCT:
        case Types.JAVA_OBJECT:
            return M_OBJECT;
        case Types.DOUBLE:
        case Types.FLOAT:
            return M_DOUBLE;
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
            return M_INTEGER;
        case Types.LONGVARBINARY:
            return M_BYTES;
        case Types.CHAR:
        case Types.LONGVARCHAR:
        case Types.VARCHAR:
        case Types.LONGNVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
            return M_STRING;
        case Types.DECIMAL:
        case Types.NUMERIC:
            ColumnConfig column = attribute.getColumnConfig();
            if (column.getDecimalDigits() > 0) {
                if (column.getSize() < 11 && column.getDecimalDigits() < 4) {
                    return M_DOUBLE;
                } else {
                    return M_BIGDECIMAL;
                }
            } else {
                if (column.getSize() == 1 && IS_BOOLEAN_PREFIX.apply(attribute)) {
                    return M_BOOLEAN;
                } else {
                    if (column.getSize() < 11) {
                        return M_INTEGER;
                    } else if (column.getSize() < 19 || attribute.isInPk() || attribute.isInFk()) { // BIG INTEGER IS NOT
                        // ACCEPTED BY HIBERNATE
                        // FOR PK
                        return M_LONG;
                    } else {
                        return M_BIGINTEGER;
                    }
                }
            }
        case Types.OTHER:
            return M_OBJECT;
        case Types.REAL:
            return M_FLOAT;
        case Types.REF:
            return M_REF;
        case Types.STRUCT:
            return M_OBJECT;
        case Types.TIME:
        case Types.TIMESTAMP:
            return M_UTILDATE;
        case Types.VARBINARY:
            if (attribute.getColumnConfig().getSize() == 1) {
                return M_BYTE;
            } else {
                return M_BYTES;
            }
        case Types.ROWID:
            return M_LONG;
        default:
            throw new RuntimeException("Could not retrieve the type of " + this);
    }
}
 
Example 20
Source File: JDBCUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Get the SQLType for the given java.sql.Type type.
 *
 * @param type the java.sql.Type type specifier
 * @return SQLType.the SQLType for this java.sql.Type, or null if it's not recognized
 */
public static SQLType getSQLType(int type) {
    switch (type) {
        case Types.BIT: return SQLType.BIT;
        case Types.TINYINT: return SQLType.TINYINT;
        case Types.SMALLINT: return SQLType.SMALLINT;
        case Types.INTEGER: return SQLType.INTEGER;
        case Types.BIGINT: return SQLType.BIGINT;
        case Types.FLOAT: return SQLType.FLOAT;
        case Types.REAL: return SQLType.REAL;
        case Types.DOUBLE: return SQLType.DOUBLE;
        case Types.NUMERIC: return SQLType.NUMERIC;
        case Types.DECIMAL: return SQLType.DECIMAL;
        case Types.CHAR: return SQLType.CHAR;
        case Types.VARCHAR: return SQLType.VARCHAR;
        case Types.LONGVARCHAR: return SQLType.LONGVARCHAR;
        case Types.DATE: return SQLType.DATE;
        case Types.TIME: return SQLType.TIME;
        case Types.TIMESTAMP: return SQLType.TIMESTAMP;
        case Types.BINARY: return SQLType.BINARY;
        case Types.VARBINARY: return SQLType.VARBINARY;
        case Types.LONGVARBINARY: return SQLType.LONGVARBINARY;
        case Types.NULL: return SQLType.NULL;
        case Types.OTHER: return SQLType.OTHER;
        case Types.JAVA_OBJECT: return SQLType.JAVA_OBJECT;
        case Types.DISTINCT: return SQLType.DISTINCT;
        case Types.STRUCT: return SQLType.STRUCT;
        case Types.ARRAY: return SQLType.ARRAY;
        case Types.BLOB: return SQLType.BLOB;
        case Types.CLOB: return SQLType.CLOB;
        case Types.REF: return SQLType.REF;
        case Types.DATALINK: return SQLType.DATALINK;
        case Types.BOOLEAN: return SQLType.BOOLEAN;
        case Types.LONGNVARCHAR: return SQLType.LONGVARCHAR;
        case Types.NCHAR: return SQLType.CHAR;
        case Types.NCLOB: return SQLType.CLOB;
        case Types.NVARCHAR: return SQLType.VARCHAR;
        case Types.SQLXML: return SQLType.SQLXML;
        case Types.ROWID: return SQLType.ROWID;
        default:
            Logger.getLogger(JDBCUtils.class.getName()).log(Level.WARNING, "Unknown JDBC column type: " + type + ". Returns null.");
            return null;
    }
}