Search in sources :

Example 1 with PersistableExpression

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");
    }
}
Also used : Method(java.lang.reflect.Method) PersistableExpression(javax.jdo.query.PersistableExpression) InvocationTargetException(java.lang.reflect.InvocationTargetException) JDOException(javax.jdo.JDOException)

Example 2 with PersistableExpression

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");
    }
}
Also used : Constructor(java.lang.reflect.Constructor) PersistableExpression(javax.jdo.query.PersistableExpression) InvocationTargetException(java.lang.reflect.InvocationTargetException) JDOException(javax.jdo.JDOException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 JDOException (javax.jdo.JDOException)2 PersistableExpression (javax.jdo.query.PersistableExpression)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1