use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class CayenneContext method newObject.
/**
* Creates and registers a new Persistent object instance.
*/
@Override
public <T> T newObject(Class<T> persistentClass) {
if (persistentClass == null) {
throw new NullPointerException("Persistent class can't be null.");
}
ObjEntity entity = getEntityResolver().getObjEntity(persistentClass);
if (entity == null) {
throw new CayenneRuntimeException("No entity mapped for class: %s", persistentClass);
}
ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(entity.getName());
@SuppressWarnings("unchecked") T object = (T) descriptor.createObject();
descriptor.injectValueHolders(object);
registerNewObject((Persistent) object, entity.getName(), descriptor);
return object;
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ClientReturnDiffFilter method isClientArc.
private boolean isClientArc(Object id, Object targetId, Object arcId) {
ObjectId oid = (ObjectId) id;
ObjEntity entity = resolver.getObjEntity(oid.getEntityName());
if (!entity.isClientAllowed()) {
return false;
}
if (entity.getRelationship(arcId.toString()).isRuntime()) {
return false;
}
ObjectId targetOid = (ObjectId) targetId;
ObjEntity targetEntity = resolver.getObjEntity(targetOid.getEntityName());
if (!targetEntity.isClientAllowed()) {
return false;
}
return true;
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class Cayenne method buildId.
static ObjectId buildId(ObjectContext context, Class<?> dataObjectClass, Object pk) {
if (pk == null) {
throw new IllegalArgumentException("Null PK");
}
if (dataObjectClass == null) {
throw new IllegalArgumentException("Null DataObject class.");
}
ObjEntity entity = context.getEntityResolver().getObjEntity(dataObjectClass);
if (entity == null) {
throw new CayenneRuntimeException("Unmapped DataObject Class: %s", dataObjectClass.getName());
}
Collection<String> pkAttributes = entity.getPrimaryKeyNames();
if (pkAttributes.size() != 1) {
throw new CayenneRuntimeException("PK contains %d columns, expected 1.", pkAttributes.size());
}
String attr = pkAttributes.iterator().next();
return ObjectId.of(entity.getName(), attr, pk);
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class Cayenne method buildId.
static ObjectId buildId(ObjectContext context, String objEntityName, Object pk) {
if (pk == null) {
throw new IllegalArgumentException("Null PK");
}
if (objEntityName == null) {
throw new IllegalArgumentException("Null ObjEntity name.");
}
ObjEntity entity = context.getEntityResolver().getObjEntity(objEntityName);
if (entity == null) {
throw new CayenneRuntimeException("Non-existent ObjEntity: %s", objEntityName);
}
Collection<String> pkAttributes = entity.getPrimaryKeyNames();
if (pkAttributes.size() != 1) {
throw new CayenneRuntimeException("PK contains %d columns, expected 1.", pkAttributes.size());
}
String attr = pkAttributes.iterator().next();
return ObjectId.of(objEntityName, attr, pk);
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ASTDbIdPath method evaluateEntityNode.
@Override
protected CayenneMapEntry evaluateEntityNode(Entity entity) {
int lastDot = path.lastIndexOf('.');
String objPath = null;
String id = path;
if (lastDot > -1) {
objPath = path.substring(0, lastDot);
id = path.substring(lastDot + 1);
}
if (!(entity instanceof ObjEntity)) {
throw new CayenneRuntimeException("Unable to evaluate DBID path for DbEntity");
}
ObjEntity objEntity = (ObjEntity) entity;
if (objPath != null) {
CayenneMapEntry entry = new ASTObjPath(objPath).evaluateEntityNode(objEntity);
if (!(entry instanceof ObjRelationship)) {
throw new CayenneRuntimeException("Unable to evaluate DBID path %s, relationship expected", path);
}
objEntity = ((ObjRelationship) entry).getTargetEntity();
}
DbAttribute pk = objEntity.getDbEntity().getAttribute(id);
if (pk == null || !pk.isPrimaryKey()) {
throw new CayenneRuntimeException("Unable to find PK %s for entity %s", id, objEntity.getName());
}
return pk;
}
Aggregations