Java Code Examples for java.sql.Types#BOOLEAN

The following examples show how to use java.sql.Types#BOOLEAN . 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: AnnotationStoreRepositoryJDBCImplTest.java    From elucidate-server with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("serial")
public void testGetAnnotationByCollectionIdAndAnnotationIdOne() {

    W3CAnnotation w3cAnnotation = generateRandomW3CAnnotation();

    String collectionId = generateRandomId();
    String annotationId = generateRandomId();
    Object[] params = {collectionId, annotationId, false};
    int[] sqlTypes = {Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN};

    when(jdbcTemplate.query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any())).thenReturn(new ArrayList<W3CAnnotation>() {
        {
            add(w3cAnnotation);
        }
    });
    W3CAnnotation returnedW3CAnnotation = annotationStoreRepository.getAnnotationByCollectionIdAndAnnotationId(collectionId, annotationId);
    verify(jdbcTemplate, times(1)).query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any());

    assertThat(w3cAnnotation, is(equalTo(returnedW3CAnnotation)));
}
 
Example 2
Source File: DataViewUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static boolean isNumeric(int jdbcType) {
    switch (jdbcType) {
        case Types.BIT:
        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.DECIMAL:
        case Types.NUMERIC:
            return true;

        default:
            return false;
    }
}
 
Example 3
Source File: AnnotationCollectionStoreRepositoryJDBCImpl.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@Transactional(readOnly = true)
public W3CAnnotationCollection getAnnotationCollectionById(String collectionId) {
    String sql = "SELECT * FROM annotation_collection_get WHERE collectionid = ? AND deleted = ?";
    Object[] params = {collectionId, false};
    int[] sqlTypes = {Types.VARCHAR, Types.BOOLEAN};

    return queryForObject(sql, params, sqlTypes, new W3CAnnotationCollectionRowMapper());
}
 
Example 4
Source File: DefaultStorageDataTypeContext.java    From registry with Apache License 2.0 5 votes vote down vote up
protected int getSqlType(Schema.Type type) {
    switch (type) {
        case BOOLEAN:
            return Types.BOOLEAN;
        case BYTE:
            return Types.TINYINT;
        case SHORT:
            return Types.SMALLINT;
        case INTEGER:
            return Types.INTEGER;
        case LONG:
            return Types.BIGINT;
        case FLOAT:
            return Types.REAL;
        case DOUBLE:
            return Types.DOUBLE;
        case STRING:
            // it might be a VARCHAR or LONGVARCHAR
            return Types.VARCHAR;
        case BINARY:
            // it might be a VARBINARY or LONGVARBINARY
            return Types.VARBINARY;
        case BLOB:
            return Types.BLOB;
        case NESTED:
        case ARRAY:
            return Types.JAVA_OBJECT;
        default:
            throw new IllegalArgumentException("Not supported type: " + type);
    }
}
 
Example 5
Source File: AnnotationStoreRepositoryJDBCImplTest.java    From elucidate-server with MIT License 5 votes vote down vote up
@Test
public void testGetAnnotationByCollectionIdAndAnnotationIdEmpty() {

    String collectionId = generateRandomId();
    String annotationId = generateRandomId();
    Object[] params = {collectionId, annotationId, false};
    int[] sqlTypes = {Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN};

    when(jdbcTemplate.query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any())).thenReturn(Collections.emptyList());
    W3CAnnotation w3cAnnotation = annotationStoreRepository.getAnnotationByCollectionIdAndAnnotationId(collectionId, annotationId);
    verify(jdbcTemplate, times(1)).query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any());

    assertThat(w3cAnnotation, is(nullValue()));
}
 
Example 6
Source File: SQLUtil.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Converts sql type into string.
 * @param sqlType
 * @return
 */
