Search in sources :

Example 11 with DbAttributeBinding

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());
        }
    }
}
Also used : DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 12 with DbAttributeBinding

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);
    }
}
Also used : DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Example 13 with DbAttributeBinding

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);
    }
}
Also used : InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute) PreparedStatement(java.sql.PreparedStatement) DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) BatchQueryRow(org.apache.cayenne.query.BatchQueryRow) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) CayenneException(org.apache.cayenne.CayenneException)

Example 14 with DbAttributeBinding

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;
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding)

Example 15 with DbAttributeBinding

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);
    }
}
Also used : DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding)

Aggregations

DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)24 DbAttribute (org.apache.cayenne.map.DbAttribute)12 ExtendedType (org.apache.cayenne.access.types.ExtendedType)8 BatchQueryRow (org.apache.cayenne.query.BatchQueryRow)7 DbAdapter (org.apache.cayenne.dba.DbAdapter)5 PreparedStatement (java.sql.PreparedStatement)3 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)3 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)3 BatchQuery (org.apache.cayenne.query.BatchQuery)3 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)3 Test (org.junit.Test)3 ResultSet (java.sql.ResultSet)2 DbEntity (org.apache.cayenne.map.DbEntity)2 UpdateBatchQuery (org.apache.cayenne.query.UpdateBatchQuery)2 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 SQLException (java.sql.SQLException)1 CayenneException (org.apache.cayenne.CayenneException)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataRow (org.apache.cayenne.DataRow)1