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;
}
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;
}
Aggregations