@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; }
@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 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()); }
@Override public long execute() { context = startContext(connection, metadata, entity); try { if (batches.isEmpty()) { stmt = createStatement(); listeners.notifyUpdate(entity, metadata, updates); return rc; } else { stmts = createStatements(); listeners.notifyUpdates(entity, batches); long rc = executeBatch(stmts); listeners.executed(context); return rc; onException(context,e); throw configuration.translate(queryString, constants, e); } finally { if (stmt != null) { close(stmt); close(stmts); reset(); endContext(context);
@Override public SQLUpdateClause update(final RelationalPath<?> entity) { return new SQLUpdateClause(con, dialect, entity); }
/** * 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 List<SQLBindings> getSQL() { if (batches.isEmpty()) { SQLSerializer serializer = createSerializer(); serializer.serializeUpdate(metadata, entity, updates); return ImmutableList.of(createBindings(metadata, serializer)); } else { ImmutableList.Builder<SQLBindings> builder = ImmutableList.builder(); for (SQLUpdateBatch batch : batches) { SQLSerializer serializer = createSerializer(); serializer.serializeUpdate(batch.getMetadata(), entity, batch.getUpdates()); builder.add(createBindings(metadata, serializer)); } return builder.build(); } }
@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 final SQLUpdateClause update(RelationalPath<?> path) { return new SQLUpdateClause(connection.get(), configuration, path); }
@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 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; }
if (hasRow()) { SQLUpdateClause update = new SQLUpdateClause(connection, configuration, entity); populate(update); addKeyConditions(update);
@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 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; }
@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())); }
@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)); }
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(); } }
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()); }