Package org.jpox

Examples of org.jpox.ManagedConnection


        // Perform the query
        try
        {
            Transaction tx = om.getTransaction();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            boolean useUpdateLock = ((Boolean)tx.getOptions().get("transaction.serializeReadObjects")).booleanValue();
            String statement = storeMgr.getStatementTextForQuery(qs_base, useUpdateLock);
            try
            {
                PreparedStatement ps = storeMgr.getStatementForQuery(qs_base, om, mconn, useUpdateLock, null, null);
                try
                {
                    ResultSet rs = sqlControl.executeStatementQuery(mconn, statement, ps);
                    try
                    {
                        if (rs != null)
                        {
                            while (rs.next())
                            {
                                className = RDBMSQueryUtils.getClassNameFromJPOXMetaDataResultSetRow(rs);
                            }
                        }
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException sqe)
        {
            JPOXLogger.DATASTORE.error(sqe);
View Full Code Here


        // Perform the query
        try
        {
            Transaction tx = om.getTransaction();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            boolean useUpdateLock = ((Boolean)tx.getOptions().get("transaction.serializeReadObjects")).booleanValue();
            String statement = storeMgr.getStatementTextForQuery(stmt, useUpdateLock);
            try
            {
                PreparedStatement ps = storeMgr.getStatementForQuery(stmt, om, mconn, useUpdateLock, null, null);
                try
                {
                    ResultSet rs = sqlControl.executeStatementQuery(mconn, statement, ps);
                    try
                    {
                        if (rs != null)
                        {
                            while (rs.next())
                            {
                                className = RDBMSQueryUtils.getClassNameFromDiscriminatorResultSetRow(primaryTable, rs, om);
                            }
                        }
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException sqe)
        {
            JPOXLogger.DATASTORE.error(sqe);
View Full Code Here

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

            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, textStmt);

                try
                {
                    Object pcObject = sm.getObject();
                    idMapping.setObject(om, ps, Mappings.getParametersIndex(1, idMapping), pcObject);

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, textStmt, ps);
                    try
                    {
                        if (!rs.next())
                        {
                            throw new JPOXObjectNotFoundException("No such database row", sm.getInternalObjectId());
                        }

                        int jdbcMajorVersion = ((DatabaseAdapter)datastoreContainer.getStoreManager().getDatastoreAdapter()).getDriverMajorVersion();
                        if (jdbcMajorVersion < 10)
                        {
                            // Oracle JDBC drivers version 9 and below use some sh*tty Oracle-specific CLOB type
                            // we have to cast to that, face west, pray whilst saying ommmmmmmmmmm
                            oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob(1);
                            if (clob != null)
                            {
                                clob.putString(1, value);
                            }
                        }
                        else
                        {
                            // Oracle JDBC drivers 10 and above supposedly use the JDBC standard class for Clobs
                            java.sql.Clob clob = rs.getClob(1);
                            if (clob != null)
                            {
                                clob.setString(1, value);
                            }
                        }
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException("Update of CLOB value failed: " + textStmt, e);
View Full Code Here

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

            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, textStmt);
                try
                {
                    Object pcObject = sm.getObject();
                    idMapping.setObject(om, ps, Mappings.getParametersIndex(1, idMapping), pcObject);

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, textStmt, ps);

                    try
                    {
                        if (!rs.next())
                        {
                            throw new JPOXObjectNotFoundException("No such database row", sm.getInternalObjectId());
                        }

                        int jdbcMajorVersion = ((DatabaseAdapter)datastoreContainer.getStoreManager().getDatastoreAdapter()).getDriverMajorVersion();
                        if (jdbcMajorVersion < 10)
                        {
                            // Oracle JDBC drivers version 9 and below use some sh*tty Oracle-specific BLOB type
                            // we have to cast to that, face west, pray whilst saying ommmmmmmmmmm
                            oracle.sql.BLOB blob = null;
                            if (jdbcMajorVersion <= 8)
                            {
                                OracleResultSet ors = (OracleResultSet)rs;
                                blob = ors.getBLOB(1);
                            }
                            else
                            {
                                blob = (oracle.sql.BLOB)rs.getBlob(1);
                            }

                            if (blob != null)
                            {
                                blob.putBytes(1, bytes);
                            }
                        }
                        else
                        {
                            // Oracle JDBC drivers 10 and above supposedly use the JDBC standard class for Blobs
                            java.sql.Blob blob = rs.getBlob(1);
                            if (blob != null)
                            {
                                blob.setBytes(1, bytes);
                            }
                        }
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException("Update of BLOB value failed: " + textStmt, e);
View Full Code Here

     * @throws SQLException
     */
    public List getTableInfo(String schemaNamePattern)
    throws SQLException
    {
        ManagedConnection mc = getConnection();
        try
        {
            Connection conn = (Connection)mc.getConnection();
            return RDBMSStoreHelper.getTableInfo(this, this.catalogName, schemaNamePattern, conn);
        }
        finally
        {
            if (mc != null)
            {
                mc.close();
            }
        }
    }
View Full Code Here

     * @throws SQLException
     */
    public List getColumnInfo(String schemaNamePattern, String tableNamePattern)
    throws SQLException
    {
        ManagedConnection mc = getConnection();
        try
        {
            Connection conn = (Connection)mc.getConnection();
            List cols = new ArrayList();
            ResultSet rs = ((RDBMSAdapter)dba).getColumns(conn, catalogName, schemaNamePattern, tableNamePattern);
            try
            {
                while (rs.next())
                {
                    cols.add(((RDBMSAdapter)dba).newColumnInfo(rs));
                }
            }
            finally
            {
                rs.close();
            }
            return cols;
        }
        finally
        {
            if (mc != null)
            {
                mc.close();
            }
        }
    }
View Full Code Here

    public Date getDatastoreDate()
    {
        Date serverDate = null;

        String dateStmt = ((RDBMSAdapter)dba).getDatastoreDateStatement();
        ManagedConnection mconn = null;
        try
        {
            mconn = getConnection(UserTransaction.TRANSACTION_NONE);

            PreparedStatement ps = null;
            ResultSet rs = null;
            try
            {
                ps = getSQLController().getStatementForQuery(mconn, dateStmt);
                rs = getSQLController().executeStatementQuery(mconn, dateStmt, ps);
                if (rs.next())
                {
                    // Retrieve the timestamp for the server date/time using the server TimeZone from OMF
                    // Assume that the dateStmt returns 1 column and is Timestamp
                    Timestamp time = rs.getTimestamp(1,
                        getOMFContext().getPersistenceConfiguration().getCalendarForDateTimezone());
                    serverDate = new Date(time.getTime());
                }
                else
                {
                    return null;
                }
            }
            catch (SQLException sqle)
            {
                String msg = LOCALISER_RDBMS.msg("050052", sqle.getMessage());
                JPOXLogger.DATASTORE.warn(msg, sqle);
                throw new JPOXUserException(msg, sqle).setFatal();
            }
            finally
            {
                if (rs != null)
                {
                    rs.close();
                }
                if (ps != null)
                {
                    getSQLController().closeStatement(mconn, ps);
                }
            }
        }
        catch (SQLException sqle)
        {
            String msg = LOCALISER_RDBMS.msg("050052", sqle.getMessage());
            JPOXLogger.DATASTORE.warn(msg, sqle);
            throw new JPOXException(msg, sqle).setFatal();
        }
        finally
        {
            mconn.close();
        }

        return serverDate;
    }
View Full Code Here

        persistenceHandler = new RDBMSPersistenceHandler(this);

        // Retrieve the Database Adapter for this datastore
        try
        {
            ManagedConnection mc = getConnection();
            Connection conn = (Connection)mc.getConnection();
            if (conn == null)
            {
                //somehow we haven't got an exception from the JDBC driver
                //to troubleshoot the user should telnet to ip/port of database and check if he can open a connection
                //this may be due to security / firewall things.
                throw new JPOXDataStoreException(LOCALISER_RDBMS.msg("050007"));
            }

            try
            {
                dba = RDBMSAdapterFactory.getInstance().getDatastoreAdapter(clr, conn,
                    conf.getStringProperty("org.jpox.datastoreAdapterClassName"),
                    omfContext.getPluginManager());
                dba.loadDatastoreMapping(omfContext.getPluginManager(), clr);

                // Check if the user has specified DefaultCatalogName/DefaultSchemaName and whether the DBA allows it
                if (conf.hasProperty("org.jpox.mapping.Catalog") && !((RDBMSAdapter)dba).supportsCatalogsInTableDefinitions())
                {
                   JPOXLogger.DATASTORE.warn(LOCALISER_RDBMS.msg("050002",
                       conf.getStringProperty("org.jpox.mapping.Catalog")));
                }
                if (conf.hasProperty("org.jpox.mapping.Schema") && !((RDBMSAdapter)dba).supportsSchemasInTableDefinitions())
                {
                    JPOXLogger.DATASTORE.warn(LOCALISER_RDBMS.msg("050003",
                        conf.getStringProperty("org.jpox.mapping.Schema")));
                }

                // Create an identifier factory - needs the database adapter to exist first
                initialiseIdentifierFactory(omfContext);

                // Create the SQL controller
                sqlController = new SQLController(((RDBMSAdapter)dba).supportsStatementBatching(),
                    conf.getIntProperty("org.jpox.rdbms.statementBatchLimit"),
                    conf.getIntProperty("org.jpox.query.timeout"));

                if (autoStartMechanism == null)
                {
                    // No auto-start specified so use RDBMS default of SchemaTable
                    // TODO When CORE-3328 is fixed change this to "SchemaTable2"
                    autoStartMechanism = "SchemaTable";
                }

                // Initialise the Schema "Name", and "Data"
                initialiseSchema(autoStartMechanism, conf.getStringProperty("org.jpox.autoStartMechanismMode"),
                    conn, clr);
            }
            finally
            {
                mc.close();
            }
        }
        catch (JPOXException jpex)
        {
            JPOXLogger.DATASTORE_SCHEMA.error(LOCALISER_RDBMS.msg("050004"), jpex);
View Full Code Here

     * @param om ObjectManager
     * @return The JPOXConnection
     */
    public JPOXConnection getJPOXConnection(final ObjectManager om)
    {
        final ManagedConnection mc;
        final boolean enlisted;
        if (!om.getTransaction().isActive())
        {
            // no active transaction so dont enlist
            enlisted = false;
        }
        else
        {
            enlisted = true;
        }
        ConnectionFactory cf = null;
        if (enlisted)
        {
            cf = getOMFContext().getConnectionFactoryRegistry().lookupConnectionFactory(txConnectionFactoryName);
        }
        else
        {
            cf = getOMFContext().getConnectionFactoryRegistry().lookupConnectionFactory(nontxConnectionFactoryName);
        }
        mc = cf.getConnection(enlisted?om:null, null); // Will throw exception if already locked

        // Lock the connection now that it is in use by the user
        mc.lock();

        return new JDOConnectionImpl(mc.getConnection(), new Runnable()
        {
            public void run()
            {
                // Unlock the connection now that the user has finished with it
                mc.unlock();
                if (!enlisted)
                {
                    // Close the (unenlisted) connection (committing its statements)
                    try
                    {
                        ((Connection)mc.getConnection()).close();
                    }
                    catch (SQLException sqle)
                    {
                        throw new JPOXDataStoreException(sqle.getMessage());
                    }
View Full Code Here

        String clearStmt = getClearStmt();
        try
        {
            ObjectManager om = ownerSM.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, clearStmt, false);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = populateOwnerInStatement(ownerSM, om, ps, jdbcPosition);
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                    }

                    sqlControl.executeStatementUpdate(mconn, clearStmt, ps, true);
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException(LOCALISER.msg("056013", clearStmt), e);
View Full Code Here

TOP

Related Classes of org.jpox.ManagedConnection

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.