static Common.TypedValue serializeScalar(Object element) { final Common.TypedValue.Builder valueBuilder = Common.TypedValue.newBuilder(); // Let TypedValue handle the serialization for us. TypedValue.toProto(valueBuilder, element); return valueBuilder.build(); }
static Common.TypedValue serializeScalar(Object element) { final Common.TypedValue.Builder valueBuilder = Common.TypedValue.newBuilder(); // Let TypedValue handle the serialization for us. TypedValue.toProto(valueBuilder, element); return valueBuilder.build(); }
@Override Requests.ExecuteRequest serialize() { Requests.ExecuteRequest.Builder builder = Requests.ExecuteRequest.newBuilder(); if (null != statementHandle) { builder.setStatementHandle(statementHandle.toProto()); } if (null != parameterValues) { builder.setHasParameterValues(true); for (TypedValue paramValue : parameterValues) { if (paramValue == null) { builder.addParameterValues(TypedValue.NULL.toProto()); } else { builder.addParameterValues(paramValue.toProto()); } } } else { builder.setHasParameterValues(false); } builder.setMaxRowCount(maxRowCount); return builder.build(); }
private void serializeAndEqualityCheck(TypedValue value) { TypedValue copy = TypedValue.fromProto(value.toProto()); assertEquals(value.type, copy.type); assertEquals(value.value, copy.value); }
private void serializeAndEqualityCheck(TypedValue value) { TypedValue copy = TypedValue.fromProto(value.toProto()); assertEquals(value.type, copy.type); assertEquals(value.value, copy.value); }
private void serializeAndEqualityCheck(TypedValue value) { TypedValue copy = TypedValue.fromProto(value.toProto()); assertEquals(value.type, copy.type); assertEquals(value.value, copy.value); }
@Test public void testDecimal() { final BigDecimal decimal = new BigDecimal("1.2345"); final TypedValue decimalTypedValue = TypedValue.ofLocal(Rep.NUMBER, decimal); serializeAndEqualityCheck(decimalTypedValue); final Common.TypedValue protoTypedValue = decimalTypedValue.toProto(); assertEquals(Common.Rep.BIG_DECIMAL, protoTypedValue.getType()); final String strValue = protoTypedValue.getStringValue(); assertNotNull(strValue); assertEquals(decimal.toPlainString(), strValue); }
@Test public void testDecimal() { final BigDecimal decimal = new BigDecimal("1.2345"); final TypedValue decimalTypedValue = TypedValue.ofLocal(Rep.NUMBER, decimal); serializeAndEqualityCheck(decimalTypedValue); final Common.TypedValue protoTypedValue = decimalTypedValue.toProto(); assertEquals(Common.Rep.BIG_DECIMAL, protoTypedValue.getType()); final String strValue = protoTypedValue.getStringValue(); assertNotNull(strValue); assertEquals(decimal.toPlainString(), strValue); }
@Test public void testProtobufBytesNotSentAsBase64() { final byte[] bytes = "asdf".getBytes(UTF_8); final byte[] b64Bytes = Base64.encodeBytes(bytes).getBytes(UTF_8); TypedValue tv = TypedValue.ofLocal(Rep.BYTE_STRING, new ByteString(bytes)); // JSON encodes it as base64 assertEquals(new String(b64Bytes, UTF_8), tv.value); // Get the protobuf variant Common.TypedValue protoTv = tv.toProto(); Common.Rep protoRep = protoTv.getType(); assertEquals(Common.Rep.BYTE_STRING, protoRep); // The pb variant should have the native bytes of the original value com.google.protobuf.ByteString protoByteString = protoTv.getBytesValue(); assertNotNull(protoByteString); assertArrayEquals(bytes, protoByteString.toByteArray()); // We should have the b64 string as a backwards compatibility feature assertEquals(new String(b64Bytes, UTF_8), protoTv.getStringValue()); }
@Test public void testProtobufBytesNotSentAsBase64() { final byte[] bytes = "asdf".getBytes(UTF_8); final byte[] b64Bytes = Base64.encodeBytes(bytes).getBytes(UTF_8); TypedValue tv = TypedValue.ofLocal(Rep.BYTE_STRING, new ByteString(bytes)); // JSON encodes it as base64 assertEquals(new String(b64Bytes, UTF_8), tv.value); // Get the protobuf variant Common.TypedValue protoTv = tv.toProto(); Common.Rep protoRep = protoTv.getType(); assertEquals(Common.Rep.BYTE_STRING, protoRep); // The pb variant should have the native bytes of the original value com.google.protobuf.ByteString protoByteString = protoTv.getBytesValue(); assertNotNull(protoByteString); assertArrayEquals(bytes, protoByteString.toByteArray()); // We should have the b64 string as a backwards compatibility feature assertEquals(new String(b64Bytes, UTF_8), protoTv.getStringValue()); }
@Override Requests.ExecuteBatchRequest serialize() { Requests.ExecuteBatchRequest.Builder builder = Requests.ExecuteBatchRequest.newBuilder(); if (hasProtoUpdateBatches()) { builder.addAllUpdates(protoParameterValues); } else if (null != parameterValues) { for (List<TypedValue> updateBatch : parameterValues) { Requests.UpdateBatch.Builder batchBuilder = Requests.UpdateBatch.newBuilder(); for (TypedValue update : updateBatch) { batchBuilder.addParameterValues(update.toProto()); } builder.addUpdates(batchBuilder.build()); } } if (null != connectionId) { builder.setConnectionId(connectionId); } return builder.setStatementId(statementId).build(); }
@Override Requests.ExecuteBatchRequest serialize() { Requests.ExecuteBatchRequest.Builder builder = Requests.ExecuteBatchRequest.newBuilder(); if (hasProtoUpdateBatches()) { builder.addAllUpdates(protoParameterValues); } else if (null != parameterValues) { for (List<TypedValue> updateBatch : parameterValues) { Requests.UpdateBatch.Builder batchBuilder = Requests.UpdateBatch.newBuilder(); for (TypedValue update : updateBatch) { batchBuilder.addParameterValues(update.toProto()); } builder.addUpdates(batchBuilder.build()); } } if (null != connectionId) { builder.setConnectionId(connectionId); } return builder.setStatementId(statementId).build(); }
@Override Requests.ExecuteRequest serialize() { Requests.ExecuteRequest.Builder builder = Requests.ExecuteRequest.newBuilder(); if (null != statementHandle) { builder.setStatementHandle(statementHandle.toProto()); } if (null != parameterValues) { builder.setHasParameterValues(true); for (TypedValue paramValue : parameterValues) { if (paramValue == null) { builder.addParameterValues(TypedValue.PROTO_IMPLICIT_NULL); } else { builder.addParameterValues(paramValue.toProto()); } } } else { builder.setHasParameterValues(false); } // Set the old and new field builder.setDeprecatedFirstFrameMaxSize(maxRowCount); builder.setFirstFrameMaxSize(maxRowCount); return builder.build(); }
@Override Requests.ExecuteRequest serialize() { Requests.ExecuteRequest.Builder builder = Requests.ExecuteRequest.newBuilder(); if (null != statementHandle) { builder.setStatementHandle(statementHandle.toProto()); } if (null != parameterValues) { builder.setHasParameterValues(true); for (TypedValue paramValue : parameterValues) { if (paramValue == null) { builder.addParameterValues(TypedValue.PROTO_IMPLICIT_NULL); } else { builder.addParameterValues(paramValue.toProto()); } } } else { builder.setHasParameterValues(false); } // Set the old and new field builder.setDeprecatedFirstFrameMaxSize(maxRowCount); builder.setFirstFrameMaxSize(maxRowCount); return builder.build(); }
@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); } }
Common.TypedValue.Builder listElementBuilder = Common.TypedValue.newBuilder(); Common.Rep componentRep = toProto(listElementBuilder, listElement); if (!setComponentType) { if (Common.Rep.NULL != componentRep) { Common.TypedValue.Builder listElementBuilder = Common.TypedValue.newBuilder(); Object arrayValue = rs.getObject(2); Common.Rep componentRep = toProto(listElementBuilder, arrayValue); if (!setComponentType) { if (Common.Rep.NULL != componentRep) {
Common.TypedValue.Builder listElementBuilder = Common.TypedValue.newBuilder(); Common.Rep componentRep = toProto(listElementBuilder, listElement); if (!setComponentType) { if (Common.Rep.NULL != componentRep) { Common.TypedValue.Builder listElementBuilder = Common.TypedValue.newBuilder(); Object arrayValue = rs.getObject(2); Common.Rep componentRep = toProto(listElementBuilder, arrayValue); if (!setComponentType) { if (Common.Rep.NULL != componentRep) {
@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); } }