Java Code Examples for java.sql.Types#LONGVARBINARY

The following examples show how to use java.sql.Types#LONGVARBINARY . 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: AsyncStatement.java    From dbtransfer with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static int calculateEffectiveColumns( boolean noBlob, int[] types) 
   {
	int cols = 0;
	if( noBlob )
	{
		for( int i = 0; i < types.length; ++i )
		{
			if( types[ i ] != Types.BLOB
               		&& types[ i ] != Types.LONGVARBINARY 
               		&& types[ i ] != Types.VARBINARY )
               {
               	++cols;
               }
		}
	}
	else
	{
		cols = types.length;
	}
   	return cols;
}
 
Example 2
Source File: ConcatenationOperatorNode.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private static int clobBlobHandling(DataTypeDescriptor clobBlobType,
		DataTypeDescriptor otherType) throws StandardException {
	int resultLength;

	if (otherType.getTypeId().getJDBCTypeId() == Types.LONGVARCHAR
			|| otherType.getTypeId().getJDBCTypeId() == Types.LONGVARBINARY) {
		//operands CLOB(A), LONG VARCHAR then result is CLOB(MIN(A+32K,2G))
		//operands BLOB(A), LONG VARCHAR FOR BIT DATA then result is
		// BLOB(MIN(A+32K,2G))
		resultLength = clobBlobType.getMaximumWidth() + 32768;
	} else {
		//operands CLOB(A), CHAR(B) then result is CLOB(MIN(A+B,2G))
		//operands CLOB(A), VARCHAR(B) then result is CLOB(MIN(A+B,2G))
		//operands CLOB(A), CLOB(B) then result is CLOB(MIN(A+B,2G))
		//operands BLOB(A), CHAR FOR BIT DATA(B) then result is
		// BLOB(MIN(A+B,2G))
		//operands BLOB(A), VARCHAR FOR BIT DATA(B) then result is
		// BLOB(MIN(A+B,2G))
		//operands BLOB(A), BLOB(B) then result is BLOB(MIN(A+B,2G))
		resultLength = clobBlobType.getMaximumWidth()
				+ otherType.getMaximumWidth();
	}

	if (resultLength < 1) //this mean A+B or A+32K is bigger than 2G
		return (Integer.MAX_VALUE);
	else
		return (resultLength);

}
 
Example 3
Source File: InformixSpecific.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public int jetelType2sql(DataFieldMetadata field) {
	switch (field.getType()) {
	case DataFieldMetadata.BYTE_FIELD:
       case DataFieldMetadata.BYTE_FIELD_COMPRESSED:
       	return Types.LONGVARBINARY;
       case DataFieldMetadata.NUMERIC_FIELD:
       	return Types.DOUBLE;
	default: 
       	return super.jetelType2sql(field);
	}
}
 
Example 4
Source File: DVDStoreResultSet.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public InputStream getAsciiStream(int columnIndex) throws SQLException {
  if (columnIndex > 0 && columnIndex <= this.numColumns) {
    final TableMetaData metadata = getMetaData();
    final int colType = metadata.getColumnType(columnIndex);
    switch (colType) {
      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
      case JDBC40Translation.JSON:
      case Types.CLOB: // Embedded and JCC extension
        break;

      // JDBC says to support these, we match JCC by returning the raw bytes.
      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
      case Types.BLOB:
        return getBinaryStream(columnIndex);

      default:
        throw dataConversionException(
            metadata.getColumnTypeName(columnIndex), "InputStream(ASCII)",
            columnIndex);
    }

    final Reader reader = getCharacterStream(columnIndex);
    if (reader != null) {
      return new ReaderToAscii(reader);
    }
    else {
      return null;
    }
  }
  else {
    throw invalidColumnException(columnIndex);
  }
}
 
