Package org.datanucleus.management.runtime

Examples of org.datanucleus.management.runtime.QueryRuntime


        if (nucleusContext.getJMXManager() != null)
        {
            // register MBean in MbeanServer
            ManagementManager mgmtMgr = nucleusContext.getJMXManager();
            ManagementServer mgntServer = nucleusContext.getJMXManager().getManagementServer();
            queryRuntime = new QueryRuntime();
            String mbeanName = mgmtMgr.getDomainName() + ":InstanceName=" + mgmtMgr.getInstanceName() +
                ",Type=" + ClassUtils.getClassNameForClass(queryRuntime.getClass())+
                ",Name=QueryRuntime";
            mgntServer.registerMBean(this.queryRuntime, mbeanName);
        }
View Full Code Here


            // Make sure the datastore is prepared (new objects flushed as required)
            prepareDatastore();

            boolean failed = true; // flag to use for checking the state of the execution results
            long start = 0;
            QueryRuntime queryRuntime = getQueryManager().getQueryRuntime();
            if (queryRuntime != null)
            {
                start = System.currentTimeMillis();
                queryRuntime.queryBegin();
            }

            try
            {
                // Execute the query
                Object result = performExecute(inputParameters);

                // Process the results
                if (type == BULK_DELETE || type == BULK_UPDATE)
                {
                    // Bulk update/delete return a Long
                    return result;
                }
                else
                {
                    // Select, so return the range of objects
                    Collection qr = (Collection)result;

                    failed = false;
                    if (shouldReturnSingleRow())
                    {
                        // Single row only needed (unique specified, or using aggregates etc), so just take first row
                        try
                        {
                            if (qr == null || qr.size() == 0)
                            {
                                throw new NoQueryResultsException("No query results were returned");
                            }
                            else
                            {
                                if (applyRangeChecks() && (toExclNo - fromInclNo <= 0))
                                {
                                    // JDO2 spec 14.6.8 (range excludes instances, so return null)
                                    throw new NoQueryResultsException("No query results were returned in the required range");
                                }

                                Iterator qrIter = qr.iterator();
                                Object firstRow = qrIter.next();
                                if (qrIter.hasNext())
                                {
                                    failed = true;
                                    throw new QueryNotUniqueException();
                                }
                                return firstRow;
                            }
                        }
                        finally
                        {
                            // can close results right now because we don't return it,
                            // also user cannot close it otherwise except for calling closeAll()
                            if (qr != null)
                            {
                                close(qr);
                            }
                        }
                    }
                    else
                    {
                        if (qr instanceof QueryResult && queryResults != null)
                        {
                            // Result handler, so register the results so we can close later
                            queryResults.add((QueryResult)qr);
                        }

                        return qr;
                    }
                }
            }
            finally
            {
                if (queryRuntime != null)
                {
                    if (failed)
                    {
                        queryRuntime.queryExecutedWithError();
                    }
                    else
                    {
                        queryRuntime.queryExecuted(System.currentTimeMillis()-start);
                    }
                }
            }
        }
        finally
View Full Code Here

        // Make sure the datastore is prepared (new objects flushed as required)
        prepareDatastore();

        boolean failed = true; // flag to use for checking the state of the execution results
        long start = 0;
        QueryRuntime queryRuntime = om.getOMFContext().getQueryManager().getQueryRuntime();
        if (queryRuntime != null)
        {
            start = System.currentTimeMillis();
            queryRuntime.queryBegin();
        }

        try
        {
            // Execute the query
            Object result = performExecute(inputParameters);

            // Process the results
            if (type == BULK_DELETE || type == BULK_UPDATE)
            {
                // Bulk update/delete return a Long
                return result;
            }
            else
            {
                // Select, so return the range of objects
                Collection qr = (Collection)result;

                failed = false;
                if (shouldReturnSingleRow())
                {
                    // Single row only needed (unique specified, or using aggregates etc), so just take first row
                    try
                    {
                        if (qr == null || qr.size() == 0)
                        {
                            throw new NoQueryResultsException("No query results were returned");
                        }
                        else
                        {
                            if (applyRangeChecks() && (toExclNo - fromInclNo <= 0))
                            {
                                // JDO2 spec 14.6.8 (range excludes instances, so return null)
                                throw new NoQueryResultsException("No query results were returned in the required range");
                            }

                            Iterator qrIter = qr.iterator();
                            Object firstRow = qrIter.next();
                            if (qrIter.hasNext())
                            {
                                failed = true;
                                throw new QueryNotUniqueException();
                            }
                            return firstRow;
                        }
                    }
                    finally
                    {
                        // can close results right now because we don't return it,
                        // also user cannot close it otherwise except for calling closeAll()
                        if (qr != null)
                        {
                            close(qr);
                        }
                    }
                }
                else
                {
                    if (qr instanceof QueryResult)
                    {
                        // Result handler, so register the results so we can close later
                        queryResults.add((QueryResult)qr);
                    }

                    // Process any specified range
                    if (applyRangeChecks())
                    {
                        // Range not applied in the compiled query so throw away objects outside the required range
                        int i = 0;
                        Iterator qr_iter = qr.iterator();
                        Collection res = new ArrayList();
                        while (qr_iter.hasNext())
                        {
                            Object obj=qr_iter.next();
                            if (i >= fromInclNo && i < toExclNo)
                            {
                                // Accept the item if within range
                                res.add(obj);
                            }
                            i++;
                        }
                        return res;
                    }
                    else
                    {
                        // Range applied in the compiled query (or no range) so just return it
                        return qr;
                    }
                }
            }
        }
        finally
        {
            if (queryRuntime != null)
            {
                if (failed)
                {
                    queryRuntime.queryExecutedWithError();
                }
                else
                {
                    queryRuntime.queryExecuted(System.currentTimeMillis()-start);
                }
            }
        }
    }
View Full Code Here

        if (omfContext.getJMXManager() != null)
        {
            // register MBean in MbeanServer
            ManagementManager mgmtMgr = omfContext.getJMXManager();
            ManagementServer mgntServer = omfContext.getJMXManager().getManagementServer();
            queryRuntime = new QueryRuntime();
            String mbeanName = mgmtMgr.getDomainName() + ":InstanceName=" + mgmtMgr.getInstanceName() +
                ",Type=" + ClassUtils.getClassNameForClass(queryRuntime.getClass())+
                ",Name=QueryRuntime";
            mgntServer.registerMBean(this.queryRuntime, mbeanName);
        }
View Full Code Here

TOP

Related Classes of org.datanucleus.management.runtime.QueryRuntime

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.