@Override public long doInSqlInsertClause(SQLInsertClause insert) { return insert.columns(qAddress.customerId, qAddress.street, qAddress.city, qAddress.country) .values(customer.getId(), a.getStreet(), a.getCity(), a.getCountry()).execute(); } });
/** * 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 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; } });
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 void addPermissionInheritance(final long parentResourceId, final long childResourceId) { transactionPropagator.required(() -> querydslSupport.execute((connection, configuration) -> { lockOnResource(connection, configuration, childResourceId); QPermissionInheritance permissionInheritance = QPermissionInheritance.permissionInheritance; SQLInsertClause insert = new SQLInsertClause(connection, configuration, permissionInheritance); insert .set(permissionInheritance.parentResourceId, parentResourceId) .set(permissionInheritance.childResourceId, childResourceId) .execute(); permissionInheritanceCache.remove(childResourceId); return null; })); }
@Override public void addPermission(final long authorizedResourceId, final long targetResourceId, final String action) { Objects.requireNonNull(action); transactionPropagator.required(() -> querydslSupport.execute((connection, configuration) -> { boolean authorizedResourceExists = lockOnResource(connection, configuration, authorizedResourceId); if (!authorizedResourceExists) { throw new IllegalArgumentException("Authorized resource does not exist with id " + authorizedResourceId); } QPermission p = QPermission.permission; SQLInsertClause insert = new SQLInsertClause(connection, configuration, p); insert .set(p.authorizedResourceId, authorizedResourceId) .set(p.targetResourceId, targetResourceId) .set(p.action, action) .execute(); permissionCache.put(generatePermissionKey(authorizedResourceId, targetResourceId, action), true); return null; })); }
@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()); }
@Test public void Insert_Query_Update() { QPerson person = QPerson.person; // insert SQLInsertClause insert = new SQLInsertClause(connection, configuration, person); insert.set(person.id, 10); insert.set(person.firstname, "Bob"); insert.set(person.gender, Gender.MALE); assertEquals(1l, insert.execute()); // query SQLQuery query = new SQLQuery(connection, configuration); assertEquals(Gender.MALE, query.from(person).where(person.id.eq(10)).uniqueResult(person.gender)); // update SQLUpdateClause update = new SQLUpdateClause(connection, configuration, person); update.set(person.gender, Gender.FEMALE); update.set(person.firstname, "Jane"); update.where(person.id.eq(10)); update.execute(); // query query = new SQLQuery(connection, configuration); assertEquals(Gender.FEMALE, query.from(person).where(person.id.eq(10)).uniqueResult(person.gender)); }