use of org.datanucleus.store.rdbms.sql.expression.EnumLiteral in project datanucleus-rdbms by datanucleus.
the class EnumToStringMethod 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 expr, List<SQLExpression> args) {
if (expr instanceof EnumLiteral) {
Enum val = (Enum) ((EnumLiteral) expr).getValue();
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
return new StringLiteral(stmt, exprFactory.getMappingForType(String.class, false), val.toString(), null);
} else if (expr instanceof EnumExpression) {
EnumExpression enumExpr = (EnumExpression) expr;
JavaTypeMapping m = enumExpr.getJavaTypeMapping();
if (m.getJavaTypeForDatastoreMapping(0).equals(ClassNameConstants.JAVA_LANG_STRING)) {
return enumExpr.getDelegate();
}
throw new NucleusException("EnumExpression.toString is not supported when the enum is stored as a numeric");
} else {
throw new NucleusException(Localiser.msg("060001", "ordinal", expr));
}
}
Aggregations