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());
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations