Package org.jpox.store.rdbms

Examples of org.jpox.store.rdbms.SQLController


     **/
    public void deleteSequence(String sequenceName, ManagedConnection conn)
    throws SQLException
    {
        PreparedStatement ps=null;
        SQLController sqlControl = storeMgr.getSQLController();
        try
        {
            ps = sqlControl.getStatementForUpdate(conn, deleteStmt, false);
            ps.setString(1, sequenceName);

            sqlControl.executeStatementUpdate(conn, deleteStmt, ps, true);

            // TODO : handle any warning messages
        }
        finally
        {
            if (ps != null)
            {
                sqlControl.closeStatement(conn, ps);
            }
        }
    }
View Full Code Here


            String stmt = getUpdateEmbeddedElementStmt(fieldMapping);
            try
            {
                ObjectManager om = sm.getObjectManager();
                ManagedConnection mconn = storeMgr.getConnection(om);
                SQLController sqlControl = storeMgr.getSQLController();

                try
                {
                    PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, stmt, false);
                    try
                    {
                        int jdbcPosition = 1;
                        fieldMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, fieldMapping), value);
                        jdbcPosition += fieldMapping.getNumberOfDatastoreFields();
                        jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                        jdbcPosition = populateEmbeddedElementFieldsInStatement(sm, element, ps, jdbcPosition, (JoinTable)containerTable);

                        sqlControl.executeStatementUpdate(mconn, stmt, ps, true);
                        modified = true;
                    }
                    finally
                    {
                        sqlControl.closeStatement(mconn, ps);
                    }
                }
                finally
                {
                    mconn.release();
View Full Code Here

     **/
    public void deleteAllSequences(ManagedConnection conn)
    throws SQLException
    {
        PreparedStatement ps=null;
        SQLController sqlControl = storeMgr.getSQLController();
        try
        {
            ps = sqlControl.getStatementForUpdate(conn, deleteAllStmt, false);

            sqlControl.executeStatementUpdate(conn, deleteAllStmt, ps, true);

            // TODO : handle any warning messages
        }
        finally
        {
            if (ps != null)
            {
                sqlControl.closeStatement(conn, ps);
            }
        }
    }
View Full Code Here

        String stmt = getContainsStmt();
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                    jdbcPosition = populateElementInStatement(om, ps, element, jdbcPosition);
                    // TODO Remove the containerTable == part of this so that the discrim restriction applies to JoinTable case too
                    // Needs to pass TCK M-M relation test
                    if (elementInfo != null && elementInfo[0].getDiscriminatorMapping() != null && elementInfo[0].getDatastoreClass() == containerTable)
                    {
                        jdbcPosition = populateElementDiscriminatorInStatement(om, ps, jdbcPosition, true, elementInfo[0]);
                    }
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                    }

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, stmt, ps);
                    try
                    {
                        retval = rs.next();

                        SQLWarnings.log(rs);
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here

     */
    protected int[] internalRemove(StateManager ownerSM, ManagedConnection conn, boolean batched, Object element, boolean executeNow)
    throws SQLException
    {
        ObjectManager om = ownerSM.getObjectManager();
        SQLController sqlControl = storeMgr.getSQLController();
        String removeStmt = getRemoveStmt();
        PreparedStatement ps = sqlControl.getStatementForUpdate(conn, removeStmt, batched);
        try
        {
            int jdbcPosition = 1;
            jdbcPosition = populateOwnerInStatement(ownerSM, om, ps, jdbcPosition);
            jdbcPosition = populateElementInStatement(om, ps, element, jdbcPosition);
            if (relationDiscriminatorMapping != null)
            {
                jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
            }

            // Execute the statement
            return sqlControl.executeStatementUpdate(conn, removeStmt, ps, executeNow);
        }
        finally
        {
            sqlControl.closeStatement(conn, ps);
        }
    }
View Full Code Here

        ObjectManager om = sm.getObjectManager();
        String stmt = getUpdateFkStmt();
        try
        {
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                int jdbcPosition = 1;
                if (elementInfo.length > 1)
                {
                    DatastoreClass table = storeMgr.getDatastoreClass(element.getClass().getName(), clr);
                    if (table != null)
                    {
                        stmt = StringUtils.replaceAll(stmt, "<TABLE NAME>", table.toString());
                    }
                    else
                    {
                        JPOXLogger.PERSISTENCE.warn("FKSetStore.updateElementFK : need to set table in statement but dont know table where to store " + element);
                    }
                }
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, stmt, false);
                try
                {
                    if (owner == null)
                    {
                        if (ownerMemberMetaData != null)
                        {
                            ownerMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, ownerMapping),
                                null, sm, ownerMemberMetaData.getAbsoluteFieldNumber());
                        }
                        else
                        {
                            ownerMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, ownerMapping),
                                null);
                        }
                    }
                    else
                    {
                        if (ownerMemberMetaData != null)
                        {
                            ownerMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, ownerMapping),
                                sm.getObject(), sm, ownerMemberMetaData.getAbsoluteFieldNumber());
                        }
                        else
                        {
                            ownerMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, ownerMapping),
                                sm.getObject());
                        }
                    }
                    jdbcPosition += ownerMapping.getNumberOfDatastoreFields();

                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                    }
                    elementMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, elementMapping), element);
                    jdbcPosition += elementMapping.getNumberOfDatastoreFields();

                    sqlControl.executeStatementUpdate(mconn, stmt, ps, true);
                    retval = true;
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here

        PreparedStatement ps = null;
        ResultSet rs = null;
        List oid = new ArrayList();
        RDBMSManager srm = (RDBMSManager)storeMgr;
        SQLController sqlControl = srm.getSQLController();
        try
        {
            // Get next available id
            RDBMSAdapter dba = (RDBMSAdapter) srm.getDatastoreAdapter();

            String stmt = dba.getSequenceNextStmt(getSequenceName());
            ps = sqlControl.getStatementForQuery(connection, stmt);
            rs = sqlControl.executeStatementQuery(connection, stmt, ps);
            Long nextId = new Long(0);
            if (rs.next())
            {
                nextId = new Long(rs.getLong(1));
                oid.add(nextId);
            }
            for (int i=1; i<size; i++)
            {
                // size must match key-increment-by otherwise it will
                // cause duplicates keys
                nextId = new Long(nextId.longValue()+1);
                oid.add(nextId);
            }
            if (JPOXLogger.POID.isDebugEnabled())
            {
                JPOXLogger.POID.debug(LOCALISER.msg("040004", "" + size));
            }
            return new PoidBlock(oid);
        }
        catch (SQLException e)
        {
            throw new PoidException(LOCALISER_RDBMS.msg("061001",e.getMessage()));
        }
        finally
        {
            try
            {
                if (rs != null)
                {
                    rs.close();
                }
                if (ps != null)
                {
                    sqlControl.closeStatement(connection, ps);
                }
            }
            catch (SQLException e)
            {
                // non-recoverable error
View Full Code Here

                            elementInfo[0].getClassName());
                    }
                }

                ManagedConnection mconn = storeMgr.getConnection(om);
                SQLController sqlControl = storeMgr.getSQLController();
                try
                {
                    PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, stmt, false);
                    try
                    {
                        int jdbcPosition = 1;
                        jdbcPosition = populateOwnerInStatement(ownerSM, om, ps, jdbcPosition);
                        sqlControl.executeStatementUpdate(mconn, stmt, ps, true);
                    }
                    finally
                    {
                        sqlControl.closeStatement(mconn, ps);
                    }
                }
                finally
                {
                    mconn.release();
View Full Code Here

    protected boolean createRepository()
    {
        PreparedStatement ps = null;
        RDBMSManager srm = (RDBMSManager)storeMgr;
        RDBMSAdapter dba = (RDBMSAdapter)srm.getDatastoreAdapter();
        SQLController sqlControl = srm.getSQLController();

        String stmt = dba.getSequenceCreateStmt(getSequenceName(),
                    (String) properties.get("key-min-value"),
                    (String) properties.get("key-max-value"),
                    (String) properties.get("key-start-with"),
                    (String) properties.get("key-increment-by"),
                    (String) properties.get("key-database-cache-size"));
        try
        {
            ps = sqlControl.getStatementForUpdate(connection, stmt, false);
            sqlControl.executeStatementUpdate(connection, stmt, ps, true);
        }
        catch (SQLException e)
        {
            JPOXLogger.DATASTORE.error(e);
            throw new PoidException(LOCALISER_RDBMS.msg("061000",e.getMessage()) + stmt);
        }
        finally
        {
            try
            {
                if (ps != null)
                {
                    sqlControl.closeStatement(connection, ps);
                }
            }
            catch (SQLException e)
            {
                // non-recoverable error
View Full Code Here

        try
        {
            RDBMSManager storeMgr = (RDBMSManager)om.getStoreManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
           
            SQLController sqlControl = storeMgr.getSQLController();

            try
            {
                StatementText stmtText = null;
                if (query.getType() == Query.SELECT)
                {
                    stmtText = queryStmt.toStatementText(useUpdateLock);
                }
                else if (query.getType() == Query.BULK_UPDATE)
                {
                    stmtText = queryStmt.toUpdateStatementText();
                    throw new JPOXException("JPOX doesnt currently support bulk update statements");
                }
                else if (query.getType() == Query.BULK_DELETE)
                {
                    // TODO Distinguish between update and delete
                    stmtText = queryStmt.toDeleteStatementText();
                    throw new JPOXException("JPOX doesnt currently support bulk delete statements");
                }

                PreparedStatement ps = getStatement(mconn, stmtText);
                try
                {
                    // Apply timeouts, result set constraints etc
                    prepareStatementForExecution(ps);

                    // Add a limit on the number of rows to include the maximum we may need
                    long toExclNo = query.getRangeToExcl();
                    if (toExclNo != 0 && toExclNo != Long.MAX_VALUE)
                    {
                        if (toExclNo > Integer.MAX_VALUE)
                        {
                            // setMaxRows takes an int as input so limit to the correct range
                            ps.setMaxRows(Integer.MAX_VALUE);
                        }
                        else
                        {
                            ps.setMaxRows((int)toExclNo);
                        }
                    }

                    if (query.getType() != Query.SELECT)
                    {
                        JPOXLogger.JDO.debug(">> SQLEvaluator.evaluate BULK operation SELECT");
                    }
                    if (query.getType() == Query.SELECT)
                    {
                        // SELECT query
                        ResultSet rs = sqlControl.executeStatementQuery(mconn, stmtText.toString(), ps);
                        try
                        {
                            // Check the type of result set needed
                            if (getResultSetType().equals("scroll-insensitive") ||
                                getResultSetType().equals("scroll-sensitive"))
                            {
                                qr = new ScrollableQueryResult(queryStmt, query, rof, rs,
                                    distinct ? null : candidateCollection);
                            }
                            else
                            {
                                qr = new ForwardQueryResult(queryStmt, query, rof, rs,
                                    distinct ? null : candidateCollection);
                            }

                            final QueryResult qr1 = qr;
                            final ManagedConnection mconn1 = mconn;
                            ManagedConnectionResourceListener listener = new ManagedConnectionResourceListener()
                            {
                                public void managedConnectionPreClose(){}
                                public void managedConnectionPostClose(){}
                                public void managedConnectionFlushed()
                                {
                                    // Disconnect the query from this ManagedConnection (read in unread rows etc)
                                    qr1.disconnect();
                                }
                                public void resourcePostClose()
                                {
                                    mconn1.removeListener(this);
                                }
                            };
                            mconn.addListener(listener);
                            ((AbstractRDBMSQueryResult)qr).addConnectionListener(listener);
                        }
                        finally
                        {
                            if (qr == null)
                            {
                                rs.close();
                            }
                        }
                    }
                    else
                    {
                        // UPDATE/DELETE query
                        int[] rcs = sqlControl.executeStatementUpdate(mconn, stmtText.toString(), ps, true);
                        JPOXLogger.JDO.info(">> Update statement returned " + rcs[0]);
                        // TODO Return the number of affected records
                    }
                }
                finally
                {
                    if (qr == null)
                    {
                        sqlControl.closeStatement(mconn, ps);
                    }
                }
            }
            finally
            {
View Full Code Here

TOP

Related Classes of org.jpox.store.rdbms.SQLController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.