Search in sources :

Example 1 with BatchTranslator

use of org.apache.cayenne.access.translator.batch.BatchTranslator in project cayenne by apache.

the class BatchAction method performAction.

@Override
public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
    BatchTranslator translator = createTranslator();
    boolean generatesKeys = hasGeneratedKeys();
    if (runningAsBatch && !generatesKeys) {
        runAsBatch(connection, translator, observer);
    } else {
        runAsIndividualQueries(connection, translator, observer, generatesKeys);
    }
}
Also used : BatchTranslator(org.apache.cayenne.access.translator.batch.BatchTranslator)

Example 2 with BatchTranslator

use of org.apache.cayenne.access.translator.batch.BatchTranslator in project cayenne by apache.

the class CryptoBatchTranslatorFactoryDecorator method translator.

@Override
public BatchTranslator translator(BatchQuery query, final DbAdapter adapter, String trimFunction) {
    final BatchTranslator delegateTranslator = delegate.translator(query, adapter, trimFunction);
    return new BatchTranslator() {

        private boolean encryptorCompiled;

        private BindingsTransformer encryptor;

        private void ensureEncryptorCompiled() {
            if (!encryptorCompiled) {
                encryptor = cryptoFactory.encryptor(getBindings(), adapter.getExtendedTypes());
                encryptorCompiled = true;
            }
        }

        @Override
        public String getSql() {
            return delegateTranslator.getSql();
        }

        @Override
        public DbAttributeBinding[] getBindings() {
            return delegateTranslator.getBindings();
        }

        @Override
        public DbAttributeBinding[] updateBindings(BatchQueryRow row) {
            ensureEncryptorCompiled();
            DbAttributeBinding[] bindings = delegateTranslator.updateBindings(row);
            if (encryptor != null) {
                encryptor.transform(bindings);
            }
            return bindings;
        }
    };
}
Also used : BatchTranslator(org.apache.cayenne.access.translator.batch.BatchTranslator) BatchQueryRow(org.apache.cayenne.query.BatchQueryRow) DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) BindingsTransformer(org.apache.cayenne.crypto.transformer.BindingsTransformer)

Aggregations

BatchTranslator (org.apache.cayenne.access.translator.batch.BatchTranslator)2 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)1 BindingsTransformer (org.apache.cayenne.crypto.transformer.BindingsTransformer)1 BatchQueryRow (org.apache.cayenne.query.BatchQueryRow)1