use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class DefaultSelectTranslator method appendGroupByColumn.
/**
* Append single column to GROUP BY clause
* @since 4.0
*/
protected void appendGroupByColumn(StringBuilder buffer, Map.Entry<ColumnDescriptor, List<DbAttributeBinding>> entry) {
String fullName;
if (entry.getKey().isExpression()) {
fullName = entry.getKey().getDataRowKey();
} else {
QuotingStrategy strategy = getAdapter().getQuotingStrategy();
fullName = strategy.quotedIdentifier(queryMetadata.getDataMap(), entry.getKey().getNamePrefix(), entry.getKey().getName());
}
buffer.append(fullName);
if (entry.getKey().getDataRowKey().equals(entry.getKey().getName())) {
for (DbAttributeBinding binding : entry.getValue()) {
addToParamList(binding.getAttribute(), binding.getValue());
}
}
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class QueryAssembler method addToParamList.
/**
* Registers <code>anObject</code> as a PreparedStatement parameter.
*
* @param anObject
* object that represents a value of DbAttribute
* @param dbAttr
* DbAttribute being processed.
*/
public void addToParamList(DbAttribute dbAttr, Object anObject) {
ExtendedType extendedType = anObject != null ? adapter.getExtendedTypes().getRegisteredType(anObject.getClass()) : adapter.getExtendedTypes().getDefaultType();
DbAttributeBinding binding = new DbAttributeBinding(dbAttr);
binding.setStatementPosition(bindings.size() + 1);
binding.setValue(anObject);
binding.setExtendedType(extendedType);
bindings.add(binding);
if (addBindingListener != null) {
addBindingListener.onAdd(binding);
}
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class Oracle8LOBBatchAction method performAction.
@Override
public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
Oracle8LOBBatchTranslator translator;
if (query instanceof InsertBatchQuery) {
translator = new Oracle8LOBInsertBatchTranslator((InsertBatchQuery) query, adapter, OracleAdapter.TRIM_FUNCTION);
} else if (query instanceof UpdateBatchQuery) {
translator = new Oracle8LOBUpdateBatchTranslator((UpdateBatchQuery) query, adapter, OracleAdapter.TRIM_FUNCTION);
} else {
throw new CayenneException("Unsupported batch type for special LOB processing: " + query);
}
translator.setNewBlobFunction(OracleAdapter.NEW_BLOB_FUNCTION);
translator.setNewClobFunction(OracleAdapter.NEW_CLOB_FUNCTION);
// no batching is done, queries are translated
// for each batch set, since prepared statements
// may be different depending on whether LOBs are NULL or not..
Oracle8LOBBatchQueryWrapper selectQuery = new Oracle8LOBBatchQueryWrapper(query);
List<DbAttribute> qualifierAttributes = selectQuery.getDbAttributesForLOBSelectQualifier();
for (BatchQueryRow row : query.getRows()) {
selectQuery.indexLOBAttributes(row);
int updated;
String updateStr = translator.createSql(row);
// 1. run row update
logger.log(updateStr);
try (PreparedStatement statement = connection.prepareStatement(updateStr)) {
DbAttributeBinding[] bindings = translator.updateBindings(row);
logger.logQueryParameters("bind", bindings);
bind(adapter, statement, bindings);
updated = statement.executeUpdate();
logger.logUpdateCount(updated);
}
// 2. run row LOB update (SELECT...FOR UPDATE and writing out LOBs)
processLOBRow(connection, translator, selectQuery, qualifierAttributes, row);
// finally, notify delegate that the row was updated
observer.nextCount(query, updated);
}
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class Oracle8LOBBatchTranslator method createBindings.
@Override
protected DbAttributeBinding[] createBindings() {
List<DbAttribute> dbAttributes = query.getDbAttributes();
int len = dbAttributes.size();
DbAttributeBinding[] bindings = new DbAttributeBinding[len];
for (int i = 0; i < len; i++) {
bindings[i] = new DbAttributeBinding(dbAttributes.get(i));
}
return bindings;
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class Oracle8LOBBatchAction method bind.
private static void bind(DbAdapter adapter, PreparedStatement statement, DbAttributeBinding[] bindings) throws SQLException, Exception {
for (DbAttributeBinding b : bindings) {
DbAttributeBinding binding = new DbAttributeBinding(b.getAttribute());
adapter.bindParameter(statement, binding);
}
}
Aggregations