Java Code Examples for java.sql.JDBCType

The following examples show how to use java.sql.JDBCType. These examples are extracted from open source projects. 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 Project: das   Source File: DatabaseSet.java    License: Apache License 2.0 6 votes vote down vote up
public DatabasesetDefinition() {
       super("databaseset");
id = column("id", JDBCType.BIGINT);
name = column("name", JDBCType.VARCHAR);
dbType = column("db_type", JDBCType.TINYINT);
strategyType = column("strategy_type", JDBCType.TINYINT);
className = column("class_name", JDBCType.VARCHAR);
strategySource = column("strategy_source", JDBCType.LONGVARCHAR);
groupId = column("group_id", JDBCType.BIGINT);
dynamicStrategyId = column("dynamic_strategy_id", JDBCType.INTEGER);
updateUserNo = column("update_user_no", JDBCType.VARCHAR);
insertTime = column("insert_time", JDBCType.TIMESTAMP);
updateTime = column("update_time", JDBCType.TIMESTAMP);
         setColumnDefinitions(
                   id, name, dbType, strategyType, className, strategySource, groupId, 
                   dynamicStrategyId, updateUserNo, insertTime, updateTime
       );
   }
 
Example 2
Source Project: presto   Source File: ShardOrganizerUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static Object getValue(ResultSet resultSet, Type type, String columnName, JDBCType jdbcType)
        throws SQLException
{
    switch (jdbcType) {
        case BOOLEAN:
            return resultSet.getBoolean(columnName);
        case INTEGER:
            return resultSet.getInt(columnName);
        case BIGINT:
            return resultSet.getLong(columnName);
        case DOUBLE:
            return resultSet.getDouble(columnName);
        case VARBINARY:
            return wrappedBuffer(resultSet.getBytes(columnName)).toStringUtf8();
    }
    throw new IllegalArgumentException("Unhandled type: " + type);
}
 
Example 3
Source Project: beam   Source File: JdbcIOTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadRowsWithDataSourceConfiguration() {
  PCollection<Row> rows =
      pipeline.apply(
          JdbcIO.readRows()
              .withDataSourceConfiguration(JdbcIO.DataSourceConfiguration.create(dataSource))
              .withQuery(String.format("select name,id from %s where name = ?", readTableName))
              .withStatementPreparator(
                  preparedStatement ->
                      preparedStatement.setString(1, TestRow.getNameForSeed(1))));

  Schema expectedSchema =
      Schema.of(
          Schema.Field.of("NAME", LogicalTypes.variableLengthString(JDBCType.VARCHAR, 500))
              .withNullable(true),
          Schema.Field.of("ID", Schema.FieldType.INT32).withNullable(true));

  assertEquals(expectedSchema, rows.getSchema());

  PCollection<Row> output = rows.apply(Select.fieldNames("NAME", "ID"));
  PAssert.that(output)
      .containsInAnyOrder(
          ImmutableList.of(Row.withSchema(expectedSchema).addValues("Testval1", 1).build()));

  pipeline.run();
}
 
Example 4
@DataProvider(name = "rowsetUsingDataTypes")
protected Object[][] rowsetUsingDataTypes() throws Exception {

    CachedRowSet rs = createDataTypesRowSet();
    return new Object[][]{
        {rs, JDBCType.INTEGER},
        {rs, JDBCType.CHAR},
        {rs, JDBCType.VARCHAR},
        {rs, JDBCType.BIGINT},
        {rs, JDBCType.BOOLEAN},
        {rs, JDBCType.SMALLINT},
        {rs, JDBCType.DOUBLE},
        {rs, JDBCType.DECIMAL},
        {rs, JDBCType.REAL},
        {rs, JDBCType.TINYINT},
        {rs, JDBCType.DATE},
        {rs, JDBCType.TIME},
        {rs, JDBCType.TIMESTAMP},
        {rs, JDBCType.VARBINARY},
        {rs, JDBCType.ARRAY},
        {rs, JDBCType.REF},
        {rs, JDBCType.FLOAT}
    };
}
 
Example 5
Source Project: das   Source File: CallBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCallWithOutParam() throws Exception {
    for (int i = 0; i < DB_MODE; i++) {
        CallBuilder cb = new CallBuilder(SP_WITH_OUT_PARAM);
        cb.registerInput("v_id", JDBCType.INTEGER, 4);
        cb.registerOutput("count", JDBCType.INTEGER);
        cb.hints().inShard(i);

        dao.call(cb);

        long count = cb.getOutput("count");
        assertEquals(3, count);
        Person p = new Person();
        p.setPeopleID(4);
        assertNull(dao.queryByPk(p, Hints.hints().inShard(i)));
    }
}
 
