Search in sources :

Example 1 with ValueDecryptor

use of org.apache.cayenne.crypto.transformer.value.ValueDecryptor in project cayenne by apache.

the class DefaultTransformerFactory method decryptor.

@Override
public MapTransformer decryptor(ColumnDescriptor[] columns, Object sampleRow) {
    if (!(sampleRow instanceof Map)) {
        return null;
    }
    int len = columns.length;
    List<Integer> cryptoColumns = null;
    for (int i = 0; i < len; i++) {
        DbAttribute a = columns[i].getAttribute();
        if (a != null && columnMapper.isEncrypted(a)) {
            if (cryptoColumns == null) {
                cryptoColumns = new ArrayList<>(len - i);
            }
            cryptoColumns.add(i);
        }
    }
    if (cryptoColumns != null) {
        int dlen = cryptoColumns.size();
        String[] mapKeys = new String[dlen];
        ValueDecryptor[] transformers = new ValueDecryptor[dlen];
        for (int i = 0; i < dlen; i++) {
            ColumnDescriptor cd = columns[cryptoColumns.get(i)];
            mapKeys[i] = cd.getDataRowKey();
            transformers[i] = transformerFactory.decryptor(cd.getAttribute());
        }
        return new DefaultMapTransformer(mapKeys, transformers, bytesTransformerFactory.decryptor());
    }
    return null;
}
Also used : ValueDecryptor(org.apache.cayenne.crypto.transformer.value.ValueDecryptor) ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor) DbAttribute(org.apache.cayenne.map.DbAttribute) ExtendedTypeMap(org.apache.cayenne.access.types.ExtendedTypeMap) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 ColumnDescriptor (org.apache.cayenne.access.jdbc.ColumnDescriptor)1 ExtendedTypeMap (org.apache.cayenne.access.types.ExtendedTypeMap)1 ValueDecryptor (org.apache.cayenne.crypto.transformer.value.ValueDecryptor)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1