@Override public long doInSqlUpdateClause(SQLUpdateClause update) { return update.where(qAddress.id.eq(a.getId())).set(qAddress.customerId, customer.getId()) .set(qAddress.street, a.getStreet()).set(qAddress.city, a.getCity()) .set(qAddress.country, a.getCountry()).execute(); } });
@Override public long doInSqlUpdateClause(SQLUpdateClause update) { return update .where(qCustomer.id.eq(customer.getId())) .set(qCustomer.firstName, customer.getFirstName()) .set(qCustomer.lastName, customer.getLastName()) .set(qCustomer.emailAddress, customer.getEmailAddress() == null ? null : customer.getEmailAddress().toString()).execute(); } });
@Override public int swapWorklogGroupRestriction(final String groupName, final String swapGroup) { checkArgument(groupName != null, "You must provide a non null group name."); checkArgument(swapGroup != null, "You must provide a non null swap group name."); return Ints.checkedCast(dbConnectionManager.executeQuery(dc -> dc.update(WORKLOG) .set(WORKLOG.grouplevel, swapGroup) .where(WORKLOG.grouplevel.eq(groupName)) .execute())); }
@Override public int swapWorklogRoleRestriction(final Long roleId, final Long swapRoleId) { checkNotNull(roleId, "You must provide a non null role id."); checkNotNull(swapRoleId, "You must provide a non null swap role id."); return Ints.checkedCast(dbConnectionManager.executeQuery(dc -> dc.update(WORKLOG) .set(WORKLOG.rolelevel, swapRoleId) .where(WORKLOG.rolelevel.eq(roleId)) .execute())); }
@Override public Object execute() { try (Connection connection = dataSource.getConnection()) { QProperties prop = QProperties.propProperties; cache.replace(key, newValue); new SQLUpdateClause(connection, sqlTemplates, prop) .where(prop.key.eq(key)) .set(prop.value, newValue) .execute(); } catch (SQLException e) { throw new PropertyServiceDataSourceConnectionException("Cannot connect to DataSource.", e); } return null; } });
@Override public boolean updatePrincipal(final String principal, final String newPrincipal) { long updateCount = querydslSupport.execute((connection, configuration) -> { QSimpleSubject qSimpleSubject = QSimpleSubject.simpleSubject; return new SQLUpdateClause(connection, configuration, qSimpleSubject) .where(qSimpleSubject.principal.eq(principal)) .set(qSimpleSubject.principal, newPrincipal) .execute(); }); return updateCount > 0; }
@Override public boolean updateCredential(final String principal, final String newPlainCredential) { String encryptedCredential = (newPlainCredential == null) ? null : credentialEncryptor.encrypt(newPlainCredential); long updateCount = querydslSupport.execute((connection, configuration) -> { QSimpleSubject qSimpleSubject = QSimpleSubject.simpleSubject; return new SQLUpdateClause(connection, configuration, qSimpleSubject) .where(qSimpleSubject.principal.eq(principal)) .set(qSimpleSubject.encryptedCredential, encryptedCredential) .execute(); }); return updateCount > 0; }
private void updateIssueLinkType(final IssueLink issueLink, final IssueLinkType issueLinkType) { dbConnectionManager.execute(dbConnection -> dbConnection.update(QIssueLink.ISSUE_LINK) .set(QIssueLink.ISSUE_LINK.linktype, issueLinkType.getId()) .where(QIssueLink.ISSUE_LINK.id.eq(issueLink.getId())) .execute()); }
@Override public Project updateProjectType(final ApplicationUser user, final Project project, final ProjectTypeKey newProjectType) { checkState(projectTypeValidator.isValid(user, newProjectType)); dbConnectionManager.execute(dbConnection -> { dbConnection.update(QProject.PROJECT) .set(QProject.PROJECT.projecttype, newProjectType != null ? newProjectType.getKey() : null) .where(QProject.PROJECT.id.eq(project.getId())) .execute(); }); return getProjectObj(project.getId()); }
public void updateIssueType(String id, String name, Long sequence, String style, String description, String iconurl) throws DataAccessException { if (id == null) { throw new IllegalArgumentException("Id cannot be null."); } try { dbConnectionManager.execute(dbConnection -> { final long rowCount = dbConnection.update(ISSUE_TYPE) .set(ISSUE_TYPE.name, name) .set(ISSUE_TYPE.sequence, sequence) .set(ISSUE_TYPE.style, style) .set(ISSUE_TYPE.description, description) .set(ISSUE_TYPE.iconurl, iconurl) .where(ISSUE_TYPE.id.eq(id)) .execute(); if (rowCount == 0) { throw new IllegalArgumentException("Issue Type with id '" + id + "' does not exist."); } }); } finally { refreshIssueTypes(); } }
@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(); } }
public void updateIssueType(String id, String name, Long sequence, String style, String description, Long avatarId) throws DataAccessException { if (id == null) { throw new IllegalArgumentException("Id cannot be null."); } try { dbConnectionManager.execute(dbConnection -> { final long rowCount = dbConnection.update(ISSUE_TYPE) .set(ISSUE_TYPE.name, name) .set(ISSUE_TYPE.sequence, sequence) .set(ISSUE_TYPE.style, style) .set(ISSUE_TYPE.description, description) .set(ISSUE_TYPE.avatar, avatarId) .where(ISSUE_TYPE.id.eq(id)) .execute(); if (rowCount == 0) { throw new IllegalArgumentException("Issue Type with id '" + id + "' does not exist."); } }); } finally { refreshIssueTypes(); } }
private void recalculateSequenceAndStore(final List<? extends IssueConstant> constants, final RelationalPath<?> entity, final NumberPath<Long> sequencePath, final StringPath idPath) { dbConnectionManager.execute(dbConnection -> { dbConnection.setAutoCommit(false); long sequence = 0; for (IssueConstant constant : constants) { dbConnection.update(entity) .set(sequencePath, sequence) .where(idPath.eq(constant.getId())) .execute(); sequence++; } dbConnection.commit(); }); }
@Override public boolean updateCredential(final String principal, final String originalPlainCredential, final String newPlainCredential) { QSimpleSubject qSimpleSubject = QSimpleSubject.simpleSubject; String originalEncryptedCredential = readEncryptedCredential(principal); if ((originalEncryptedCredential != null) && !credentialMatcher.match(originalPlainCredential, originalEncryptedCredential)) { return false; } String encryptedNewCredential = (newPlainCredential == null) ? null : credentialEncryptor.encrypt(newPlainCredential); long updateCount = querydslSupport.execute((connection, configuration) -> { return new SQLUpdateClause(connection, configuration, qSimpleSubject) .where(qSimpleSubject.principal.eq(principal)) .set(qSimpleSubject.encryptedCredential, encryptedNewCredential) .execute(); }); return updateCount > 0; }
public void updateIssueLinkType(final IssueLinkType issueLinkType, final String name, final String outward, final String inward) { try { dbConnectionManager.execute(dbConnection -> { final QIssueLinkType ilt = new QIssueLinkType("ilt"); dbConnection.update(ilt) .set(ilt.linkname, name) .set(ilt.outward, outward) .set(ilt.inward, inward) .where(ilt.id.eq(issueLinkType.getId())) .execute(); }); } finally { clearCache(); } }
@Override public Worklog update(final Worklog worklog) { final WorklogDTO worklogDTO = dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery() .from(WORKLOG) .where(WORKLOG.id.eq(worklog.getId())) .singleResult(WORKLOG)); if (worklogDTO != null) { dbConnectionManager.execute(dbConnection -> { setWorklogFields(dbConnection.update(WORKLOG), worklog) .where(WORKLOG.id.eq(worklog.getId())) .execute(); }); } else { throw new IllegalArgumentException("Could not find original worklog entity to update."); } return getById(worklog.getId()); }
public void resetSequences(final List<IssueLink> issueLinks) { dbConnectionManager.execute(dbConnection -> { dbConnection.setAutoCommit(false); long i = 0; for (final IssueLink issueLink : issueLinks) { dbConnection.update(QIssueLink.ISSUE_LINK) .set(QIssueLink.ISSUE_LINK.sequence, i) .where(QIssueLink.ISSUE_LINK.id.eq(issueLink.getId())) .execute(); i++; } dbConnection.commit(); // Make sure we don't clear the cache until after the DB is committed, else we get a race condition // whereby another thread can put stale values back into the cache. for (IssueLink issueLink : issueLinks) { outwardLinkCache.remove(issueLink.getSourceId()); inwardLinkCache.remove(issueLink.getDestinationId()); } }); }
.set(a.fileName, newIconName) .set(a.contentType, SVG_CONTENT_TYPE) .execute();
@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)); }