public static String sqlType2str(int sqlType) {
    switch(sqlType) {
    case Types.BIT: return "BIT";
    case Types.TINYINT: return "TINYINT";
    case Types.SMALLINT: return "SMALLINT";
    case Types.INTEGER: return "INTEGER";
    case Types.BIGINT: return "BIGINT";
    case Types.FLOAT: return "FLOAT";
    case Types.REAL: return "REAL";
    case Types.DOUBLE: return "DOUBLE";
    case Types.NUMERIC: return "NUMERIC";
    case Types.DECIMAL: return "DECIMAL";
    case Types.CHAR: return "CHAR";
    case Types.VARCHAR: return "VARCHAR";
    case Types.LONGVARCHAR: return "LONGVARCHAR";
    case Types.DATE: return "DATE";
    case Types.TIME: return "TIME";
    case Types.TIMESTAMP: return "TIMESTAMP";
    case Types.BINARY: return "BINARY";
    case Types.VARBINARY: return "VARBINARY";
    case Types.LONGVARBINARY: return "LONGVARBINARY";
    case Types.NULL: return "NULL";
    case Types.OTHER: return "OTHER";
    case Types.JAVA_OBJECT: return "JAVA_OBJECT";
    case Types.DISTINCT: return "DISTINCT";
    case Types.STRUCT: return "STRUCT";
    case Types.ARRAY: return "ARRAY";
    case Types.BLOB: return "BLOB";
    case Types.CLOB: return "CLOB";
    case Types.REF: return "REF";
    case Types.DATALINK: return "DATALINK";
    case Types.BOOLEAN: return "BOOLEAN";
    default: return "<unknown sql type>";
    }
    
}
 
Example 7
Source File: DerbyBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected String getNativeDefaultValue(Column column)
{
    if ((column.getTypeCode() == Types.BIT) || (column.getTypeCode() == Types.BOOLEAN))
    {
        return getDefaultValueHelper().convert(column.getDefaultValue(), column.getTypeCode(), Types.SMALLINT);
    }
    else
    {
        return super.getNativeDefaultValue(column);
    }
}
 
Example 8
Source File: PrestoPreparedStatement.java    From presto with Apache License 2.0 4 votes vote down vote up
private static String typedNull(int targetSqlType)
        throws SQLException
{
    switch (targetSqlType) {
        case Types.BOOLEAN:
        case Types.BIT:
            return typedNull("BOOLEAN");
        case Types.TINYINT:
            return typedNull("TINYINT");
        case Types.SMALLINT:
            return typedNull("SMALLINT");
        case Types.INTEGER:
            return typedNull("INTEGER");
        case Types.BIGINT:
            return typedNull("BIGINT");
        case Types.FLOAT:
        case Types.REAL:
            return typedNull("REAL");
        case Types.DOUBLE:
            return typedNull("DOUBLE");
        case Types.DECIMAL:
        case Types.NUMERIC:
            return typedNull("DECIMAL");
        case Types.CHAR:
        case Types.NCHAR:
            return typedNull("CHAR");
        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CLOB:
        case Types.NCLOB:
            return typedNull("VARCHAR");
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            return typedNull("VARBINARY");
        case Types.DATE:
            return typedNull("DATE");
        case Types.TIME:
            return typedNull("TIME");
        case Types.TIMESTAMP:
            return typedNull("TIMESTAMP");
        // TODO Types.TIME_WITH_TIMEZONE
        // TODO Types.TIMESTAMP_WITH_TIMEZONE
        case Types.NULL:
            return "NULL";
    }
    throw new SQLException("Unsupported target SQL type: " + targetSqlType);
}
 
Example 9
Source File: ColumnInfo.java    From presto with Apache License 2.0 4 votes vote down vote up
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 10
Source File: KylinClient.java    From kylin with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public static Class convertType(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:
    case Types.BOOLEAN:
        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;
    default:
        //do nothing
        break;
    }

    return result;
}
 
