Search in sources :

Example 51 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager in project datanucleus-rdbms by datanucleus.

the class TemporalMonthJavaMethod3 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, "month"));
    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), "date_part", 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 RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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 53 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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 54 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager 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 55 with RDBMSStoreManager

use of org.datanucleus.store.rdbms.RDBMSStoreManager in project datanucleus-rdbms by datanucleus.

the class MaxGenerator method reserveBlock.

/**
 * Method to reserve a block of identities.
 * Note : Only allocates a single id always.
 * @param size The block size
 * @return The reserved block
 */
public ValueGenerationBlock reserveBlock(long size) {
    try {
        // search an Id in the database
        ManagedConnection mconn = connectionProvider.retrieveConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        SQLController sqlControl = ((RDBMSStoreManager) storeMgr).getSQLController();
        try {
            String stmt = getStatement();
            ps = sqlControl.getStatementForUpdate(mconn, stmt, false);
            rs = sqlControl.executeStatementQuery(null, mconn, stmt, ps);
            if (!rs.next()) {
                return new ValueGenerationBlock(new Object[] { Long.valueOf(1) });
            }
            return new ValueGenerationBlock(new Object[] { Long.valueOf(rs.getLong(1) + 1) });
        } catch (SQLException e) {
            NucleusLogger.VALUEGENERATION.warn("Exception thrown getting next value for MaxGenerator", e);
            throw new ValueGenerationException("Exception thrown getting next value for MaxGenerator", e);
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (ps != null) {
                    sqlControl.closeStatement(mconn, ps);
                }
            } catch (SQLException e) {
            // no recoverable error
            }
        }
    } finally {
        connectionProvider.releaseConnection();
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ValueGenerationBlock(org.datanucleus.store.valuegenerator.ValueGenerationBlock) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) PreparedStatement(java.sql.PreparedStatement) ValueGenerationException(org.datanucleus.store.valuegenerator.ValueGenerationException) SQLController(org.datanucleus.store.rdbms.SQLController) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Aggregations

RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)197 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)84 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)82 SQLException (java.sql.SQLException)78 Connection (java.sql.Connection)76 HashSet (java.util.HashSet)72 DatabaseMetaData (java.sql.DatabaseMetaData)62 PersistenceManager (javax.jdo.PersistenceManager)61 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)56 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)55 Transaction (javax.jdo.Transaction)52 ArrayList (java.util.ArrayList)49 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)49 JDOFatalUserException (javax.jdo.JDOFatalUserException)48 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)44 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)42 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)41 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)38 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)28 JDOFatalInternalException (javax.jdo.JDOFatalInternalException)25