Java 类org.jooq.UpdateSetMoreStep 实例源码

项目:killbill-adyen-plugin    文件:AdyenDao.java   
/**
 * Update the PSP reference and additional data of the latest response row for a payment transaction
 *
 * @param kbPaymentTransactionId       Kill Bill payment transaction id
 * @param paymentServiceProviderResult New PSP result (null if unchanged)
 * @param additionalPluginProperties   Latest properties
 * @param kbTenantId                   Kill Bill tenant id
 * @return the latest version of the response row, null if one couldn't be found
 * @throws SQLException For any unexpected SQL error
 */
public AdyenResponsesRecord updateResponse(final UUID kbPaymentTransactionId, @Nullable final PaymentServiceProviderResult paymentServiceProviderResult, final Iterable<PluginProperty> additionalPluginProperties, final UUID kbTenantId) throws SQLException {
    final Map<String, Object> additionalProperties = PluginProperties.toMap(additionalPluginProperties);

    return execute(dataSource.getConnection(),
                   new WithConnectionCallback<AdyenResponsesRecord>() {
                       @Override
                       public AdyenResponsesRecord withConnection(final Connection conn) throws SQLException {
                           final AdyenResponsesRecord response = DSL.using(conn, dialect, settings)
                                                                    .selectFrom(ADYEN_RESPONSES)
                                                                    .where(ADYEN_RESPONSES.KB_PAYMENT_TRANSACTION_ID.equal(kbPaymentTransactionId.toString()))
                                                                    .and(ADYEN_RESPONSES.KB_TENANT_ID.equal(kbTenantId.toString()))
                                                                    .orderBy(ADYEN_RESPONSES.RECORD_ID.desc())
                                                                    .limit(1)
                                                                    .fetchOne();

                           if (response == null) {
                               return null;
                           }

                           final Map originalData = new HashMap(fromAdditionalData(response.getAdditionalData()));
                           originalData.putAll(additionalProperties);
                           final String pspReference = getProperty(PROPERTY_PSP_REFERENCE, additionalProperties);
                           if (pspReference != null) {
                               // If there is a PSP reference, the call went eventually to Adyen. Remove exceptions
                               originalData.remove(ADYEN_CALL_ERROR_STATUS);
                               originalData.remove(EXCEPTION_CLASS);
                               originalData.remove(EXCEPTION_MESSAGE);
                           }
                           final String mergedAdditionalData = asString(originalData);

                           UpdateSetMoreStep<AdyenResponsesRecord> step = DSL.using(conn, dialect, settings)
                                                                             .update(ADYEN_RESPONSES)
                                                                             .set(ADYEN_RESPONSES.PSP_REFERENCE, pspReference)
                                                                             .set(ADYEN_RESPONSES.ADDITIONAL_DATA, mergedAdditionalData);
                           if (paymentServiceProviderResult != null) {
                               step = step.set(ADYEN_RESPONSES.PSP_RESULT, paymentServiceProviderResult.toString());
                           }
                           step.where(ADYEN_RESPONSES.RECORD_ID.equal(response.getRecordId()))
                               .execute();

                           return DSL.using(conn, dialect, settings)
                                     .selectFrom(ADYEN_RESPONSES)
                                     .where(ADYEN_RESPONSES.KB_PAYMENT_TRANSACTION_ID.equal(kbPaymentTransactionId.toString()))
                                     .and(ADYEN_RESPONSES.KB_TENANT_ID.equal(kbTenantId.toString()))
                                     .orderBy(ADYEN_RESPONSES.RECORD_ID.desc())
                                     .limit(1)
                                     .fetchOne();
                       }
                   });
}
项目:adjule    文件:JooqProblemDetailDao.java   
@Override
public String editProblem(@Nonnull final String problemCode,
                          @Nonnull final ProblemDetailView problemDetailView,
                          @Nullable final String contentType,
                          @Nullable final byte[] content)
        throws FormException {
    validateProblemDetailView(problemDetailView);

    editProblemLanguages(problemCode, problemDetailView);

    final UpdateSetMoreStep<TasksRecord> whereStep =
            jooq.update(TASKS)
                .set(TASKS.CODE, problemDetailView.getCode())
                .set(TASKS.NAME, problemDetailView.getName())
                .set(TASKS.CONTENT, problemDetailView.getContent() != null ? String.valueOf(problemDetailView.getContent()) : null)
                .set(TASKS.CHECKSRC, problemDetailView.getCheckerSource())
                .set(TASKS.AUTHOR, problemDetailView.getAuthor())
                .set(TASKS.DEFAULT_TIME_LIMIT, problemDetailView.getDefaultTimeLimit())
                .set(TASKS.DEFAULT_MEMORY_LIMIT, problemDetailView.getDefaultMemoryLimit());

    if (!problemDetailView.isHasAttachment()) {
        whereStep.set(TASKS.FILETYPE, (String) null)
                 .set(TASKS.FILECONTENT, (byte[]) null);
    } else {
        if (contentType != null && content != null) {
            whereStep.set(TASKS.FILETYPE, contentType)
                     .set(TASKS.FILECONTENT, content);
        }
    }

    final UpdateResultStep<TasksRecord> step =
            whereStep.where(TASKS.CODE.eq(problemCode))
                     .returning(TASKS.CODE);

    try {
        final TasksRecord problemRecord = step.fetchOne();
        return problemRecord.getCode();
    } catch (DataIntegrityViolationException ex) {
        throw new FormException().addError("code", "unique");
    }
}