throw new JDOUserException(LOCALISER_JDO.msg("011005", queryName, cls));
}
// Find the Query for the specified class
ClassLoaderResolver clr = objectMgr.getClassLoaderResolver();
QueryMetaData qmd = objectMgr.getMetaDataManager().getMetaDataForQuery(cls, clr, queryName);
if (qmd == null)
{
throw new JDOUserException(LOCALISER_JDO.msg("011005", queryName, cls));
}
// Create the Query
Query query = newQuery(qmd.getLanguage().toString(), qmd.getQuery());
if (cls != null)
{
query.setClass(cls);
if (!objectMgr.getStoreManager().managesClass(cls.getName()))
{
// Load the candidate class since not yet managed
objectMgr.getStoreManager().addClass(cls.getName(), clr);
}
}
// Optional args that should only be used with SQL
if (qmd.getLanguage() == QueryLanguage.JDOQL && (qmd.isUnique() || qmd.getResultClass() != null))
{
throw new JDOUserException(LOCALISER_JDO.msg("011007", queryName));
}
if (qmd.isUnique())
{
query.setUnique(true);
}
if (qmd.getResultClass() != null)
{
// Set the result class, allowing for it being in the same package as the candidate
Class resultCls = null;
try
{
resultCls = clr.classForName(qmd.getResultClass());
}
catch (ClassNotResolvedException cnre)
{
try
{
String resultClassName = cls.getPackage().getName() + "." + qmd.getResultClass();
resultCls = clr.classForName(resultClassName);
}
catch (ClassNotResolvedException cnre2)
{
throw new JDOUserException(LOCALISER_JDO.msg("011008", queryName, qmd.getResultClass()));
}
}
query.setResultClass(resultCls);
}
// Add any JPOX extensions
if (qmd.getLanguage() == QueryLanguage.JPOXSQL)
{
// Apply any imports specified
if (qmd.hasExtension("imports"))
{
query.declareImports(qmd.getValueForExtension("imports"));
}
// Apply any parameters specified
if (qmd.hasExtension("parameters"))
{
query.declareParameters(qmd.getValueForExtension("parameters"));
}
}
if (qmd.isUnmodifiable())
{
query.setUnmodifiable();
}
if (qmd.getFetchPlanName() != null)
{
// Apply any named FetchPlan to the query
FetchPlanMetaData fpmd =
getObjectManager().getMetaDataManager().getMetaDataForFetchPlan(qmd.getFetchPlanName());
if (fpmd != null)
{
org.jpox.FetchPlan fp = new org.jpox.FetchPlan(apmf, clr);
fp.removeGroup(org.jpox.FetchPlan.DEFAULT);
FetchGroupMetaData[] fgmds = fpmd.getFetchGroupMetaData();