1 19 package org.apache.cayenne.access.jdbc; 20 21 import java.sql.Connection ; 22 import java.sql.SQLException ; 23 24 import org.apache.cayenne.access.OperationObserver; 25 import org.apache.cayenne.dba.DbAdapter; 26 import org.apache.cayenne.ejbql.EJBQLBaseVisitor; 27 import org.apache.cayenne.ejbql.EJBQLCompiledExpression; 28 import org.apache.cayenne.ejbql.EJBQLExpression; 29 import org.apache.cayenne.map.EntityResolver; 30 import org.apache.cayenne.query.EJBQLQuery; 31 import org.apache.cayenne.query.SQLActionVisitor; 32 import org.apache.cayenne.query.SQLTemplate; 33 34 40 public class EJBQLAction extends BaseSQLAction { 41 42 protected SQLActionVisitor actionFactory; 43 protected EJBQLQuery query; 44 45 public EJBQLAction(EJBQLQuery query, SQLActionVisitor actionFactory, 46 DbAdapter adapter, EntityResolver entityResolver) { 47 super(adapter, entityResolver); 48 49 this.query = query; 50 this.actionFactory = actionFactory; 51 } 52 53 public void performAction(Connection connection, OperationObserver observer) 54 throws SQLException , Exception { 55 EJBQLCompiledExpression compiledExpression = query 56 .getExpression(getEntityResolver()); 57 final EJBQLTranslationContext context = new EJBQLTranslationContext( 58 compiledExpression, 59 query.getParameters()); 60 61 compiledExpression.getExpression().visit(new EJBQLBaseVisitor(false) { 62 63 public boolean visitSelect(EJBQLExpression expression) { 64 EJBQLSelectTranslator visitor = new EJBQLSelectTranslator(context); 65 expression.visit(visitor); 66 return false; 67 } 68 69 public boolean visitDelete(EJBQLExpression expression) { 70 throw new UnsupportedOperationException ("Not yet implemented"); 71 } 72 73 public boolean visitUpdate(EJBQLExpression expression) { 74 throw new UnsupportedOperationException ("Not yet implemented"); 75 } 76 }); 77 78 SQLTemplate sqlQuery = context.getQuery(); 79 actionFactory.sqlAction(sqlQuery).performAction(connection, observer); 80 } 81 } 82 | Popular Tags |