Search in sources :

Example 16 with ColumnDescriptor

use of org.apache.cayenne.access.jdbc.ColumnDescriptor 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)

Example 17 with ColumnDescriptor

use of org.apache.cayenne.access.jdbc.ColumnDescriptor in project cayenne by apache.

the class ResultDirective method render.

@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
    String column = getChildAsString(context, node, 0);
    if (column == null) {
        throw new ParseErrorException("Column name expected at line " + node.getLine() + ", column " + node.getColumn());
    }
    String alias = getChildAsString(context, node, 2);
    String dataRowKey = getChildAsString(context, node, 3);
    // determine what we want to name this column in a resulting DataRow...
    String label = (!Util.isEmptyString(dataRowKey)) ? dataRowKey : (!Util.isEmptyString(alias)) ? alias : null;
    ColumnDescriptor columnDescriptor = new ColumnDescriptor();
    columnDescriptor.setName(column);
    columnDescriptor.setDataRowKey(label);
    String type = getChildAsString(context, node, 1);
    if (type != null) {
        columnDescriptor.setJavaClass(guessType(type));
    }
    // TODO: andrus 6/27/2007 - this is an unofficial jdbcType parameter
    // that is added
    // temporarily pending CAY-813 implementation for the sake of EJBQL
    // query...
    Object jdbcType = getChild(context, node, 4);
    if (jdbcType instanceof Number) {
        columnDescriptor.setJdbcType(((Number) jdbcType).intValue());
    }
    writer.write(column);
    // won't probably buy us much.
    if (!Util.isEmptyString(alias) && !alias.equals(column)) {
        writer.write(" AS ");
        writer.write(alias);
    }
    bindResult(context, columnDescriptor);
    return true;
}
Also used : ParseErrorException(org.apache.velocity.exception.ParseErrorException) ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor)

Aggregations

ColumnDescriptor (org.apache.cayenne.access.jdbc.ColumnDescriptor)17 DbAttribute (org.apache.cayenne.map.DbAttribute)5 Test (org.junit.Test)5 DataRow (org.apache.cayenne.DataRow)4 ArrayList (java.util.ArrayList)3 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 RowDescriptor (org.apache.cayenne.access.jdbc.RowDescriptor)2 SQLStatement (org.apache.cayenne.access.jdbc.SQLStatement)2 ExtendedType (org.apache.cayenne.access.types.ExtendedType)2 Expression (org.apache.cayenne.exp.Expression)2 DataMap (org.apache.cayenne.map.DataMap)2 DbEntity (org.apache.cayenne.map.DbEntity)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 ResultSet (java.sql.ResultSet)1 Collection (java.util.Collection)1