JDBCQueryMetaData findByPKMD = manager.getMetaData().getQueryMetaDataForMethod(method);
JDBCReadAheadMetaData readAhead = (findByPKMD == null ?
entity.getMetaData().getReadAhead() : findByPKMD.getReadAhead());
// got it add it to known finders
JDBCQueryMetaData q = new JDBCAutomaticQueryMetaData(
method,
readAhead,
entity.getMetaData().getQlCompiler(),
false
);
knownQueries.put(method, factory.createFindByPrimaryKeyQuery(q));
if (log.isDebugEnabled())
log.debug("Added findByPrimaryKey query command for home interface");
} catch (NoSuchMethodException e) {
throw new RuntimeException("Home interface does not have a findByPrimaryKey method");
}
}
if (localHomeClass != null) {
Method method;
try {
// try to get the finder method on the local home interface
method = localHomeClass.getMethod(FIND_BY_PK, new Class[]{entity.getPrimaryKeyClass()});
} catch (NoSuchMethodException e) {
throw new RuntimeException("Local home interface does " +
"not have the method findByPrimaryKey(" +
entity.getPrimaryKeyClass().getName() + ")");
}
// got it add it to known finders
JDBCQueryMetaData findByPKMD = manager.getMetaData().getQueryMetaDataForMethod(method);
JDBCReadAheadMetaData readAhead = (findByPKMD == null ?
entity.getMetaData().getReadAhead() : findByPKMD.getReadAhead());
JDBCQueryMetaData q = new JDBCAutomaticQueryMetaData(method, readAhead, entity.getMetaData().getQlCompiler(), false);
knownQueries.put(method, factory.createFindByPrimaryKeyQuery(q));
if (log.isDebugEnabled())
log.debug("Added findByPrimaryKey query command for local home interface");
}
//
// Custom finders - Overrides defined and automatic finders.
//
Class ejbClass = manager.getMetaData().getEntityClass();
Method[] customMethods = ejbClass.getMethods();
for (int i = 0; i < customMethods.length; i++) {
Method m = customMethods[i];
String methodName = m.getName();
if (methodName.startsWith(EJB_FIND)) {
String interfaceName = 'f' + methodName.substring(4);
if (homeClass != null) {
try {
// try to get the finder method on the home interface
Method interfaceMethod = homeClass.getMethod(
interfaceName,
m.getParameterTypes());
// got it add it to known finders
knownQueries.put(interfaceMethod, new JDBCCustomFinderQuery(manager, m));
if (log.isDebugEnabled())
log.debug("Added custom finder " + methodName + " on home interface");
} catch (NoSuchMethodException e) {
// this is ok method may not be defined on this interface
}
}
if (localHomeClass != null) {
try {
// try to get the finder method on the local home interface
Method interfaceMethod = localHomeClass.getMethod(
interfaceName,
m.getParameterTypes());
// got it add it to known finders
knownQueries.put(interfaceMethod, new JDBCCustomFinderQuery(manager, m));
if (log.isDebugEnabled())
log.debug("Added custom finder " + methodName + " on local home interface");
} catch (NoSuchMethodException e) {
// this is ok method may not be defined on this interface
}
}
}
}
//
// Defined finders - Overrides automatic finders.
//
Iterator definedFinders = manager.getMetaData().getQueries().iterator();
while (definedFinders.hasNext()) {
JDBCQueryMetaData q = (JDBCQueryMetaData) definedFinders.next();
if (!knownQueries.containsKey(q.getMethod())) {
if (q instanceof JDBCJBossQLQueryMetaData) {
knownQueries.put(q.getMethod(), factory.createJBossQLQuery(q));
} else if (q instanceof JDBCDynamicQLQueryMetaData) {
knownQueries.put(q.getMethod(), factory.createDynamicQLQuery(q));
} else if (q instanceof JDBCDeclaredQueryMetaData) {
knownQueries.put(q.getMethod(), factory.createDeclaredSQLQuery(q));
} else if (q instanceof JDBCQlQueryMetaData) {
knownQueries.put(q.getMethod(), factory.createEJBQLQuery(q));
}
}
}
//