Search in sources :

Example 36 with ObjAttribute

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());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) PrintWriter(java.io.PrintWriter)

Example 37 with ObjAttribute

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());
}
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 38 with ObjAttribute

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();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 39 with ObjAttribute

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"));
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) VelocityContext(org.apache.velocity.VelocityContext) Test(org.junit.Test)

Example 40 with ObjAttribute

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"));
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute) VelocityContext(org.apache.velocity.VelocityContext) Test(org.junit.Test)

Aggregations

ObjAttribute (org.apache.cayenne.map.ObjAttribute)81 ObjEntity (org.apache.cayenne.map.ObjEntity)57 DbAttribute (org.apache.cayenne.map.DbAttribute)31 ObjRelationship (org.apache.cayenne.map.ObjRelationship)27 DbEntity (org.apache.cayenne.map.DbEntity)26 Test (org.junit.Test)26 DbRelationship (org.apache.cayenne.map.DbRelationship)19 DbJoin (org.apache.cayenne.map.DbJoin)12 DataMap (org.apache.cayenne.map.DataMap)9 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)9 HashMap (java.util.HashMap)8 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)8 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 ArrayList (java.util.ArrayList)7 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)7 HashSet (java.util.HashSet)6 Expression (org.apache.cayenne.exp.Expression)6