Examples of SQLController


Examples of org.datanucleus.store.rdbms.SQLController

    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

Examples of org.datanucleus.store.rdbms.SQLController

            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 (initialValue >= 0)
                    {
                        // Just start at "initialValue" since value provided
                        addSequence(sequenceName, Long.valueOf(incrementBy + initialValue), conn);
                        nextVal = Long.valueOf(initialValue);
                    }
                    else
                    {
                        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, Long.valueOf(incrementBy + 1 + val), conn);
                                    nextVal = Long.valueOf(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, Long.valueOf(incrementBy + 0), conn);
                            nextVal = Long.valueOf(initialValue);
                        }
                    }
                }
                else
                {
                    // Data already exists in sequence table for this key so increment it
                    nextVal = Long.valueOf(rs.getLong(1));
                    incrementSequence(sequenceName, incrementBy, conn);
                }
            }
            finally
            {
                rs.close();
            }
        }
        catch (SQLException e)
        {
           throw new ValueGenerationException(LOCALISER.msg("061001", e.getMessage()),e);
        }
        finally
        {
            if (ps != null)
            {
                sqlControl.closeStatement(conn, ps);
            }
        }

        return nextVal;
    }
View Full Code Here

Examples of org.datanucleus.store.rdbms.SQLController

     **/
    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

Examples of org.datanucleus.store.rdbms.SQLController

     **/
    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

