Package org.eclipse.persistence.sessions

Examples of org.eclipse.persistence.sessions.UnitOfWork


        // a named query created via ORM metadata processing needs initialization
        if (query instanceof JPAQuery) {
            query = ((JPAQuery) query).processSQLQuery(xrService.getORSession().getActiveSession());
        }

        UnitOfWork uow = xrService.getORSession().acquireUnitOfWork();
        Object toBeDeleted;

        // a query created via ORM metadata processing does not have parameters set, however, the operation should
        if (query.getArguments().size() == 0) {
            int idx = 0;
            for (Parameter  param : getParameters()) {
                // for custom SQL query (as configured via ORM metadata processing) we add args by position
                query.addArgument(Integer.toString(++idx), Util.SCHEMA_2_CLASS.get(param.getType()));
                query.addArgumentValue(invocation.getParameter(param.getName()));
            }
            toBeDeleted = uow.executeQuery(query);
        } else {
            // set query args or execute args for the non-JPAQuery case,
            // i.e. stored proc/funcs get populated from ORM metadata
            // whereas named queries (SQL strings) do not...
            List queryArguments = query.getArguments();
            int queryArgumentsSize = queryArguments.size();
            Vector executeArguments = new NonSynchronizedVector();
            for (int i = 0; i < queryArgumentsSize; i++) {
                String argName = (String)queryArguments.get(i);
                executeArguments.add(invocation.getParameter(argName));
            }
            toBeDeleted = uow.executeQuery(query, executeArguments);
        }

        // JPAQuery will return a single result in a Vector
        if (!isCollection() && toBeDeleted instanceof Vector) {
            if (((Vector) toBeDeleted).isEmpty()) {
                toBeDeleted = null;
            } else {
                toBeDeleted = ((Vector)toBeDeleted).firstElement();
            }
        }
        if (toBeDeleted != null) {
            uow.deleteObject(toBeDeleted);
            uow.commit();
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.sessions.UnitOfWork

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.