Search in sources :

Example 36 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EOModelPrototypesTest method testSameColumnMapping.

// TODO: move this test to EOModelProcessorInheritanceTst. The original problem had
// nothing
// to do with prototypes...
@Test
public void testSameColumnMapping() throws Exception {
    DataMap map = new EOModelProcessor().loadEOModel(url);
    ObjEntity estimateOE = map.getObjEntity("Estimate");
    ObjEntity invoiceOE = map.getObjEntity("Invoice");
    ObjEntity vendorOE = map.getObjEntity("VendorPO");
    assertNotNull(estimateOE);
    assertNotNull(invoiceOE);
    assertNotNull(vendorOE);
    ObjAttribute en = (ObjAttribute) estimateOE.getAttribute("estimateNumber");
    assertEquals("DOCUMENT_NUMBER", en.getDbAttributePath());
    ObjAttribute in = (ObjAttribute) invoiceOE.getAttribute("invoiceNumber");
    assertEquals("DOCUMENT_NUMBER", in.getDbAttributePath());
    ObjAttribute vn = (ObjAttribute) vendorOE.getAttribute("purchaseOrderNumber");
    assertEquals("DOCUMENT_NUMBER", vn.getDbAttributePath());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 37 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class OsgiDataDomainProvider method get.

@Override
public DataDomain get() throws ConfigurationException {
    // here goes the class loading hack, temporarily setting application
    // bundle ClassLoader to be a thread ClassLoader for runtime to start.
    Thread thread = Thread.currentThread();
    ClassLoader activeCl = thread.getContextClassLoader();
    try {
        // using fake package name... as long as it is not
        // org.apache.cayenne, this do the right trick
        thread.setContextClassLoader(classLoaderManager.getClassLoader("com/"));
        DataDomain domain = super.get();
        EntityResolver entityResolver = domain.getEntityResolver();
        for (ObjEntity e : entityResolver.getObjEntities()) {
            // it is not enough to just call 'getObjectClass()' on
            // ClassDescriptor - there's an optimization that prevents full
            // descriptor resolving... so calling some other method...
            entityResolver.getClassDescriptor(e.getName()).getProperty("__dummy__");
            entityResolver.getCallbackRegistry();
        }
        // this triggers callbacks initialization using thread class loader
        entityResolver.getCallbackRegistry();
        return domain;
    } finally {
        thread.setContextClassLoader(activeCl);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataDomain(org.apache.cayenne.access.DataDomain) EntityResolver(org.apache.cayenne.map.EntityResolver)

Example 38 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EntityIdCoderTest method testSingleIntPk.

@Test
public void testSingleIntPk() {
    DbEntity dbEntity = new DbEntity("X");
    DbAttribute pk = new DbAttribute("ID");
    pk.setType(Types.INTEGER);
    pk.setPrimaryKey(true);
    dbEntity.addAttribute(pk);
    ObjEntity entity = mock(ObjEntity.class);
    when(entity.getName()).thenReturn("x");
    when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
    when(entity.getDbEntity()).thenReturn(dbEntity);
    ObjectId id = ObjectId.of("x", "ID", 3);
    EntityIdCoder coder = new EntityIdCoder(entity);
    assertEquals("x:3", coder.toStringId(id));
    ObjectId parsedId = coder.toObjectId("x:3");
    assertEquals(id, parsedId);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) ObjectId(org.apache.cayenne.ObjectId) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 39 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EntityIdCoderTest method testSingleStringPk.

@Test
public void testSingleStringPk() {
    DbEntity dbEntity = new DbEntity("X");
    DbAttribute pk = new DbAttribute("ID");
    pk.setType(Types.VARCHAR);
    pk.setPrimaryKey(true);
    dbEntity.addAttribute(pk);
    ObjEntity entity = mock(ObjEntity.class);
    when(entity.getName()).thenReturn("x");
    when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
    when(entity.getDbEntity()).thenReturn(dbEntity);
    EntityIdCoder coder = new EntityIdCoder(entity);
    ObjectId id = ObjectId.of("x", "ID", "AbC");
    assertEquals("x:AbC", coder.toStringId(id));
    ObjectId parsedId = coder.toObjectId("x:AbC");
    assertEquals(id, parsedId);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) ObjectId(org.apache.cayenne.ObjectId) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 40 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EntityIdCoderTest method testSingleLongPk.

@Test
public void testSingleLongPk() {
    DbEntity dbEntity = new DbEntity("X");
    DbAttribute pk = new DbAttribute("ID");
    pk.setType(Types.BIGINT);
    pk.setPrimaryKey(true);
    dbEntity.addAttribute(pk);
    ObjEntity entity = mock(ObjEntity.class);
    when(entity.getName()).thenReturn("x");
    when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
    when(entity.getDbEntity()).thenReturn(dbEntity);
    ObjectId id = ObjectId.of("x", "ID", 3L);
    EntityIdCoder coder = new EntityIdCoder(entity);
    assertEquals("x:3", coder.toStringId(id));
    ObjectId parsedId = coder.toObjectId("x:3");
    assertEquals(id, parsedId);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) ObjectId(org.apache.cayenne.ObjectId) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Aggregations

ObjEntity (org.apache.cayenne.map.ObjEntity)294 Test (org.junit.Test)110 DbEntity (org.apache.cayenne.map.DbEntity)72 ObjAttribute (org.apache.cayenne.map.ObjAttribute)68 ObjRelationship (org.apache.cayenne.map.ObjRelationship)62 DataMap (org.apache.cayenne.map.DataMap)57 DbAttribute (org.apache.cayenne.map.DbAttribute)37 DbRelationship (org.apache.cayenne.map.DbRelationship)29 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)27 ObjectId (org.apache.cayenne.ObjectId)26 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)22 ArrayList (java.util.ArrayList)19 Embeddable (org.apache.cayenne.map.Embeddable)18 EntityResolver (org.apache.cayenne.map.EntityResolver)17 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)16 Expression (org.apache.cayenne.exp.Expression)15 Persistent (org.apache.cayenne.Persistent)12 EntityEvent (org.apache.cayenne.map.event.EntityEvent)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Entity (org.apache.cayenne.map.Entity)11