use of javax.jdo.query.PersistableExpression in project datanucleus-api-jdo by datanucleus.
the class JDOQLTypedQueryImpl method candidate.
/* (non-Javadoc)
* @see javax.jdo.JDOQLTypedQuery#candidate()
*/
public PersistableExpression candidate() {
assertIsOpen();
String candName = candidateCls.getName();
int pos = candName.lastIndexOf('.');
String qName = candName.substring(0, pos + 1) + getQueryClassNameForClassName(candName.substring(pos + 1));
try {
// Use the candidate() static method for access
Class qClass = ec.getClassLoaderResolver().classForName(qName);
Method method = qClass.getMethod("candidate", new Class[] {});
Object candObj = method.invoke(null, (Object[]) null);
if (candObj == null || !(candObj instanceof PersistableExpression)) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
}
return (PersistableExpression) candObj;
} catch (NoSuchMethodException nsfe) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
} catch (InvocationTargetException ite) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
} catch (IllegalAccessException iae) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
}
}
use of javax.jdo.query.PersistableExpression in project datanucleus-api-jdo by datanucleus.
the class JDOQLTypedSubqueryImpl method candidate.
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.TypesafeSubquery#candidate()
*/
public PersistableExpression candidate() {
String candName = candidateCls.getName();
int pos = candName.lastIndexOf('.');
String qName = candName.substring(0, pos + 1) + JDOQLTypedQueryImpl.getQueryClassNameForClassName(candName.substring(pos + 1));
try {
// Access the "candidate" field of the query class
Class qClass = ec.getClassLoaderResolver().classForName(qName);
Constructor ctr = qClass.getConstructor(new Class[] { PersistableExpression.class, String.class });
Object candObj = ctr.newInstance(new Object[] { null, candidateAlias });
if (candObj == null || !(candObj instanceof PersistableExpression)) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
}
return (PersistableExpression) candObj;
} catch (NoSuchMethodException nsfe) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
} catch (InvocationTargetException ite) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
} catch (InstantiationException ie) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
} catch (IllegalAccessException iae) {
throw new JDOException("Class " + candidateCls.getName() + " has a Query class but the candidate is invalid");
}
}
Aggregations