@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { if(!shouldProcess(sqlMethod)) return next.deSerialize(src , sqlMethod); return CompletableFuture.runAsync(() -> {}); }
@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { com.github.andyshao.neo4j.annotation.DeSerializer annotation = sqlMethod.getDefinition().getAnnotation(com.github.andyshao.neo4j.annotation.DeSerializer.class); if(annotation == null) return next.deSerialize(src , sqlMethod); DeSerializer deS = cache.computeIfAbsent(annotation , key -> ConstructorOperation.newInstance(key.value())); return deS.deSerialize(src , sqlMethod); }
@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { if(!shouldProcess(sqlMethod)) return next.deSerialize(src , sqlMethod); Method definition = sqlMethod.getDefinition(); Class<?> declaringClass = definition.getDeclaringClass(); com.github.andyshao.neo4j.annotation.DeSerializer annotation = declaringClass.getAnnotation(com.github.andyshao.neo4j.annotation.DeSerializer.class); if(annotation != null) return ConstructorOperation.newInstance(annotation.value()).deSerialize(src , sqlMethod); Class<?> returnType = DeSerializers.getReturnType(sqlMethod); return src.nextAsync().thenApplyAsync(record -> { if(record == null) return Optional.empty(); return Optional.ofNullable(DeSerializers.formatJavaBean(returnType , sqlMethod , record.get(0))); }); }
@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { GenericNode returnTypeInfo = sqlMethod.getSqlMethodRet().getReturnTypeInfo(); if(!shouldProcess(returnTypeInfo)) return next.deSerialize(src , sqlMethod); Class<?> returnType = getReturnType(returnTypeInfo); return src.nextAsync().thenApplyAsync(record -> Optional.ofNullable(DeSerializers.formatValue(returnType , record.get(0)))); }
@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { if(!shouldProcess(sqlMethod)) return next.deSerialize(src , sqlMethod); Class<?> returnType = DeSerializers.getReturnType(sqlMethod); final AtomicInteger pageNum = new AtomicInteger(0); final AtomicInteger pageSize = new AtomicInteger(0); if(DeSerializers.isBaseType(returnType)) { return src.listAsync(record -> { pageNum.set(record.get(1).asInt()); pageSize.set(record.get(2).asInt()); return DeSerializers.formatValue(returnType , record.get(0)); }).thenApplyAsync(records -> wrapPageReturn(pageNum , pageSize , records)); } else { return src.listAsync(record -> { pageNum.set(record.get(1).asInt()); pageSize.set(record.get(2).asInt()); return DeSerializers.formatJavaBean(returnType , sqlMethod , record.get(0)); }).thenApplyAsync(records -> wrapPageReturn(pageNum , pageSize , records)); } }
@SuppressWarnings("unchecked") public <T> T process(DaoProcessorParam param, Neo4jDaoInfo neo4jDaoInfo) { MethodKey methodKey = new MethodKey(); methodKey.setMethodName(param.getMethodName()); methodKey.setParameTypes(param.getArgTypes()); SqlMethod sqlMethod = neo4jDaoInfo.getSqlMethods().get(methodKey); Optional<Sql> query = sqlCompute.compute(sqlMethod.getDefinition() , neo4jDaoInfo , param.getArgs()); if(!query.isPresent()) throw new Neo4jException("No Query find out"); Sql sql = query.get(); Transaction tx = null; for(Object arg : param.getArgs()) { if(arg instanceof Transaction) tx = (Transaction) arg; } Object obj = tx.runAsync(sql.getSql(), Values.value(sql.getParameters())) .thenComposeAsync(src -> deSerializer.deSerialize(src , sqlMethod)); return (T) obj; } }
@Override public CompletionStage<?> deSerialize(StatementResultCursor src , SqlMethod sqlMethod) throws NotSupportConvertException { if(!shouldProcess(sqlMethod)) return next.deSerialize(src , sqlMethod); Class<?> returnType = DeSerializers.getReturnType(sqlMethod); if(DeSerializers.isBaseType(returnType)) { return src.listAsync(record -> DeSerializers.formatValue(returnType , record.get(0))); } else { return src.listAsync(record -> DeSerializers.formatJavaBean(returnType , sqlMethod , record.get(0))); } }
final Transaction transaction = session == null ? tx : session.beginTransaction(); CompletionStage<StatementResultCursor> runAsync = transaction.runAsync(sql.getSql(), Values.value(sql.getParameters())); Object obj = runAsync.thenComposeAsync(src -> deSerializer.deSerialize(src , sqlMethod)) .whenComplete((obj2,ex)->{ if(ex != null) {