use of com.acgist.snail.pojo.bean.M3u8.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.acgist.snail.pojo.bean.M3u8.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));
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project openwebbeans by apache.
the class NormalScopeProxyFactory method delegateNonInterceptedMethods.
@Override
protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods) throws ProxyGenerationException {
for (Method delegatedMethod : noninterceptedMethods) {
if (isIgnoredMethod(delegatedMethod)) {
return;
}
String methodDescriptor = Type.getMethodDescriptor(delegatedMethod);
// X TODO handle generic exception types?
Class[] exceptionTypes = delegatedMethod.getExceptionTypes();
String[] exceptionTypeNames = new String[exceptionTypes.length];
for (int i = 0; i < exceptionTypes.length; i++) {
exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName();
}
int targetModifiers = delegatedMethod.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC | MODIFIER_VARARGS);
MethodVisitor mv = cw.visitMethod(targetModifiers, delegatedMethod.getName(), methodDescriptor, null, exceptionTypeNames);
// fill method body
mv.visitCode();
// load the contextual instance Provider
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName, FIELD_INSTANCE_PROVIDER, Type.getDescriptor(Provider.class));
// invoke the get() method on the Provider
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Provider.class), "get", "()Ljava/lang/Object;", true);
// and convert the Object to the target class type
mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(classToProxy));
// now calculate the parameters
int offset = 1;
for (Class<?> aClass : delegatedMethod.getParameterTypes()) {
Type type = Type.getType(aClass);
mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), offset);
offset += type.getSize();
}
// and finally invoke the target method on the provided Contextual Instance
Type declaringClass = Type.getType(delegatedMethod.getDeclaringClass());
boolean interfaceMethod = Modifier.isInterface(delegatedMethod.getDeclaringClass().getModifiers());
mv.visitMethodInsn(interfaceMethod ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, interfaceMethod);
generateReturn(mv, delegatedMethod);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project osate2 by osate.
the class TypedElementImpl method setType.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setType(Type newType) {
Type oldType = type;
type = newType;
if (eNotificationRequired()) {
eNotify(new ENotificationImpl(this, Notification.SET, Aadl2Package.TYPED_ELEMENT__TYPE, oldType, type));
}
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.
the class CELTest method GlobalVars.
@Test
void GlobalVars() {
Type mapStrDyn = Decls.newMapType(Decls.String, Decls.Dyn);
Env e = newEnv(declarations(Decls.newVar("attrs", mapStrDyn), Decls.newVar("default", Decls.Dyn), Decls.newFunction("get", Decls.newInstanceOverload("get_map", asList(mapStrDyn, Decls.String, Decls.Dyn), Decls.Dyn))));
AstIssuesTuple astIss = e.compile("attrs.get(\"first\", attrs.get(\"second\", default))");
// Create the program.
ProgramOption funcs = functions(Overload.function("get", args -> {
if (args.length != 3) {
return newErr("invalid arguments to 'get'");
}
if (!(args[0] instanceof Mapper)) {
return newErr("invalid operand of type '%s' to obj.get(key, def)", args[0].type());
}
Mapper attrs = (Mapper) args[0];
if (!(args[1] instanceof StringT)) {
return newErr("invalid key of type '%s' to obj.get(key, def)", args[1].type());
}
StringT key = (StringT) args[1];
Val defVal = args[2];
if (attrs.contains(key) == True) {
return attrs.get(key);
}
return defVal;
}));
// Global variables can be configured as a ProgramOption and optionally overridden on Eval.
Program prg = e.program(astIss.getAst(), funcs, globals(mapOf("default", "third")));
// t.Run("global_default", func(t *testing.T) {
Object vars = mapOf("attrs", mapOf());
EvalResult out = prg.eval(vars);
assertThat(out.getVal().equal(stringOf("third"))).isSameAs(True);
// })
// t.Run("attrs_alt", func(t *testing.T) {
vars = mapOf("attrs", mapOf("second", "yep"));
out = prg.eval(vars);
assertThat(out.getVal().equal(stringOf("yep"))).isSameAs(True);
// })
// t.Run("local_default", func(t *testing.T) {
vars = mapOf("attrs", mapOf(), "default", "fourth");
out = prg.eval(vars);
assertThat(out.getVal().equal(stringOf("fourth"))).isSameAs(True);
// })
}
Aggregations