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