use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class PrefetchProcessorJointNode method buildPKIndex.
/**
* Creates an internal index of PK columns in the result.
*/
private void buildPKIndex() {
// index PK
Collection<DbAttribute> pks = getResolver().getEntity().getDbEntity().getPrimaryKeys();
this.idIndices = new int[pks.size()];
// this is needed for checking that a valid index is made
Arrays.fill(idIndices, -1);
Iterator<DbAttribute> it = pks.iterator();
for (int i = 0; i < idIndices.length; i++) {
DbAttribute pk = it.next();
for (int j = 0; j < columns.length; j++) {
if (pk.getName().equals(columns[j].getName())) {
idIndices[i] = j;
break;
}
}
// sanity check
if (idIndices[i] == -1) {
throw new CayenneRuntimeException("PK column is not part of result row: %s", pk.getName());
}
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class PrefetchProcessorTreeBuilder method addNode.
boolean addNode(PrefetchProcessorNode node) {
List rows;
ArcProperty arc;
ClassDescriptor descriptor;
PrefetchProcessorNode currentNode = getParent();
if (currentNode != null) {
rows = (List) extraResultsByPath.get(node.getPath());
arc = (ArcProperty) currentNode.getResolver().getDescriptor().getProperty(node.getName());
if (arc == null) {
throw new CayenneRuntimeException("No relationship with name '%s' found in entity '%s'", node.getName(), currentNode.getResolver().getEntity().getName());
}
descriptor = arc.getTargetDescriptor();
} else {
arc = null;
if (this.descriptor != null) {
descriptor = this.descriptor;
} else {
descriptor = queryMetadata.getClassDescriptor();
}
rows = mainResultRows;
}
node.setDataRows(rows);
node.setIncoming(arc);
if (node.getParent() != null && !node.isJointPrefetch()) {
node.setResolver(new HierarchicalObjectResolverNode(node, context, descriptor, queryMetadata.isRefreshingObjects(), seen));
} else {
node.setResolver(new PrefetchObjectResolver(context, descriptor, queryMetadata.isRefreshingObjects(), seen));
}
if (node.getParent() == null || node.getParent().isPhantom()) {
node.setParentAttachmentStrategy(new NoopParentAttachmentStrategy());
} else if (node.isJointPrefetch()) {
node.setParentAttachmentStrategy(new StackLookupParentAttachmentStrategy(node));
} else if (node.getIncoming().getRelationship().isSourceIndependentFromTargetChange()) {
node.setParentAttachmentStrategy(new JoinedIdParentAttachementStrategy(context.getGraphManager(), node));
} else {
node.setParentAttachmentStrategy(new ResultScanParentAttachmentStrategy(node));
}
if (currentNode != null) {
currentNode.addChild(node);
}
node.afterInit();
// push node on stack
if (nodeStack.isEmpty()) {
root = node;
}
nodeStack.addLast(node);
return true;
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class ToOneFault method doResolveFault.
Object doResolveFault(Persistent sourceObject, String relationshipName) {
RelationshipQuery query = new RelationshipQuery(sourceObject.getObjectId(), relationshipName, false);
List objects = sourceObject.getObjectContext().performQuery(query);
if (objects.isEmpty()) {
return null;
} else if (objects.size() == 1) {
return objects.get(0);
} else {
throw new CayenneRuntimeException("Error resolving to-one fault. " + "More than one object found. Source Id: %s, relationship: %s", sourceObject.getObjectId(), relationshipName);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class CreateIfNoSchemaStrategy method generate.
private void generate(DataNode dataNode) {
Collection<DataMap> map = dataNode.getDataMaps();
Iterator<DataMap> iterator = map.iterator();
while (iterator.hasNext()) {
DbGenerator gen = new DbGenerator(dataNode.getAdapter(), iterator.next(), dataNode.getJdbcEventLogger());
gen.setShouldCreateTables(true);
gen.setShouldDropTables(false);
gen.setShouldCreateFKConstraints(true);
gen.setShouldCreatePKSupport(true);
gen.setShouldDropPKSupport(false);
try {
gen.runGenerator(dataNode.getDataSource());
} catch (Exception e) {
throw new CayenneRuntimeException(e);
}
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class EntityRowReader method readRow.
@Override
public DataRow readRow(ResultSet resultSet) {
try {
DataRow row = new DataRow(mapCapacity);
int len = converters.length;
for (int i = 0; i < len; i++) {
// note: jdbc column indexes start from 1, not 0 as in arrays
Object val = converters[i].materializeObject(resultSet, startIndex + i + 1, types[i]);
row.put(labels[i], val);
}
postprocessRow(resultSet, row);
return row;
} catch (CayenneRuntimeException cex) {
// rethrow unmodified
throw cex;
} catch (Exception otherex) {
throw new CayenneRuntimeException("Exception materializing id column.", Util.unwindException(otherex));
}
}
Aggregations