Example 5
Source File: Type1BlobCollectionConversionHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public Object getValidateSource(String id, ResultSet rs) throws SQLException
{
	ResultSetMetaData metadata = rs.getMetaData();
	byte[] rv = null;
	switch(metadata.getColumnType(1))
	{
	case Types.BLOB:
		Blob blob = rs.getBlob(1);
		if(blob != null)
		{
			rv = blob.getBytes(1L, (int) blob.length());
		}
		else
		{
			log.info("getValidateSource(" + id + ") blob is null" );
		}
		break;
	case Types.CLOB:
		Clob clob = rs.getClob(1);
		if(clob != null)
		{
			rv = clob.getSubString(1L, (int) clob.length()).getBytes();
		}
		break;
	case Types.CHAR:
	case Types.LONGVARCHAR:
	case Types.VARCHAR:
		rv = rs.getString(1).getBytes();
		break;
	case Types.BINARY:
	case Types.VARBINARY:
	case Types.LONGVARBINARY:
		rv = rs.getBytes(1);
		break;
	}
	return rv;
}
 
Example 6
Source File: RawStoreResultSetWithByteSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public InputStream getAsciiStream(int columnIndex) throws SQLException {
  if (columnIndex > 0 && columnIndex <= this.numColumns) {
    final TableMetaData metadata = getMetaData();
    final int colType = metadata.getColumnType(columnIndex);
    switch (colType) {
      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
      case Types.CLOB: // Embedded and JCC extension
        break;

      // JDBC says to support these, we match JCC by returning the raw bytes.
      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
      case Types.BLOB:
        return getBinaryStream(columnIndex);

      default:
        throw dataConversionException(
            metadata.getColumnTypeName(columnIndex), "InputStream(ASCII)",
            columnIndex);
    }

    final Reader reader = getCharacterStream(columnIndex);
    if (reader != null) {
      return new ReaderToAscii(reader);
    }
    else {
      return null;
    }
  }
  else {
    throw invalidColumnException(columnIndex);
  }
}
 
Example 7
Source File: ParallelQueryBuilder.java    From dbeam with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function which finds the min and max limits for the given split column with the
 * partition conditions.
 *
 * @return A long array of two elements, with [0] being min and [1] being max.
 * @throws SQLException when there is an exception retrieving the max and min fails.
 */
static long[] findInputBounds(
    Connection connection, QueryBuilder queryBuilder, String splitColumn) throws SQLException {
  String minColumnName = "min_s";
  String maxColumnName = "max_s";
  String limitsQuery =
      queryBuilder
          .generateQueryToGetLimitsOfSplitColumn(splitColumn, minColumnName, maxColumnName)
          .build();
  long min;
  long max;
  try (Statement statement = connection.createStatement()) {
    final ResultSet resultSet = statement.executeQuery(limitsQuery);
    // Check and make sure we have a record. This should ideally succeed always.
    checkState(resultSet.next(), "Result Set for Min/Max returned zero records");

    // minColumnName and maxColumnName would be both of the same type
    switch (resultSet.getMetaData().getColumnType(1)) {
      case Types.LONGVARBINARY:
      case Types.BIGINT:
      case Types.INTEGER:
        min = resultSet.getLong(minColumnName);
        // TODO
        // check resultSet.wasNull(); NULL -> 0L
        // there is no value to carry on since it will be empty set anyway
        max = resultSet.getLong(maxColumnName);
        break;
      default:
        throw new IllegalArgumentException("splitColumn should be of type Integer / Long");
    }
  }

  return new long[] {min, max};
}
 
