1 22 package org.jboss.ejb.plugins.cmp.jdbc; 23 24 import org.jboss.deployment.DeploymentException; 25 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge; 26 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge; 27 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCFieldBridge; 28 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData; 29 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData; 30 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData; 31 32 39 public final class JDBCEJBQLQuery extends JDBCAbstractQueryCommand 40 { 41 42 public JDBCEJBQLQuery(JDBCStoreManager manager, 43 JDBCQueryMetaData q) 44 throws DeploymentException 45 { 46 super(manager, q); 47 48 JDBCQlQueryMetaData metadata = (JDBCQlQueryMetaData) q; 49 if(getLog().isDebugEnabled()) 50 { 51 getLog().debug("EJB-QL: " + metadata.getEjbQl()); 52 } 53 54 QLCompiler compiler = JDBCQueryManager.getInstance(metadata.getQLCompilerClass(), manager.getCatalog()); 55 56 try 57 { 58 compiler.compileEJBQL( 59 metadata.getEjbQl(), 60 metadata.getMethod().getReturnType(), 61 metadata.getMethod().getParameterTypes(), 62 metadata); 63 } 64 catch(Throwable t) 65 { 66 log.error(t.getMessage(), t); 67 throw new DeploymentException("Error compiling EJB-QL statement for EJB '" + 68 manager.getContainer().getBeanMetaData().getEjbName() + "': " + metadata.getEjbQl(), t); 69 } 70 71 setSQL(compiler.getSQL()); 72 73 if(compiler.isSelectEntity()) 75 { 76 JDBCEntityBridge selectEntity = (JDBCEntityBridge) compiler.getSelectEntity(); 77 78 setSelectEntity(selectEntity); 80 81 JDBCReadAheadMetaData readahead = metadata.getReadAhead(); 83 if(readahead.isOnFind()) 84 { 85 setEagerLoadGroup(readahead.getEagerLoadGroup()); 86 setOnFindCMRList(compiler.getLeftJoinCMRList()); 87 88 if(compiler.isSelectDistinct()) 90 { 91 boolean[] mask = getEagerLoadMask(); 92 JDBCFieldBridge[] tableFields = selectEntity.getTableFields(); 93 for(int i = 0; i < tableFields.length; ++i) 94 { 95 if(mask[i] && !tableFields[i].getJDBCType().isSearchable()) 96 { 97 mask[i] = false; 98 } 99 } 100 } 101 } 102 } 103 else if(compiler.isSelectField()) 104 { 105 setSelectField((JDBCCMPFieldBridge)compiler.getSelectField()); 106 } 107 else 108 { 109 setSelectFunction(compiler.getSelectFunction(), manager); 110 } 111 112 setParameterList(compiler.getInputParameters()); 114 } 115 } 116 | Popular Tags |