use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class RelationshipQuery method updateMetadata.
void updateMetadata(EntityResolver resolver) {
// caching metadata as it may be accessed multiple times (at a DC and DD level)
if (metadataResolver != resolver) {
if (objectId == null) {
throw new CayenneRuntimeException("Can't resolve query - objectID is null.");
}
ClassDescriptor descriptor = resolver.getClassDescriptor(objectId.getEntityName());
this.arc = (ArcProperty) descriptor.getProperty(relationshipName);
if (arc == null) {
throw new CayenneRuntimeException("No relationship named %s found in entity %s; object id: %s", relationshipName, objectId.getEntityName(), objectId);
}
this.metadata = new DefaultQueryMetadata() {
@Override
public boolean isRefreshingObjects() {
return refreshing;
}
@Override
public ObjEntity getObjEntity() {
return arc.getTargetDescriptor().getEntity();
}
@Override
public ClassDescriptor getClassDescriptor() {
return arc.getTargetDescriptor();
}
@Override
public int getStatementFetchSize() {
return statementFetchSize;
}
};
this.metadataResolver = resolver;
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class LifecycleCallbackRegistry method getAnnotatedEntities.
private Collection<Class<?>> getAnnotatedEntities(Class<? extends Annotation> annotationType) {
Collection<Class<?>> entities = entitiesByAnnotation.get(annotationType.getName());
if (entities == null) {
// ensure no dupes
entities = new HashSet<>();
for (ObjEntity entity : entityResolver.getObjEntities()) {
Class<?> entityType;
try {
entityType = Util.getJavaClass(entity.getClassName());
} catch (ClassNotFoundException e) {
throw new CayenneRuntimeException("Class not found: " + entity.getClassName(), e);
}
while (entityType != null && entityType.isAnnotationPresent(annotationType)) {
Class<?> superType = entityType.getSuperclass();
if (superType == null || !superType.isAnnotationPresent(annotationType)) {
entities.add(entityType);
break;
}
entityType = superType;
}
}
entitiesByAnnotation.put(annotationType.getName(), entities);
}
return entities;
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class PersistentDescriptorFactory method getDescriptor.
public ClassDescriptor getDescriptor(String entityName) {
ObjEntity entity = descriptorMap.getResolver().getObjEntity(entityName);
if (entity == null) {
throw new CayenneRuntimeException("Unmapped entity: %s", entityName);
}
Class<?> entityClass = entity.getJavaClass();
return getDescriptor(entity, entityClass);
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class DefaultEventManager method addListener.
protected void addListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender, boolean blocking) {
if (listener == null) {
throw new IllegalArgumentException("Listener must not be null.");
}
if (eventParameterClass == null) {
throw new IllegalArgumentException("Event class must not be null.");
}
if (subject == null) {
throw new IllegalArgumentException("Subject must not be null.");
}
try {
Invocation invocation = (blocking) ? new Invocation(listener, methodName, eventParameterClass) : new NonBlockingInvocation(listener, methodName, eventParameterClass);
dispatchQueueForSubject(subject, true).addInvocation(invocation, sender);
} catch (NoSuchMethodException nsm) {
throw new CayenneRuntimeException("Error adding listener, method name: " + methodName, nsm);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class ChildDiffLoader method nodePropertyChanged.
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
// this change is for simple property, so no need to convert targets to
// server
// objects...
Persistent object = findObject(nodeId);
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(((ObjectId) nodeId).getEntityName());
setExternalChange(Boolean.TRUE);
try {
descriptor.getProperty(property).writeProperty(object, oldValue, newValue);
} catch (Exception e) {
throw new CayenneRuntimeException("Error setting property: " + property, e);
} finally {
setExternalChange(Boolean.FALSE);
}
}
Aggregations