@Override public final SQLUpdateClause update(RelationalPath<?> path) { return new SQLUpdateClause(connection, configuration, path); }
@Override public String updateProperty(final String key, final String newValue) { Objects.requireNonNull(key, "Null key is not supported!"); Objects.requireNonNull(newValue, "Null values are not supported!"); String previousValue = getProperty(key); boolean updated = transactionPropagator.required(() -> { return querydslSupport.execute((connection, configuration) -> { QProperty prop = QProperty.property; long updatedRowNum = new SQLUpdateClause(connection, configuration, prop) .where(prop.key.eq(key)) .set(prop.value, newValue) .execute(); cache.replace(key, newValue); return updatedRowNum > 0; }); }); if (updated) { return previousValue; } else { return null; } } }
protected SQLUpdateClause update(RelationalPath<?> e) { SQLUpdateClause sqlUpdateClause = new SQLUpdateClause(connection, configuration, e); sqlUpdateClause.addListener(new TestLoggingListener()); return sqlUpdateClause; }
@Test(expected = IllegalStateException.class) public void noConnection() { QEmployee emp1 = new QEmployee("emp1"); SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1); update.set(emp1.id, 1); update.execute(); }
@Test public void getSQL() { QEmployee emp1 = new QEmployee("emp1"); SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1); update.set(emp1.id, 1); SQLBindings sql = update.getSQL().get(0); assertEquals("update EMPLOYEE\nset ID = ?", sql.getSQL()); assertEquals(ImmutableList.of(1), sql.getBindings()); }
@Override protected void executeAfterBlobStatementClosedButBeforeConnectionClose() throws SQLException { super.executeAfterBlobStatementClosedButBeforeConnectionClose(); if (!this.updateBlobContentInUpdateSQLNecessary && getVersion() == this.newVersion) { return; } QBlobstoreBlob qBlob = QBlobstoreBlob.blobstoreBlob; SQLUpdateClause updateClause = new SQLUpdateClause(this.connection, this.querydslConfiguration, qBlob) .set(qBlob.version, getNewVersion()) .where(qBlob.blobId.eq(this.connectedBlob.blobId)); if (this.updateBlobContentInUpdateSQLNecessary) { updateClause.set(qBlob.blob, this.connectedBlob.blobChannel.getBlobExpression()); } updateClause.execute(); }
@Test public void update() { SQLUpdateClause updateClause = new SQLUpdateClause(connection,SQLTemplates.DEFAULT,survey); updateClause.set(survey.id, 1); updateClause.set(survey.name, (String) null); assertEquals("update SURVEY\nset ID = ?, NAME = ?", updateClause.toString()); }
if (hasRow()) { SQLUpdateClause update = new SQLUpdateClause(connection(), configuration, entity); update.addListener(listeners); populate(update);
@Test public void update_limit() { SQLUpdateClause clause = new SQLUpdateClause(null, createTemplates(), survey1); clause.set(survey1.name, "Bob"); clause.limit(5); assertEquals("update top 5 SURVEY\n" + "set NAME = ?", clause.toString()); }
@SuppressWarnings("unchecked") protected long executeCompositeMerge() { if (hasRow()) { // update SQLUpdateClause update = new SQLUpdateClause(connection(), configuration, entity); populate(update); addListeners(update); addKeyConditions(update); return update.execute(); } else { // insert SQLInsertClause insert = new SQLInsertClause(connection(), configuration, entity); addListeners(insert); populate(insert); return insert.execute(); } }
@Test public void update_where() { SQLUpdateClause updateClause = new SQLUpdateClause(connection,SQLTemplates.DEFAULT,survey); updateClause.set(survey.id, 1); updateClause.set(survey.name, (String) null); updateClause.where(survey.name.eq("XXX")); assertEquals("update SURVEY\nset ID = ?, NAME = ?\nwhere SURVEY.NAME = ?", updateClause.toString()); }
@Test public void intertable3() { QEmployee emp1 = new QEmployee("emp1"); QEmployee emp2 = new QEmployee("emp2"); SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1); update.set(emp1.superiorId, select(emp2.id).from(emp2) .where(emp2.id.eq(emp1.id))); SQLBindings sql = update.getSQL().get(0); assertEquals("update EMPLOYEE\n" + "set SUPERIOR_ID = (select emp2.ID\n" + "from EMPLOYEE emp2\n" + "where emp2.ID = EMPLOYEE.ID)", sql.getSQL()); }
@Test public void intertable2() { QEmployee emp1 = new QEmployee("emp1"); QEmployee emp2 = new QEmployee("emp2"); SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1); update.set(emp1.id, select(emp2.id).from(emp2) .where(emp2.superiorId.isNotNull())); SQLBindings sql = update.getSQL().get(0); assertEquals("update EMPLOYEE\n" + "set ID = (select emp2.ID\n" + "from EMPLOYEE emp2\n" + "where emp2.SUPERIOR_ID is not null)", sql.getSQL()); }
@Test public void clear() { QEmployee emp1 = new QEmployee("emp1"); SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1); update.set(emp1.id, 1); update.addBatch(); assertEquals(1, update.getBatchCount()); update.clear(); assertEquals(0, update.getBatchCount()); }
@Test public void intertable() { QEmployee emp1 = new QEmployee("emp1"); QEmployee emp2 = new QEmployee("emp2"); SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1); update.set(emp1.id, 1) .where(emp1.id.eq(select(emp2.id).from(emp2) .where(emp2.superiorId.isNotNull()))); SQLBindings sql = update.getSQL().get(0); assertEquals("update EMPLOYEE\n" + "set ID = ?\n" + "where EMPLOYEE.ID = (select emp2.ID\n" + "from EMPLOYEE emp2\n" + "where emp2.SUPERIOR_ID is not null)", sql.getSQL()); }