use of com.google.spanner.v1.Type in project tomee by apache.
the class KeysAnnotationVisitor method visit.
@Override
public void visit(final String name, final Object value) {
if ("value".equals(name)) {
if (value instanceof Type) {
final Type type = (Type) value;
final int sort = type.getSort();
switch(sort) {
case Type.OBJECT:
if (type.getClassName().equals(ValidationRunner.class.getName())) {
classInfos.add(current);
}
break;
}
} else {
currentMethod.keys.add((String) value);
}
}
}
use of com.google.spanner.v1.Type in project tomee by apache.
the class JwtValidationGenerator method generateMethods.
protected void generateMethods(final ClassWriter cw) {
for (final MethodConstraints methodConstraints : constraints) {
final Method method = methodConstraints.getMethod();
final String name = method.getName();
// Declare a method of return type JsonWebToken for use with
// a call to BeanValidation's ExecutableValidator.validateReturnValue
final Type returnType = Type.getType(JsonWebToken.class);
final Type[] parameterTypes = Type.getArgumentTypes(method);
final String descriptor = Type.getMethodDescriptor(returnType, parameterTypes);
final int access = method.isVarArgs() ? ACC_PUBLIC + ACC_VARARGS : ACC_PUBLIC;
final MethodVisitor mv = cw.visitMethod(access, name, descriptor, null, null);
// Put the method name on the
final AnnotationVisitor av = mv.visitAnnotation(Type.getDescriptor(Generated.class), true);
av.visit("value", this.getClass().getName());
av.visitEnd();
// track the MethodVisitor
// We will later copy over the annotations
generatedMethods.put(method.getName() + Type.getMethodDescriptor(method), new ConstrainedMethodVisitor(mv, methodConstraints));
// The method will simply return null
mv.visitCode();
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
}
}
use of com.google.spanner.v1.Type in project tomee by apache.
the class ReturnValidationGenerator method generateMethods.
protected void generateMethods(final ClassWriter cw) {
for (final MethodConstraints methodConstraints : constraints) {
final Method method = methodConstraints.getMethod();
final String name = method.getName();
// Declare a method of return type JsonWebToken for use with
// a call to BeanValidation's ExecutableValidator.validateReturnValue
final Type returnType = Type.getReturnType(method);
final Type[] parameterTypes = Type.getArgumentTypes(method);
final String descriptor = Type.getMethodDescriptor(returnType, parameterTypes);
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, name, descriptor, null, null);
// Put the method name on the
final AnnotationVisitor av = mv.visitAnnotation(Type.getDescriptor(Generated.class), true);
av.visit("value", this.getClass().getName());
av.visitEnd();
// track the MethodVisitor
// We will later copy over the annotations
generatedMethods.put(method.getName() + Type.getMethodDescriptor(method), new ConstrainedMethodVisitor(mv, methodConstraints));
if (method.getReturnType().equals(Void.TYPE)) {
mv.visitCode();
mv.visitInsn(RETURN);
mv.visitMaxs(0, 1);
} else if (method.getReturnType().equals(Long.TYPE)) {
mv.visitCode();
mv.visitInsn(LCONST_0);
mv.visitInsn(LRETURN);
mv.visitMaxs(2, 4);
mv.visitEnd();
} else if (method.getReturnType().equals(Float.TYPE)) {
mv.visitCode();
mv.visitInsn(FCONST_0);
mv.visitInsn(FRETURN);
mv.visitMaxs(1, 3);
mv.visitEnd();
} else if (method.getReturnType().equals(Double.TYPE)) {
mv.visitCode();
mv.visitInsn(DCONST_0);
mv.visitInsn(DRETURN);
mv.visitMaxs(2, 4);
mv.visitEnd();
} else if (method.getReturnType().isPrimitive()) {
mv.visitCode();
mv.visitInsn(ICONST_0);
mv.visitInsn(IRETURN);
mv.visitMaxs(1, 3);
mv.visitEnd();
} else {
// The method will simply return null
mv.visitCode();
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
}
}
}
use of com.google.spanner.v1.Type in project java-spanner by googleapis.
the class MockSpannerServiceImpl method executeBatchDml.
@Override
public void executeBatchDml(ExecuteBatchDmlRequest request, StreamObserver<ExecuteBatchDmlResponse> responseObserver) {
requests.add(request);
Preconditions.checkNotNull(request.getSession());
Session session = sessions.get(request.getSession());
if (session == null) {
setSessionNotFound(request.getSession(), responseObserver);
return;
}
sessionLastUsed.put(session.getName(), Instant.now());
try {
executeBatchDmlExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
// Get or start transaction
ByteString transactionId = getTransactionId(session, request.getTransaction());
if (isPartitionedDmlTransaction(transactionId)) {
throw Status.FAILED_PRECONDITION.withDescription("This transaction is a partitioned DML transaction and cannot be used for batch DML updates.").asRuntimeException();
}
simulateAbort(session, transactionId);
List<StatementResult> results = new ArrayList<>();
com.google.rpc.Status status = com.google.rpc.Status.newBuilder().setCode(Code.OK_VALUE).build();
resultLoop: for (com.google.spanner.v1.ExecuteBatchDmlRequest.Statement statement : request.getStatementsList()) {
try {
Statement spannerStatement = buildStatement(statement.getSql(), statement.getParamTypesMap(), statement.getParams());
StatementResult res = getResult(spannerStatement);
switch(res.getType()) {
case EXCEPTION:
status = com.google.rpc.Status.newBuilder().setCode(res.getException().getStatus().getCode().value()).setMessage(res.getException().getMessage()).build();
break resultLoop;
case RESULT_SET:
throw Status.INVALID_ARGUMENT.withDescription("Not a DML statement: " + statement.getSql()).asRuntimeException();
case UPDATE_COUNT:
results.add(res);
break;
default:
throw new IllegalStateException("Unknown result type: " + res.getType());
}
} catch (StatusRuntimeException e) {
status = com.google.rpc.Status.newBuilder().setCode(e.getStatus().getCode().value()).setMessage(e.getMessage()).build();
break;
} catch (Exception e) {
status = com.google.rpc.Status.newBuilder().setCode(Code.UNKNOWN_VALUE).setMessage(e.getMessage()).build();
break;
}
}
ExecuteBatchDmlResponse.Builder builder = ExecuteBatchDmlResponse.newBuilder();
for (StatementResult res : results) {
builder.addResultSets(ResultSet.newBuilder().setStats(ResultSetStats.newBuilder().setRowCountExact(res.getUpdateCount()).build()).setMetadata(ResultSetMetadata.newBuilder().setTransaction(ignoreNextInlineBeginRequest.getAndSet(false) ? Transaction.getDefaultInstance() : Transaction.newBuilder().setId(transactionId).build()).build()).build());
}
builder.setStatus(status);
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
} catch (Throwable t) {
responseObserver.onError(Status.INTERNAL.asRuntimeException());
}
}
use of com.google.spanner.v1.Type in project java-spanner by googleapis.
the class GrpcResultSetTest method metadata.
@Test
public void metadata() {
Type rowType = Type.struct(Type.StructField.of("f", Type.string()));
ResultSetMetadata.Builder metadataBuilder = ResultSetMetadata.newBuilder();
metadataBuilder.setRowType(rowType.toProto().getStructType()).getTransactionBuilder().setId(ByteString.copyFromUtf8("t1"));
PartialResultSet partialResultSet = PartialResultSet.newBuilder().setMetadata(metadataBuilder.build()).build();
consumer.onPartialResultSet(partialResultSet);
consumer.onCompleted();
assertThat(resultSet.next()).isFalse();
assertThat(resultSet.getType()).isEqualTo(rowType);
}
Aggregations