use of com.google.api.expr.v1alpha1.Type in project tomee by apache.
the class CmrField method createSignature.
private static String createSignature(final Type type, final Type... genericTypes) {
final StringBuilder builder = new StringBuilder();
builder.append("L").append(type.getInternalName());
if (genericTypes.length > 0) {
builder.append("<");
for (final Type genericType : genericTypes) {
builder.append(genericType.getDescriptor());
}
builder.append(">");
}
builder.append(";");
return builder.toString();
}
use of com.google.api.expr.v1alpha1.Type in project tomee by apache.
the class DependencyVisitor method addMethodDesc.
private void addMethodDesc(final String desc) {
addType(Type.getReturnType(desc));
final Type[] types = Type.getArgumentTypes(desc);
for (Type type : types) {
addType(type);
}
}
use of com.google.api.expr.v1alpha1.Type in project tomee by apache.
the class DynamicSubclass method visitConstructor.
private static MethodVisitor visitConstructor(final ClassWriter cw, final String proxyClassFileName, final String classFileName, final Constructor<?> constructor) {
final String descriptor = Type.getConstructorDescriptor(constructor);
final String[] exceptions = new String[constructor.getExceptionTypes().length];
for (int i = 0; i < exceptions.length; i++) {
exceptions[i] = Type.getInternalName(constructor.getExceptionTypes()[i]);
}
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor, null, exceptions);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
int index = 1;
for (final Type type : Type.getArgumentTypes(descriptor)) {
mv.visitVarInsn(type.getOpcode(ILOAD), index);
index += size(type);
}
mv.visitMethodInsn(INVOKESPECIAL, classFileName, "<init>", descriptor, false);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(PUTFIELD, proxyClassFileName, "this$handler", "Ljava/lang/reflect/InvocationHandler;");
mv.visitInsn(RETURN);
mv.visitMaxs(2, 1);
return mv;
}
use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.
the class MockSpannerServiceImpl method buildStatement.
@SuppressWarnings("unchecked")
private Statement buildStatement(String sql, Map<String, Type> paramTypes, com.google.protobuf.Struct params) {
Statement.Builder builder = Statement.newBuilder(sql);
// Set all untyped null values first.
for (Entry<String, com.google.protobuf.Value> entry : params.getFieldsMap().entrySet()) {
if (entry.getValue().hasNullValue() && !paramTypes.containsKey(entry.getKey())) {
builder.bind(entry.getKey()).to((Value) null);
}
}
for (Entry<String, Type> entry : paramTypes.entrySet()) {
final String fieldName = entry.getKey();
final Type fieldType = entry.getValue();
final Type elementType = fieldType.getArrayElementType();
com.google.protobuf.Value value = params.getFieldsOrThrow(fieldName);
if (value.getKindCase() == KindCase.NULL_VALUE) {
switch(fieldType.getCode()) {
case ARRAY:
switch(elementType.getCode()) {
case BOOL:
builder.bind(fieldName).toBoolArray((Iterable<Boolean>) null);
break;
case BYTES:
builder.bind(fieldName).toBytesArray(null);
break;
case DATE:
builder.bind(fieldName).toDateArray(null);
break;
case FLOAT64:
builder.bind(fieldName).toFloat64Array((Iterable<Double>) null);
break;
case INT64:
builder.bind(fieldName).toInt64Array((Iterable<Long>) null);
break;
case STRING:
builder.bind(fieldName).toStringArray(null);
break;
case NUMERIC:
if (elementType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
builder.bind(fieldName).toPgNumericArray(null);
} else {
builder.bind(fieldName).toNumericArray(null);
}
break;
case TIMESTAMP:
builder.bind(fieldName).toTimestampArray(null);
break;
case JSON:
builder.bind(fieldName).toJsonArray(null);
break;
case STRUCT:
case TYPE_CODE_UNSPECIFIED:
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown or invalid array parameter type: " + elementType.getCode());
}
break;
case BOOL:
builder.bind(fieldName).to((Boolean) null);
break;
case BYTES:
builder.bind(fieldName).to((ByteArray) null);
break;
case DATE:
builder.bind(fieldName).to((Date) null);
break;
case FLOAT64:
builder.bind(fieldName).to((Double) null);
break;
case INT64:
builder.bind(fieldName).to((Long) null);
break;
case STRING:
builder.bind(fieldName).to((String) null);
break;
case NUMERIC:
if (fieldType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
builder.bind(fieldName).to(Value.pgNumeric(null));
} else {
builder.bind(fieldName).to((BigDecimal) null);
}
break;
case STRUCT:
builder.bind(fieldName).to((Struct) null);
break;
case TIMESTAMP:
builder.bind(fieldName).to((com.google.cloud.Timestamp) null);
break;
case JSON:
builder.bind(fieldName).to(Value.json(null));
break;
case TYPE_CODE_UNSPECIFIED:
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown parameter type: " + fieldType.getCode());
}
} else {
switch(fieldType.getCode()) {
case ARRAY:
switch(elementType.getCode()) {
case BOOL:
builder.bind(fieldName).toBoolArray((Iterable<Boolean>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.bool(), value.getListValue()));
break;
case BYTES:
builder.bind(fieldName).toBytesArray((Iterable<ByteArray>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.bytes(), value.getListValue()));
break;
case DATE:
builder.bind(fieldName).toDateArray((Iterable<Date>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.date(), value.getListValue()));
break;
case FLOAT64:
builder.bind(fieldName).toFloat64Array((Iterable<Double>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.float64(), value.getListValue()));
break;
case INT64:
builder.bind(fieldName).toInt64Array((Iterable<Long>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.int64(), value.getListValue()));
break;
case STRING:
builder.bind(fieldName).toStringArray((Iterable<String>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.string(), value.getListValue()));
break;
case NUMERIC:
if (elementType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
builder.bind(fieldName).toPgNumericArray((Iterable<String>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.pgNumeric(), value.getListValue()));
} else {
builder.bind(fieldName).toNumericArray((Iterable<BigDecimal>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.numeric(), value.getListValue()));
}
break;
case TIMESTAMP:
builder.bind(fieldName).toTimestampArray((Iterable<com.google.cloud.Timestamp>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.timestamp(), value.getListValue()));
break;
case JSON:
builder.bind(fieldName).toJsonArray((Iterable<String>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.json(), value.getListValue()));
break;
case STRUCT:
case TYPE_CODE_UNSPECIFIED:
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown or invalid array parameter type: " + elementType.getCode());
}
break;
case BOOL:
builder.bind(fieldName).to(value.getBoolValue());
break;
case BYTES:
builder.bind(fieldName).to(ByteArray.fromBase64(value.getStringValue()));
break;
case DATE:
builder.bind(fieldName).to(Date.parseDate(value.getStringValue()));
break;
case FLOAT64:
builder.bind(fieldName).to(value.getNumberValue());
break;
case INT64:
builder.bind(fieldName).to(Long.valueOf(value.getStringValue()));
break;
case STRING:
builder.bind(fieldName).to(value.getStringValue());
break;
case NUMERIC:
if (fieldType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
builder.bind(fieldName).to(Value.pgNumeric(value.getStringValue()));
} else {
builder.bind(fieldName).to(new BigDecimal(value.getStringValue()));
}
break;
case STRUCT:
throw new IllegalArgumentException("Struct parameters not (yet) supported");
case TIMESTAMP:
builder.bind(fieldName).to(com.google.cloud.Timestamp.parseTimestamp(value.getStringValue()));
break;
case JSON:
builder.bind(fieldName).to(Value.json(value.getStringValue()));
break;
case TYPE_CODE_UNSPECIFIED:
case UNRECOGNIZED:
default:
throw new IllegalArgumentException("Unknown parameter type: " + fieldType.getCode());
}
}
}
return builder.build();
}
use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.
the class SpannerClientTest method executeStreamingSqlTest.
@Test
public void executeStreamingSqlTest() throws Exception {
PartialResultSet expectedResponse = PartialResultSet.newBuilder().setMetadata(ResultSetMetadata.newBuilder().build()).addAllValues(new ArrayList<Value>()).setChunkedValue(true).setResumeToken(ByteString.EMPTY).setStats(ResultSetStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setResumeToken(ByteString.EMPTY).setPartitionToken(ByteString.EMPTY).setSeqno(109325920).setQueryOptions(ExecuteSqlRequest.QueryOptions.newBuilder().build()).setRequestOptions(RequestOptions.newBuilder().build()).build();
MockStreamObserver<PartialResultSet> responseObserver = new MockStreamObserver<>();
ServerStreamingCallable<ExecuteSqlRequest, PartialResultSet> callable = client.executeStreamingSqlCallable();
callable.serverStreamingCall(request, responseObserver);
List<PartialResultSet> actualResponses = responseObserver.future().get();
Assert.assertEquals(1, actualResponses.size());
Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
Aggregations