Search in sources :

Example 51 with NumericExpression

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

the class TemporalMonthJavaMethod4 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, "MONTH_JAVA");
    SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping2 = storeMgr.getMappingManager().getMapping(String.class);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    ArrayList funcArgs = new ArrayList();
    funcArgs.add(exprFactory.newLiteral(stmt, mapping2, "%m"));
    funcArgs.add(invokedExpr);
    // Delete one from the SQL "month" (origin=1) to be compatible with Java month (origin=0)
    NumericExpression numExpr = new NumericExpression(new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "strftime", funcArgs), Expression.OP_SUB, one);
    numExpr.encloseInParentheses();
    return numExpr;
}
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 52 with NumericExpression

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

the class TemporalMonthMethod3 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, "MONTH");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping2 = storeMgr.getMappingManager().getMapping(String.class);
    ArrayList funcArgs = new ArrayList();
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    funcArgs.add(exprFactory.newLiteral(stmt, mapping2, "month"));
    funcArgs.add(invokedExpr);
    NumericExpression numExpr = new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "date_part", funcArgs);
    numExpr.encloseInParentheses();
    return numExpr;
}
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 53 with NumericExpression

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

the class TemporalSecondMethod2 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, "SECOND");
    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, "SS"));
    ArrayList funcArgs2 = new ArrayList();
    funcArgs2.add(new StringExpression(stmt, mapping, "TO_CHAR", funcArgs));
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "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 54 with NumericExpression

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

the class TemporalSecondMethod4 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, "SECOND");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    SQLExpression ss = exprFactory.newLiteral(stmt, mapping, "ss");
    ((StringLiteral) ss).generateStatementWithoutQuotes();
    List funcArgs = new ArrayList<>();
    funcArgs.add(ss);
    // CAST {invokedExpr} AS DATETIME
    List castArgs = new ArrayList<>();
    castArgs.add(invokedExpr);
    funcArgs.add(new TemporalExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(Date.class, true), "CAST", castArgs, asList("DATETIME")));
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "DATEPART", funcArgs);
}
Also used : TemporalExpression(org.datanucleus.store.rdbms.sql.expression.TemporalExpression) SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) StringLiteral(org.datanucleus.store.rdbms.sql.expression.StringLiteral) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Example 55 with NumericExpression

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

the class TemporalDayOfWeekMethod3 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, "DAYOFWEEK");
    ArrayList funcArgs = new ArrayList();
    funcArgs.add(invokedExpr);
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "DAYOFWEEK", funcArgs);
}
Also used : SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression)

Aggregations

NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)74 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)67 ArrayList (java.util.ArrayList)60 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)40 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)40 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)28 StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)25 NucleusException (org.datanucleus.exceptions.NucleusException)20 TemporalExpression (org.datanucleus.store.rdbms.sql.expression.TemporalExpression)13 ParameterLiteral (org.datanucleus.store.rdbms.sql.expression.ParameterLiteral)12 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)10 CharacterExpression (org.datanucleus.store.rdbms.sql.expression.CharacterExpression)10 List (java.util.List)9 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)8 StringLiteral (org.datanucleus.store.rdbms.sql.expression.StringLiteral)8 IntegerLiteral (org.datanucleus.store.rdbms.sql.expression.IntegerLiteral)6 UnboundExpression (org.datanucleus.store.rdbms.sql.expression.UnboundExpression)6 Arrays.asList (java.util.Arrays.asList)5 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)5 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)4