use of com.couchbase.client.java.CommonOptions in project spring-data-couchbase by spring-projects.
the class DynamicInvocationHandler method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("toString".equals(method.getName())) {
return "proxy -> target:" + target;
}
if (method.getName().equals("withOptions")) {
return Proxy.newProxyInstance(repositoryClass.getClassLoader(), target.getClass().getInterfaces(), new DynamicInvocationHandler<>(target, (CommonOptions) args[0], collection, scope));
}
if (method.getName().equals("withScope")) {
return Proxy.newProxyInstance(repositoryClass.getClassLoader(), target.getClass().getInterfaces(), new DynamicInvocationHandler<>(target, options, collection, (String) args[0]));
}
if (method.getName().equals("withCollection")) {
return Proxy.newProxyInstance(repositoryClass.getClassLoader(), target.getClass().getInterfaces(), new DynamicInvocationHandler<>(target, options, (String) args[0], scope));
}
Class<?>[] paramTypes = null;
if (args != null) {
// the CouchbaseRepository methods - save(entity) etc - will have a parameter type of Object instead of entityType
// so change the paramType to match
paramTypes = Arrays.stream(args).map(o -> o == null ? null : (o.getClass() == entityInformation.getJavaType() ? Object.class : o.getClass())).toArray(Class<?>[]::new);
// the CouchbaseRepository methods - findById(id) etc - will have a parameter type of Object instead of ID
if (method.getName().endsWith("ById") && args.length == 1) {
paramTypes[0] = Object.class;
}
}
Method theMethod = repositoryClass.getMethod(method.getName(), paramTypes);
Object result;
try {
setThreadLocal();
result = theMethod.invoke(target, args);
} catch (InvocationTargetException ite) {
throw ite.getCause();
}
return result;
}
use of com.couchbase.client.java.CommonOptions in project couchbase-jvm-clients by couchbase.
the class AsyncQueryIndexManager method exec.
private CompletableFuture<QueryResult> exec(QueryType queryType, CharSequence statement, CommonOptions<?>.BuiltCommonOptions options, String spanName, String bucketName, JsonArray parameters) {
QueryOptions queryOpts = toQueryOptions(options).readonly(requireNonNull(queryType) == READ_ONLY);
if (parameters != null && !parameters.isEmpty()) {
queryOpts.parameters(parameters);
}
RequestSpan parent = cluster.environment().requestTracer().requestSpan(spanName, options.parentSpan().orElse(null));
parent.attribute(TracingIdentifiers.ATTR_SYSTEM, TracingIdentifiers.ATTR_SYSTEM_COUCHBASE);
if (bucketName != null) {
parent.attribute(TracingIdentifiers.ATTR_NAME, bucketName);
}
queryOpts.parentSpan(parent);
return cluster.query(statement.toString(), queryOpts).exceptionally(t -> {
throw translateException(t);
}).whenComplete((r, t) -> parent.end());
}
Aggregations