protected List<Object> getParameterJDBCValues() { List<TypedValue> typeValues = getParameterValues(); List<Object> jdbcValues = new ArrayList<Object>(typeValues.size()); for (TypedValue typeValue : typeValues) { jdbcValues.add(typeValue.toJdbc(getCalendar())); } return jdbcValues; }
@Override public ExecuteBatchResult executeBatch(StatementHandle h, List<List<TypedValue>> updateBatches) throws NoSuchStatementException { try { final StatementInfo info = statementCache.getIfPresent(h.id); if (null == info) { throw new NoSuchStatementException(h); } final PreparedStatement preparedStmt = (PreparedStatement) info.statement; int rowUpdate = 1; for (List<TypedValue> batch : updateBatches) { int i = 1; for (TypedValue value : batch) { // Set the TypedValue in the PreparedStatement try { preparedStmt.setObject(i, value.toJdbc(calendar)); i++; } catch (SQLException e) { throw new RuntimeException("Failed to set value on row #" + rowUpdate + " and column #" + i, e); } // Track the update number for better error messages rowUpdate++; } preparedStmt.addBatch(); } return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt)); } catch (SQLException e) { throw propagate(e); } }
@Override public ExecuteBatchResult executeBatch(StatementHandle h, List<List<TypedValue>> updateBatches) throws NoSuchStatementException { try { final StatementInfo info = statementCache.getIfPresent(h.id); if (null == info) { throw new NoSuchStatementException(h); } final PreparedStatement preparedStmt = (PreparedStatement) info.statement; int rowUpdate = 1; for (List<TypedValue> batch : updateBatches) { int i = 1; for (TypedValue value : batch) { // Set the TypedValue in the PreparedStatement try { preparedStmt.setObject(i, value.toJdbc(calendar)); i++; } catch (SQLException e) { throw new RuntimeException("Failed to set value on row #" + rowUpdate + " and column #" + i, e); } // Track the update number for better error messages rowUpdate++; } preparedStmt.addBatch(); } return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt)); } catch (SQLException e) { throw propagate(e); } }
for (int i = 0; i < parameterValues.size(); i++) { TypedValue o = parameterValues.get(i); preparedStatement.setObject(i + 1, o.toJdbc(calendar));
for (int i = 0; i < parameterValues.size(); i++) { TypedValue o = parameterValues.get(i); preparedStatement.setObject(i + 1, o.toJdbc(calendar));
for (int i = 0; i < parameterValues.size(); i++) { TypedValue o = parameterValues.get(i); preparedStatement.setObject(i + 1, o.toJdbc(calendar));
} else if (o instanceof TypedValue) { copy.add(((TypedValue) o).toJdbc(calendar)); } else {
} else if (o instanceof TypedValue) { copy.add(((TypedValue) o).toJdbc(calendar)); } else {
@Test public void testLegacyDecimalParsing() { final BigDecimal decimal = new BigDecimal("123451234512345"); final Calendar calendar = DateTimeUtils.calendar(); // CALCITE-1103 Decimals were (incorrectly) getting serialized as normal "numbers" which // caused them to use the numberValue field. TypedValue should still be able to handle // values like this (but large values will be truncated and return bad values). Common.TypedValue oldProtoStyle = Common.TypedValue.newBuilder().setType(Common.Rep.NUMBER) .setNumberValue(decimal.longValue()).build(); TypedValue fromProtoTv = TypedValue.fromProto(oldProtoStyle); Object o = fromProtoTv.toJdbc(calendar); assertEquals(decimal, o); }
@Test public void testLegacyDecimalParsing() { final BigDecimal decimal = new BigDecimal("123451234512345"); final Calendar calendar = DateTimeUtils.calendar(); // CALCITE-1103 Decimals were (incorrectly) getting serialized as normal "numbers" which // caused them to use the numberValue field. TypedValue should still be able to handle // values like this (but large values will be truncated and return bad values). Common.TypedValue oldProtoStyle = Common.TypedValue.newBuilder().setType(Common.Rep.NUMBER) .setNumberValue(decimal.longValue()).build(); TypedValue fromProtoTv = TypedValue.fromProto(oldProtoStyle); Object o = fromProtoTv.toJdbc(calendar); assertEquals(decimal, o); }
@Test public void testArrays() { List<Object> serialObj = Arrays.<Object>asList(1, 2, 3, 4); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); ScalarType scalarType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); Array a1 = factory.createArray(scalarType, serialObj); TypedValue tv1 = TypedValue.ofJdbc(Rep.ARRAY, a1, Unsafe.localCalendar()); Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObj.getClass(), jdbcObj instanceof Array); Object localObj = tv1.toLocal(); assertTrue("The local object is an " + localObj.getClass(), localObj instanceof List); Common.TypedValue protoTv1 = tv1.toProto(); assertEquals(serialObj.size(), protoTv1.getArrayValueCount()); TypedValue tv1Copy = TypedValue.fromProto(protoTv1); Object jdbcObjCopy = tv1Copy.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObjCopy.getClass(), jdbcObjCopy instanceof Array); Object localObjCopy = tv1Copy.toLocal(); assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List); } }
@Test public void testArrays() { List<Object> serialObj = Arrays.<Object>asList(1, 2, 3, 4); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); ScalarType scalarType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); Array a1 = factory.createArray(scalarType, serialObj); TypedValue tv1 = TypedValue.ofJdbc(Rep.ARRAY, a1, Unsafe.localCalendar()); Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObj.getClass(), jdbcObj instanceof Array); Object localObj = tv1.toLocal(); assertTrue("The local object is an " + localObj.getClass(), localObj instanceof List); Common.TypedValue protoTv1 = tv1.toProto(); assertEquals(serialObj.size(), protoTv1.getArrayValueCount()); TypedValue tv1Copy = TypedValue.fromProto(protoTv1); Object jdbcObjCopy = tv1Copy.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObjCopy.getClass(), jdbcObjCopy instanceof Array); Object localObjCopy = tv1Copy.toLocal(); assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List); } }