Example 11
Source File: TypeId.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
     * Get a TypeId of the given JDBC type.  This factory method is
     * intended to be used for built-in types.  For user-defined types,
     * we will need a factory method that takes a Java type name.
     *
     * @param JDBCTypeId    The JDBC Id of the type, as listed in
     *                      java.sql.Types
     *
     * @return      The appropriate TypeId, or null if there is no such
     *                      TypeId.
     */

    public static TypeId getBuiltInTypeId(int JDBCTypeId) {

    switch (JDBCTypeId) {
    case Types.TINYINT:
        return TINYINT_ID;

    case Types.SMALLINT:
        return SMALLINT_ID;

    case Types.INTEGER:
        return INTEGER_ID;

    case Types.BIGINT:
        return BIGINT_ID;

    case Types.REAL:
        return REAL_ID;

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

    case Types.DECIMAL:
        return DECIMAL_ID;

    case Types.NUMERIC:
        return NUMERIC_ID;

    case Types.CHAR:
        return CHAR_ID;

    case Types.VARCHAR:
        return VARCHAR_ID;

    case Types.DATE:
        return DATE_ID;
    case Types.TIME:
        return TIME_ID;

    case Types.TIMESTAMP:
        return TIMESTAMP_ID;

    case Types.BIT:
    case Types.BOOLEAN:
        return BOOLEAN_ID;

    case Types.BINARY:
        return BIT_ID;

    case Types.VARBINARY:
        return VARBIT_ID;

    case Types.LONGVARBINARY:
        return LONGVARBIT_ID;

    case Types.LONGVARCHAR:
        return LONGVARCHAR_ID;


    case Types.BLOB:
        return BLOB_ID;

    case Types.CLOB:
        return CLOB_ID;

    case JDBC40Translation.SQLXML:
        return XML_ID;
        
    case JDBC40Translation.JSON:
      return JSON_ID;
        
    default:
        return null;
    }
}
 
Example 12
Source File: ResultSetTableModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected static Class<? extends Object> getTypeClass(DBColumn col) {
    int colType = col.getJdbcType();

    if (colType == Types.BIT && col.getPrecision() <= 1) {
        colType = Types.BOOLEAN;
    }

    switch (colType) {
        case Types.BOOLEAN:
            return Boolean.class;
        case Types.TIME:
            return Time.class;
        case Types.DATE:
            return Date.class;
        case Types.TIMESTAMP:
        case DBReadWriteHelper.SQL_TYPE_ORACLE_TIMESTAMP:
        case DBReadWriteHelper.SQL_TYPE_ORACLE_TIMESTAMP_WITH_TZ:
            return Timestamp.class;
        case Types.BIGINT:
            return BigInteger.class;
        case Types.DOUBLE:
            return Double.class;
        case Types.FLOAT:
        case Types.REAL:
            return Float.class;
        case Types.DECIMAL:
        case Types.NUMERIC:
            return BigDecimal.class;
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
            return Long.class;

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.ROWID:
            return String.class;

        case Types.BIT:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            return Blob.class;
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CLOB:
        case Types.NCLOB: /*NCLOB */
            return Clob.class;
        case Types.OTHER:
        default:
            return Object.class;
    }
}
 
