use of org.apache.cayenne.access.types.ValueObjectType in project cayenne by apache.
the class SelectQueryMetadataCacheKeyTest method createObjects.
@SuppressWarnings("unchecked")
@Before
public void createObjects() {
registry = mock(ValueObjectTypeRegistry.class);
// mock value type for Double class
ValueObjectType mockType = mock(ValueObjectType.class);
when(mockType.getValueType()).thenReturn(Double.class);
when(mockType.toCacheKey(any())).thenReturn("<value placeholder>");
when(registry.getValueType(eq(Double.class))).thenReturn(mockType);
// value type for TestValue class
ValueObjectType testType = new TestValueType();
when(registry.getValueType(eq(TestValue.class))).thenReturn(testType);
}
use of org.apache.cayenne.access.types.ValueObjectType in project cayenne by apache.
the class ToCacheKeyTraversalHandler method objectNode.
@Override
public void objectNode(Object leaf, Expression parentNode) {
if (leaf == null) {
out.append("null");
return;
}
if (leaf instanceof ASTScalar) {
leaf = ((ASTScalar) leaf).getValue();
} else if (leaf instanceof Object[]) {
for (Object value : (Object[]) leaf) {
objectNode(value, parentNode);
out.append(',');
}
return;
}
if (leaf instanceof Persistent) {
ObjectId id = ((Persistent) leaf).getObjectId();
Object encode = (id != null) ? id : leaf;
out.append(encode);
} else if (leaf instanceof Enum<?>) {
Enum<?> e = (Enum<?>) leaf;
out.append("e:").append(leaf.getClass().getName()).append(':').append(e.ordinal());
} else {
ValueObjectType<Object, ?> valueObjectType;
if (registry == null || (valueObjectType = registry.getValueType(leaf.getClass())) == null) {
// Registry will be null in cayenne-client context.
// Maybe we shouldn't create cache key at all in that case...
out.append(leaf);
} else {
out.append(valueObjectType.toCacheKey(leaf));
}
}
}
Aggregations