@Override public Long doInSqlInsertWithKeyClause(SQLInsertClause insert) throws SQLException { return insert .columns(qCustomer.firstName, qCustomer.lastName, qCustomer.emailAddress) .values(customer.getFirstName(), customer.getLastName(), customer.getEmailAddress() == null ? null : customer.getEmailAddress().toString()) .executeWithKey(qCustomer.id); } });
/** * Execute the clause and return the generated key cast to the given type. * If no rows were created, null is returned, otherwise the key of the first * row is returned. * * @param <T> * @param type * @return */ public <T> T executeWithKey(Class<T> type) { return executeWithKey(type, null); }
/** * Execute the clause and return the generated key with the type of the * given path. If no rows were created, null is returned, otherwise the key * of the first row is returned. * * @param <T> * @param path * @return */ @SuppressWarnings("unchecked") @Nullable public <T> T executeWithKey(Path<T> path) { return executeWithKey((Class<T>) path.getType(), path); }
@Override public Long call(Connection connection, Configuration configuration) throws SQLException { QResource qResource = new QResource("qResource"); SQLInsertClause insertClause = new SQLInsertClause(connection, configuration, qResource); return insertClause.executeWithKey(qResource.resourceId); } });
@Override public SimpleSubject create(final long resourceId, final String principal, final String plainCredential) { String encryptedCredential = (plainCredential == null) ? null : credentialEncryptor.encrypt(plainCredential); return querydslSupport.execute((connection, configuration) -> { QSimpleSubject qSimpleSubject = QSimpleSubject.simpleSubject; long simpleSubjectId = new SQLInsertClause(connection, configuration, qSimpleSubject) .set(qSimpleSubject.resourceId, resourceId) .set(qSimpleSubject.principal, principal) .set(qSimpleSubject.encryptedCredential, encryptedCredential) .executeWithKey(qSimpleSubject.simpleSubjectId); return new SimpleSubject(simpleSubjectId, principal, resourceId); }); }
/** * Note: transaction must be provided to this method. */ private AuditApplication insertAuditApplication(final String applicationName) { return querydslSupport.execute((connection, configuration) -> { long resourceId = resourceService.createResource(); QApplication qApplication = QApplication.application; long applicationId = new SQLInsertClause(connection, configuration, qApplication) .set(qApplication.resourceId, resourceId) .set(qApplication.applicationName, applicationName) .executeWithKey(qApplication.applicationId); return new AuditApplication.Builder() .applicationId(applicationId) .applicationName(applicationName) .resourceId(resourceId) .build(); }); }
/** * Note: transaction must be provided to this method. */ private void insertAuditEvent(final long eventTypeId, final AuditEvent auditEvent) { querydslSupport.execute((connection, configuration) -> { QEvent qEvent = QEvent.event; long eventId = new SQLInsertClause(connection, configuration, qEvent) .set(qEvent.createdAt, Timestamp.from(Instant.now())) .set(qEvent.occuredAt, Timestamp.from(auditEvent.occuredAt)) .set(qEvent.eventTypeId, eventTypeId) .executeWithKey(qEvent.eventId); for (EventData eventData : auditEvent.eventDataArray) { QEventData qEventData = QEventData.eventData; SQLInsertClause insert = new SQLInsertClause(connection, configuration, qEventData) .set(qEventData.eventId, eventId) .set(qEventData.eventDataName, eventData.eventDataName) .set(qEventData.eventDataType, eventData.eventDataType.toString()); addEventDataValue(insert, qEventData, eventData); insert.execute(); } return null; }); }
/** * Note: transaction must be provided to this method. */ private Void insertAndCacheAuditEventTypes(final AuditApplication auditApplication, final List<String> eventTypeNames) { return querydslSupport.execute((connection, configuration) -> { for (String eventTypeName : eventTypeNames) { Long resourceId = resourceService.createResource(); QEventType qEventType = QEventType.eventType; long eventTypeId = new SQLInsertClause(connection, configuration, qEventType) .set(qEventType.eventTypeName, eventTypeName) .set(qEventType.applicationId, auditApplication.applicationId) .set(qEventType.resourceId, resourceId) .executeWithKey(qEventType.eventTypeId); AuditEventType auditEventType = new AuditEventType.Builder() .eventTypeId(eventTypeId) .eventTypeName(eventTypeName) .resourceId(resourceId) .build(); cacheAuditEventType(auditApplication.applicationId, auditEventType); } return null; }); }