Example 13
Source File: JdbcBroker.java    From geoportal-server-harvester with Apache License 2.0 4 votes vote down vote up
private List<AttributeInjector> createAttributeInjectors(final String columnName, final int columnType) {
  List<AttributeInjector> attributeInjectors = new ArrayList<>();
  
  switch (columnType) {
    case Types.VARCHAR:
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.SQLXML:
      createAttributeNames("src_%s_txt", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->{
                if (!name.endsWith("_xml")) {
                  a.put(name, readValue(r, columnName, String.class));
                } else {
                  x.xml = readValue(r, columnName, String.class);
                }
              }));
      break;

    case Types.DOUBLE:
      createAttributeNames("src_%s_d", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Double.class))));
      break;

    case Types.FLOAT:
      createAttributeNames("src_%s_f", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Float.class))));
      break;

    case Types.INTEGER:
      createAttributeNames("src_%s_i", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Integer.class))));
      break;
      
    case Types.SMALLINT:
    case Types.TINYINT:
      createAttributeNames("src_%s_i", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Short.class))));
      break;

    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.NUMERIC:
      createAttributeNames("src_%s_d", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, BigDecimal.class))));
      break;

    case Types.BOOLEAN:
      createAttributeNames("src_%s_b", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Boolean.class))));
      break;


    case Types.DATE:
      createAttributeNames("src_%s_dt", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, formatIsoDate(r.getDate(columnName)))));
      break;
    case Types.TIME:
      createAttributeNames("src_%s_dt", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, formatIsoDate(r.getTime(columnName)))));
      break;
    case Types.TIMESTAMP:
      createAttributeNames("src_%s_dt", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->a.put(name, formatIsoDate(r.getTimestamp(columnName)))));
      break;
      
    case Types.CLOB:
      createAttributeNames("src_%s_txt", norm(columnName)).forEach(
              name -> attributeInjectors.add((a,x,r)->{ 
                if (!name.endsWith("_xml")) {
                  a.put(name, formatClob(r.getClob(columnName))); 
                } else {
                  x.xml = formatClob(r.getClob(columnName));
                }
              }));
      break;
      
    case Types.BLOB:
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
      if (columnMappings.containsKey(norm(columnName)) && columnMappings.get(norm(columnName)).endsWith("_txt")) {
        createAttributeNames("src_%s_txt", norm(columnName)).forEach(
            name -> attributeInjectors.add((a,x,r)->a.put(name, formatBlob(r.getBlob(columnName)))));
      }
      break;
  }
  
  return attributeInjectors;
}
 
Example 14
Source File: DataDrivenDBInputFormat.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 4 votes vote down vote up
/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits.
 */
