use of org.apache.cayenne.ejbql.EJBQLException in project cayenne by apache.
the class EJBQLPathTranslator method visitIdentifier.
@Override
public boolean visitIdentifier(EJBQLExpression expression) {
ClassDescriptor descriptor = context.getEntityDescriptor(expression.getText());
if (descriptor == null) {
throw new EJBQLException("Invalid identification variable: " + expression.getText());
}
this.currentEntity = descriptor.getEntity();
this.idPath = expression.getText();
this.joinMarker = EJBQLJoinAppender.makeJoinTailMarker(idPath);
this.fullPath = idPath;
return true;
}
use of org.apache.cayenne.ejbql.EJBQLException in project cayenne by apache.
the class EJBQLPathTranslator method processIntermediatePathComponent.
protected void processIntermediatePathComponent() {
ObjRelationship relationship = currentEntity.getRelationship(lastPathComponent);
if (relationship == null) {
throw new EJBQLException("Unknown relationship '" + lastPathComponent + "' for entity '" + currentEntity.getName() + "'");
}
this.currentEntity = (ObjEntity) relationship.getTargetEntity();
}
use of org.apache.cayenne.ejbql.EJBQLException in project cayenne by apache.
the class EJBQLSelectColumnsTranslator method visitDbPath.
@Override
public boolean visitDbPath(EJBQLExpression expression, int finishedChildIndex) {
EJBQLDbPathTranslator pathTranslator = new EJBQLDbPathTranslator(context) {
@Override
protected void appendMultiColumnPath(EJBQLMultiColumnOperand operand) {
throw new EJBQLException("Can't use multi-column paths in column clause");
}
@Override
protected void processTerminatingRelationship(DbRelationship relationship) {
Map<String, String> xfields = null;
if (context.isAppendingResultColumns()) {
xfields = context.nextEntityResult().getFields();
}
final Map<String, String> fields = xfields;
DbEntity table = (DbEntity) relationship.getTargetEntity();
Collection<DbAttribute> dbAttr = table.getAttributes();
Iterator<DbAttribute> it = dbAttr.iterator();
if (dbAttr.size() > 0) {
resolveJoin();
}
String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context.getQuotingStrategy().quotedFullyQualifiedName(table));
boolean first = true;
while (it.hasNext()) {
context.append(!first ? ", " : " ");
DbAttribute dbAttribute = it.next();
appendColumn(TypesMapping.getJavaBySqlType(dbAttribute.getType()), alias, dbAttribute, fields != null ? fields.get(dbAttribute.getName()) : "");
first = false;
}
}
@Override
protected void processTerminatingAttribute(DbAttribute attribute) {
String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context.getQuotingStrategy().quotedFullyQualifiedName(currentEntity));
appendColumn(TypesMapping.getJavaBySqlType(attribute.getType()), alias, attribute, context.isAppendingResultColumns() ? context.nextColumnAlias() : "");
}
};
expression.visit(pathTranslator);
return false;
}
use of org.apache.cayenne.ejbql.EJBQLException in project cayenne by apache.
the class EJBQLSelectColumnsTranslator method visitPath.
@Override
public boolean visitPath(EJBQLExpression expression, int finishedChildIndex) {
EJBQLPathTranslator pathTranslator = new EJBQLPathTranslator(context) {
@Override
protected void appendMultiColumnPath(EJBQLMultiColumnOperand operand) {
throw new EJBQLException("Can't use multi-column paths in column clause");
}
@Override
protected void processTerminatingRelationship(ObjRelationship relationship) {
Map<String, String> xfields = null;
if (context.isAppendingResultColumns()) {
xfields = context.nextEntityResult().getFields();
}
final Map<String, String> fields = xfields;
Collection<DbAttribute> dbAttr = ((ObjEntity) relationship.getTargetEntity()).getDbEntity().getAttributes();
DbRelationship dbRelationship = relationship.getDbRelationships().get(0);
DbEntity table = (DbEntity) dbRelationship.getTargetEntity();
Iterator<DbAttribute> it = dbAttr.iterator();
if (dbAttr.size() > 0) {
resolveJoin();
}
String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context.getQuotingStrategy().quotedFullyQualifiedName(table));
boolean first = true;
while (it.hasNext()) {
context.append(!first ? ", " : " ");
DbAttribute dbAttribute = it.next();
appendColumn(TypesMapping.getJavaBySqlType(dbAttribute.getType()), alias, dbAttribute, fields != null ? fields.get(dbAttribute.getName()) : "");
first = false;
}
}
@Override
protected void processTerminatingAttribute(ObjAttribute attribute) {
DbEntity table = currentEntity.getDbEntity();
String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context.getQuotingStrategy().quotedFullyQualifiedName(table));
if (attribute.isFlattened()) {
Iterator<?> dbPathIterator = attribute.getDbPathIterator();
EJBQLTableId lhsId = new EJBQLTableId(idPath);
while (dbPathIterator.hasNext()) {
Object pathPart = dbPathIterator.next();
// later when appending table
if (pathPart == null) {
throw new CayenneRuntimeException("ObjAttribute has no component: %s", attribute.getName());
} else if (pathPart instanceof DbAttribute) {
DbAttribute dbAttribute = (DbAttribute) pathPart;
appendColumn(attribute.getType(), context.getTableAlias(lhsId.getEntityId(), context.getQuotingStrategy().quotedFullyQualifiedName((DbEntity) dbAttribute.getEntity())), dbAttribute, context.isAppendingResultColumns() ? context.nextColumnAlias() : "");
}
}
} else {
DbAttribute dbAttribute = attribute.getDbAttribute();
appendColumn(attribute.getType(), alias, dbAttribute, context.isAppendingResultColumns() ? context.nextColumnAlias() : "");
}
}
};
expression.visit(pathTranslator);
return false;
}
Aggregations