java.sql.JDBCType Java Examples

The following examples show how to use java.sql.JDBCType. 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: CommonCachedRowSetTests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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 #2
Source File: JdbcIOTest.java    From beam with 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 #3
Source File: ShardOrganizerUtil.java    From presto with 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 #4
Source File: DatabaseSet.java    From das with 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 #5
Source File: CommonCachedRowSetTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 #6
Source File: CallBuilderTest.java    From das with 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 #7
Source File: DasGroup.java    From das with 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 File: ShowReplicaCommand.java    From Mycat2 with 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 #9
Source File: UserGroup.java    From das with 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 #10
Source File: SqlBuilderTest.java    From das with 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 #11
Source File: AbstractDalParser.java    From das with 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 #12
Source File: StatementsTest.java    From FoxTelem with 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 File: SqlBuilderTest.java    From das with 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 #14
Source File: UserProject.java    From das with 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 #15
Source File: SimpleDynamicFormService.java    From hsweb-framework with 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 #16
Source File: SqlBuilderParameterTest.java    From das with 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 #17
Source File: BaseTest.java    From dragonwell8_jdk with 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 #18
Source File: Person.java    From das with 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 #19
Source File: StatementsTest.java    From Komondor with 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 #20
Source File: ColumnTest.java    From das with 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 #21
Source File: ParameterTest.java    From das with 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 #22
Source File: ShowMetaDataSchemaCommand.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
@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 #23
Source File: SqlStoredConnectorMetaDataExtensionTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: BuilderUtils.java    From das with 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 #25
Source File: TestHiveStorageFormats.java    From presto with 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 #26
Source File: PhoenixClient.java    From presto with 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 #27
Source File: ProjectDbsetRelation.java    From das with 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 #28
Source File: CommonCachedRowSetTests.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@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 File: StatementsTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Helper method for *SetObject* tests.
 * Check unsupported types behavior for the given PreparedStatement with a single placeholder. If this is a CallableStatement then the placeholder must
 * coincide with a parameter named `param`.
 * 
 * @param prepStmt
 */
private void checkUnsupportedTypesBehavior(final PreparedStatement prepStmt) {
    final CallableStatement cstmt = prepStmt instanceof CallableStatement ? (CallableStatement) prepStmt : null;

    /*
     * Unsupported SQL types TIME_WITH_TIMEZONE and TIMESTAMP_WITH_TIMEZONE.
     */
    assertThrows(SQLFeatureNotSupportedException.class, "Unsupported SQL type: TIME_WITH_TIMEZONE", new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            prepStmt.setObject(1, OffsetTime.now(), JDBCType.TIME_WITH_TIMEZONE);
            return null;
        }
    });
    assertThrows(SQLFeatureNotSupportedException.class, "Unsupported SQL type: TIMESTAMP_WITH_TIMEZONE", new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            prepStmt.setObject(1, OffsetDateTime.now(), JDBCType.TIMESTAMP_WITH_TIMEZONE);
            return null;
        }
    });
    if (cstmt != null) {
        assertThrows(SQLFeatureNotSupportedException.class, "Unsupported SQL type: TIME_WITH_TIMEZONE", new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                cstmt.setObject("param", OffsetTime.now(), JDBCType.TIME_WITH_TIMEZONE);
                return null;
            }
        });
        assertThrows(SQLFeatureNotSupportedException.class, "Unsupported SQL type: TIMESTAMP_WITH_TIMEZONE", new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                cstmt.setObject("param", OffsetDateTime.now(), JDBCType.TIMESTAMP_WITH_TIMEZONE);
                return null;
            }
        });
    }
    /*
     * Unsupported SQL type REF_CURSOR.
     */
    assertThrows(SQLFeatureNotSupportedException.class, "Unsupported SQL type: REF_CURSOR", new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            prepStmt.setObject(1, new Object(), JDBCType.REF_CURSOR);
            return null;
        }
    });
    if (cstmt != null) {
        assertThrows(SQLFeatureNotSupportedException.class, "Unsupported SQL type: REF_CURSOR", new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                cstmt.setObject("param", new Object(), JDBCType.REF_CURSOR);
                return null;
            }
        });
    }
}
 
Example #30
Source File: BatchCallBuilder.java    From das with Apache License 2.0 4 votes vote down vote up
public BatchCallBuilder registerInput(String name, JDBCType type) {
    parameterDefinitions.add(new ParameterDefinition(ParameterDirection.Input, name, type, false));
    return this;
}