Search in sources :

Example 1 with ValueObjectType

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);
}
Also used : ValueObjectType(org.apache.cayenne.access.types.ValueObjectType) ValueObjectTypeRegistry(org.apache.cayenne.access.types.ValueObjectTypeRegistry) Before(org.junit.Before)

Example 2 with ValueObjectType

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));
        }
    }
}
Also used : ValueObjectType(org.apache.cayenne.access.types.ValueObjectType) ObjectId(org.apache.cayenne.ObjectId) Persistent(org.apache.cayenne.Persistent) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar)

Aggregations

ValueObjectType (org.apache.cayenne.access.types.ValueObjectType)2 ObjectId (org.apache.cayenne.ObjectId)1 Persistent (org.apache.cayenne.Persistent)1 ValueObjectTypeRegistry (org.apache.cayenne.access.types.ValueObjectTypeRegistry)1 ASTScalar (org.apache.cayenne.exp.parser.ASTScalar)1 Before (org.junit.Before)1