Search in sources :

Example 16 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOQLTypedQueryImpl method variable.

/* (non-Javadoc)
     * @see javax.jdo.JDOQLTypedQuery#variable(java.lang.String, java.lang.Class)
     */
public <V> Expression<V> variable(String name, Class<V> type) {
    assertIsOpen();
    discardCompiled();
    Expression varExpr = null;
    if (ec.getApiAdapter().isPersistable(type)) {
        // Persistable class
        String typeName = type.getName();
        int pos = typeName.lastIndexOf('.');
        String qName = typeName.substring(0, pos + 1) + getQueryClassNameForClassName(typeName.substring(pos + 1));
        try {
            Class qClass = ec.getClassLoaderResolver().classForName(qName);
            Constructor ctr = qClass.getConstructor(new Class[] { Class.class, String.class, ExpressionType.class });
            Object candObj = ctr.newInstance(new Object[] { type, name, ExpressionType.VARIABLE });
            varExpr = (Expression) candObj;
        } catch (NoSuchMethodException nsme) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for variables");
        } catch (IllegalAccessException iae) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for variables");
        } catch (InvocationTargetException ite) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for variables");
        } catch (InstantiationException ie) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for variables");
        }
    } else if (type == Boolean.class || type == boolean.class) {
        varExpr = new BooleanExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == Byte.class || type == byte.class) {
        varExpr = new ByteExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == Character.class || type == char.class) {
        varExpr = new CharacterExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == Double.class || type == double.class) {
        varExpr = new NumericExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == Float.class || type == float.class) {
        varExpr = new NumericExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == Integer.class || type == int.class) {
        varExpr = new NumericExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == Long.class || type == long.class) {
        varExpr = new NumericExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == Short.class || type == short.class) {
        varExpr = new NumericExpressionImpl(type, name, ExpressionType.VARIABLE);
    } else if (type == String.class) {
        varExpr = new StringExpressionImpl((Class<String>) type, name, ExpressionType.VARIABLE);
    } else if (Time.class.isAssignableFrom(type)) {
        varExpr = new TimeExpressionImpl((Class<Time>) type, name, ExpressionType.VARIABLE);
    } else if (Date.class.isAssignableFrom(type)) {
        varExpr = new DateExpressionImpl((Class<Date>) type, name, ExpressionType.VARIABLE);
    } else if (java.util.Date.class.isAssignableFrom(type)) {
        varExpr = new DateTimeExpressionImpl((Class<java.util.Date>) type, name, ExpressionType.VARIABLE);
    } else {
        varExpr = new ObjectExpressionImpl(type, name, ExpressionType.VARIABLE);
    }
    return varExpr;
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException) Date(java.sql.Date) CharacterExpression(javax.jdo.query.CharacterExpression) StringExpression(javax.jdo.query.StringExpression) NumericExpression(javax.jdo.query.NumericExpression) TimeExpression(javax.jdo.query.TimeExpression) ListExpression(javax.jdo.query.ListExpression) PersistableExpression(javax.jdo.query.PersistableExpression) OrderExpression(javax.jdo.query.OrderExpression) DateTimeExpression(javax.jdo.query.DateTimeExpression) DateExpression(javax.jdo.query.DateExpression) BooleanExpression(javax.jdo.query.BooleanExpression) CollectionExpression(javax.jdo.query.CollectionExpression) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) MapExpression(javax.jdo.query.MapExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) Expression(javax.jdo.query.Expression) JDOException(javax.jdo.JDOException)

Example 17 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOQLTypedQueryImpl method cancel.

/* (non-Javadoc)
     * @see javax.jdo.JDOQLTypedQuery#cancel(java.lang.Thread)
     */
@Override
public void cancel(Thread thread) {
    assertIsOpen();
    if (internalQueries == null || internalQueries.isEmpty()) {
        return;
    }
    try {
        Iterator<Query> iter = internalQueries.iterator();
        while (iter.hasNext()) {
            Query query = iter.next();
            query.cancel(thread);
        }
    } catch (NucleusException ne) {
        throw new JDOException("Error in calling Query.cancelAll. See the nested exception", ne);
    } catch (UnsupportedOperationException uoe) {
        throw new JDOUnsupportedOptionException();
    }
}
Also used : Query(org.datanucleus.store.query.Query) JDOQLTypedQuery(javax.jdo.JDOQLTypedQuery) JDOQuery(org.datanucleus.api.jdo.JDOQuery) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) NucleusException(org.datanucleus.exceptions.NucleusException) JDOException(javax.jdo.JDOException)

Example 18 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOQLTypedQueryImpl method cancelAll.

/* (non-Javadoc)
     * @see javax.jdo.JDOQLTypedQuery#cancelAll()
     */