Example 8
Source File: Util.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static String typeName(int jdbcType) {
	switch (jdbcType) {
		case Types.ARRAY: return TypeId.ARRAY_NAME;
		case Types.BIT 		:  return TypeId.BIT_NAME;
		case Types.BOOLEAN  : return TypeId.BOOLEAN_NAME;
		case Types.DATALINK: return TypeId.DATALINK_NAME;
		case Types.TINYINT 	:  return TypeId.TINYINT_NAME;
		case Types.SMALLINT	:  return TypeId.SMALLINT_NAME;
		case Types.INTEGER 	:  return TypeId.INTEGER_NAME;
		case Types.BIGINT 	:  return TypeId.LONGINT_NAME;

		case Types.FLOAT 	:  return TypeId.FLOAT_NAME;
		case Types.REAL 	:  return TypeId.REAL_NAME;
		case Types.DOUBLE 	:  return TypeId.DOUBLE_NAME;

		case Types.NUMERIC 	:  return TypeId.NUMERIC_NAME;
		case Types.DECIMAL	:  return TypeId.DECIMAL_NAME;

		case Types.CHAR		:  return TypeId.CHAR_NAME;
		case Types.VARCHAR 	:  return TypeId.VARCHAR_NAME;
		case Types.LONGVARCHAR 	:  return "LONGVARCHAR";
           case Types.CLOB     :  return TypeId.CLOB_NAME;

		case Types.DATE 		:  return TypeId.DATE_NAME;
		case Types.TIME 		:  return TypeId.TIME_NAME;
		case Types.TIMESTAMP 	:  return TypeId.TIMESTAMP_NAME;

		case Types.BINARY			:  return TypeId.BINARY_NAME;
		case Types.VARBINARY	 	:  return TypeId.VARBINARY_NAME;
		case Types.LONGVARBINARY 	:  return TypeId.LONGVARBINARY_NAME;
           case Types.BLOB             :  return TypeId.BLOB_NAME;

		case Types.OTHER		:  return "OTHER";
		case Types.JAVA_OBJECT	:  return "Types.JAVA_OBJECT";
		case Types.REF : return TypeId.REF_NAME;
		case JDBC40Translation.ROWID: return TypeId.ROWID_NAME;
		case Types.STRUCT: return TypeId.STRUCT_NAME;
		case StoredFormatIds.XML_TYPE_ID :  return TypeId.XML_NAME;
		case JDBC40Translation.SQLXML: return TypeId.SQLXML_NAME;
		case JDBC40Translation.JSON: return TypeId.JSON_NAME;
		default : return String.valueOf(jdbcType);
	}
}
 
Example 9
Source File: EventErrorFileToDBWriter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Set the value of a parameter in prepared statement given a string
 * representation as returned by
 */
public static void setParameters(PreparedStatement pstmt, String[] params,
    ArrayList<Integer> paramTypes) throws Exception {
  for (int index = 0; index < params.length; index++) {
    String param = params[index];
    int paramIndex = index + 1;
    int paramType = paramTypes.get(index);
    byte[] bytes;

    if (param == null) {
      pstmt.setNull(paramIndex, paramType);
      continue;
    }
    switch (paramType) {
      case Types.BIGINT:
        final long longVal = Long.parseLong(param);
        pstmt.setLong(paramIndex, longVal);
        break;
      case Types.BIT:
      case Types.BOOLEAN:
        final boolean boolVal;
        if ("1".equals(param)) {
          boolVal = true;
        }
        else if ("0".equals(param)) {
          boolVal = false;
        }
        else {
          boolVal = Boolean.parseBoolean(param);
        }
        pstmt.setBoolean(paramIndex, boolVal);
        break;
      case Types.DATE:
        final java.sql.Date dateVal = java.sql.Date.valueOf(param);
        pstmt.setDate(paramIndex, dateVal);
        break;
      case Types.DECIMAL:
      case Types.NUMERIC:
        final BigDecimal decimalVal = new BigDecimal(param);
        pstmt.setBigDecimal(paramIndex, decimalVal);
        break;
      case Types.DOUBLE:
        final double doubleVal = Double.parseDouble(param);
        pstmt.setDouble(paramIndex, doubleVal);
        break;
      case Types.FLOAT:
      case Types.REAL:
        final float floatVal = Float.parseFloat(param);
        pstmt.setFloat(paramIndex, floatVal);
        break;
      case Types.INTEGER:
      case Types.SMALLINT:
      case Types.TINYINT:
        final int intVal = Integer.parseInt(param);
        pstmt.setInt(paramIndex, intVal);
        break;
      case Types.TIME:
        final java.sql.Time timeVal = java.sql.Time.valueOf(param);
        pstmt.setTime(paramIndex, timeVal);
        break;
      case Types.TIMESTAMP:
        final java.sql.Timestamp timestampVal = java.sql.Timestamp
            .valueOf(param);
        pstmt.setTimestamp(paramIndex, timestampVal);
        break;
      case Types.BINARY:
      case Types.BLOB:
      case Types.LONGVARBINARY:
      case Types.VARBINARY:
        bytes = ClientSharedUtils.fromHexString(param, 0, param.length());
        pstmt.setBytes(paramIndex, bytes);
        break;
      case Types.JAVA_OBJECT:
        bytes = ClientSharedUtils.fromHexString(param, 0, param.length());
        ByteArrayDataInput in = new ByteArrayDataInput();
        in.initialize(bytes, null);
        pstmt.setObject(paramIndex, DataSerializer.readObject(in));
        break;
      default:
        pstmt.setString(paramIndex, param);
        break;
    }
  }
}
 
