Package org.jpox.store.rdbms

Examples of org.jpox.store.rdbms.SQLController$ConnectionStatementState


        String statement = storeMgr.getStatementTextForQuery(stmt, useUpdateLock);

        try
        {
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = storeMgr.getStatementForQuery(stmt, om, mconn, useUpdateLock, null, null);
                try
                {
                    ResultSet rs = sqlControl.executeStatementQuery(mconn, statement, ps);
                    try
                    {
                        while (rs.next())
                        {
                            Object obj = null;

                            if (elementsAreEmbedded || elementsAreSerialised)
                            {
                                int param[] = new int[elementMapping.getNumberOfDatastoreFields()];
                                for (int i = 0; i < param.length; ++i)
                                {
                                    param[i] = i + 1;
                                }
                                obj = elementMapping.getObject(om, rs, param);
                            }
                            else if (elementMapping instanceof ReferenceMapping)
                            {
                                // Element = Reference (Interface/Object)
                                int param[] = new int[elementMapping.getNumberOfDatastoreFields()];
                                for (int i = 0; i < param.length; ++i)
                                {
                                    param[i] = i + 1;
                                }
                                obj = elementMapping.getObject(om, rs, param);
                            }
                            else
                            {
                                obj = getROF.getObject(om, rs);
                            }

                            list.add(obj);
                        }

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


        String unsetStmt = getUnsetStmt();
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                // Unset the existing object from this position
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, unsetStmt, false);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                    if (orderMapping != null)
                    {
                        jdbcPosition = populateOrderInStatement(om, ps, index, jdbcPosition);
                    }
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                    }

                    sqlControl.executeStatementUpdate(mconn, unsetStmt, ps, true);
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }

                // Set the new object at this position
                PreparedStatement ps2 = sqlControl.getStatementForUpdate(mconn, setStmt, false);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = populateOwnerInStatement(sm, om, ps2, jdbcPosition);
                    if (orderMapping != null)
                    {
                        jdbcPosition = populateOrderInStatement(om, ps2, index, jdbcPosition);
                    }
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps2, jdbcPosition);
                    }
                    jdbcPosition = populateElementInStatement(om, ps2, element, jdbcPosition);

                    sqlControl.executeStatementUpdate(mconn, setStmt, ps2, true);
                }
                finally
                {
                    ps2.close();
                }
