use of org.jooq.AttachableInternal in project jOOQ by jOOQ.
the class DefaultRecordMapper method attach.
private static <E> E attach(E attachable, Record record) {
// Settings.attachRecords flag is set
if (attachable instanceof Attachable && record instanceof AttachableInternal) {
Attachable a = (Attachable) attachable;
AttachableInternal r = (AttachableInternal) record;
if (Tools.attachRecords(r.configuration())) {
a.attach(r.configuration());
}
}
return attachable;
}
use of org.jooq.AttachableInternal in project jOOQ by jOOQ.
the class BatchCRUD method executeStatic.
private final int[] executeStatic() {
List<Query> queries = new ArrayList<Query>();
QueryCollector collector = new QueryCollector();
Configuration local = configuration.derive(Tools.combine(configuration.executeListenerProviders(), new DefaultExecuteListenerProvider(collector)));
for (int i = 0; i < records.length; i++) {
Configuration previous = ((AttachableInternal) records[i]).configuration();
try {
records[i].attach(local);
executeAction(i);
} catch (QueryCollectorSignal e) {
Query query = e.getQuery();
if (query.isExecutable()) {
queries.add(query);
}
} finally {
records[i].attach(previous);
}
}
// Resulting statements can be batch executed in their requested order
int[] result = create.batch(queries).execute();
updateChangedFlag();
return result;
}
use of org.jooq.AttachableInternal in project jOOQ by jOOQ.
the class BatchCRUD method executePrepared.
private final int[] executePrepared() {
Map<String, List<Query>> queries = new LinkedHashMap<String, List<Query>>();
QueryCollector collector = new QueryCollector();
// Add the QueryCollector to intercept query execution after rendering
Configuration local = configuration.derive(Tools.combine(configuration.executeListenerProviders(), new DefaultExecuteListenerProvider(collector)));
// [#1537] Communicate with UpdatableRecordImpl
local.data(DATA_OMIT_RETURNING_CLAUSE, true);
// [#1529] Avoid DEBUG logging of single INSERT / UPDATE statements
local.settings().setExecuteLogging(false);
for (int i = 0; i < records.length; i++) {
Configuration previous = ((AttachableInternal) records[i]).configuration();
try {
records[i].attach(local);
executeAction(i);
} catch (QueryCollectorSignal e) {
Query query = e.getQuery();
String sql = e.getSQL();
// Aggregate executable queries by identical SQL
if (query.isExecutable()) {
List<Query> list = queries.get(sql);
if (list == null) {
list = new ArrayList<Query>();
queries.put(sql, list);
}
list.add(query);
}
} finally {
records[i].attach(previous);
}
}
// Execute one batch statement for each identical SQL statement. Every
// SQL statement may have several queries with different bind values.
// The order is preserved as much as possible
List<Integer> result = new ArrayList<Integer>();
for (Entry<String, List<Query>> entry : queries.entrySet()) {
BatchBindStep batch = create.batch(entry.getValue().get(0));
for (Query query : entry.getValue()) {
batch.bind(query.getBindValues().toArray());
}
int[] array = batch.execute();
for (int i : array) {
result.add(i);
}
}
int[] array = new int[result.size()];
for (int i = 0; i < result.size(); i++) {
array[i] = result.get(i);
}
updateChangedFlag();
return array;
}
use of org.jooq.AttachableInternal in project jOOQ by jOOQ.
the class MockResultSetMetaData method getSchemaName.
@Override
public String getSchemaName(int column) throws SQLException {
rs.checkNotClosed();
Field<?> field = rs.result.field(column - 1);
if (field instanceof TableField) {
Table<?> table = ((TableField<?, ?>) field).getTable();
if (table != null) {
Schema schema = table.getSchema();
if (schema != null) {
Configuration configuration = ((AttachableInternal) rs.result).configuration();
Schema mapped = null;
if (configuration != null) {
mapped = DSL.using(configuration).map(schema);
}
if (mapped != null) {
return mapped.getName();
} else {
return schema.getName();
}
}
}
}
// By default, no schema is available
return "";
}
use of org.jooq.AttachableInternal in project jOOQ by jOOQ.
the class Mock method result.
/**
* Wrap a record in a result.
*/
static final Result<?> result(Record data) {
Configuration configuration = data instanceof AttachableInternal ? ((AttachableInternal) data).configuration() : new DefaultConfiguration();
Result<Record> result = using(configuration).newResult(data.fields());
result.add(data);
return result;
}
Aggregations