Example 6
private void compareRowSets(CachedRowSet crs, CachedRowSet crs1) throws Exception {

        int rows = crs.size();
        assertTrue(rows == crs1.size());

        ResultSetMetaData rsmd = crs.getMetaData();

        compareMetaData(rsmd, crs1.getMetaData());
        int cols = rsmd.getColumnCount();

        for (int row = 1; row <= rows; row++) {
            crs.absolute((row));
            crs1.absolute(row);
            for (int col = 1; col <= cols; col++) {
                compareColumnValue(JDBCType.valueOf(rsmd.getColumnType(col)),
                        crs, crs1, col);
            }
        }

    }
 
Example 7
Source Project: das   Source File: DasGroup.java    License: Apache License 2.0 5 votes vote down vote up
public DalGroupDefinition() {
       super("dal_group");
id = column("id", JDBCType.BIGINT);
groupName = column("group_name", JDBCType.VARCHAR);
groupComment = column("group_comment", JDBCType.LONGVARCHAR);
insertTime = column("insert_time", JDBCType.TIMESTAMP);
updateTime = column("update_time", JDBCType.TIMESTAMP);
updateUserNo = column("update_user_no", JDBCType.VARCHAR);
         setColumnDefinitions(
                   id, groupName, groupComment, insertTime, updateTime, updateUserNo
       );
   }
 
Example 8
Source Project: das   Source File: UserGroup.java    License: Apache License 2.0 5 votes vote down vote up
public UserGroupDefinition() {
       super("user_group");
id = column("id", JDBCType.BIGINT);
userId = column("user_id", JDBCType.INTEGER);
groupId = column("group_id", JDBCType.INTEGER);
role = column("role", JDBCType.TINYINT);
optUser = column("opt_user", JDBCType.TINYINT);
insertTime = column("insert_time", JDBCType.TIMESTAMP);
updateTime = column("update_time", JDBCType.TIMESTAMP);
updateUserNo = column("update_user_no", JDBCType.VARCHAR);
         setColumnDefinitions(
                   id, userId, groupId, role, optUser, insertTime, updateTime, updateUserNo
       );
   }
 
Example 9
Source Project: das   Source File: AbstractDalParser.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractDalParser(
		String dataBaseName,
		String tableName,
		String[] columns,
		String[] primaryKeyColumns,
		JDBCType[] columnTypes) {
	this.dataBaseName = dataBaseName;
	this.tableName = tableName;
	this.columns = columns;
	this.updatableColumnNames = columns;
	this.insertableColumnNames = columns;
	this.primaryKeyColumns = primaryKeyColumns;
	this.columnTypes = columnTypes;
}
 
Example 10
Source Project: FoxTelem   Source File: StatementsTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test for PreparedStatement.executeLargeUpdate().
 * Validate update count returned and generated keys.
 * Case: explicitly requesting generated keys.
 */
public void testPrepStmtExecuteLargeUpdateExplicitGeneratedKeys() throws Exception {
    createTable("testExecuteLargeUpdate", "(id BIGINT AUTO_INCREMENT PRIMARY KEY, n INT)");

    this.pstmt = this.conn.prepareStatement("INSERT INTO testExecuteLargeUpdate (n) VALUES (?), (?), (?), (?), (?)", Statement.RETURN_GENERATED_KEYS);
    this.pstmt.setInt(1, 1);
    this.pstmt.setInt(2, 2);
    this.pstmt.setInt(3, 3);
    this.pstmt.setInt(4, 4);
    this.pstmt.setInt(5, 5);

    long count = this.pstmt.executeLargeUpdate();
    assertEquals(5, count);
    assertEquals(5, this.pstmt.getLargeUpdateCount());

    this.rs = this.pstmt.getGeneratedKeys();

    ResultSetMetaData rsmd = this.rs.getMetaData();
    assertEquals(1, rsmd.getColumnCount());
    assertEquals(JDBCType.BIGINT.getVendorTypeNumber().intValue(), rsmd.getColumnType(1));
    assertEquals(20, rsmd.getColumnDisplaySize(1));

    long generatedKey = 0;
    while (this.rs.next()) {
        assertEquals(++generatedKey, this.rs.getLong(1));
    }
    assertEquals(5, generatedKey);
    this.rs.close();
}
 
