Search in sources :

Example 71 with CayenneRuntimeException

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

Example 72 with CayenneRuntimeException

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

Example 73 with CayenneRuntimeException

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

Example 74 with CayenneRuntimeException

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);
    }
}
Also used : Invocation(org.apache.cayenne.util.Invocation) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 75 with CayenneRuntimeException

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);
    }
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) Persistent(org.apache.cayenne.Persistent) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Aggregations

CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)168 Test (org.junit.Test)25 DbAttribute (org.apache.cayenne.map.DbAttribute)21 DataMap (org.apache.cayenne.map.DataMap)19 ObjectId (org.apache.cayenne.ObjectId)18 ObjEntity (org.apache.cayenne.map.ObjEntity)18 Persistent (org.apache.cayenne.Persistent)17 Expression (org.apache.cayenne.exp.Expression)17 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)17 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 DbEntity (org.apache.cayenne.map.DbEntity)14 IOException (java.io.IOException)13 List (java.util.List)12 ObjRelationship (org.apache.cayenne.map.ObjRelationship)12 DbRelationship (org.apache.cayenne.map.DbRelationship)10 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)10 File (java.io.File)9 Connection (java.sql.Connection)9 SQLException (java.sql.SQLException)9