protected DBSplitter getSplitter(int sqlDataType, long splitLimit) {
  switch (sqlDataType) {
  case Types.NUMERIC:
  case Types.DECIMAL:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new BigDecimalSplitter();

  case Types.BIT:
  case Types.BOOLEAN:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new BooleanSplitter();

  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
  case Types.BIGINT:
    return new IntegerSplitter();

  case Types.REAL:
  case Types.FLOAT:
  case Types.DOUBLE:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new FloatSplitter();

  case Types.NVARCHAR:
  case Types.NCHAR:
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new NTextSplitter();

  case Types.CHAR:
  case Types.VARCHAR:
  case Types.LONGVARCHAR:
    if(splitLimit >= 0) {
       throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return new TextSplitter();

  case Types.DATE:
  case Types.TIME:
  case Types.TIMESTAMP:
    return new DateSplitter();

  default:
    // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
    // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT.
    if(splitLimit >= 0) {
      throw new IllegalArgumentException("split-limit is supported only with Integer and Date columns");
    }
    return null;
  }
}
 
Example 15
Source File: ParserUtils.java    From CodeGen with MIT License 4 votes vote down vote up
/**
 * 根据Types获取字段类型
 *
 * @see Types
 * @return 对应字段的java类型
 */
public static FieldType getFieldType(Integer sqlType) {
    FieldType fieldType = sqlTypes.get(UNKNOWN_FIELD);
    if (sqlType == null) {
        return fieldType;
    }

    // https://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/mapping.html
    if (sqlType == Types.INTEGER) {
        fieldType = sqlTypes.get("INTEGER");
    } else if (sqlType == Types.VARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.CHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.LONGVARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.NVARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.NCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.LONGNVARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.NUMERIC) {
        fieldType = sqlTypes.get("DECIMAL");
    } else if (sqlType == Types.DECIMAL) {
        fieldType = sqlTypes.get("DECIMAL");
    } else if (sqlType == Types.BIT) {
        fieldType = sqlTypes.get("BOOLEAN");
    } else if (sqlType == Types.BOOLEAN) {
        fieldType = sqlTypes.get("BOOLEAN");
    } else if (sqlType == Types.TINYINT) {
        fieldType = sqlTypes.get("INTEGER");
    } else if (sqlType == Types.SMALLINT) {
        fieldType = sqlTypes.get("INTEGER");
    } else if (sqlType == Types.BIGINT) {
        fieldType = sqlTypes.get("BIGINT");
    } else if (sqlType == Types.REAL) {
        fieldType = sqlTypes.get("REAL");
    } else if (sqlType == Types.FLOAT) {
        fieldType = sqlTypes.get("FLOAT");
    } else if (sqlType == Types.DOUBLE) {
        fieldType = sqlTypes.get("DOUBLE");
    } else if (sqlType == Types.DATE) {
        // java.sql.Date ?
        fieldType = sqlTypes.get("DATE");
    } else if (sqlType == Types.TIME) {
        // java.sql.Time ?
        fieldType = sqlTypes.get("TIME");
    } else if (sqlType == Types.TIMESTAMP) {
        // java.sql.Timestamp ?
        fieldType = sqlTypes.get("TIMESTAMP");
    } else if (sqlType == Types.BINARY
            || sqlType == Types.VARBINARY) {
        fieldType = sqlTypes.get("BINARY");
    } else if (sqlType == Types.CLOB) {
        fieldType = sqlTypes.get("CLOB");
    } else if (sqlType == Types.BLOB
            || sqlType == Types.LONGVARBINARY) {
        fieldType = sqlTypes.get("BLOB");
    } else {
        // DISTINCT, ARRAY, STRUCT, REF, JAVA_OBJECT.
        return fieldType;
    }
    return fieldType;
}
 
Example 16
Source File: TypeId.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Get a TypeId of the given JDBC type.  This factory method is
 * intended to be used for built-in types.  For user-defined types,
 * we will need a factory method that takes a Java type name.
 *
 * @param JDBCTypeId The JDBC Id of the type, as listed in
 *                   java.sql.Types
 * @return The appropriate TypeId, or null if there is no such
 * TypeId.
 */

public static TypeId getBuiltInTypeId(int JDBCTypeId){

    switch(JDBCTypeId){
        case Types.TINYINT:
            return TINYINT_ID;
        case Types.SMALLINT:
            return SMALLINT_ID;
        case Types.INTEGER:
            return INTEGER_ID;
        case Types.BIGINT:
            return BIGINT_ID;
        case Types.REAL:
            return REAL_ID;
        case Types.FLOAT:
        case Types.DOUBLE:
            return DOUBLE_ID;
        case Types.DECIMAL:
            return DECIMAL_ID;
        case Types.NUMERIC:
            return NUMERIC_ID;
        case Types.CHAR:
            return CHAR_ID;
        case Types.VARCHAR:
            return VARCHAR_ID;
        case Types.DATE:
            return DATE_ID;
        case Types.TIME:
            return TIME_ID;
        case Types.TIMESTAMP:
            return TIMESTAMP_ID;
        case Types.BIT:
        case Types.BOOLEAN:
            return BOOLEAN_ID;
        case Types.BINARY:
            return BIT_ID;
        case Types.VARBINARY:
            return VARBIT_ID;
        case Types.LONGVARBINARY:
            return LONGVARBIT_ID;
        case Types.LONGVARCHAR:
            return LONGVARCHAR_ID;
        case Types.BLOB:
            return BLOB_ID;
        case Types.CLOB:
            return CLOB_ID;
        case JDBC40Translation.SQLXML:
            return XML_ID;
        case Types.ARRAY:
            return ARRAY_ID;
        default:
            return null;
    }
}
 
Example 17
Source File: AbstractJdbcPOJOOutputOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void setStatementParameters(PreparedStatement statement, Object tuple) throws SQLException
{
  final int size = columnDataTypes.size();
  for (int i = 0; i < size; i++) {
    final int type = columnDataTypes.get(i);
    ActiveFieldInfo activeFieldInfo = columnFieldGetters.get(i);
    switch (type) {
      case (Types.CHAR):
      case (Types.VARCHAR):
        statement.setString(i + 1, ((Getter<Object, String>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.BOOLEAN):
        statement.setBoolean(i + 1, ((GetterBoolean<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.TINYINT):
        statement.setByte(i + 1, ((PojoUtils.GetterByte<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.SMALLINT):
        statement.setShort(i + 1, ((GetterShort<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.INTEGER):
        statement.setInt(i + 1, ((GetterInt<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.BIGINT):
        statement.setLong(i + 1, ((GetterLong<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.FLOAT):
        statement.setFloat(i + 1, ((GetterFloat<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.DOUBLE):
        statement.setDouble(i + 1, ((GetterDouble<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.DECIMAL:
        statement.setBigDecimal(i + 1, ((Getter<Object, BigDecimal>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.TIMESTAMP:
        statement.setTimestamp(i + 1, ((Getter<Object, Timestamp>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.TIME:
        statement.setTime(i + 1, ((Getter<Object, Time>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.DATE:
        statement.setDate(i + 1, ((Getter<Object, Date>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      default:
        handleUnknownDataType(type, tuple, activeFieldInfo);
        break;
    }
  }
}
 
Example 18
Source File: Converters.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Get JDBC {@link Types} type for given {@link GFXDType}.
 */
public static int getJdbcType(GFXDType type) {
  switch (type) {
    case ARRAY:
      return Types.ARRAY;
    case BIGINT:
      return Types.BIGINT;
    case BINARY:
      return Types.BINARY;
    case BLOB:
      return Types.BLOB;
    case BOOLEAN:
      return Types.BOOLEAN;
    case CHAR:
      return Types.CHAR;
    case CLOB:
      return Types.CLOB;
    case DATALINK:
      return Types.DATALINK;
    case DATE:
      return Types.DATE;
    case DECIMAL:
      return Types.DECIMAL;
    case DISTINCT:
      return Types.DISTINCT;
    case DOUBLE:
      return Types.DOUBLE;
    case FLOAT:
      return Types.FLOAT;
    case INTEGER:
      return Types.INTEGER;
    case JAVA_OBJECT:
      return Types.JAVA_OBJECT;
    case JSON_OBJECT:
      return TYPE_JSON_OBJECT;
    case LONGNVARCHAR:
      return Types.LONGNVARCHAR;
    case LONGVARBINARY:
      return Types.LONGVARBINARY;
    case LONGVARCHAR:
      return Types.LONGVARCHAR;
    case NCHAR:
      return Types.NCHAR;
    case NCLOB:
      return Types.NCLOB;
    case NULLTYPE:
      return Types.NULL;
    case NVARCHAR:
      return Types.NVARCHAR;
    case OTHER:
      return Types.OTHER;
    case PDX_OBJECT:
      return TYPE_PDX_OBJECT;
    case REAL:
      return Types.REAL;
    case REF:
      return Types.REF;
    case ROWID:
      return Types.ROWID;
    case SMALLINT:
      return Types.SMALLINT;
    case SQLXML:
      return Types.SQLXML;
    case STRUCT:
      return Types.STRUCT;
    case TIME:
      return Types.TIME;
    case TIMESTAMP:
      return Types.TIMESTAMP;
    case TINYINT:
      return Types.TINYINT;
    case VARBINARY:
      return Types.VARBINARY;
    case VARCHAR:
      return Types.VARCHAR;
    default:
      return Types.OTHER;
  }
}
 
Example 19
Source File: JDBCServiceMethod.java    From diirt with MIT License 4 votes vote down vote up
/**
 * Maps a result set to a VTable.
 */
static VTable resultSetToVTable(ResultSet resultSet) throws SQLException {
    ResultSetMetaData metaData = resultSet.getMetaData();
    int nColumns = metaData.getColumnCount();
    List<Class<?>> types = new ArrayList<>(nColumns);
    List<Object> data = new ArrayList<>(nColumns);
    List<String> names = new ArrayList<>(nColumns);
    for (int j = 1; j <= nColumns; j++) {
        names.add(metaData.getColumnName(j));
        switch (metaData.getColumnType(j)) {
            case Types.DOUBLE:
            case Types.FLOAT:
                // XXX: NUMERIC should be BigInteger
            case Types.NUMERIC:
                // XXX: Integers should be Long/Int
            case Types.INTEGER:
            case Types.TINYINT:
            case Types.BIGINT:
            case Types.SMALLINT:
                types.add(double.class);
                data.add(new CircularBufferDouble(Integer.MAX_VALUE));
                break;

            case Types.LONGNVARCHAR:
            case Types.CHAR:
            case Types.VARCHAR:
                // XXX: should be a booloean
            case Types.BOOLEAN:
            case Types.BIT:
                types.add(String.class);
                data.add(new ArrayList<>());
                break;

            case Types.TIMESTAMP:
                types.add(Instant.class);
                data.add(new ArrayList<>());
                break;

            default:
                if ("java.lang.String".equals(metaData.getColumnClassName(j))) {
                    types.add(String.class);
                    data.add(new ArrayList<>());
                } else {
                    throw new IllegalArgumentException("Unsupported type " + metaData.getColumnTypeName(j));
                }

        }
    }

    while (resultSet.next()) {
        for (int i = 0; i < nColumns; i++) {
            Class<?> type = types.get(i);
            if (type.equals(String.class)) {
                @SuppressWarnings("unchecked")
                List<String> strings = (List<String>) data.get(i);
                strings.add(resultSet.getString(i+1));
            } else if (type.equals(Instant.class)) {
                @SuppressWarnings("unchecked")
                List<Instant> timestamps = (List<Instant>) data.get(i);
                java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp(i+1);
                if (sqlTimestamp == null) {
                    timestamps.add(null);
                } else {
                    timestamps.add((new Date(sqlTimestamp.getTime())).toInstant());
                }
            } else if (type.equals(double.class)) {
                ((CircularBufferDouble) data.get(i)).addDouble(resultSet.getDouble(i+1));
            }
        }
    }

    return ValueFactory.newVTable(types, names, data);
}
 
Example 20
Source File: SqoopHCatUtilities.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 4 votes vote down vote up
/**
 * Resolve a database-specific type to HCat data type. Largely follows Sqoop's
 * hive translation.
 * @param sqlType
 *          sql type
 * @return hcat type
 */
public static String toHCatType(int sqlType) {
  switch (sqlType) {

  // Ideally TINYINT and SMALLINT should be mapped to their
  // HCat equivalents tinyint and smallint respectively
  // But the Sqoop Java type conversion has them mapped to Integer
  // Even though the referenced Java doc clearly recommends otherwise.
  // Changing this now can cause many of the sequence file usages to
  // break as value class implementations will change. So, we
  // just use the same behavior here.
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.INTEGER:
      return "int";

    case Types.VARCHAR:
      return "varchar";
    case Types.CHAR:
      return "char";
    case Types.LONGVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.CLOB:
      return "string";

    case Types.FLOAT:
    case Types.REAL:
      return "float";

    case Types.NUMERIC:
    case Types.DECIMAL:
      return "decimal";

    case Types.DOUBLE:
      return "double";

    case Types.BIT:
    case Types.BOOLEAN:
      return "boolean";

    case Types.BIGINT:
      return "bigint";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
    case Types.LONGVARBINARY:
      return "binary";

    default:
      throw new IllegalArgumentException(
        "Cannot convert SQL type to HCatalog type " + sqlType);
  }
}