1 22 package org.jboss.ejb.plugins.cmp.jdbc2; 23 24 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2; 25 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2; 26 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData; 27 import org.jboss.ejb.plugins.cmp.jdbc.QLCompiler; 28 import org.jboss.ejb.plugins.cmp.jdbc.EJBQLToSQL92Compiler; 29 import org.jboss.logging.Logger; 30 import org.jboss.deployment.DeploymentException; 31 32 33 37 public class EJBQLQueryCommand 38 extends AbstractQueryCommand 39 { 40 public EJBQLQueryCommand(JDBCEntityBridge2 entity, JDBCQlQueryMetaData metadata) throws DeploymentException 41 { 42 this.entity = entity; 43 44 JDBCStoreManager2 manager = (JDBCStoreManager2)entity.getManager(); 45 QLCompiler compiler = new EJBQLToSQL92Compiler(manager.getCatalog()); 46 47 try 48 { 49 compiler.compileEJBQL( 50 metadata.getEjbQl(), 51 metadata.getMethod().getReturnType(), 52 metadata.getMethod().getParameterTypes(), 53 metadata); 54 } 55 catch(Throwable t) 56 { 57 t.printStackTrace(); 58 throw new DeploymentException("Error compiling EJBQL statement '" + metadata.getEjbQl() + "'", t); 59 } 60 61 sql = compiler.getSQL(); 62 63 log = Logger.getLogger(getClass().getName() + "." + entity.getEntityName() + "#" + metadata.getMethod().getName()); 64 log.debug("sql: " + sql); 65 66 setParameters(compiler.getInputParameters()); 67 setResultType(metadata.getMethod().getReturnType()); 68 69 if(!compiler.isSelectEntity()) 70 { 71 if(compiler.isSelectField()) 72 { 73 setFieldReader((JDBCCMPFieldBridge2)compiler.getSelectField()); 74 } 75 else 76 { 77 setFunctionReader(compiler.getSelectFunction()); 78 } 79 } 80 else 81 { 82 setEntityReader((JDBCEntityBridge2)compiler.getSelectEntity(), compiler.isSelectDistinct()); 83 } 84 } 85 } 86 | Popular Tags |