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.metadata.JDBCJBossQLQueryMetaData; 28 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData; 29 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData; 30 31 38 public final class JDBCJBossQLQuery extends JDBCAbstractQueryCommand 39 { 40 41 public JDBCJBossQLQuery(JDBCStoreManager manager, 42 JDBCQueryMetaData q) 43 throws DeploymentException 44 { 45 super(manager, q); 46 47 JDBCJBossQLQueryMetaData metadata = (JDBCJBossQLQueryMetaData)q; 48 if(getLog().isDebugEnabled()) 49 { 50 getLog().debug("JBossQL: " + metadata.getJBossQL()); 51 } 52 53 QLCompiler compiler = JDBCQueryManager.getInstance(metadata.getQLCompilerClass(), manager.getCatalog()); 54 55 try 56 { 57 compiler.compileJBossQL( 58 metadata.getJBossQL(), 59 metadata.getMethod().getReturnType(), 60 metadata.getMethod().getParameterTypes(), 61 metadata); 62 } 63 catch(Throwable t) 64 { 65 t.printStackTrace(); 66 throw new DeploymentException("Error compiling JBossQL " + 67 "statement '" + metadata.getJBossQL() + "'", t); 68 } 69 70 setSQL(compiler.getSQL()); 71 setOffsetParam(compiler.getOffsetParam()); 72 setOffsetValue(compiler.getOffsetValue()); 73 setLimitParam(compiler.getLimitParam()); 74 setLimitValue(compiler.getLimitValue()); 75 76 if(compiler.isSelectEntity()) 78 { 79 JDBCEntityBridge selectEntity = (JDBCEntityBridge) compiler.getSelectEntity(); 80 81 setSelectEntity(selectEntity); 83 84 JDBCReadAheadMetaData readahead = metadata.getReadAhead(); 86 if(readahead.isOnFind()) 87 { 88 setEagerLoadGroup(readahead.getEagerLoadGroup()); 89 setOnFindCMRList(compiler.getLeftJoinCMRList()); 90 91 if(compiler.isSelectDistinct()) 93 { 94 boolean[] mask = getEagerLoadMask(); 95 JDBCCMPFieldBridge[] tableFields = (JDBCCMPFieldBridge[])selectEntity.getTableFields(); 96 for(int i = 0; i < tableFields.length; ++i) 97 { 98 if(mask[i] && !tableFields[i].getJDBCType().isSearchable()) 99 { 100 mask[i] = false; 101 } 102 } 103 } 104 } 105 } 106 else if(compiler.isSelectField()) 107 { 108 setSelectField((JDBCCMPFieldBridge) compiler.getSelectField()); 109 } 110 else 111 { 112 setSelectFunction(compiler.getSelectFunction(), (JDBCStoreManager) compiler.getStoreManager()); 113 } 114 115 setParameterList(compiler.getInputParameters()); 117 } 118 } 119 | Popular Tags |