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