@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); } });
private void enqueueStoredEmailId(final long storedEmailId) { querydslSupport.execute((connection, configuration) -> { QEmailQueue qEmailQueue = QEmailQueue.emailQueue; return new SQLInsertClause(connection, configuration, qEmailQueue) .set(qEmailQueue.storedEmailId, storedEmailId) .set(qEmailQueue.timestamp_, Timestamp.from(Instant.now())) .execute(); }); }
@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 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; }); }
@Override public <T> IdGeneratingSQLInsertClause set(final Path<T> path, final Expression<? extends T> expression) { return (IdGeneratingSQLInsertClause) super.set(path, expression); }
@SuppressWarnings("unchecked") private long executeCompositeMerge() { if (hasRow()) { // update SQLUpdateClause update = new SQLUpdateClause(connection, configuration, entity); populate(update); addKeyConditions(update); return update.execute(); } else { // insert SQLInsertClause insert = new SQLInsertClause(connection, configuration, entity); populate(insert); return insert.execute(); } }
@Override public Worklog create(final Worklog worklog) { final Long nextId = delegator.getDelegatorInterface().getNextSeqId(WORKLOG.getEntityName()); dbConnectionManager.executeQuery(dbConnection -> setWorklogFields(dbConnection.insert(WORKLOG), worklog) .set(WORKLOG.id, nextId) .execute() ); return new WorklogImpl2(worklog.getIssue(), nextId, worklog.getAuthorKey(), worklog.getComment(), worklog.getStartDate(), worklog.getGroupLevel(), worklog.getRoleLevelId(), worklog.getTimeSpent(), worklog.getUpdateAuthorKey(), worklog.getCreated(), worklog.getUpdated(), worklog.getRoleLevel()); }
@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); } });
} else { SQLInsertClause insert = new SQLInsertClause(connection, configuration, entity); populate(insert); return insert.executeWithKeys();
@Override public final SQLInsertClause insert(RelationalPath<?> path) { return new SQLInsertClause(connection.get(), configuration, path); }
/** * 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); }
@Override public IdGeneratingSQLInsertClause addFlag(final QueryFlag.Position position, final Expression<?> flag) { return (IdGeneratingSQLInsertClause) super.addFlag(position, flag); }
@Override public <T> IdGeneratingSQLInsertClause populate(final T obj, final Mapper<T> mapper) { return (IdGeneratingSQLInsertClause) super.populate(obj, mapper); }
@Override public IdGeneratingSQLInsertClause columns(final Path<?>... columns) { return (IdGeneratingSQLInsertClause) super.columns(columns); }
@Override public Object execute() { try (Connection connection = dataSource.getConnection()) { QProperties prop = QProperties.propProperties; cache.put(key, value); new SQLInsertClause(connection, sqlTemplates, prop) .set(prop.key, key) .set(prop.value, value) .execute(); } catch (SQLException e) { throw new PropertyServiceDataSourceConnectionException("Cannot connect to DataSource.", e); } return null; } });
/** * 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(); }); }
@Override public <T> IdGeneratingSQLInsertClause set(final Path<T> path, final T value) { return (IdGeneratingSQLInsertClause) super.set(path, value); }
/** * 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 IdGeneratingSQLInsertClause addFlag(final QueryFlag.Position position, final String flag) { return (IdGeneratingSQLInsertClause) super.addFlag(position, flag); } }