Example 11
Source Project: das   Source File: SqlBuilderParameterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testColumnParameter( ) {
    SqlBuilder builder = new SqlBuilder();
    PersonDefinition p = Person.PERSON;
    builder.where(p.CityID.equal(1), AND, p.CountryID.greaterThan(2), OR, p.Name.like(null).nullable());
    List<Parameter> params =  builder.buildParameters();
    assertEquals(2, params.size());
    
    assertX(params.get(0), "CityID", JDBCType.INTEGER, 1);
    assertX(params.get(1), "CountryID", JDBCType.INTEGER, 2);
}
 
Example 12
Source Project: Komondor   Source File: StatementsTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test for PreparedStatement.executeLargeUpdate().
 * Validate update count returned and generated keys.
 * Case: explicitly requesting generated keys.
 */
public void testPrepStmtExecuteLargeUpdateExplicitGeneratedKeys() throws Exception {
    createTable("testExecuteLargeUpdate", "(id BIGINT AUTO_INCREMENT PRIMARY KEY, n INT)");

    this.pstmt = this.conn.prepareStatement("INSERT INTO testExecuteLargeUpdate (n) VALUES (?), (?), (?), (?), (?)", Statement.RETURN_GENERATED_KEYS);
    this.pstmt.setInt(1, 1);
    this.pstmt.setInt(2, 2);
    this.pstmt.setInt(3, 3);
    this.pstmt.setInt(4, 4);
    this.pstmt.setInt(5, 5);

    long count = this.pstmt.executeLargeUpdate();
    assertEquals(5, count);
    assertEquals(5, this.pstmt.getLargeUpdateCount());

    this.rs = this.pstmt.getGeneratedKeys();

    ResultSetMetaData rsmd = this.rs.getMetaData();
    assertEquals(1, rsmd.getColumnCount());
    assertEquals(JDBCType.BIGINT.getVendorTypeNumber().intValue(), rsmd.getColumnType(1));
    assertEquals(20, rsmd.getColumnDisplaySize(1));

    long generatedKey = 0;
    while (this.rs.next()) {
        assertEquals(++generatedKey, this.rs.getLong(1));
    }
    assertEquals(5, generatedKey);
    this.rs.close();
}
 
Example 13
Source Project: das   Source File: UserProject.java    License: Apache License 2.0 5 votes vote down vote up
public UserProjectDefinition() {
       super("user_project");
id = column("id", JDBCType.BIGINT);
projectId = column("project_id", JDBCType.INTEGER);
userId = column("user_id", JDBCType.INTEGER);
         setColumnDefinitions(
                   id, projectId, userId
       );
   }
 
Example 14
Source Project: das   Source File: ProjectDbsetRelation.java    License: Apache License 2.0 5 votes vote down vote up
public ProjectDbsetRelationDefinition() {
       super("project_dbset_relation");
id = column("id", JDBCType.BIGINT);
dbsetId = column("dbset_id", JDBCType.INTEGER);
projectId = column("project_id", JDBCType.INTEGER);
updateUserNo = column("update_user_no", JDBCType.VARCHAR);
insertTime = column("insert_time", JDBCType.TIMESTAMP);
updateTime = column("update_time", JDBCType.TIMESTAMP);
         setColumnDefinitions(
                   id, dbsetId, projectId, updateUserNo, insertTime, updateTime
       );
   }
 
Example 15
Source Project: das   Source File: BuilderUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static List<ParameterDefinition> fromDefinition(List<DasParameterDefinition> definitions) {
    return toList(definitions, p -> {
                return new ParameterDefinition(fromDasParameterDirection(p.getDirection()), p.getName(),
                        JDBCType.valueOf(p.getJdbcType()), p.isInValues());
            }
    );
}
 
