@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(); } });
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(); } }
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(); } }
/** * Populate the UPDATE clause with the properties of the given bean using the given Mapper. * * @param obj * @param mapper * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public <T> SQLUpdateClause populate(T obj, Mapper<T> mapper) { Collection<? extends Path<?>> primaryKeyColumns = entity.getPrimaryKey() != null ? entity.getPrimaryKey().getLocalColumns() : Collections.<Path<?>>emptyList(); Map<Path<?>, Object> values = mapper.createMap(entity, obj); for (Map.Entry<Path<?>, Object> entry : values.entrySet()) { if (!primaryKeyColumns.contains(entry.getKey())) { set((Path)entry.getKey(), entry.getValue()); } } return this; }
@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())); }
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 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()); }
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; }
.update(it) .where(it.avatar.eq(iconToReplaceId)) .set(it.avatar, replacementIconId) .execute(); .and(a.systemAvatar.eq(TRUE)) .and(a.fileName.eq(oldIconName))) .set(a.fileName, newIconName) .set(a.contentType, SVG_CONTENT_TYPE) .execute(); .where(it.avatar.isNull() .and(it.iconurl.eq(oldIconUrl))) .set(it.avatar, new SQLSubQuery() .from(a) .where(a.avatarType.eq(ISSUE_TYPE_AVATAR)
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()); } }); }
@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)); }