Search in sources :

Example 6 with EJBQLExpression

use of org.apache.cayenne.ejbql.EJBQLExpression in project cayenne by apache.

the class EJBQLAction method performAction.

@Override
public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
    EJBQLCompiledExpression compiledExpression = query.getExpression(dataNode.getEntityResolver());
    final EJBQLTranslatorFactory translatorFactory = dataNode.getAdapter().getEjbqlTranslatorFactory();
    final EJBQLTranslationContext context = new EJBQLTranslationContext(dataNode.getEntityResolver(), query, compiledExpression, translatorFactory, dataNode.getAdapter().getQuotingStrategy());
    compiledExpression.getExpression().visit(new EJBQLBaseVisitor(false) {

        @Override
        public boolean visitSelect(EJBQLExpression expression) {
            EJBQLExpressionVisitor visitor = translatorFactory.getSelectTranslator(context);
            expression.visit(visitor);
            return false;
        }

        @Override
        public boolean visitDelete(EJBQLExpression expression) {
            EJBQLExpressionVisitor visitor = translatorFactory.getDeleteTranslator(context);
            expression.visit(visitor);
            return false;
        }

        @Override
        public boolean visitUpdate(EJBQLExpression expression) {
            EJBQLExpressionVisitor visitor = translatorFactory.getUpdateTranslator(context);
            expression.visit(visitor);
            return false;
        }
    });
    SQLTemplate sqlQuery = context.getQuery();
    // update with metadata
    QueryMetadata md = query.getMetaData(dataNode.getEntityResolver());
    sqlQuery.setFetchLimit(md.getFetchLimit());
    sqlQuery.setFetchOffset(md.getFetchOffset());
    sqlQuery.setResult(compiledExpression.getResult());
    sqlQuery.setPageSize(md.getPageSize());
    if (md.getStatementFetchSize() != 0) {
        sqlQuery.setStatementFetchSize(md.getStatementFetchSize());
    }
    actionFactory.sqlAction(sqlQuery).performAction(connection, observer);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) EJBQLTranslationContext(org.apache.cayenne.access.translator.ejbql.EJBQLTranslationContext) EJBQLBaseVisitor(org.apache.cayenne.ejbql.EJBQLBaseVisitor) QueryMetadata(org.apache.cayenne.query.QueryMetadata) EJBQLCompiledExpression(org.apache.cayenne.ejbql.EJBQLCompiledExpression) EJBQLTranslatorFactory(org.apache.cayenne.access.translator.ejbql.EJBQLTranslatorFactory) EJBQLExpression(org.apache.cayenne.ejbql.EJBQLExpression) EJBQLExpressionVisitor(org.apache.cayenne.ejbql.EJBQLExpressionVisitor)

Aggregations

EJBQLExpression (org.apache.cayenne.ejbql.EJBQLExpression)6 EJBQLBaseVisitor (org.apache.cayenne.ejbql.EJBQLBaseVisitor)3 EJBQLCompiledExpression (org.apache.cayenne.ejbql.EJBQLCompiledExpression)2 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)2 EJBQLExpressionVisitor (org.apache.cayenne.ejbql.EJBQLExpressionVisitor)2 DbEntity (org.apache.cayenne.map.DbEntity)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2 HashMap (java.util.HashMap)1 EJBQLTranslationContext (org.apache.cayenne.access.translator.ejbql.EJBQLTranslationContext)1 EJBQLTranslatorFactory (org.apache.cayenne.access.translator.ejbql.EJBQLTranslatorFactory)1 Expression (org.apache.cayenne.exp.Expression)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EntityResult (org.apache.cayenne.map.EntityResult)1 SQLResult (org.apache.cayenne.map.SQLResult)1 PrefetchTreeNode (org.apache.cayenne.query.PrefetchTreeNode)1 QueryMetadata (org.apache.cayenne.query.QueryMetadata)1 SQLTemplate (org.apache.cayenne.query.SQLTemplate)1 ArcProperty (org.apache.cayenne.reflect.ArcProperty)1