@Override public ExecuteBatchResult executeBatchProtobuf(StatementHandle h, List<Requests.UpdateBatch> updateBatches) throws NoSuchStatementException { try { final StatementInfo info = statementCache.getIfPresent(h.id); if (null == info) { throw new NoSuchStatementException(h); } final PreparedStatement preparedStmt = (PreparedStatement) info.statement; for (Requests.UpdateBatch update : updateBatches) { int i = 1; for (Common.TypedValue value : update.getParameterValuesList()) { // Use the value and then increment preparedStmt.setObject(i++, TypedValue.protoToJdbc(value, calendar)); } preparedStmt.addBatch(); } return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt)); } catch (SQLException e) { throw propagate(e); } }
@Override public ExecuteBatchResult executeBatchProtobuf(StatementHandle h, List<Requests.UpdateBatch> updateBatches) throws NoSuchStatementException { try { final StatementInfo info = statementCache.getIfPresent(h.id); if (null == info) { throw new NoSuchStatementException(h); } final PreparedStatement preparedStmt = (PreparedStatement) info.statement; for (Requests.UpdateBatch update : updateBatches) { int i = 1; for (Common.TypedValue value : update.getParameterValuesList()) { // Use the value and then increment preparedStmt.setObject(i++, TypedValue.protoToJdbc(value, calendar)); } preparedStmt.addBatch(); } return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt)); } catch (SQLException e) { throw propagate(e); } }
@Test public void testBase64() { byte[] bytes = "qwertyasdf".getBytes(UTF_8); // Plain bytes get put into protobuf for simplicitly Common.TypedValue proto = Common.TypedValue.newBuilder().setBytesValue( com.google.protobuf.ByteString.copyFrom(bytes)) .setType(Common.Rep.BYTE_STRING).build(); // But we should get back a b64-string to make sure TypedValue doesn't get confused. Object deserializedObj = TypedValue.getSerialFromProto(proto); assertThat(deserializedObj, is(instanceOf(String.class))); assertEquals(new ByteString(bytes).toBase64String(), (String) deserializedObj); // But we should get a non-b64 byte array as the JDBC representation deserializedObj = TypedValue.protoToJdbc(proto, DateTimeUtils.calendar()); assertThat(deserializedObj, is(instanceOf(byte[].class))); assertArrayEquals(bytes, (byte[]) deserializedObj); }
@Test public void testBase64() { byte[] bytes = "qwertyasdf".getBytes(UTF_8); // Plain bytes get put into protobuf for simplicitly Common.TypedValue proto = Common.TypedValue.newBuilder().setBytesValue( com.google.protobuf.ByteString.copyFrom(bytes)) .setType(Common.Rep.BYTE_STRING).build(); // But we should get back a b64-string to make sure TypedValue doesn't get confused. Object deserializedObj = TypedValue.getSerialFromProto(proto); assertThat(deserializedObj, is(instanceOf(String.class))); assertEquals(new ByteString(bytes).toBase64String(), (String) deserializedObj); // But we should get a non-b64 byte array as the JDBC representation deserializedObj = TypedValue.protoToJdbc(proto, DateTimeUtils.calendar()); assertThat(deserializedObj, is(instanceOf(byte[].class))); assertArrayEquals(bytes, (byte[]) deserializedObj); }