Search in sources :

Example 76 with ObjEntity

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

the class ChildDiffLoader method nodeCreated.

@Override
public void nodeCreated(Object nodeId) {
    setExternalChange(Boolean.TRUE);
    try {
        ObjectId id = (ObjectId) nodeId;
        if (id.getEntityName() == null) {
            throw new NullPointerException("Null entity name in id " + id);
        }
        ObjEntity entity = context.getEntityResolver().getObjEntity(id.getEntityName());
        if (entity == null) {
            throw new IllegalArgumentException("Entity not mapped with Cayenne: " + id);
        }
        Persistent dataObject;
        try {
            dataObject = (Persistent) entity.getJavaClass().newInstance();
        } catch (Exception ex) {
            throw new CayenneRuntimeException("Error instantiating object.", ex);
        }
        dataObject.setObjectId(id);
        context.registerNewObject(dataObject);
    } finally {
        setExternalChange(Boolean.FALSE);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjectId(org.apache.cayenne.ObjectId) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) Persistent(org.apache.cayenne.Persistent) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 77 with ObjEntity

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

the class ASTObjPath method getDataTypeForObject.

private Class<?> getDataTypeForObject(DataObject source) {
    ObjectContext context = source.getObjectContext();
    ObjectId objectId = source.getObjectId();
    if (context == null || objectId == null) {
        return null;
    }
    ObjEntity entity = context.getEntityResolver().getObjEntity(objectId.getEntityName());
    CayenneMapEntry entry = evaluateEntityNode(entity);
    if (!(entry instanceof ObjAttribute)) {
        return null;
    }
    return ((ObjAttribute) entry).getJavaClass();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) ObjAttribute(org.apache.cayenne.map.ObjAttribute) ObjectId(org.apache.cayenne.ObjectId) ObjectContext(org.apache.cayenne.ObjectContext)

Example 78 with ObjEntity

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

the class HybridDataObjectIT method addRuntimeAttribute.

private void addRuntimeAttribute(Class<?> entityClass, String attributeName, String attributeType) {
    ObjEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(entityClass);
    ObjAttribute attribute = new ObjAttribute();
    attribute.setName(attributeName);
    attribute.setDbAttributePath(attributeName);
    attribute.setType(attributeType);
    entity.addAttribute(attribute);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute)

Example 79 with ObjEntity

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

the class TranslateExpressionIT method testRelationshipNoneLeadingParts.

@Test
public void testRelationshipNoneLeadingParts() {
    ObjEntity entity = context.getEntityResolver().getObjEntity("Painting");
    Expression expression = ExpressionFactory.pathExp("toGallery");
    Expression translatedExpression = entity.translateToRelatedEntity(expression, "toArtist");
    assertEquals(ExpressionFactory.dbPathExp("paintingArray.toGallery"), translatedExpression);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Test(org.junit.Test)

Example 80 with ObjEntity

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

the class TranslateExpressionIT method testTranslateExpression.

@Test
public void testTranslateExpression() {
    ObjEntity entity = context.getEntityResolver().getObjEntity("Painting");
    Expression expression = ExpressionFactory.pathExp("toArtist.paintingArray");
    Expression translatedExpression = entity.translateToRelatedEntity(expression, "toArtist");
    assertEquals(ExpressionFactory.dbPathExp("paintingArray.toArtist.paintingArray"), translatedExpression);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) 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