Search in sources :

Example 1 with BindingsTransformer

use of org.apache.cayenne.crypto.transformer.BindingsTransformer 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

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