Package org.jpox.store.rdbms

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


     */
    protected int[] internalAdd(StateManager sm, Object element, ManagedConnection conn, boolean batched, int orderId, boolean executeNow)
    throws SQLException
    {
        ObjectManager om = sm.getObjectManager();
        SQLController sqlControl = storeMgr.getSQLController();
        String addStmt = getAddStmt();
        PreparedStatement ps = sqlControl.getStatementForUpdate(conn, addStmt, false);
        boolean notYetFlushedError = false;
        try
        {
            // Insert the join table row
            int jdbcPosition = 1;
            jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
            jdbcPosition = populateElementInStatement(om, ps, element, jdbcPosition);
            jdbcPosition = populateOrderInStatement(om, ps, orderId, jdbcPosition);
            if (relationDiscriminatorMapping != null)
            {
                jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
            }

            // Execute the statement
            return sqlControl.executeStatementUpdate(conn, addStmt, ps, executeNow);
        }
        catch (NotYetFlushedException nfe)
        {
            notYetFlushedError = true;
            throw nfe;
        }
        finally
        {
            if (notYetFlushedError)
            {
                sqlControl.abortStatementForConnection(conn, ps);
            }
            else
            {
                sqlControl.closeStatement(conn, ps);
            }
        }
    }
View Full Code Here


        Iterator iter;
        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
                    {
                        iter = new ArrayStoreIterator(ownerSM, rs, rof);
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here

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

                try
                {
                    PreparedStatement ps = getStatement(mconn, compiledSQL);
                    try
                    {
                        // Set the values of any parameters
                        if (parameters != null)
                        {
                            for (int i=0;i<parameters.size();i++)
                            {
                                Object obj = parameters.get(new Integer(i+1));
                                ps.setObject((i+1), obj);
                            }
                        }

                        // Apply any user-specified constraints over timeouts and ResultSet
                        prepareStatementForExecution(ps);

                        // Execute the query
                        ResultSet rs = sqlControl.executeStatementQuery(mconn, compiledSQL, ps);
                        try
                        {
                            // Generate a ResultObjectFactory
                            if (resultMetaData != null)
                            {
                                // Each row of the ResultSet is defined by MetaData
                                rof = new ResultMetaDataROF(resultMetaData);
                            }
                            else if (resultClass != null || candidateClass == null)
                            {
                                // Each row of the ResultSet is either an instance of resultClass, or Object[]
                                rof = getResultObjectFactoryForNoCandidateClass(rs, resultClass);
                            }
                            else
                            {
                                // Each row of the ResultSet is an instance of the candidate class
                                rof = getResultObjectFactoryForCandidateClass(rs);
                            }

                            // Return the associated type of results depending on whether scrollable or not
                            if (getResultSetType().equals("scroll-insensitive") ||
                                getResultSetType().equals("scroll-sensitive"))
                            {
                                qr = new ScrollableQueryResult(null, query, rof, rs, null);
                            }
                            else
                            {
                                qr = new ForwardQueryResult(null, query, rof, rs, null);
                            }

                            final QueryResult qr1 = qr;
                            final ManagedConnection mconn1 = mconn;
                            mconn.addListener(new ManagedConnectionResourceListener()
                            {
                                public void managedConnectionFlushed()
                                {
                                    qr1.disconnect();                       
                                }

                                public void managedConnectionPreClose(){}
                                public void managedConnectionPostClose(){}
                                public void resourcePostClose()
                                {
                                    mconn1.removeListener(this);
                                }
                            });                           
                        }
                        finally
                        {
                            if (qr == null)
                            {
                                rs.close();
                            }
                        }
                    }
                    finally
                    {
                        if (qr == null)
                        {
                            sqlControl.closeStatement(mconn, ps);
                        }
                    }
                }
                finally
                {
View Full Code Here

        // Process the delete of this object
        try
        {
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();

            try
            {
                // Perform the delete
                boolean batch = true;
                if (optimisticChecks || !om.getTransaction().isActive())
                {
                    // Turn OFF batching if doing optimistic checks (since we need the result of the delete)
                    // or if using nontransactional writes (since we want it sending to the datastore now)
                    batch = false;
                }
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, stmt, batch);
                try
                {
                    // provide primary key field(s)
                    if (cmd.getIdentityType() == IdentityType.DATASTORE)
                    {
                        table.getDataStoreObjectIdMapping().setObject(om, ps,
                            mappingStatementIndex.getDatastoreId().getParameterIndex(), sm.getInternalObjectId());
                    }
                    else if (cmd.getIdentityType() == IdentityType.APPLICATION)
                    {
                        sm.provideFields(pkFieldNumbers, new ParameterSetter(sm, ps,
                            mappingStatementIndex.getPrimaryKeys(),true));
                    }

                    if (optimisticChecks)
                    {
                        // WHERE clause - current version discriminator
                        JavaTypeMapping verMapping = mappingStatementIndex.getVersion2().getMapping();
                        Object currentVersion = sm.getTransactionalVersion(sm.getObject());
                        if (currentVersion == null)
                        {
                            // Somehow the version is not set on this object (not read in ?) so report the bug
                            String msg = LOCALISER.msg("052202",
                                sm.getInternalObjectId(), table);
                            JPOXLogger.PERSISTENCE.error(msg);
                            throw new JPOXException(msg);
                        }
                        verMapping.setObject(om, ps,
                            mappingStatementIndex.getVersion2().getParameterIndex(), currentVersion);
                    }

                    int[] rcs = sqlControl.executeStatementUpdate(mconn, stmt, ps, !batch);
                    if (optimisticChecks && rcs[0] == 0)
                    {
                        // No object deleted so either object disappeared or failed optimistic version checks
                        String msg = LOCALISER.msg("052203",
                            StringUtils.toJVMIDString(sm.getObject()), sm.getInternalObjectId(),
                            "" + sm.getTransactionalVersion(sm.getObject()));
                        JPOXLogger.DATASTORE.error(msg);
                        throw new JPOXOptimisticException(msg, sm.getObject());
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here

                }

                try
                {
                    ManagedConnection mconn = storeMgr.getConnection(om);
                    SQLController sqlControl = storeMgr.getSQLController();
                    try
                    {
                        // Null out the relationship to the object being deleted.
                        PreparedStatement ps = null;
                        try
                        {
                            ps = sqlControl.getStatementForUpdate(mconn, clearLinkStmt.toString(), false);
                            refMapping.setObject(om, ps, Mappings.getParametersIndex(1, refMapping), sm.getObject());

                            sqlControl.executeStatementUpdate(mconn, clearLinkStmt.toString(), ps, true);
                        }
                        finally
                        {
                            if (ps != null)
                            {
                                sqlControl.closeStatement(mconn, ps);
                            }
                        }
                    }
                    finally
                    {
View Full Code Here

            // do not query non-existing schema table when DDL is only written to file
            return schema_data;
        }
        else
        {
            SQLController sqlControl = storeMgr.getSQLController();
            PreparedStatement ps = sqlControl.getStatementForQuery(conn, fetchAllStmt);
            try
            {
                ResultSet rs = sqlControl.executeStatementQuery(conn, fetchAllStmt, ps);
                try
                {
                    while (rs.next())
                    {
                        StoreData data = new MappedStoreData(rs.getString(1), rs.getString(2), rs.getString(4).equals("1") ? true : false,
                                rs.getString(3).equals("FCO") ? StoreData.FCO_TYPE : StoreData.SCO_TYPE, rs.getString(6));
                        schema_data.add(data);
                    }
                }
                finally
                {
                    rs.close();
                }
            }
            finally
            {
                sqlControl.closeStatement(conn, ps);
            }

            return schema_data;
        }
    }
View Full Code Here

        {
            // Data already exists, so remove the chance of a duplicate insert
            return;
        }

        SQLController sqlControl = storeMgr.getSQLController();
        PreparedStatement ps = sqlControl.getStatementForUpdate(conn, insertStmt, false);
        try
        {
            int jdbc_id = 1;

            classMapping.setString(null, ps, Mappings.getParametersIndex(jdbc_id, classMapping), data.getName());
            jdbc_id += classMapping.getNumberOfDatastoreFields();

            tableMapping.setString(null, ps, Mappings.getParametersIndex(jdbc_id, tableMapping), data.hasTable() ? data.getTableName() : "");
            jdbc_id += tableMapping.getNumberOfDatastoreFields();

            typeMapping.setString(null, ps, Mappings.getParametersIndex(jdbc_id, typeMapping), data.isFCO() ? "FCO" : "SCO");
            jdbc_id += typeMapping.getNumberOfDatastoreFields();

            ownerMapping.setString(null, ps, Mappings.getParametersIndex(jdbc_id, ownerMapping), data.isTableOwner() ? "1" : "0");
            jdbc_id += ownerMapping.getNumberOfDatastoreFields();

            // TODO Sort out version
            versionMapping.setString(null, ps, Mappings.getParametersIndex(jdbc_id, versionMapping), "JPOX");
            jdbc_id += versionMapping.getNumberOfDatastoreFields();

            interfaceNameMapping.setString(null, ps, Mappings.getParametersIndex(jdbc_id, interfaceNameMapping), data.getInterfaceName());
            jdbc_id += interfaceNameMapping.getNumberOfDatastoreFields();

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

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

        {
            return false;
        }
        else
        {
            SQLController sqlControl = storeMgr.getSQLController();
            PreparedStatement ps = sqlControl.getStatementForQuery(conn, fetchStmt);
            try
            {
                int jdbc_id = 1;
                tableMapping.setString(null, ps, Mappings.getParametersIndex(jdbc_id, tableMapping), data.getName());

                ResultSet rs = sqlControl.executeStatementQuery(conn, fetchStmt, ps);
                try
                {
                    if (rs.next())
                    {
                        return true;
                    }
                }
                finally
                {
                    rs.close();
                }
            }
            finally
            {
                sqlControl.closeStatement(conn, ps);
            }
            return false;
        }
    }
View Full Code Here

     * @throws SQLException Thrown when an error occurs deleting the schema.
     **/
    public void deleteClass(String class_name, ManagedConnection conn)
    throws SQLException
    {
        SQLController sqlControl = storeMgr.getSQLController();
        PreparedStatement ps = sqlControl.getStatementForUpdate(conn, deleteStmt, false);
        try
        {
            ps.setString(1, class_name);

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

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

     * @throws SQLException Thrown when an error occurs deleting the schema.
     **/
    public void deleteAllClasses(ManagedConnection conn)
    throws SQLException
    {
        SQLController sqlControl = storeMgr.getSQLController();
        PreparedStatement ps = sqlControl.getStatementForUpdate(conn, deleteAllStmt, false);
        try
        {
            sqlControl.executeStatementUpdate(conn, deleteAllStmt, ps, true);

            // TODO : handle any warning messages
        }
        finally
        {
            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.