Example 16
Source Project: presto   Source File: PhoenixClient.java    License: Apache License 2.0 5 votes vote down vote up
private JdbcTypeHandle getArrayElementTypeHandle(JdbcTypeHandle arrayTypeHandle)
{
    String arrayTypeName = arrayTypeHandle.getJdbcTypeName()
            .orElseThrow(() -> new PrestoException(PHOENIX_METADATA_ERROR, "Type name is missing for jdbc type: " + JDBCType.valueOf(arrayTypeHandle.getJdbcType())));
    checkArgument(arrayTypeName.endsWith(" ARRAY"), "array type must end with ' ARRAY'");
    arrayTypeName = arrayTypeName.substring(0, arrayTypeName.length() - " ARRAY".length());
    return new JdbcTypeHandle(
            PDataType.fromSqlTypeName(arrayTypeName).getSqlType(),
            Optional.of(arrayTypeName),
            arrayTypeHandle.getColumnSize(),
            arrayTypeHandle.getDecimalDigits(),
            arrayTypeHandle.getArrayDimensions());
}
 
Example 17
Source Project: Mycat2   Source File: ShowReplicaCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@NotNull
public static ResultSetBuilder getResultSet() {
    ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
    resultSetBuilder.addColumnInfo("NAME", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("SWITCH_TYPE", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("MAX_REQUEST_COUNT", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("TYPE", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("WRITE_DS", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("READ_DS", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("WRITE_L", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("READ_L", JDBCType.VARCHAR);
    resultSetBuilder.addColumnInfo("AVAILABLE", JDBCType.BOOLEAN);
    Collection<ReplicaDataSourceSelector> values =
            ReplicaSelectorRuntime.INSTANCE.getReplicaMap().values();
    MycatConfig mycatConfig = RootHelper.INSTANCE.getConfigProvider().currentConfig();

    Map<String, ClusterRootConfig.ClusterConfig> clusterConfigMap = mycatConfig.getCluster().getClusters().stream().collect(Collectors.toMap(k -> k.getName(), v -> v));

    for (ReplicaDataSourceSelector value : values) {
        String NAME = value.getName();

        Optional<ClusterRootConfig.ClusterConfig> e = Optional.ofNullable(clusterConfigMap.get(NAME));

        ReplicaSwitchType SWITCH_TYPE = value.getSwitchType();
        int MAX_REQUEST_COUNT = value.maxRequestCount();
        String TYPE = value.getBalanceType().name();
        String WRITE_DS = ((List<PhysicsInstance>) value.getWriteDataSource()).stream().map(i -> i.getName()).collect(Collectors.joining(","));
        String READ_DS = (value.getReadDataSource()).stream().map(i -> i.getName()).collect(Collectors.joining(","));
        String WL = Optional.ofNullable(value.getDefaultWriteLoadBalanceStrategy()).map(i -> i.getClass().getName()).orElse(null);
        String RL = Optional.ofNullable(value.getDefaultReadLoadBalanceStrategy()).map(i -> i.getClass().getName()).orElse(null);
        boolean AVAILABLE = ((List<PhysicsInstance>) value.getWriteDataSource()).stream().anyMatch(PhysicsInstance::isAlive);

        resultSetBuilder.addObjectRowPayload(
                Arrays.asList(NAME, SWITCH_TYPE, MAX_REQUEST_COUNT, TYPE,
                        WRITE_DS, READ_DS,
                        WL, RL,AVAILABLE
                ));
    }
    return resultSetBuilder;
}
 
Example 18
@Test
public void shouldFetchStoredProcedureMetadataWithSingleParameter() throws SQLException {
    final Connection connection = mock(Connection.class);

    final DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
    when(connection.getMetaData()).thenReturn(databaseMetaData);

    when(databaseMetaData.getDatabaseProductName()).thenReturn("POSTGRESQL");

    final ResultSet result = mock(ResultSet.class);
    when(databaseMetaData.getProcedureColumns("catalog", "schema", "procedureName", null)).thenReturn(result);

    when(result.next()).thenReturn(true, false);
    when(result.getString("COLUMN_NAME")).thenReturn("A");
    when(result.getInt("COLUMN_TYPE")).thenReturn(ColumnMode.IN.ordinal());
    when(result.getInt("DATA_TYPE")).thenReturn(JDBCType.INTEGER.getVendorTypeNumber());

    final StoredProcedureMetadata metadata = SqlSupport.getStoredProcedureMetadata(connection, "catalog", "schema",
        "procedureName");

    final StoredProcedureColumn columnA = new StoredProcedureColumn();
    columnA.setJdbcType(JDBCType.INTEGER);
    columnA.setName("A");
    columnA.setOrdinal(0);
    columnA.setMode(ColumnMode.IN);

    assertThat(metadata.getName()).isEqualTo("procedureName");
    assertThat(metadata.getTemplate()).isEqualTo("procedureName(INTEGER ${body[A]})");
    final List<StoredProcedureColumn> columnList = metadata.getColumnList();
    assertThat(columnList.get(0)).isEqualToComparingFieldByField(columnA);
}
 
Example 19
Source Project: dragonwell8_jdk   Source File: BaseTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "jdbcTypes")
protected Object[][] jdbcTypes() {
    Object[][] o = new Object[JDBCType.values().length][1];
    int pos = 0;
    for (JDBCType c : JDBCType.values()) {
        o[pos++][0] = c.getVendorTypeNumber();
    }
    return o;
}
 
Example 20
Source Project: hsweb-framework   Source File: SimpleDynamicFormService.java    License: Apache License 2.0 5 votes vote down vote up
protected RDBColumnMetaData createPrimaryKeyColumn() {
    RDBColumnMetaData id = new RDBColumnMetaData();
    id.setName("id");
    id.setJdbcType(JDBCType.VARCHAR);
    id.setJavaType(String.class);
    id.setLength(32);
    id.setDefaultValue(IDGenerator.MD5::generate);
    id.setComment("主键");
    id.setPrimaryKey(true);
    id.setNotNull(true);
    id.setProperty("read-only", true);
    return id;
}
 
Example 21
Source Project: das   Source File: Person.java    License: Apache License 2.0 5 votes vote down vote up
public PersonDefinition() {
    super("person");
    PeopleID = column("PeopleID", JDBCType.INTEGER);
    Name = column("Name", JDBCType.VARCHAR);
    CityID = column("CityID", JDBCType.INTEGER);
    ProvinceID = column("ProvinceID", JDBCType.INTEGER);
    CountryID = column("CountryID", JDBCType.INTEGER);
    DataChange_LastTime = column("DataChange_LastTime", JDBCType.TIMESTAMP);
    setColumnDefinitions(PeopleID, Name, CityID, ProvinceID, CountryID, DataChange_LastTime);
}
 
Example 22
Source Project: das   Source File: ColumnTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTypeAlias( ) {
    Table table = new Table("t");
    Column c = new Column(table, "col", JDBCType.VARBINARY);
    assertEquals("col", c.getColumnName());
    assertFalse(c.getAlias().isPresent());
    c.as("c");
    assertTrue(c.getAlias().isPresent());
    
    assertEquals(JDBCType.VARBINARY, c.getType());
    assertEquals("t.col AS c", c.build(new DefaultBuilderContext()));
}
 
Example 23
Source Project: presto   Source File: TestHiveStorageFormats.java    License: Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "storage_formats_with_null_format", groups = STORAGE_FORMATS)
public void testInsertAndSelectWithNullFormat(StorageFormat storageFormat)
{
    String nullFormat = "null_value";
    String tableName = format("test_storage_format_%s_insert_and_select_with_null_format",
            storageFormat.getName());
    query(format("CREATE TABLE %s (value VARCHAR) " +
                    "WITH (format = '%s', null_format = '%s')",
            tableName,
            storageFormat.getName(),
            nullFormat));

    // \N is the default null format
    String[] values = new String[] {nullFormat, null, "non-null", "", "\\N"};
    Row[] storedValues = Arrays.stream(values).map(Row::row).toArray(Row[]::new);
    storedValues[0] = row((Object) null); // if you put in the null format, it saves as null

    String placeholders = String.join(", ", Collections.nCopies(values.length, "(?)"));
    query(format("INSERT INTO %s VALUES %s", tableName, placeholders),
            Arrays.stream(values)
                    .map(value -> param(JDBCType.VARCHAR, value))
                    .toArray(QueryParam[]::new));

    assertThat(query(format("SELECT * FROM %s", tableName))).containsOnly(storedValues);

    onHive().executeQuery(format("DROP TABLE %s", tableName));
}
 
Example 24
@Override
public void handle(MycatRequest request, MycatDataContext context, Response response) {
    ResultSetBuilder builder = ResultSetBuilder.create();
    builder.addColumnInfo("SCHEMA_NAME", JDBCType.VARCHAR)
            .addColumnInfo("DEFAULT_TARGET_NAME",JDBCType.VARCHAR)
            .addColumnInfo("TABLE_NAMES",JDBCType.VARCHAR);
    for (SchemaHandler value : MetadataManager.INSTANCE.getSchemaMap().values()) {
        String SCHEMA_NAME = value.getName();
        String DEFAULT_TARGET_NAME = value.defaultTargetName();
        String TABLE_NAMES = String.join(",",value.logicTables().keySet());
        builder.addObjectRowPayload(Arrays.asList(SCHEMA_NAME,DEFAULT_TARGET_NAME,TABLE_NAMES));
    }
    response.sendResultSet(()->builder.build());
}
 
Example 25
Source Project: das   Source File: ParameterTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertX(Parameter param, ParameterDirection dir, String name, JDBCType type, Object value, boolean inValues) {
    assertEquals(dir, param.getDirection());
    assertEquals(name, param.getName());
    assertEquals(type, param.getType());
    if(inValues)
        assertEquals(value, param.getValues());
    else
        assertEquals(value, param.getValue());

    assertEquals(inValues, param.isInValues());
}
 
Example 26
Source Project: das   Source File: SqlBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLimitCountDef( ) {
    SqlBuilder sb = new SqlBuilder();
    sb.limit(ParameterDefinition.integerVar("start"));
    assertEquals("LIMIT ?", sb.build(ctx));
    List<ParameterDefinition> pl = sb.buildDefinitions();
    assertEquals(1, pl.size());
    assertX(pl.get(0), "start", JDBCType.INTEGER, false);
}
 
Example 27
Source Project: das   Source File: SqlBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLimitCount( ) {
    SqlBuilder sb = new SqlBuilder();
    sb.limit(10);
    List<Parameter> pl = sb.buildParameters();
    assertEquals(1, pl.size());
    Parameter p = pl.get(0);
    assertX(pl.get(0), "", JDBCType.INTEGER, 10);
}
 
Example 28
@Test(dataProvider = "rowsetUsingDataTypes")
public void commonCachedRowSetTest0040(CachedRowSet rs, JDBCType type) throws Exception {
    rs.beforeFirst();
    assertTrue(rs.next());
    switch (type) {
        case INTEGER:
            assertFalse(rs.columnUpdated(1));
            rs.updateInt(1, Integer.MIN_VALUE);
            assertTrue(rs.columnUpdated(1));
            break;
        case CHAR:
            assertFalse(rs.columnUpdated(2));
            rs.updateString(2, "foo");
            assertTrue(rs.columnUpdated(2));
            break;
        case VARCHAR:
            assertFalse(rs.columnUpdated(3));
            rs.updateString(3, "foo");
            assertTrue(rs.columnUpdated(3));
            break;
        case BIGINT:
            assertFalse(rs.columnUpdated(4));
            rs.updateLong(4, Long.MIN_VALUE);
            assertTrue(rs.columnUpdated(4));
            break;
        case BOOLEAN:
            assertFalse(rs.columnUpdated(5));
            rs.updateBoolean(5, false);
            assertTrue(rs.columnUpdated(5));
            break;
        case SMALLINT:
            assertFalse(rs.columnUpdated(6));
            rs.updateShort(6, Short.MIN_VALUE);
            assertTrue(rs.columnUpdated(6));
            break;
        case DOUBLE:
            assertFalse(rs.columnUpdated(7));
            rs.updateDouble(7, Double.MIN_VALUE);
            assertTrue(rs.columnUpdated(7));
            break;
        case DECIMAL:
            assertFalse(rs.columnUpdated(8));
            rs.updateBigDecimal(8, BigDecimal.TEN);
            assertTrue(rs.columnUpdated(8));
            break;
        case REAL:
            assertFalse(rs.columnUpdated(9));
            rs.updateFloat(9, Float.MIN_VALUE);
            assertTrue(rs.columnUpdated(9));
            break;
        case TINYINT:
            assertFalse(rs.columnUpdated(10));
            rs.updateByte(10, Byte.MIN_VALUE);
            assertTrue(rs.columnUpdated(10));
            break;
        case DATE:
            assertFalse(rs.columnUpdated(11));
            rs.updateDate(11, Date.valueOf(LocalDate.now()));
            assertTrue(rs.columnUpdated(11));
            break;
        case TIME:
            assertFalse(rs.columnUpdated(12));
            rs.updateTime(12, Time.valueOf(LocalTime.now()));
            assertTrue(rs.columnUpdated(12));
            break;
        case TIMESTAMP:
            assertFalse(rs.columnUpdated(13));
            rs.updateTimestamp(13, Timestamp.valueOf(LocalDateTime.now()));
            assertTrue(rs.columnUpdated(13));
            break;
        case VARBINARY:
            assertFalse(rs.columnUpdated(14));
            rs.updateBytes(14, new byte[1]);
            assertTrue(rs.columnUpdated(14));
            break;
        case ARRAY:
            assertFalse(rs.columnUpdated(15));
            rs.updateArray(15, new StubArray("VARCHAR", new Object[10]));
            assertTrue(rs.columnUpdated(15));
            break;
        case REF:
            assertFalse(rs.columnUpdated(16));
            rs.updateRef(16, new StubRef("INTEGER", query));
            assertTrue(rs.columnUpdated(16));
            break;
        case FLOAT:
            assertFalse(rs.columnUpdated(17));
            rs.updateDouble(17, Double.MIN_NORMAL);
            assertTrue(rs.columnUpdated(17));
    }

}
 
Example 29
Source Project: syndesis   Source File: ColumnMetaData.java    License: Apache License 2.0 4 votes vote down vote up
public JDBCType getType() {
    return type;
}
 
Example 30
@Test(dataProvider = "rowsetUsingDataTypes")
public void commonCachedRowSetTest0041(CachedRowSet rs, JDBCType type) throws Exception {
    rs.beforeFirst();
    assertTrue(rs.next());
    switch (type) {
        case INTEGER:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[0]));
            rs.updateInt(DATATYPES_COLUMN_NAMES[0], Integer.MIN_VALUE);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[0]));
            break;
        case CHAR:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[1]));
            rs.updateString(DATATYPES_COLUMN_NAMES[1], "foo");
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[1]));
            break;
        case VARCHAR:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[2]));
            rs.updateString(DATATYPES_COLUMN_NAMES[2], "foo");
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[2]));
            break;
        case BIGINT:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[3]));
            rs.updateLong(DATATYPES_COLUMN_NAMES[3], Long.MIN_VALUE);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[3]));
            break;
        case BOOLEAN:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[4]));
            rs.updateBoolean(DATATYPES_COLUMN_NAMES[4], false);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[4]));
            break;
        case SMALLINT:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[5]));
            rs.updateShort(DATATYPES_COLUMN_NAMES[5], Short.MIN_VALUE);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[5]));
            break;
        case DOUBLE:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[6]));
            rs.updateDouble(DATATYPES_COLUMN_NAMES[6], Double.MIN_VALUE);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[6]));
            break;
        case DECIMAL:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[7]));
            rs.updateBigDecimal(DATATYPES_COLUMN_NAMES[7], BigDecimal.TEN);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[7]));
            break;
        case REAL:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[8]));
            rs.updateFloat(DATATYPES_COLUMN_NAMES[8], Float.MIN_VALUE);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[8]));
            break;
        case TINYINT:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[9]));
            rs.updateByte(DATATYPES_COLUMN_NAMES[9], Byte.MIN_VALUE);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[9]));
            break;
        case DATE:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[10]));
            rs.updateDate(DATATYPES_COLUMN_NAMES[10], Date.valueOf(LocalDate.now()));
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[10]));
            break;
        case TIME:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[11]));
            rs.updateTime(DATATYPES_COLUMN_NAMES[11], Time.valueOf(LocalTime.now()));
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[11]));
            break;
        case TIMESTAMP:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[12]));
            rs.updateTimestamp(DATATYPES_COLUMN_NAMES[12], Timestamp.valueOf(LocalDateTime.now()));
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[12]));
            break;
        case VARBINARY:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[13]));
            rs.updateBytes(DATATYPES_COLUMN_NAMES[13], new byte[1]);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[13]));
            break;
        case ARRAY:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[14]));
            rs.updateArray(DATATYPES_COLUMN_NAMES[14], new StubArray("VARCHAR", new Object[10]));
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[14]));
            break;
        case REF:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[15]));
            rs.updateRef(DATATYPES_COLUMN_NAMES[15], new StubRef("INTEGER", query));
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[15]));
            break;
        case FLOAT:
            assertFalse(rs.columnUpdated(DATATYPES_COLUMN_NAMES[16]));
            rs.updateDouble(DATATYPES_COLUMN_NAMES[16], Double.MIN_NORMAL);
            assertTrue(rs.columnUpdated(DATATYPES_COLUMN_NAMES[16]));
            break;
    }

}