Examples of org.datanucleus.store.rdbms.SQLController

        String removeAllStmt = getRemoveAllStmt(sm, elements);
        try
        {
            ExecutionContext ec = sm.getExecutionContext();
            ManagedConnection mconn = getStoreMgr().getConnection(ec);
            SQLController sqlControl = getStoreMgr().getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, removeAllStmt, false);
                try
                {
                    int jdbcPosition = 1;
                    Iterator iter = elements.iterator();
                    while (iter.hasNext())
                    {
                        Object element = iter.next();
                        jdbcPosition = BackingStoreHelper.populateOwnerInStatement(sm, ec, ps, jdbcPosition, this);
                        jdbcPosition = BackingStoreHelper.populateElementInStatement(ec, ps, element, jdbcPosition, elementMapping);
                        if (relationDiscriminatorMapping != null)
                        {
                            jdbcPosition = BackingStoreHelper.populateRelationDiscriminatorInStatement(ec, ps, jdbcPosition, this);
                        }
                    }

                    int[] number = sqlControl.executeStatementUpdate(mconn, removeAllStmt, ps, true);
                    if (number[0] > 0)
                    {
                        modified = true;
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here

Examples of org.datanucleus.store.rdbms.SQLController

        String stmt = getLocateStmt();
        try
        {
            ExecutionContext ec = sm.getExecutionContext();
            ManagedConnection mconn = getStoreMgr().getConnection(ec);
            SQLController sqlControl = getStoreMgr().getSQLController();
            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition =
                        BackingStoreHelper.populateOwnerInStatement(sm, ec, ps, jdbcPosition, this);
                    jdbcPosition =
                        BackingStoreHelper.populateElementInStatement(ec, ps, element, jdbcPosition, elementMapping);
                    if (relationDiscriminatorMapping != null)
                    {
                        jdbcPosition = BackingStoreHelper.populateRelationDiscriminatorInStatement(ec, ps, jdbcPosition, this);
                    }

                    ResultSet rs = sqlControl.executeStatementQuery(mconn, stmt, ps);
                    try
                    {
                        if (!rs.next())
                        {
                            exists = false;
                        }
                    }
                    catch (SQLException sqle)
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here

Examples of org.datanucleus.store.rdbms.SQLController

        }

        String addStmt = getSpecialization().getAddStmt(this);
        boolean notYetFlushedError = false;
        ExecutionContext ec = sm.getExecutionContext();
        SQLController sqlControl = getStoreMgr().getSQLController();
        try
        {
            PreparedStatement ps = sqlControl.getStatementForUpdate(conn, addStmt, batched);
            try
            {
                // Insert the join table row
                int jdbcPosition = 1;
                jdbcPosition = BackingStoreHelper.populateOwnerInStatement(sm, ec, ps, jdbcPosition, this);
                jdbcPosition = BackingStoreHelper.populateElementInStatement(ec, ps, element, jdbcPosition, elementMapping);
                if (orderMapping != null)
                {
                    jdbcPosition = BackingStoreHelper.populateOrderInStatement(ec, ps, orderId, jdbcPosition, orderMapping);
                }
                if (relationDiscriminatorMapping != null)
                {
                    jdbcPosition = BackingStoreHelper.populateRelationDiscriminatorInStatement(ec, ps, jdbcPosition, this);
                }

                // 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);
                }
            }
        }
        catch (SQLException e)
        {
View Full Code Here

Examples of org.datanucleus.store.rdbms.SQLController

        return locateStmt;
    }

    protected void preGetNextIDForOrderColumn(ManagedConnection mconn) throws MappedDatastoreException
    {
        SQLController sqlControl = getStoreMgr().getSQLController();
        try
        {
            // Process all waiting batched statements before we start our work
            sqlControl.processStatementsForConnection(mconn);
        }
        catch (SQLException e)
        {
            throw new MappedDatastoreException("SQLException", e);
        }
View Full Code Here

Examples of org.datanucleus.store.rdbms.SQLController

        ExecutionContext ec = sm.getExecutionContext();
        String stmt = getMaxOrderColumnIdStmt();
        try
        {
            ManagedConnection mconn = getStoreMgr().getConnection(ec);
            SQLController sqlControl = getStoreMgr().getSQLController();

            try
            {
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);
                try
                {
                    int jdbcPosition = 1;
                    jdbcPosition = BackingStoreHelper.populateOwnerInStatement(sm, ec, ps, jdbcPosition, this);
                    if (relationDiscriminatorMapping != null)
                    {
                        BackingStoreHelper.populateRelationDiscriminatorInStatement(ec, ps, jdbcPosition, this);
                    }

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

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

Examples of org.datanucleus.store.rdbms.SQLController

        Transaction tx = ec.getTransaction();
        String stmt = (tx.lockReadObjects() ? iteratorStmtLocked : iteratorStmtUnlocked);
        try
        {
            ManagedConnection mconn = storeMgr.getConnection(ec);
            SQLController sqlControl = ((RDBMSStoreManager)storeMgr).getSQLController();
            try
            {
                // Create the statement and set the owner
                PreparedStatement ps = sqlControl.getStatementForQuery(mconn, stmt);
                StatementMappingIndex ownerIdx = iteratorMappingParams.getMappingForParameter("owner");
                int numParams = ownerIdx.getNumberOfParameterOccurrences();
                for (int paramInstance=0;paramInstance<numParams;paramInstance++)
                {
                    ownerIdx.getMapping().setObject(ec, ps,
                        ownerIdx.getParameterPositionsForOccurrence(paramInstance), ownerSM.getObject());
                }

                try
                {
                    ResultSet rs = sqlControl.executeStatementQuery(mconn, stmt, ps);
                    try
                    {
                        if (elementsAreEmbedded || elementsAreSerialised)
                        {
                            // No ResultObjectFactory needed - handled by SetStoreIterator
                            return new RDBMSSetStoreIterator(ownerSM, rs, null, this);
                        }
                        else if (elementMapping instanceof ReferenceMapping)
                        {
                            // No ResultObjectFactory needed - handled by SetStoreIterator
                            return new RDBMSSetStoreIterator(ownerSM, rs, null, this);
                        }
                        else
                        {
                            ResultObjectFactory rof = storeMgr.newResultObjectFactory(emd,
                                iteratorMappingClass, false, null, clr.classForName(elementType));
                            return new RDBMSSetStoreIterator(ownerSM, rs, rof, this);
                        }
                    }
                    finally
                    {
                        rs.close();
                    }
                }
                finally
                {
                    sqlControl.closeStatement(mconn, ps);
                }
            }
            finally
            {
                mconn.release();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.