Spring Boot SDK3中findByN1QL的解决方案是什么?

f2uvfpb9  于 2023-01-05  发布在  Spring
关注(0)|答案(1)|浏览(103)

从Couchbase SDK 2迁移至SDK 3时,某些文档格式似乎已被删除。如何在Couchbase SDK 3中使用此格式或替代输出来处理以下API变更?这是在现有系统中使用findByN 1 QL的示例类之一。

private List<Document> getBspReconciledAgentTransactionDataList(
            BspReconciliationAgentTransactionLogicData transactionLogicData) {

        final String bucketName = getBucketName(repository);
        String query = getTransactionQueryStatement(transactionLogicData).toString();
        query = query.split(N1qlQueryUtil.WHERE)[NumberConstants.ONE];

        query = N1qlQueryUtil.selectOf(N1qlQueryUtil.metaOf(bucketName, "id", "_ID"),
                N1qlQueryUtil.metaOf(bucketName, "cas", "_CAS"), N1QlQueryConstants.COUNTRY_NAME,
                N1QlQueryConstants.COUNTRYCODE, N1QlQueryConstants.AIRLINECODE, N1QlQueryConstants.TRANSACTIONTYPE,
                N1QlQueryConstants.SUBMISSIONSTATUS, N1QlQueryConstants.RECONCILIATIONSTATUS,
                N1QlQueryConstants.IATA_CODE_CONST, N1QlQueryConstants.AGENT_CODE_CONST,
                N1QlQueryConstants.TRANSACTION_DATE_CONST, N1QlQueryConstants.DPC_PROCESSING_DATE,
                N1QlQueryConstants.E_TICKET_NO, N1QlQueryConstants.ORDER_ID, N1QlQueryConstants.PASSENGER_NAME,
                N1QlQueryConstants.CURRENCY, N1QlQueryConstants.DEBIT_AMOUNT_POSTED,
                N1QlQueryConstants.CREDIT_AMOUNT_POSTED, N1QlQueryConstants.DEBIT_AMOUNT_FROM_HOT_FILE,
                N1QlQueryConstants.CREDIT_AMOUNT_FROM_HOT_FILE, N1QlQueryConstants.ACMADM_REF_ID,
                N1QlQueryConstants.DOCUMENT_ID) +

                N1qlQueryUtil.fromOf(bucketName)
                + N1qlQueryUtil.whereOf(N1QlQueryConstants.CLASS_DETAIL_DOCUMENT + query);

        return getCouchbaseOperations(repository).findByN1QL(couchbaseConfiguration.cluster().query(query),
            BSPReconciledDetailDocument.class);

private <T, I extends Serializable> CouchbaseOperations getCouchbaseOperations(
            CouchbaseRepository<T, I> repository) {
        return repository.getOperations();
    }

显示行“findByN 1 QL”时出错

返回getCouchbaseOperations(存储库).findByN 1 QL(治疗床配置.群集().查询(查询),BSP协调详细文档.类);

什么是最佳选项?

我有一个使用集群的“findByN 1 QL”解决方案,

//      return getCouchbaseOperations(repository).findByN1QL(N1qlQuery.simple(query),
//              BSPReconciledDetailDocument.class);
        return cluster.query(query).rowsAs(BSPReconciledDetailDocument.class);

在该场景中,未使用“CouchbaseRepository”。使用了群集。

@Autowired
private Cluster cluster;

private List<Document> getBspReconciledAgentTransactionDataList(
            BspReconciliationAgentTransactionLogicData transactionLogicData) {

        final String bucketName = getBucketName(repository);
        String query = getTransactionQueryStatement(transactionLogicData).toString();
        query = query.split(N1qlQueryUtil.WHERE)[NumberConstants.ONE];

        query = N1qlQueryUtil.selectOf(N1qlQueryUtil.metaOf(bucketName, "id", "_ID"),
                N1qlQueryUtil.metaOf(bucketName, "cas", "_CAS"), N1QlQueryConstants.COUNTRY_NAME,
                N1QlQueryConstants.COUNTRYCODE, N1QlQueryConstants.AIRLINECODE, N1QlQueryConstants.TRANSACTIONTYPE,
                N1QlQueryConstants.SUBMISSIONSTATUS, N1QlQueryConstants.RECONCILIATIONSTATUS,
                N1QlQueryConstants.IATA_CODE_CONST, N1QlQueryConstants.AGENT_CODE_CONST,
                N1QlQueryConstants.TRANSACTION_DATE_CONST, N1QlQueryConstants.DPC_PROCESSING_DATE,
                N1QlQueryConstants.E_TICKET_NO, N1QlQueryConstants.ORDER_ID, N1QlQueryConstants.PASSENGER_NAME,
                N1QlQueryConstants.CURRENCY, N1QlQueryConstants.DEBIT_AMOUNT_POSTED,
                N1QlQueryConstants.CREDIT_AMOUNT_POSTED, N1QlQueryConstants.DEBIT_AMOUNT_FROM_HOT_FILE,
                N1QlQueryConstants.CREDIT_AMOUNT_FROM_HOT_FILE, N1QlQueryConstants.ACMADM_REF_ID,
                N1QlQueryConstants.DOCUMENT_ID) +

                N1qlQueryUtil.fromOf(bucketName)
                + N1qlQueryUtil.whereOf(N1QlQueryConstants.CLASS_DETAIL_DOCUMENT + query);

         return cluster.query(query).rowsAs(BSPReconciledDetailDocument.class);

它到底行不行,有人知道吗?

2lpgd968

2lpgd9681#

您可以在存储库接口的@Query方法中使用SPEL表达式,如下所示(假设n1 ql语句将返回Persons)。

@Query("#{[0]}")
List<Person> myN1ql(String n1qlString);

相关问题