1 22 package org.jboss.ejb.plugins.cmp.jdbc; 23 24 25 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge; 26 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge; 27 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData; 28 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData; 29 import org.jboss.deployment.DeploymentException; 30 31 43 public final class JDBCFindByQuery extends JDBCAbstractQueryCommand 44 { 45 private final JDBCCMPFieldBridge cmpField; 47 48 public JDBCFindByQuery(JDBCStoreManager manager, JDBCQueryMetaData q) 49 throws DeploymentException 50 { 51 52 super(manager, q); 53 54 JDBCEntityBridge entity = (JDBCEntityBridge) manager.getEntityBridge(); 55 56 String finderName = q.getMethod().getName(); 57 58 String cmpFieldName = Character.toLowerCase(finderName.charAt(6)) + finderName.substring(7); 61 62 cmpField = entity.getCMPFieldByName(cmpFieldName); 64 if(cmpField == null) 65 { 66 throw new IllegalArgumentException ( 67 "No finder for this method: " + finderName); 68 } 69 70 JDBCReadAheadMetaData readAhead = q.getReadAhead(); 72 if(readAhead.isOnFind()) 73 { 74 setEagerLoadGroup(readAhead.getEagerLoadGroup()); 75 } 76 77 StringBuffer sql = new StringBuffer (300); 79 sql.append(SQLUtil.SELECT); 80 81 SQLUtil.getColumnNamesClause(entity.getPrimaryKeyFields(), sql); 82 if(getEagerLoadGroup() != null) 83 { 84 SQLUtil.appendColumnNamesClause(entity, getEagerLoadGroup(), sql); 85 } 86 sql.append(SQLUtil.FROM) 87 .append(entity.getQualifiedTableName()) 88 .append(SQLUtil.WHERE); 89 SQLUtil.getWhereClause(cmpField, sql); 90 91 setSQL(sql.toString()); 92 setParameterList(QueryParameter.createParameters(0, cmpField)); 93 } 94 } 95 | Popular Tags |