use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class EOModelProcessorTest method assertLoaded.
protected void assertLoaded(String mapName, DataMap map) throws Exception {
assertNotNull(map);
assertEquals(mapName, map.getName());
// check obj entities
ObjEntity artistE = map.getObjEntity("Artist");
assertNotNull(artistE);
assertEquals("Artist", artistE.getName());
// check Db entities
DbEntity artistDE = map.getDbEntity("ARTIST");
DbEntity artistDE1 = artistE.getDbEntity();
assertSame(artistDE, artistDE1);
// check attributes
ObjAttribute a1 = artistE.getAttribute("artistName");
assertNotNull(a1);
DbAttribute da1 = a1.getDbAttribute();
assertNotNull(da1);
assertSame(da1, artistDE.getAttribute("ARTIST_NAME"));
// check ObjRelationships
ObjRelationship rel = artistE.getRelationship("artistExhibitArray");
assertNotNull(rel);
assertEquals(1, rel.getDbRelationships().size());
// check DbRelationships
DbRelationship drel = artistDE.getRelationship("artistExhibitArray");
assertNotNull(drel);
assertSame(drel, rel.getDbRelationships().get(0));
// flattened relationships
ObjRelationship frel = artistE.getRelationship("exhibitArray");
assertNotNull(frel);
assertEquals(2, frel.getDbRelationships().size());
// storing data map may uncover some inconsistencies
PrintWriter mockupWriter = new NullPrintWriter();
map.encodeAsXML(new XMLEncoder(mockupWriter), new EmptyConfigurationNodeVisitor());
}
use of org.apache.cayenne.map.ObjAttribute 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.ObjAttribute in project cayenne by apache.
the class EntityUtils method getMapKeyType.
/**
* Returns the map key type for a collection relationship of type
* java.util.Map.
*
* @param relationship
* The relationship to look up type information for.
* @return The type of the attribute keyed on.
*/
public String getMapKeyType(final ObjRelationship relationship) {
ObjEntity targetEntity = (ObjEntity) relationship.getTargetEntity();
// key.
if (relationship.getMapKey() == null) {
// If it's a multi-column key, then the return type is always
// ObjectId.
DbEntity dbEntity = targetEntity.getDbEntity();
if ((dbEntity != null) && (dbEntity.getPrimaryKeys().size() > 1)) {
return ObjectId.class.getName();
}
// so default to Object.
return Object.class.getName();
}
// If the map key is a non-default attribute, then fetch the attribute
// and return
// its type.
ObjAttribute attribute = targetEntity.getAttribute(relationship.getMapKey());
if (attribute == null) {
throw new CayenneRuntimeException("Invalid map key '%s', no matching attribute found", relationship.getMapKey());
}
return attribute.getType();
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class ClientSuperClassGenerationTest method testContainsPropertyImportForAttributes.
@Test
public void testContainsPropertyImportForAttributes() throws Exception {
ObjEntity objEntity = new ObjEntity("TEST1");
ObjAttribute attr = new ObjAttribute("attr");
objEntity.addAttribute(attr);
VelocityContext context = new VelocityContext();
context.put(Artifact.OBJECT_KEY, objEntity);
String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
assertTrue(res.contains("org.apache.cayenne.exp.Property"));
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class ClientSuperClassGenerationTest method testContainsPropertyImport.
@Test
public void testContainsPropertyImport() throws Exception {
ObjEntity objEntity = new ObjEntity("TEST1");
ObjAttribute attr = new ObjAttribute("attr");
ObjRelationship rel = new ObjRelationship("rel");
objEntity.addAttribute(attr);
objEntity.addRelationship(rel);
VelocityContext context = new VelocityContext();
context.put(Artifact.OBJECT_KEY, objEntity);
String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
assertTrue(res.contains("org.apache.cayenne.exp.Property"));
}
Aggregations