@Override
public void cancelAll() {
    assertIsOpen();
    if (internalQueries == null || internalQueries.isEmpty()) {
        return;
    }
    try {
        Iterator<Query> iter = internalQueries.iterator();
        while (iter.hasNext()) {
            Query query = iter.next();
            query.cancel();
        }
    } catch (NucleusException ne) {
        throw new JDOException("Error in calling Query.cancelAll. See the nested exception", ne);
    } catch (UnsupportedOperationException uoe) {
        throw new JDOUnsupportedOptionException();
    }
}
Also used : Query(org.datanucleus.store.query.Query) JDOQLTypedQuery(javax.jdo.JDOQLTypedQuery) JDOQuery(org.datanucleus.api.jdo.JDOQuery) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) NucleusException(org.datanucleus.exceptions.NucleusException) JDOException(javax.jdo.JDOException)

Example 19 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOQLTypedSubqueryImpl method internalSelect.

protected Expression internalSelect(Expression expr, Class implClass) {
    discardCompiled();
    this.result = new ArrayList<ExpressionImpl>();
    this.result.add((ExpressionImpl) expr);
    VariableExpression varExpr = new VariableExpression(getAlias());
    try {
        Constructor ctr = implClass.getConstructor(new Class[] { org.datanucleus.query.expression.Expression.class });
        return (Expression) ctr.newInstance(new Object[] { varExpr });
    } catch (NoSuchMethodException nsme) {
        throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " since required constructor doesnt exist");
    } catch (InvocationTargetException ite) {
        throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " due to error in constructor");
    } catch (IllegalAccessException iae) {
        throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " due to error in constructor");
    } catch (InstantiationException ie) {
        throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " due to error in constructor");
    }
}
Also used : Constructor(java.lang.reflect.Constructor) VariableExpression(org.datanucleus.query.expression.VariableExpression) InvocationTargetException(java.lang.reflect.InvocationTargetException) DateTimeExpression(javax.jdo.query.DateTimeExpression) CharacterExpression(javax.jdo.query.CharacterExpression) DateExpression(javax.jdo.query.DateExpression) StringExpression(javax.jdo.query.StringExpression) PersistableExpression(javax.jdo.query.PersistableExpression) BooleanExpression(javax.jdo.query.BooleanExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) CollectionExpression(javax.jdo.query.CollectionExpression) NumericExpression(javax.jdo.query.NumericExpression) TimeExpression(javax.jdo.query.TimeExpression) Expression(javax.jdo.query.Expression) JDOException(javax.jdo.JDOException)

Example 20 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOPersistenceManager method refreshAll.

/**
 * Method to do a refresh of a collection of objects.
 * @param pcs The Objects
 * @throws JDOUserException thrown if instances could not be refreshed.
 */
public void refreshAll(Collection pcs) {
    assertIsOpen();
    ArrayList failures = new ArrayList();
    Iterator iter = pcs.iterator();
    while (iter.hasNext()) {
        try {
            jdoRefresh(iter.next());
        } catch (JDOException e) {
            failures.add(e);
        }
    }
    if (!failures.isEmpty()) {
        throw new JDOUserException(Localiser.msg("010037"), (Exception[]) failures.toArray(new Exception[failures.size()]));
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JDOUserException(javax.jdo.JDOUserException) JDONullIdentityException(javax.jdo.JDONullIdentityException) TransactionNotActiveException(org.datanucleus.api.jdo.exceptions.TransactionNotActiveException) JDOException(javax.jdo.JDOException) JDOUserException(javax.jdo.JDOUserException) JDOFatalUserException(javax.jdo.JDOFatalUserException) NucleusException(org.datanucleus.exceptions.NucleusException) TransactionActiveOnCloseException(org.datanucleus.exceptions.TransactionActiveOnCloseException) JDOOptimisticVerificationException(javax.jdo.JDOOptimisticVerificationException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) TransactionNotWritableException(org.datanucleus.api.jdo.exceptions.TransactionNotWritableException) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) NucleusOptimisticException(org.datanucleus.exceptions.NucleusOptimisticException) JDOException(javax.jdo.JDOException)

Aggregations

JDOException (javax.jdo.JDOException)32 PersistenceManager (javax.jdo.PersistenceManager)14 Transaction (javax.jdo.Transaction)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 Query (javax.jdo.Query)7 Iterator (java.util.Iterator)6 JDOUserException (javax.jdo.JDOUserException)6 NucleusException (org.datanucleus.exceptions.NucleusException)6 JDOUnsupportedOptionException (javax.jdo.JDOUnsupportedOptionException)5 Constructor (java.lang.reflect.Constructor)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 JDOFatalUserException (javax.jdo.JDOFatalUserException)4 PersistableExpression (javax.jdo.query.PersistableExpression)4 Collection (java.util.Collection)3 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)3 Person (org.jpox.samples.models.company.Person)3 Method (java.lang.reflect.Method)2 Date (java.sql.Date)2 SQLException (java.sql.SQLException)2