Search in sources :

Example 81 with SQLExpression

use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.

the class MathToRadiansMethod 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 Math.toRadians without an argument");
    }
    SQLExpression expr = args.get(0);
    if (expr == null) {
        return new NullLiteral(stmt, null, null, null);
    } else if (expr instanceof SQLLiteral) {
        if (expr instanceof ByteLiteral) {
            int originalValue = ((BigInteger) ((ByteLiteral) expr).getValue()).intValue();
            BigInteger absValue = new BigInteger(String.valueOf(Math.cos(originalValue)));
            return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
        } else if (expr instanceof IntegerLiteral) {
            int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
            Double absValue = new Double(Math.cos(originalValue));
            return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
        } else if (expr instanceof FloatingPointLiteral) {
            double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
            Double absValue = new Double(Math.cos(originalValue));
            return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
        }
        throw new IllegalExpressionOperationException("Math.toRadians()", expr);
    } else {
        // Relay to the equivalent "radians(expr)" function
        SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
        return exprFactory.invokeMethod(stmt, null, "radians", null, args);
    }
}
Also used : SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) SQLLiteral(org.datanucleus.store.rdbms.sql.expression.SQLLiteral) IllegalExpressionOperationException(org.datanucleus.store.rdbms.sql.expression.IllegalExpressionOperationException) FloatingPointLiteral(org.datanucleus.store.rdbms.sql.expression.FloatingPointLiteral) ByteLiteral(org.datanucleus.store.rdbms.sql.expression.ByteLiteral) BigInteger(java.math.BigInteger) NullLiteral(org.datanucleus.store.rdbms.sql.expression.NullLiteral) IntegerLiteral(org.datanucleus.store.rdbms.sql.expression.IntegerLiteral)

Example 82 with SQLExpression

use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.

the class TemporalDayMethod2 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) {
    SQLExpression invokedExpr = getInvokedExpression(expr, args, "DAY");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
    ArrayList funcArgs = new ArrayList();
    funcArgs.add(invokedExpr);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    funcArgs.add(exprFactory.newLiteral(stmt, mapping, "DD"));
    ArrayList funcArgs2 = new ArrayList();
    funcArgs2.add(new StringExpression(stmt, mapping, "TO_CHAR", funcArgs));
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "TO_NUMBER", funcArgs2);
}
Also used : SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Example 83 with SQLExpression

use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.

the class TemporalDayMethod3 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) {
    SQLExpression invokedExpr = getInvokedExpression(expr, args, "DAY");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
    ArrayList funcArgs = new ArrayList();
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    funcArgs.add(exprFactory.newLiteral(stmt, mapping, "day"));
    funcArgs.add(invokedExpr);
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "date_part", funcArgs);
}
Also used : SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Example 84 with SQLExpression

use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.

the class TemporalDayMethod4 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) {
    SQLExpression invokedExpr = getInvokedExpression(expr, args, "DAY");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
    ArrayList funcArgs = new ArrayList();
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    funcArgs.add(exprFactory.newLiteral(stmt, mapping, "%d"));
    funcArgs.add(invokedExpr);
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "strftime", funcArgs);
}
Also used : SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Example 85 with SQLExpression

use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.

the class TemporalDayMethod5 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) {
    SQLExpression invokedExpr = getInvokedExpression(expr, args, "DAY");
    expr.toSQLText().prepend("DAY FROM ");
    ArrayList funcArgs = new ArrayList();
    funcArgs.add(invokedExpr);
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "EXTRACT", funcArgs);
}
Also used : SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression)

Aggregations

SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)199 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)98 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)95 ArrayList (java.util.ArrayList)75 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)74 NucleusException (org.datanucleus.exceptions.NucleusException)63 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)56 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)47 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)44 StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)41 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)40 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)35 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)34 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)34 SQLTable (org.datanucleus.store.rdbms.sql.SQLTable)34 UnboundExpression (org.datanucleus.store.rdbms.sql.expression.UnboundExpression)31 SQLLiteral (org.datanucleus.store.rdbms.sql.expression.SQLLiteral)29 NullLiteral (org.datanucleus.store.rdbms.sql.expression.NullLiteral)28 ParameterLiteral (org.datanucleus.store.rdbms.sql.expression.ParameterLiteral)28 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)25