Search in sources :

Example 6 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class FileProjectSaver method createSaveUnit.

SaveUnit createSaveUnit(ConfigurationNode node, Resource targetResource, SaverDelegate delegate) {
    SaveUnit unit = new SaveUnit();
    unit.node = node;
    unit.delegate = delegate;
    unit.sourceConfiguration = node.acceptVisitor(resourceGetter);
    if (unit.sourceConfiguration == null) {
        unit.sourceConfiguration = targetResource;
    }
    // attempt to convert targetResource to a File... if that fails,
    // FileProjectSaver is not appropriate for handling a given project..
    URL targetUrl = targetResource.getURL();
    try {
        unit.targetFile = Util.toFile(targetUrl);
    } catch (IllegalArgumentException e) {
        throw new CayenneRuntimeException("Can't save configuration to the following location: '%s'. " + "Is this a valid file location?. (%s)", e, targetUrl, e.getMessage());
    }
    return unit;
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) URL(java.net.URL)

Example 7 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class ClientServerChannelQueryAction method interceptSinglePageQuery.

private boolean interceptSinglePageQuery() {
    // retrieve range from the previously cached list
    if (serverMetadata.getFetchOffset() >= 0 && serverMetadata.getFetchLimit() > 0 && serverMetadata.getCacheKey() != null) {
        List cachedList = channel.getQueryCache().get(serverMetadata);
        if (cachedList == null) {
            // attempt to refetch... respawn the action...
            Query originatingQuery = serverMetadata.getOriginatingQuery();
            if (originatingQuery != null) {
                ClientServerChannelQueryAction subaction = new ClientServerChannelQueryAction(channel, originatingQuery);
                subaction.execute();
                cachedList = channel.getQueryCache().get(serverMetadata);
                if (cachedList == null) {
                    throw new CayenneRuntimeException("No cached list for %s", serverMetadata.getCacheKey());
                }
            } else {
                return !DONE;
            }
        }
        int startIndex = serverMetadata.getFetchOffset();
        int endIndex = startIndex + serverMetadata.getFetchLimit();
        // send back just one page... query sender will figure out where it fits in
        // the incremental list
        this.response = new ListResponse(new ArrayList<>(cachedList.subList(startIndex, endIndex)));
        return DONE;
    }
    return !DONE;
}
Also used : Query(org.apache.cayenne.query.Query) IncrementalListResponse(org.apache.cayenne.util.IncrementalListResponse) ListResponse(org.apache.cayenne.util.ListResponse) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class DataContext method objectFromDataRow.

/**
 * Creates a DataObject from DataRow.
 *
 * @see DataRow
 * @since 3.1
 */
public <T extends Persistent> T objectFromDataRow(Class<T> objectClass, DataRow dataRow) {
    ObjEntity entity = this.getEntityResolver().getObjEntity(objectClass);
    if (entity == null) {
        throw new CayenneRuntimeException("Unmapped Java class: %s", objectClass);
    }
    ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(entity.getName());
    List<T> list = objectsFromDataRows(descriptor, Collections.singletonList(dataRow));
    return list.get(0);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 9 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class DataDomain method lookupDataNode.

/**
 * Returns a DataNode that should handle queries for all entities in a
 * DataMap.
 *
 * @since 1.1
 */
public DataNode lookupDataNode(DataMap map) {
    DataNode node = nodesByDataMapName.get(map.getName());
    if (node == null) {
        // linked...
        for (DataNode n : getDataNodes()) {
            for (DataMap m : n.getDataMaps()) {
                if (m == map) {
                    nodesByDataMapName.put(map.getName(), n);
                    node = n;
                    break;
                }
            }
            if (node != null) {
                break;
            }
        }
        if (node == null) {
            if (defaultNode != null) {
                nodesByDataMapName.put(map.getName(), defaultNode);
                node = defaultNode;
            } else {
                throw new CayenneRuntimeException("No DataNode configured for DataMap '%s'" + " and no default DataNode set", map.getName());
            }
        }
    }
    return node;
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataMap(org.apache.cayenne.map.DataMap)

Example 10 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class DataDomainFlushAction method runQueries.

private void runQueries() {
    DataDomainFlushObserver observer = new DataDomainFlushObserver(domain.getJdbcEventLogger());
    try {
        DataNode lastNode = null;
        DbEntity lastEntity = null;
        int rangeStart = 0;
        int len = queries.size();
        for (int i = 0; i < len; i++) {
            BatchQuery query = (BatchQuery) queries.get(i);
            if (query.getDbEntity() != lastEntity) {
                lastEntity = query.getDbEntity();
                DataNode node = domain.lookupDataNode(lastEntity.getDataMap());
                if (node != lastNode) {
                    if (i - rangeStart > 0) {
                        lastNode.performQueries(queries.subList(rangeStart, i), observer);
                    }
                    rangeStart = i;
                    lastNode = node;
                }
            }
        }
        // process last segment of the query list...
        lastNode.performQueries(queries.subList(rangeStart, len), observer);
    } catch (Throwable th) {
        BaseTransaction.getThreadTransaction().setRollbackOnly();
        throw new CayenneRuntimeException("Transaction was rolledback.", th);
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) BatchQuery(org.apache.cayenne.query.BatchQuery)

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