Example 10
Source File: JdbcExtractor.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
private static boolean isBlob(int columnType) {
  return columnType == Types.LONGVARBINARY || columnType == Types.BINARY;
}
 
Example 11
Source File: Util.java    From registry with Apache License 2.0 4 votes vote down vote up
public static Class getJavaType(int sqlType, int precision) {
    switch (sqlType) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.CLOB:
            return String.class;
        case Types.BINARY:
        case Types.VARBINARY:
            return byte[].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.DOUBLE:
        case Types.FLOAT:
            return Double.class;
        case Types.DATE:
            return Date.class;
        case Types.TIME:
            return Time.class;
        case Types.TIMESTAMP:
            return Timestamp.class;
        case Types.BLOB:
        case Types.LONGVARBINARY:
            return InputStream.class;
        case Types.NUMERIC:
            switch (precision) {
                case 1:
                    return Boolean.class;
                case 3:
                    return Byte.class;
                case 10:
                    return Integer.class;
                default:
                    return Long.class;
            }
        default:
            throw new RuntimeException("We do not support tables with SqlType: " + getSqlTypeName(sqlType));
    }
}
 
Example 12
Source File: DataTypeDescriptor.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public DataValueDescriptor normalize(DataValueDescriptor source,
									DataValueDescriptor cachedDest)
		throws StandardException
{
	if (SanityManager.DEBUG) {
		if (cachedDest != null) {
			if (!getTypeId().isUserDefinedTypeId()) {
				String t1 = getTypeName();
				String t2 = cachedDest.getTypeName();
				if (!t1.equals(t2)) {

					if (!(((t1.equals("DECIMAL") || t1.equals("NUMERIC"))
						&& (t2.equals("DECIMAL") || t2.equals("NUMERIC"))) ||
						(t1.startsWith("INT") && t2.startsWith("INT"))))  //INT/INTEGER

						SanityManager.THROWASSERT(
							"Normalization of " + t2 + " being asked to convert to " + t1);
				}
			}
		}
	}

	if (source.isNull())
	{
		if (!isNullable())
			throw StandardException.newException(SQLState.LANG_NULL_INTO_NON_NULL,"");

		if (cachedDest == null)
			cachedDest = getNull();
		else
			cachedDest.setToNull();
	} else {

		if (cachedDest == null)
			cachedDest = getNull();

		int jdbcId = getJDBCTypeId();

		cachedDest.normalize(this, source);
		//doing the following check after normalize so that normalize method would get called on long varchs and long varbinary
		//Need normalize to be called on long varchar for bug 5592 where we need to enforce a lenght limit in db2 mode
		if ((jdbcId == Types.LONGVARCHAR) || (jdbcId == Types.LONGVARBINARY)) {
			// special case for possible streams
			if (source.getClass() == cachedDest.getClass()) 
				return source;
		}

	}
	return cachedDest;
}
 
Example 13
Source File: XMLContentExporter.java    From syncope with Apache License 2.0 4 votes vote down vote up
private static String getValues(final ResultSet rs, final String columnName, final Integer columnType)
        throws SQLException {

    String res = null;

    try {
        switch (columnType) {
            case Types.BINARY:
            case Types.VARBINARY:
            case Types.LONGVARBINARY:
                final InputStream is = rs.getBinaryStream(columnName);
                if (is != null) {
                    res = DatatypeConverter.printHexBinary(IOUtils.toByteArray(is));
                }
                break;

            case Types.BLOB:
                final Blob blob = rs.getBlob(columnName);
                if (blob != null) {
                    res = DatatypeConverter.printHexBinary(IOUtils.toByteArray(blob.getBinaryStream()));
                }
                break;

            case Types.BIT:
            case Types.BOOLEAN:
                if (rs.getBoolean(columnName)) {
                    res = "1";
                } else {
                    res = "0";
                }
                break;

            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                final Timestamp timestamp = rs.getTimestamp(columnName);
                if (timestamp != null) {
                    res = FormatUtils.format(new Date(timestamp.getTime()));
                }
                break;

            default:
                res = rs.getString(columnName);
        }
    } catch (IOException e) {
        LOG.error("Error retrieving hexadecimal string", e);
    }

    return res;
}
 
