use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class InsertBase method insert_batch.
@Test
public void insert_batch() {
SQLInsertClause insert = insert(survey).set(survey.id, 5).set(survey.name, "55").addBatch();
assertEquals(1, insert.getBatchCount());
insert.set(survey.id, 6).set(survey.name, "66").addBatch();
assertEquals(2, insert.getBatchCount());
assertEquals(2, insert.execute());
assertEquals(1L, query().from(survey).where(survey.name.eq("55")).fetchCount());
assertEquals(1L, query().from(survey).where(survey.name.eq("66")).fetchCount());
}
use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class InsertBase method insert_with_keys_OverriddenColumn.
@Test(expected = QueryException.class)
@IncludeIn({ DERBY, HSQLDB })
public void insert_with_keys_OverriddenColumn() throws SQLException {
String originalColumnName = ColumnMetadata.getName(survey.id);
try {
configuration.registerColumnOverride(survey.getSchemaName(), survey.getTableName(), originalColumnName, "wrongColumnName");
SQLInsertClause sqlInsertClause = new SQLInsertClause(connection, configuration, survey);
sqlInsertClause.addListener(new TestLoggingListener());
Object id = sqlInsertClause.set(survey.name, "Hello you").executeWithKey(survey.id);
assertNotNull(id);
} finally {
configuration.registerColumnOverride(survey.getSchemaName(), survey.getTableName(), originalColumnName, originalColumnName);
}
}
use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.
the class AbstractBaseTest method insert.
protected SQLInsertClause insert(RelationalPath<?> e) {
SQLInsertClause sqlInsertClause = new SQLInsertClause(connection, configuration, e);
sqlInsertClause.addListener(new TestLoggingListener());
return sqlInsertClause;
}
use of com.querydsl.sql.dml.SQLInsertClause in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertAuditDeltas.
private Collection<MAuditDelta> insertAuditDeltas(JdbcSession jdbcSession, long recordId, Collection<ObjectDeltaOperation<?>> deltas) {
// we want to keep only unique deltas, checksum is also part of PK
Map<String, MAuditDelta> deltasByChecksum = new HashMap<>();
for (ObjectDeltaOperation<?> deltaOperation : deltas) {
if (deltaOperation == null) {
continue;
}
MAuditDelta mAuditDelta = convertDelta(deltaOperation, recordId);
deltasByChecksum.put(mAuditDelta.checksum, mAuditDelta);
}
if (!deltasByChecksum.isEmpty()) {
SQLInsertClause insertBatch = jdbcSession.newInsert(QAuditDeltaMapping.get().defaultAlias());
for (MAuditDelta value : deltasByChecksum.values()) {
// NULLs are important to keep the value count consistent during the batch
insertBatch.populate(value, DefaultMapper.WITH_NULL_BINDINGS).addBatch();
}
insertBatch.setBatchToBulk(true);
insertBatch.execute();
}
return deltasByChecksum.values();
}
use of com.querydsl.sql.dml.SQLInsertClause in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertProperties.
private void insertProperties(JdbcSession jdbcSession, long recordId, Map<String, Set<String>> properties) {
if (properties.isEmpty()) {
return;
}
QAuditPropertyValue qAuditPropertyValue = QAuditPropertyValueMapping.get().defaultAlias();
SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditPropertyValue);
for (String propertyName : properties.keySet()) {
for (String propertyValue : properties.get(propertyName)) {
// id will be generated, but we're not interested in those here
insertBatch.set(qAuditPropertyValue.recordId, recordId).set(qAuditPropertyValue.name, propertyName).set(qAuditPropertyValue.value, propertyValue).addBatch();
}
}
if (insertBatch.getBatchCount() == 0) {
// strange, no values anywhere?
return;
}
insertBatch.setBatchToBulk(true);
insertBatch.execute();
}
Aggregations