use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class PersistentObject method getMapKey.
/**
* Returns a map key for a given to-many map relationship and a target object.
*
* @since 3.0
*/
protected Object getMapKey(String relationshipName, Object value) {
EntityResolver resolver = objectContext.getEntityResolver();
ClassDescriptor descriptor = resolver.getClassDescriptor(objectId.getEntityName());
if (descriptor == null) {
throw new IllegalStateException("DataObject's entity is unmapped, objectId: " + objectId);
}
PropertyDescriptor property = descriptor.getProperty(relationshipName);
if (property instanceof ToManyMapProperty) {
return ((ToManyMapProperty) property).getMapKey(value);
}
throw new IllegalArgumentException("Relationship '" + relationshipName + "' is not a to-many Map");
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class ServerRuntimeTest method testGetDataChannel_CustomModule.
@Test
public void testGetDataChannel_CustomModule() {
final DataChannel channel = new DataChannel() {
public EntityResolver getEntityResolver() {
return null;
}
public EventManager getEventManager() {
return null;
}
public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
return null;
}
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
return null;
}
};
Module module = binder -> binder.bind(DataChannel.class).toInstance(channel);
ServerRuntime runtime = new ServerRuntime(Collections.singleton(module));
assertSame(channel, runtime.getChannel());
}
Aggregations