Package org.jpox.store.rdbms

Examples of org.jpox.store.rdbms.SQLController


        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();
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();
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();
View Full Code Here

        String sizeStmt = getSizeStmt();
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, sizeStmt);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                    if (elementInfo != null && elementInfo.length == 1)
                    {
                        // TODO Allow for multiple element types (e.g interface implementations)
                        for (int i=0; i<elementInfo.length; i++)
                        {
                            if (elementInfo[i].getDiscriminatorMapping() != null)
                            {
                                jdbcPosition = populateElementDiscriminatorInStatement(om, ps, jdbcPosition, true, elementInfo[i]);
                            }
                        }
                    }
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                    }

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, sizeStmt, ps);
                    try
                    {
                        if (!rs.next())
                        {
                            throw new JPOXDataStoreException(LOCALISER.msg("056007",sizeStmt));
                        }

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

            {
                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
                        {
                            if (qr == null)
                            {
                                rs.close();
                            }
                        }
                    }
                    finally
                    {
                        if (qr == null)
                        {
                            sqlControl.closeStatement(mconn, ps);
                        }
                    }
                }
                finally
                {
View Full Code Here

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

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

                    int[] rowsDeleted = sqlControl.executeStatementUpdate(mconn, stmt, ps, true);
                    if (rowsDeleted[0] == 0)
                    {
                        //?? throw exception??
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }

                // shift down
                if (index != currentListSize - 1)
                {
View Full Code Here

     */
    protected int[] internalShift(StateManager ownerSM, ManagedConnection conn, boolean batched, int oldIndex, int amount, boolean executeNow)
    throws SQLException
    {
        ObjectManager om = ownerSM.getObjectManager();
        SQLController sqlControl = storeMgr.getSQLController();
        String shiftStmt = getShiftStmt();
        PreparedStatement ps = sqlControl.getStatementForUpdate(conn, shiftStmt, false);
        try
        {
            int jdbcPosition = 1;
            jdbcPosition = populateOrderInStatement(om, ps, amount, jdbcPosition);
            jdbcPosition = populateOwnerInStatement(ownerSM, om, ps, jdbcPosition);
            jdbcPosition = populateOrderInStatement(om, ps, oldIndex, jdbcPosition);
            if (relationDiscriminatorMapping != null)
            {
                jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
            }

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

        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;
                    jdbcPosition = populateOwnerInStatement(sm, om, ps, jdbcPosition);
                    jdbcPosition = populateElementInStatement(om, ps, element, jdbcPosition);
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = populateRelationDiscriminatorInStatement(om, ps, jdbcPosition);
                    }

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, stmt, ps);
                    try
                    {
                        boolean found = rs.next();
                        if (!found)
                        {
                            SQLWarnings.log(rs);
                            return -1;
                        }
                        int index = rs.getInt(1);
                        SQLWarnings.log(rs);
                        return index;
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here

        int[] indices = new int[elements.size()];
        try
        {
            ObjectManager om = sm.getObjectManager();
            ManagedConnection mconn = storeMgr.getConnection(om);
            SQLController sqlControl = storeMgr.getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, stmt, false);
                try
                {
                    prepareIndicesOfStmt(sm,ps,elements);

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, stmt, ps);
                    try
                    {
                        int i=0;
                        while (rs.next())
                        {
                            indices[i++] = rs.getInt(1);
                        }

                        if (i < elements.size())
                        {
                            throw new JPOXDataStoreException(LOCALISER.msg("056023", stmt));
                        }
                        SQLWarnings.log(rs);
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
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.