Example 14
Source File: SQLTypeMap.java    From Kylin with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public static Class convert(int sqlType) {
    Class result = Object.class;

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        result = String.class;
        break;
    case Types.NUMERIC:
    case Types.DECIMAL:
        result = BigDecimal.class;
        break;
    case Types.BIT:
        result = Boolean.class;
        break;
    case Types.TINYINT:
        result = Byte.class;
        break;
    case Types.SMALLINT:
        result = Short.class;
        break;
    case Types.INTEGER:
        result = Integer.class;
        break;
    case Types.BIGINT:
        result = Long.class;
        break;
    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        result = Double.class;
        break;
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        result = Byte[].class;
        break;
    case Types.DATE:
        result = Date.class;
        break;
    case Types.TIME:
        result = Time.class;
        break;
    case Types.TIMESTAMP:
        result = Timestamp.class;
        break;
    }

    return result;
}
 
Example 15
Source File: ParameterNode.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * For a ParameterNode, we generate for the return value:
 *
 *		(<java type name>)
 *			( (BaseActivation) this.getParameter(parameterNumber) )
 *
 *
 * @param acb	The ExpressionClassBuilder for the class being built
 * @param mb	The method the expression will go into
 *
 *
 * @exception StandardException		Thrown on error
 */
public void generateExpression(ExpressionClassBuilder acb,
										MethodBuilder mb)
								throws StandardException
{
	/* If we were given a specific ValueNode to generate then
	 * just use that.  See, in particular, the preprocess method
	 * of InListOperatorNode.
	 */
	if (valToGenerate != null)
	{
		valToGenerate.generateExpression(acb, mb);
		return;
	}

	DataTypeDescriptor dtd = getTypeServices();
	if ((dtd != null) && dtd.getTypeId().isXMLTypeId()) {
	// We're a parameter that corresponds to an XML column/target,
	// which we don't allow.  We throw the error here instead of
	// in "bindExpression" because at the time of bindExpression,
	// we don't know yet what the type is going to be (only when
	// the node that points to this parameter calls
	// "setType" do we figure out the type).
		throw StandardException.newException(
			SQLState.LANG_ATTEMPT_TO_BIND_XML);
	}

       /* Generate the return value */

       mb.pushThis();
       mb.push(parameterNumber); // arg

       mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "getParameter",
                     ClassName.DataValueDescriptor, 1);

	// For some types perform host variable checking
	// to match DB2/JCC where if a host variable is too
	// big it is not accepted, regardless of any trailing padding.

	switch (dtd.getJDBCTypeId()) {
	case Types.BINARY:
	case Types.VARBINARY:
	case Types.LONGVARBINARY:
	case Types.BLOB:
		mb.dup();
		mb.push(dtd.getMaximumWidth());
		mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "checkHostVariable",
                     "void", 1);
		break;

	default:
		break;
	}

       /* Cast the result to its specific interface */
       if (this.defaultValueIsArray) {
         mb.cast(ClassName.DVDSet);
       }
       else {
         mb.cast(getTypeCompiler().interfaceName());
       }
}
 
Example 16
Source File: TriggerTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test updates of the specified types in the action statement.
 * @param type
 * @throws SQLException
 * @throws IOException
 */