View Full Code Here

        ObjectManager om = sm.getObjectManager();
        String updateFkStmt = getUpdateFkStmt();
        try
        {
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, updateFkStmt, false);
                try
                {
                    int jdbcPosition = 1;
                    if (elementInfo.length > 1)
                    {
                        storeMgr.getDatastoreClass(element.getClass().getName(), clr);
                    }
                    if (owner == null)
                    {
                        if (ownerMemberMetaData != null)
                        {
                            ownerMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, ownerMapping), null);
                        }
                        else
                        {
                            ownerMapping.setObject(om, ps, Mappings.getParametersIndex(jdbcPosition, ownerMapping), null,
                                sm, ownerMemberMetaData.getAbsoluteFieldNumber());
                        }
                        jdbcPosition += ownerMapping.getNumberOfDatastoreFields();
                    }
                    else
                    {
                        jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                    }
                    if (orderMapping != null)
                    {
                        jdbcPosition = populateOrderInStatement(om, ps, index, jdbcPosition);
                    }
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                    }
                    jdbcPosition = populateElementInStatement(om, ps, element, jdbcPosition);

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

            // TODO If the relation is bidirectional we need to clear the owner in the element
            String clearNullifyStmt = getClearNullifyStmt();
            try
            {
                ManagedConnection mconn = storeMgr.getConnection(om);
                SQLController sqlControl = storeMgr.getSQLController();
                try
                {
                    PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, clearNullifyStmt, false);
                    try
                    {
                        int jdbcPosition = 1;
                        jdbcPosition = populateOwnerInStatement(ownerSM, om, ps, jdbcPosition);
                        if (relationDiscriminatorMapping != null)
                        {
                            jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                        }
                        sqlControl.executeStatementUpdate(mconn, clearNullifyStmt, ps, 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
        {
            // Find the next ID from the database
            RDBMSAdapter dba = (RDBMSAdapter) srm.getDatastoreAdapter();

            String stmt = dba.getSelectNewUUIDStmt();

            ps = sqlControl.getStatementForQuery(connection, stmt);
            for (int i=1; i<size; i++)
            {
                rs = sqlControl.executeStatementQuery(connection, stmt, ps);

                String nextId;
                if (rs.next())
                {
                    nextId = rs.getString(1);
                    oid.add(nextId);
                }
            }
            return new PoidBlock(oid);
        }
        catch (SQLException e)
        {
            throw new PoidException(LOCALISER.msg("040008",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

    {
        // search an Id in the database
        PreparedStatement ps = null;
        ResultSet rs = null;
        RDBMSManager rdbmsMgr = (RDBMSManager)storeMgr;
        SQLController sqlControl = rdbmsMgr.getSQLController();
        try
        {
            String stmt = getStatement();
            ps = sqlControl.getStatementForUpdate(connection, stmt, false);

            rs = sqlControl.executeStatementQuery(connection, stmt, ps);
            if (!rs.next())
            {
                return new PoidBlock(new Object[] { new Long(1) });
            }

            return new PoidBlock(new Object[] { new Long(rs.getLong(1) + 1)});
        }
        catch (SQLException e)
        {
            //TODO adds a message correspondent to the exception.
            //we need to work to create user friendly messages
            throw new PoidException(e.getMessage());
        }
        finally
        {
            try
            {
                if (rs != null)
                {
                    rs.close();
                }
                if (ps != null)
                {
                    sqlControl.closeStatement(connection, ps);
                }
            }
            catch (SQLException e)
            {
                // no recoverable error
View Full Code Here

    throws SQLException
    {
        HashSet sequenceNames = new HashSet();

        PreparedStatement ps = null;
        SQLController sqlControl = storeMgr.getSQLController();
        try
        {
            ps = sqlControl.getStatementForQuery(conn, fetchAllStmt);

            ResultSet rs = sqlControl.executeStatementQuery(conn, fetchAllStmt, ps);
            try
            {
              while (rs.next())
              {
                  sequenceNames.add(rs.getString(2));
              }
            }
            finally
            {
                rs.close();
            }
        }
        finally
        {
            if (ps != null)
            {
                sqlControl.closeStatement(conn, ps);
            }
        }

        return sequenceNames;
    }
View Full Code Here

            DatastoreIdentifier tableIdentifier, String columnName, int initialValue)
    throws SQLException
    {
        PreparedStatement ps = null;
        Long nextVal = null;
        SQLController sqlControl = storeMgr.getSQLController();
        try
        {
            ps = sqlControl.getStatementForQuery(conn, fetchStmt);
            sequenceNameMapping.setString(null, ps, new int[]{1}, sequenceName);

            ResultSet rs = sqlControl.executeStatementQuery(conn, fetchStmt, ps);
            try
            {
                if (!rs.next())
                {
                    // No data in the SEQUENCE_TABLE for this sequence currently
                    boolean addedSequence = false;
                    if (columnName != null && tableIdentifier != null)
                    {
                        // Table/Column specified so find the current max value for the field being generated
                        PreparedStatement ps2 = null;
                        ResultSet rs2 = null;
                        try
                        {
                            String fetchInitStmt = "SELECT MAX(" + columnName + ") FROM " + tableIdentifier.getFullyQualifiedName(false);
                            ps2 = sqlControl.getStatementForQuery(conn, fetchInitStmt);

                            rs2 = sqlControl.executeStatementQuery(conn, fetchInitStmt, ps2);
                            if (rs2.next())
                            {
                                long val = rs2.getLong(1);
                                addSequence(sequenceName, new Long(incrementBy + 1 + val), conn);
                                nextVal = new Long(1 + val);
                                addedSequence = true;
                            }
                        }
                        catch (Exception e)
                        {
                            // Do nothing - since if the table is empty we get this
                        }
                        finally
                        {
                            if (rs2 != null)
                            {
                                rs2.close();
                            }
                            if (ps2 != null)
                            {
                                sqlControl.closeStatement(conn, ps2);
                            }
                        }
                    }
                    if (!addedSequence)
                    {
                        // Just start at "initialValue"
                        addSequence(sequenceName, new Long(incrementBy + initialValue), conn);
                        nextVal = new Long(initialValue);
                    }
                }
                else
                {
                    // Data already exists in sequence table for this key so increment it
                    nextVal = new Long(rs.getLong(1));
                    incrementSequence(sequenceName, incrementBy, conn);
                }
            }
            finally
            {
                rs.close();
            }
        }
        catch (SQLException e)
        {
           throw new PoidException(LOCALISER.msg("061001", e.getMessage()),e);
        }
        finally
        {
            if (ps != null)
            {
                sqlControl.closeStatement(conn, ps);
            }
        }

        return nextVal;
    }
View Full Code Here

     **/
    private void incrementSequence(String sequenceName, long incrementBy, ManagedConnection conn)
    throws SQLException
    {
        PreparedStatement ps = null;
        SQLController sqlControl = storeMgr.getSQLController();
        try
        {
            ps = sqlControl.getStatementForUpdate(conn, incrementByStmt, false);
            nextValMapping.setLong(null, ps, new int[] {1}, incrementBy);

            sequenceNameMapping.setString(null, ps, new int[] {2}, sequenceName);

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

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

     **/
    private void addSequence(String sequenceName, Long nextVal, ManagedConnection conn)
    throws SQLException
    {
        PreparedStatement ps=null;
        SQLController sqlControl = storeMgr.getSQLController();
        try
        {
            ps = sqlControl.getStatementForUpdate(conn, insertStmt, false);
            sequenceNameMapping.setString(null, ps, new int[] {1}, sequenceName);
            nextValMapping.setLong(null, ps, new int[] {2}, nextVal.longValue());

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

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

TOP

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

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.