Package org.jpox.store.query

Examples of org.jpox.store.query.QueryResult


     * Returns an iterator over all the instances in the Extent.
     * @return an iterator over all the instances in the Extent.
     */
    public Iterator iterator()
    {
        QueryResult qr = (QueryResult)query.execute();
        Iterator iter = qr.iterator();

        queryResultsByIterator.put(iter, qr);

        return iter;
    }
View Full Code Here


     * @param iter an iterator obtained by the method iterator() on this Extent
     * instance.
     */
    public void close(Iterator iter)
    {
        QueryResult qr = (QueryResult) queryResultsByIterator.remove(iter);

        qr.close();
    }
View Full Code Here

    public void closeAll()
    {
        Iterator iter = queryResultsByIterator.values().iterator();
        while (iter.hasNext())
        {
            QueryResult qr = (QueryResult) iter.next();

            qr.close();
            iter.remove();
        }
    }
View Full Code Here

        {
            JPOXLogger.QUERY.debug(LOCALISER.msg("021046", "JPQL", getSingleStringQuery()));
        }
        Evaluator eval = getEvaluator(this, distinct, rof, candidateCollection);
        // TODO Cater for BULK_UPDATE, BULK_DELETE where return is Long
        QueryResult qr = (QueryResult)eval.evaluate(queryStmt);

        queryResults.add(qr);

        return qr;
    }
View Full Code Here

        if (useUpdateLockExt != null)
        {
            useUpdateLock = Boolean.valueOf((String)useUpdateLockExt).booleanValue();
        }

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

            try
            {
                StatementText stmtText = null;
                if (query.getType() == Query.SELECT)
                {
                    stmtText = queryStmt.toStatementText(useUpdateLock);
                }
                else if (query.getType() == Query.BULK_UPDATE)
                {
                    stmtText = queryStmt.toUpdateStatementText();
                    throw new JPOXException("JPOX doesnt currently support bulk update statements");
                }
                else if (query.getType() == Query.BULK_DELETE)
                {
                    // TODO Distinguish between update and delete
                    stmtText = queryStmt.toDeleteStatementText();
                    throw new JPOXException("JPOX doesnt currently support bulk delete statements");
                }

                PreparedStatement ps = getStatement(mconn, stmtText);
                try
                {
                    // Apply timeouts, result set constraints etc
                    prepareStatementForExecution(ps);

                    // Add a limit on the number of rows to include the maximum we may need
                    long toExclNo = query.getRangeToExcl();
                    if (toExclNo != 0 && toExclNo != Long.MAX_VALUE)
                    {
                        if (toExclNo > Integer.MAX_VALUE)
                        {
                            // setMaxRows takes an int as input so limit to the correct range
                            ps.setMaxRows(Integer.MAX_VALUE);
                        }
                        else
                        {
                            ps.setMaxRows((int)toExclNo);
                        }
                    }

                    if (query.getType() != Query.SELECT)
                    {
                        JPOXLogger.JDO.debug(">> SQLEvaluator.evaluate BULK operation SELECT");
                    }
                    if (query.getType() == Query.SELECT)
                    {
                        // SELECT query
                        ResultSet rs = sqlControl.executeStatementQuery(mconn, stmtText.toString(), ps);
                        try
                        {
                            // Check the type of result set needed
                            if (getResultSetType().equals("scroll-insensitive") ||
                                getResultSetType().equals("scroll-sensitive"))
                            {
                                qr = new ScrollableQueryResult(queryStmt, query, rof, rs,
                                    distinct ? null : candidateCollection);
                            }
                            else
                            {
                                qr = new ForwardQueryResult(queryStmt, query, rof, rs,
                                    distinct ? null : candidateCollection);
                            }

                            final QueryResult qr1 = qr;
                            final ManagedConnection mconn1 = mconn;
                            ManagedConnectionResourceListener listener = new ManagedConnectionResourceListener()
                            {
                                public void managedConnectionPreClose(){}
                                public void managedConnectionPostClose(){}
                                public void managedConnectionFlushed()
                                {
                                    // Disconnect the query from this ManagedConnection (read in unread rows etc)
                                    qr1.disconnect();
                                }
                                public void resourcePostClose()
                                {
                                    mconn1.removeListener(this);
                                }
View Full Code Here

        if (JPOXLogger.QUERY.isDebugEnabled())
        {
            JPOXLogger.QUERY.debug(LOCALISER.msg("021046", "JDOQL", getSingleStringQuery()));
        }
        Evaluator eval = getEvaluator(om, distinct, this, rof, candidateCollection);
        QueryResult qr = (QueryResult)eval.evaluate(queryStmt);
        queryResults.add(qr);

        return qr;
    }
View Full Code Here

            throw new JPOXUserException(LOCALISER_RDBMS.msg("060002",
                "" + parameterNames.length, "" + parameters.size()));
        }

        Evaluator eval = new JPOXSQLQueryEvaluator(this, parameters);
        QueryResult qr = (QueryResult)eval.evaluate(null);
        queryResults.add(qr);

        return qr;
    }
View Full Code Here

            this.parameters = parameters;
        }
       
        public Object evaluate(QueryExpression queryStmt)
        {
            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()
                                {
View Full Code Here

            this.parameters = parameters;
        }

        public Object evaluate(QueryExpression queryStmt)
        {
            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()
View Full Code Here

        }
        else
        {
            // Query statement (SELECT, stored-procedure)
            Evaluator eval = new SQLQueryEvaluator(this, parameters);
            QueryResult qr = (QueryResult)eval.evaluate(null);

            queryResults.add(qr);

            return qr;
        }
View Full Code Here

TOP

Related Classes of org.jpox.store.query.QueryResult

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.