private void actionTypesUpdateTest(String type)
    throws SQLException, IOException
{
    int jdbcType = DatabaseMetaDataTest.getJDBCType(type);
    int precision = DatabaseMetaDataTest.getPrecision(jdbcType, type);

    // BUG DERBY-2349 - need insert case to work first
    if (jdbcType == Types.BLOB)
        return;
    
    Statement s = createStatement();
    s.executeUpdate("UPDATE T_MAIN SET V = NULL WHERE ID = 2");
    s.close();
    commit();
    actionTypesCompareMainToActionForUpdate(type, 2);

    Random r = new Random();
    
    PreparedStatement ps = prepareStatement(
        (jdbcType == JDBC.SQLXML
            ? "UPDATE T_MAIN SET V = " +
              "XMLPARSE(DOCUMENT CAST (? AS CLOB) PRESERVE WHITESPACE)"
            : "UPDATE T_MAIN SET V = ?")
        + " WHERE ID >= ? AND ID <= ?");
    
    // Single row update of row 3
    setRandomValue(r, ps, 1, jdbcType, precision);
    ps.setInt(2, 3);
    ps.setInt(3, 3);
    assertUpdateCount(ps, 1);
    commit();
    actionTypesCompareMainToActionForUpdate(type, 3);
    
    // Bug DERBY-2358 - skip multi-row updates for streaming input.
    switch (jdbcType) {
    case Types.BLOB:
    case Types.CLOB:
    case Types.LONGVARBINARY:
    case Types.LONGVARCHAR:
        ps.close();
        return;
    }
    
    // multi-row update of 4,5
    setRandomValue(r, ps, 1, jdbcType, precision);
    ps.setInt(2, 4);
    ps.setInt(3, 5);
    assertUpdateCount(ps, 2);
    commit();
    actionTypesCompareMainToActionForUpdate(type, 4);
    actionTypesCompareMainToActionForUpdate(type, 5);

    ps.close();
    
}
 
Example 17
Source File: AbstractFieldMetaData.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected final String getFieldClassName(int field) throws SQLException {
    switch (getFieldType(field)) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return STRING_CLASS_NAME;

    case Types.SMALLINT:
    case Types.INTEGER:
        return INTEGER_CLASS_NAME;

    case Types.FLOAT:
    case Types.DOUBLE:
        return DOUBLE_CLASS_NAME;

    case Types.TIMESTAMP:
        return TIMESTAMP_CLASS_NAME;

    case Types.BLOB:
        return BLOB_CLASS_NAME;

    case Types.CLOB:
        return CLOB_CLASS_NAME;

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return BYTE_ARRAY_CLASS_NAME;

    case Types.ARRAY:
        return ARRAY_CLASS_NAME;

    case Types.BIGINT:
        return LONG_CLASS_NAME;

    case Types.TIME:
        return TIME_CLASS_NAME;

    case Types.DATE:
        return SQL_DATE_CLASS_NAME;

    case Types.TIME_WITH_TIMEZONE:
        return OFFSET_TIME_CLASS_NAME;

    case Types.TIMESTAMP_WITH_TIMEZONE:
        return OFFSET_DATE_TIME_CLASS_NAME;

    case Types.NUMERIC:
    case Types.DECIMAL:
    case JaybirdTypeCodes.DECFLOAT:
        return BIG_DECIMAL_CLASS_NAME;

    case Types.BOOLEAN:
        return BOOLEAN_CLASS_NAME;

    case Types.NULL:
    case Types.OTHER:
        return OBJECT_CLASS_NAME;

    case Types.ROWID:
        return ROW_ID_CLASS_NAME;

    default:
        throw new FBSQLException("Unknown SQL type.", SQLStateConstants.SQL_STATE_INVALID_PARAM_TYPE);
    }
}
 
