Package org.jpox

Examples of org.jpox.ManagedConnection


        boolean exists = false;
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, containsValueStmt);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                    jdbcPosition = populateValueInStatement(om, ps, value, jdbcPosition);

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, containsValueStmt, ps);
                    try
                    {
                        if (rs.next())
                        {
                            exists = true;
                        }

                        SQLWarnings.log(rs);
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException(LOCALISER.msg("056019",containsValueStmt),e);
View Full Code Here


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

        Object value=null;
        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
                    {
                        boolean found = rs.next();
                        if (!found)
                        {
                            throw new NoSuchElementException();
                        }

                        if (valuesAreEmbedded || valuesAreSerialised)
                        {
                            int param[] = new int[valueMapping.getNumberOfDatastoreFields()];
                            for (int i = 0; i < param.length; ++i)
                            {
                                param[i] = i + 1;
                            }

                            if (valueMapping instanceof SerialisedPCMapping ||
                                valueMapping instanceof SerialisedReferenceMapping ||
                                valueMapping instanceof EmbeddedKeyPCMapping)
                            {
                                // Value = Serialised
                                int ownerFieldNumber = -1;
                                if (mapTable != null)
                                {
                                    ownerFieldNumber = ((JoinTable)mapTable).getOwnerFieldMetaData().getAbsoluteFieldNumber();
                                }
                                value = valueMapping.getObject(om, rs, param, sm, ownerFieldNumber);
                            }
                            else
                            {
                                // Value = Non-PC
                                value = valueMapping.getObject(om, rs, param);
                            }
                        }
                        else if (valueMapping instanceof ReferenceMapping)
                        {
                            // Value = Reference (Interface/Object)
                            int param[] = new int[valueMapping.getNumberOfDatastoreFields()];
                            for (int i = 0; i < param.length; ++i)
                            {
                                param[i] = i + 1;
                            }
                            value = valueMapping.getObject(om, rs, param);
                        }
                        else
                        {
                            // Value = PC
                            value = rof.getObject(om, rs);
                        }

                        SQLWarnings.log(rs);
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException(LOCALISER.msg("056014",statement),e);
View Full Code Here

            String stmt = getUpdateEmbeddedKeyStmt(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), key);
                        jdbcPosition += fieldMapping.getNumberOfDatastoreFields();
                        jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                        jdbcPosition = populateEmbeddedKeyFieldsInStatement(sm, key, ps, jdbcPosition, (JoinTable)mapTable);

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

            String stmt = getUpdateEmbeddedValueStmt(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), newValue);
                        jdbcPosition += fieldMapping.getNumberOfDatastoreFields();
                        jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                        jdbcPosition = populateEmbeddedValueFieldsInStatement(sm, value, ps, jdbcPosition, (JoinTable)mapTable);

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

    {
        int nextID;
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                String stmt = getMaxAdapterColumnIdStmt();
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);

                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                    ResultSet rs = sqlControl.executeStatementQuery(mconn, stmt, ps);
                    try
                    {
                        if (!rs.next())
                        {
                            nextID = 1;
                        }
                        else
                        {
                            nextID = rs.getInt(1)+1;
                        }

                        SQLWarnings.log(rs);
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
            }
        }
        catch (SQLException e)
        {
            throw new JPOXDataStoreException(LOCALISER.msg("056020",getMaxAdapterColumnIdStmt()),e);
View Full Code Here

        if (puts.size() > 0)
        {
            try
            {
                ObjectManager om = sm.getObjectManager();
                ManagedConnection mconn = storeMgr.getConnection(om);
                try
                {
                    // Loop through all entries
                    Iterator iter = puts.iterator();
                    while (iter.hasNext())
                    {
                        // Add the row to the join table
                        Map.Entry entry = (Map.Entry)iter.next();
                        internalPut(sm, mconn, batched, entry.getKey(), entry.getValue(), (!iter.hasNext()));
                    }
                }
                finally
                {
                    mconn.release();
                }
            }
            catch (SQLException e)
            {
                throw new JPOXDataStoreException(LOCALISER.msg("056016", putStmt), e);
            }
        }

        // Update any changed entries
        if (updates.size() > 0)
        {
            try
            {
                ObjectManager om = sm.getObjectManager();
                ManagedConnection mconn = storeMgr.getConnection(om);
                try
                {
                    // Loop through all entries
                    Iterator iter = updates.iterator();
                    while (iter.hasNext())
                    {
                        // Update the row in the join table
                        Map.Entry entry = (Map.Entry)iter.next();
                        internalUpdate(sm, mconn, batched, entry.getKey(), entry.getValue(), !iter.hasNext());
                    }
                }
                finally
                {
                    mconn.release();
                }
            }
            catch (SQLException e)
            {
                throw new JPOXDataStoreException(LOCALISER.msg("056016", updateStmt), e);
View Full Code Here

        {
            // Value changed so update the map
            try
            {
                ObjectManager om = sm.getObjectManager();
                ManagedConnection mconn = storeMgr.getConnection(om);
                try
                {
                    if (exists)
                    {
                        internalUpdate(sm, mconn, false, key, value, true);
                    }
                    else
                    {
                        internalPut(sm, mconn, false, key, value, true);
                    }
                }
                finally
                {
                    mconn.release();
                }
            }
            catch (SQLException e)
            {
                throw new JPOXDataStoreException(LOCALISER.msg("056016", exists ? updateStmt : putStmt),e);
View Full Code Here

        ObjectManager om = sm.getObjectManager();
        if (exists)
        {
            try
            {
                ManagedConnection mconn = storeMgr.getConnection(om);
                SQLController sqlControl = storeMgr.getSQLController();
                try
                {
                    PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, removeStmt, false);
                    try
                    {
                        int jdbcPosition = 1;
                        jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                        jdbcPosition = populateKeyInStatement(om, ps, key, jdbcPosition);
                        sqlControl.executeStatementUpdate(mconn, removeStmt, ps, true);
                    }
                    finally
                    {
                        sqlControl.closeStatement(mconn, ps);
                    }
                }
                finally
                {
                    mconn.release();
                }
            }
            catch (SQLException e)
            {
                throw new JPOXDataStoreException(LOCALISER.msg("056012",removeStmt),e);
View Full Code Here

        }

        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);
                    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

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

                try
                {
                    PreparedStatement ps = conn.prepareStatement(compiledSQL);
                    try
                    {
                        Iterator iter = parameterOccurrences.iterator();
                        int stmtParamNum = 1;

                        while (iter.hasNext())
                        {
                            String paramName = (String) iter.next();
                            Class paramType = (Class) parameterTypesByName.get(paramName);

                            if (!parameters.containsKey(paramName))
                            {
                                throw new JPOXUserException(LOCALISER_RDBMS.msg("060006",
                                    paramName));
                            }
                            if (paramType == null)
                            {
                                throw new JPOXUserException(LOCALISER_RDBMS.msg("060007",
                                    paramName));
                            }

                            JavaTypeMapping mapping = dba.getMapping(paramType, storeMgr,
                                om.getClassLoaderResolver());
                            Object paramValue = parameters.get(paramName);

                            mapping.setObject(om, ps, Mappings.getParametersIndex(stmtParamNum,mapping), paramValue);
                            if (mapping.getNumberOfDatastoreFields() == 0)
                            {
                                stmtParamNum++;
                            }
                            else
                            {
                                stmtParamNum += mapping.getNumberOfDatastoreFields();
                            }
                        }

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

                        // Execute the query
                        ResultSet rs = sqlControl.executeStatementQuery(mconn, compiledSQL, ps);
                        try
                        {
                            ResultObjectFactory rof = null;
                            if (candidateClass != null)
                            {
                                ResultSetMetaData rsmd = rs.getMetaData();
                                HashSet remainingColumnNames = new HashSet(fieldColumnNames);

                                int colCount = rsmd.getColumnCount();
                                for (int colNum = 1; colNum <= colCount; ++colNum)
                                {
                                    String colName = rsmd.getColumnName(colNum);
                                    int fieldNumber = fieldColumnNames.indexOf(colName);
                                    if (fieldNumber >= 0)
                                    {
                                        statementExpressionIndex[fieldNumber].setExpressionIndex(new int[]{colNum});
                                        remainingColumnNames.remove(colName);
                                    }
                                }
                               
                                if (!remainingColumnNames.isEmpty())
                                {
                                    throw new JPOXUserException(LOCALISER_RDBMS.msg("060005",
                                        remainingColumnNames));
                                }

                                if (resultClass != null)
                                {
                                    rof = new ResultClassROF(resultClass, statementExpressionIndex);
                                }
                                else
                                {
                                    rof = new TransientIDROF(candidateClass, fieldNumbers, statementExpressionIndex);
                                }
                            }
                            else
                            {
                                rof = getResultObjectFactoryForNoCandidateClass(rs, resultClass);
                            }

                            // Return the associated type of results depending on whether insensitive 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
                        {
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.