class JpaNamedQueryVisitor extends NestedVisitor {
@Override
Object createObject(ProjectPath path) {
JpaNamedQuery jpaQuery = (JpaNamedQuery) path.getObject();
JpaIndirectQuery cayenneQuery;
JpaQueryHint hint = jpaQuery.getHint(QueryHints.QUERY_TYPE_HINT);
if (hint != null && !Util.isEmptyString(hint.getValue())) {
try {
// query class is not enhanced, so use normal class loader
Class cayenneQueryClass = Class.forName(hint.getValue(), true, Thread
.currentThread()
.getContextClassLoader());
if (!JpaIndirectQuery.class.isAssignableFrom(cayenneQueryClass)) {
recordConflict(path, "Unknown type for Cayenne query '"
+ jpaQuery.getName()
+ "': "
+ cayenneQueryClass.getName());
return null;
}
cayenneQuery = (JpaIndirectQuery) cayenneQueryClass.newInstance();
}
catch (Exception e) {
recordConflict(path, "Problem while creating Cayenne query '"
+ jpaQuery.getName()
+ "', exception"
+ e.getMessage());
return null;
}
}
else {
// by default use EJBQL query...
cayenneQuery = new JpaEjbQLQuery();
}
cayenneQuery.setName(jpaQuery.getName());
cayenneQuery.setJpaQuery(jpaQuery);
DataMap parentMap = (DataMap) targetPath.firstInstanceOf(DataMap.class);
ObjEntity parentEntity = (ObjEntity) targetPath