Search in sources :

Example 86 with EntityResolver

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");
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) PropertyDescriptor(org.apache.cayenne.reflect.PropertyDescriptor) ToManyMapProperty(org.apache.cayenne.reflect.ToManyMapProperty) EntityResolver(org.apache.cayenne.map.EntityResolver)

Example 87 with EntityResolver

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ObjectContext(org.apache.cayenne.ObjectContext) Arrays(java.util.Arrays) DataContext(org.apache.cayenne.access.DataContext) Module(org.apache.cayenne.di.Module) BaseTransaction(org.apache.cayenne.tx.BaseTransaction) EntityResolver(org.apache.cayenne.map.EntityResolver) Arrays.asList(java.util.Arrays.asList) GraphDiff(org.apache.cayenne.graph.GraphDiff) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) Key(org.apache.cayenne.di.Key) Collection(java.util.Collection) Constants(org.apache.cayenne.configuration.Constants) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DataChannel(org.apache.cayenne.DataChannel) Query(org.apache.cayenne.query.Query) TransactionDescriptor(org.apache.cayenne.tx.TransactionDescriptor) List(java.util.List) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory) EventManager(org.apache.cayenne.event.EventManager) QueryResponse(org.apache.cayenne.QueryResponse) TransactionalOperation(org.apache.cayenne.tx.TransactionalOperation) Assert(org.junit.Assert) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) DataChannel(org.apache.cayenne.DataChannel) Query(org.apache.cayenne.query.Query) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectContext(org.apache.cayenne.ObjectContext) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)87 Test (org.junit.Test)57 ObjEntity (org.apache.cayenne.map.ObjEntity)17 ObjectId (org.apache.cayenne.ObjectId)14 DataMap (org.apache.cayenne.map.DataMap)14 DbEntity (org.apache.cayenne.map.DbEntity)10 ArrayList (java.util.ArrayList)7 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)7 HashMap (java.util.HashMap)6 QueryResponse (org.apache.cayenne.QueryResponse)6 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 MockEventManager (org.apache.cayenne.event.MockEventManager)5 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)5 GenericResponse (org.apache.cayenne.util.GenericResponse)5 List (java.util.List)4 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 Artist (org.apache.cayenne.testdo.testmap.Artist)4 Map (java.util.Map)3