Search in sources :

Example 51 with SQLExpressionFactory

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

the class TemporalYearMethod3 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, "YEAR");
    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, "year"));
    funcArgs.add(invokedExpr);
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "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 52 with SQLExpressionFactory

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

the class TemporalYearMethod4 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, "YEAR");
    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, "%Y"));
    funcArgs.add(invokedExpr);
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "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 53 with SQLExpressionFactory

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

the class TemporalMonthMethod2 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();
    funcArgs.add(invokedExpr);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    funcArgs.add(exprFactory.newLiteral(stmt, mapping2, "MM"));
    StringExpression charExpr = new StringExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "TO_CHAR", funcArgs);
    ArrayList funcArgs2 = new ArrayList();
    funcArgs2.add(charExpr);
    NumericExpression numExpr = new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "TO_NUMBER", funcArgs2);
    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) 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 SQLExpressionFactory

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

the class TemporalMonthMethod4 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, "%m"));
    funcArgs.add(invokedExpr);
    NumericExpression numExpr = new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "strftime", 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 55 with SQLExpressionFactory

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

the class TemporalSecondMethod3 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 day = exprFactory.newLiteral(stmt, mapping, "second");
    ArrayList funcArgs = new ArrayList();
    funcArgs.add(day);
    funcArgs.add(invokedExpr);
    NumericExpression secondExpr = new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "date_part", funcArgs);
    List castArgs = new ArrayList();
    castArgs.add(secondExpr);
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(Integer.class, true), "CAST", castArgs, asList("INTEGER"));
}
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) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Aggregations

SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)111 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)98 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)81 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)49 NucleusException (org.datanucleus.exceptions.NucleusException)42 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)40 ArrayList (java.util.ArrayList)39 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)38 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)35 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)31 SQLTable (org.datanucleus.store.rdbms.sql.SQLTable)30 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)28 StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)23 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)22 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)20 IntegerLiteral (org.datanucleus.store.rdbms.sql.expression.IntegerLiteral)20 NullLiteral (org.datanucleus.store.rdbms.sql.expression.NullLiteral)19 SQLLiteral (org.datanucleus.store.rdbms.sql.expression.SQLLiteral)17 BigInteger (java.math.BigInteger)16 StringLiteral (org.datanucleus.store.rdbms.sql.expression.StringLiteral)16