use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class DataMapUtils method isValidParameterNames.
public Boolean isValidParameterNames(SelectQueryDescriptor query) {
if (query.getQualifier() == null) {
return true;
}
Map<String, String> queryParameters = queriesMap.get(query.getName());
if (queryParameters == null) {
try {
queryParameters = getParameterNames(query.getQualifier(), query.getRoot());
} catch (Exception e) {
// if we have wrong path in queryParameters return false.
return false;
}
}
for (Ordering ordering : query.getOrderings()) {
// validate paths in ordering
String path = ordering.getSortSpecString();
Iterator<CayenneMapEntry> it = ((ObjEntity) query.getRoot()).resolvePathComponents(path);
while (it.hasNext()) {
try {
it.next();
} catch (ExpressionException e) {
// if we have wrong path in orderings return false.
return false;
}
}
}
return true;
}
use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class DefaultSelectTranslatorIT method testCreateSqlString13.
@Test
public void testCreateSqlString13() throws Exception {
// query with invalid joint prefetches
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch("invalid.invalid").setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
try {
new DefaultSelectTranslator(q, dataNode.getAdapter(), dataNode.getEntityResolver()).getSql();
fail("Invalid jointPrefetch must have thrown...");
} catch (ExpressionException e) {
// expected
}
}
use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class EOModelProcessor method makeFlatRelationships.
/**
* Create Flattened ObjRelationships of the specified entity.
*/
protected void makeFlatRelationships(EOModelHelper helper, ObjEntity e) {
Map info = helper.entityPListMap(e.getName());
List rinfo = (List) info.get("relationships");
if (rinfo == null) {
return;
}
Iterator it = rinfo.iterator();
while (it.hasNext()) {
Map relMap = (Map) it.next();
String targetPath = (String) relMap.get("definition");
// ignore normal relationships
if (targetPath == null) {
continue;
}
ObjRelationship flatRel = new ObjRelationship();
flatRel.setName((String) relMap.get("name"));
flatRel.setSourceEntity(e);
try {
flatRel.setDbRelationshipPath(targetPath);
} catch (ExpressionException ex) {
logger.warn("Invalid relationship: " + targetPath);
continue;
}
// find target entity
Map entityInfo = info;
StringTokenizer toks = new StringTokenizer(targetPath, ".");
while (toks.hasMoreTokens() && entityInfo != null) {
String pathComponent = toks.nextToken();
// get relationship info and reset entityInfo, so that we could
// use
// entityInfo state as an indicator of valid flat relationship
// enpoint
// outside the loop
Collection relationshipInfo = (Collection) entityInfo.get("relationships");
entityInfo = null;
if (relationshipInfo == null) {
break;
}
Iterator rit = relationshipInfo.iterator();
while (rit.hasNext()) {
Map pathRelationship = (Map) rit.next();
if (pathComponent.equals(pathRelationship.get("name"))) {
String targetName = (String) pathRelationship.get("destination");
entityInfo = helper.entityPListMap(targetName);
break;
}
}
}
if (entityInfo != null) {
flatRel.setTargetEntityName((String) entityInfo.get("name"));
}
e.addRelationship(flatRel);
}
}
use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class ObjRelationship method getValidRelationshipPath.
/**
* Returns dot-separated path over DbRelationships, only including
* components that have valid DbRelationships.
*/
String getValidRelationshipPath() {
String path = getDbRelationshipPath();
if (path == null) {
return null;
}
ObjEntity entity = (ObjEntity) getSourceEntity();
if (entity == null) {
throw new CayenneRuntimeException("Can't resolve DbRelationships, null source ObjEntity");
}
DbEntity dbEntity = entity.getDbEntity();
if (dbEntity == null) {
return null;
}
StringBuilder validPath = new StringBuilder();
try {
for (PathComponent<DbAttribute, DbRelationship> pathComponent : dbEntity.resolvePath(new ASTDbPath(path), Collections.emptyMap())) {
if (validPath.length() > 0) {
validPath.append(Entity.PATH_SEPARATOR);
}
validPath.append(pathComponent.getName());
}
} catch (ExpressionException ex) {
}
return validPath.toString();
}
use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class ObjRelationship method refreshFromPath.
/**
* Rebuild a list of relationships if String relationshipPath has changed.
*/
final void refreshFromPath(String dbRelationshipPath, boolean stripInvalid) {
// remove existing relationships
dbRelationships.clear();
if (dbRelationshipPath != null) {
ObjEntity entity = (ObjEntity) getSourceEntity();
if (entity == null) {
throw new CayenneRuntimeException("Can't resolve DbRelationships, null source ObjEntity");
}
try {
// add new relationships from path
Iterator<CayenneMapEntry> it = entity.resolvePathComponents(new ASTDbPath(dbRelationshipPath));
while (it.hasNext()) {
DbRelationship relationship = (DbRelationship) it.next();
dbRelationships.add(relationship);
}
} catch (ExpressionException ex) {
if (!stripInvalid) {
throw ex;
}
}
}
recalculateToManyValue();
recalculateReadOnlyValue();
}
Aggregations