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;
}
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();
}
}
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();
}
}
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");
}
}
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()]));
}
}
Aggregations