Example 18
Source File: JDBCTypeMapper.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Class getJavaType(short jdbcType) {
	switch (jdbcType) {
	case Types.ARRAY:
		return java.sql.Array.class;
	case Types.BIGINT:
		return java.lang.Long.class;
	case Types.BINARY:
		return java.lang.Byte[].class;
	case Types.BIT:
		return java.lang.Boolean.class;
	case Types.BLOB:
		return java.sql.Blob.class;
	case Types.CHAR:
		return java.lang.String.class;
	case Types.CLOB:
		return java.sql.Clob.class;
	case Types.DATE:
		return java.sql.Date.class;
	case Types.DECIMAL:
		return java.math.BigDecimal.class;
	case Types.DISTINCT:
		return java.lang.Object.class;
	case Types.DOUBLE:
		return java.lang.Double.class;
	case Types.FLOAT:
		return java.lang.Double.class;
	case Types.INTEGER:
		return java.lang.Integer.class;
	case Types.JAVA_OBJECT:
		return java.lang.Object.class;
	case Types.LONGVARBINARY:
		return java.lang.Byte[].class;
	case Types.LONGVARCHAR:
		return java.lang.String.class;
	case Types.NULL:
		return java.lang.Object.class;
	case Types.NUMERIC:
		return java.math.BigDecimal.class;
	case Types.OTHER:
		return java.lang.Object.class;
	case Types.REAL:
		return java.lang.Float.class;
	case Types.REF:
		return java.sql.Ref.class;
	case Types.SMALLINT:
		return java.lang.Short.class;
	case Types.STRUCT:
		return java.sql.Struct.class;
	case Types.TIME:
		return java.sql.Time.class;
	case Types.TIMESTAMP:
		return java.sql.Timestamp.class;
	case Types.TINYINT:
		return java.lang.Byte.class;
	case Types.VARBINARY:
		return java.lang.Byte[].class;
	case Types.VARCHAR:
		return java.lang.String.class;
	case Types.NVARCHAR:
		return java.lang.String.class;
	default:
		return null;
	}
}
 
Example 19
Source File: StandardColumnMappings.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Optional<ColumnMapping> jdbcTypeToPrestoType(ConnectorSession session, JdbcTypeHandle type)
{
    int columnSize = type.getColumnSize();
    switch (type.getJdbcType()) {
        case Types.BIT:
        case Types.BOOLEAN:
            return Optional.of(booleanColumnMapping());

        case Types.TINYINT:
            return Optional.of(tinyintColumnMapping());

        case Types.SMALLINT:
            return Optional.of(smallintColumnMapping());

        case Types.INTEGER:
            return Optional.of(integerColumnMapping());

        case Types.BIGINT:
            return Optional.of(bigintColumnMapping());

        case Types.REAL:
            return Optional.of(realColumnMapping());

        case Types.FLOAT:
        case Types.DOUBLE:
            return Optional.of(doubleColumnMapping());

        case Types.NUMERIC:
        case Types.DECIMAL:
            int decimalDigits = type.getDecimalDigits();
            int precision = columnSize + max(-decimalDigits, 0); // Map decimal(p, -s) (negative scale) to decimal(p+s, 0).
            if (precision > Decimals.MAX_PRECISION) {
                return Optional.empty();
            }
            return Optional.of(decimalColumnMapping(createDecimalType(precision, max(decimalDigits, 0)), UNNECESSARY));

        case Types.CHAR:
        case Types.NCHAR:
            // TODO this is wrong, we're going to construct malformed Slice representation if source > charLength
            int charLength = min(columnSize, CharType.MAX_LENGTH);
            return Optional.of(charColumnMapping(createCharType(charLength)));

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
            if (columnSize > VarcharType.MAX_LENGTH) {
                return Optional.of(varcharColumnMapping(createUnboundedVarcharType()));
            }
            return Optional.of(varcharColumnMapping(createVarcharType(columnSize)));

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return Optional.of(varbinaryColumnMapping());

        case Types.DATE:
            return Optional.of(dateColumnMapping());

        case Types.TIME:
            // TODO default to `timeColumnMapping`
            return Optional.of(timeColumnMappingUsingSqlTime(session));

        case Types.TIMESTAMP:
            // TODO default to `timestampColumnMapping`
            return Optional.of(timestampColumnMappingUsingSqlTimestamp(session));
    }
    return Optional.empty();
}
 
Example 20
Source File: DataTypeDescriptor.java    From Oceanus with Apache License 2.0 3 votes vote down vote up
/**
 * Check whether a JDBC type is compatible with the Java type
 * <code>byte[]</code>.
 *
 * <p><strong>Note:</strong> <code>BLOB</code> is not compatible with
 * <code>byte[]</code>. See tables B-4, B-5 and B-6 in the JDBC 3.0
 * Specification.
 *
 * @param jdbcType a JDBC type
 * @return <code>true</code> iff <code>jdbcType</code> is compatible with
 * <code>byte[]</code>
 * @see java.sql.Types
 */
private static boolean isBinaryType(int jdbcType) {
    switch (jdbcType) {
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return true;
    default:
        return false;
    }
}