use of org.datanucleus.store.rdbms.sql.expression.IllegalExpressionOperationException in project datanucleus-rdbms by datanucleus.
the class JDOHelperGetObjectIdMethod method getExpression.
/* (non-Javadoc)
* @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
*/
public SQLExpression getExpression(SQLStatement stmt, SQLExpression ignore, List<SQLExpression> args) {
if (args == null || args.size() == 0) {
throw new NucleusUserException("Cannot invoke JDOHelper.getObjectId without an argument");
}
SQLExpression expr = args.get(0);
if (expr == null) {
return new NullLiteral(stmt, null, null, null);
}
if (expr instanceof SQLLiteral) {
RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
ApiAdapter api = storeMgr.getApiAdapter();
Object id = api.getIdForObject(((SQLLiteral) expr).getValue());
if (id == null) {
return new NullLiteral(stmt, null, null, null);
}
JavaTypeMapping m = stmt.getSQLExpressionFactory().getMappingForType(id.getClass(), true);
return new ObjectLiteral(stmt, m, id, null);
} else if (ObjectExpression.class.isAssignableFrom(expr.getClass())) {
// When the expression represents a PC object need to extract out as the identity
if (expr.getJavaTypeMapping() instanceof PersistableMapping) {
JavaTypeMapping mapping = new PersistableIdMapping((PersistableMapping) expr.getJavaTypeMapping());
return new ObjectExpression(stmt, expr.getSQLTable(), mapping);
} else if (expr.getJavaTypeMapping() instanceof ReferenceMapping) {
JavaTypeMapping mapping = new ReferenceIdMapping((ReferenceMapping) expr.getJavaTypeMapping());
return new ObjectExpression(stmt, expr.getSQLTable(), mapping);
}
return expr;
}
throw new IllegalExpressionOperationException("JDOHelper.getObjectId", expr);
}
use of org.datanucleus.store.rdbms.sql.expression.IllegalExpressionOperationException in project datanucleus-rdbms by datanucleus.
the class JDOHelperGetVersionMethod method getExpression.
/* (non-Javadoc)
* @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
*/
public SQLExpression getExpression(SQLStatement stmt, SQLExpression ignore, List<SQLExpression> args) {
if (args == null || args.size() == 0) {
throw new NucleusUserException("Cannot invoke JDOHelper.getVersion without an argument");
}
SQLExpression expr = args.get(0);
if (expr == null) {
throw new NucleusUserException("Cannot invoke JDOHelper.getVersion on null expression");
}
if (expr instanceof SQLLiteral) {
RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
ApiAdapter api = storeMgr.getApiAdapter();
Object obj = ((SQLLiteral) expr).getValue();
if (obj == null || !api.isPersistable(obj)) {
return new NullLiteral(stmt, null, null, null);
}
Object ver = stmt.getRDBMSManager().getApiAdapter().getVersionForObject(obj);
JavaTypeMapping m = stmt.getSQLExpressionFactory().getMappingForType(ver.getClass(), true);
return new ObjectLiteral(stmt, m, ver, null);
} else if (ObjectExpression.class.isAssignableFrom(expr.getClass())) {
if (((ObjectExpression) expr).getJavaTypeMapping() instanceof PersistableMapping) {
JavaTypeMapping mapping = ((ObjectExpression) expr).getJavaTypeMapping();
DatastoreClass table = (DatastoreClass) expr.getSQLTable().getTable();
if (// Version of candidate
table.getIdMapping() == mapping) {
mapping = table.getSurrogateMapping(SurrogateColumnType.VERSION, true);
if (mapping == null) {
throw new NucleusUserException("Cannot use JDOHelper.getVersion on object that has no version information");
}
if (table.getVersionMetaData().getVersionStrategy() == VersionStrategy.VERSION_NUMBER) {
return new NumericExpression(stmt, expr.getSQLTable(), mapping);
}
return new TemporalExpression(stmt, expr.getSQLTable(), mapping);
}
throw new NucleusUserException("Dont currently support JDOHelper.getVersion(ObjectExpression) for expr=" + expr + " on table=" + expr.getSQLTable());
// TODO Implement this
}
return expr;
}
throw new IllegalExpressionOperationException("JDOHelper.getVersion", expr);
}
Aggregations