Package org.eclipse.persistence.queries

Examples of org.eclipse.persistence.queries.DatabaseQuery


        if (statement == null) {
            decrementCallCount();
            return;
        }

        DatabaseQuery query = ((call == null)? null : call.getQuery());
        try {
            session.startOperationProfile(SessionProfiler.STATEMENT_EXECUTE, query, SessionProfiler.ALL);
            statement.close();
        } finally {
            session.endOperationProfile(SessionProfiler.STATEMENT_EXECUTE, query, SessionProfiler.ALL);
View Full Code Here


        XMLCompositeCollectionMapping argumentsMapping = new XMLCompositeCollectionMapping();

        // Handle translation of argument lists to query-arguments.
        argumentsMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                DatabaseQuery query = (DatabaseQuery)object;
                Vector arguments = query.getArguments();
                Vector types = query.getArgumentTypeNames();
                Vector values = query.getArgumentValues();
                Vector queryArguments = new Vector(arguments.size());
                for (int index = 0; index < arguments.size(); index++) {
                    QueryArgument queryArgument = new QueryArgument();
                    queryArgument.setKey(arguments.get(index));
                    if (!types.isEmpty()) {
                        queryArgument.setTypeName((String)types.get(index));
                    }
                    if (!values.isEmpty()) {
                        queryArgument.setValue(values.get(index));
                    }
                    queryArguments.add(queryArgument);
                }
                return queryArguments;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                DatabaseQuery query = (DatabaseQuery)object;
                Vector queryArguments = (Vector)value;
                Vector arguments = NonSynchronizedVector.newInstance(queryArguments.size());
                Vector types = NonSynchronizedVector.newInstance(queryArguments.size());
                Vector values = NonSynchronizedVector.newInstance(queryArguments.size());
                for (int index = 0; index < queryArguments.size(); index++) {
                    QueryArgument queryArgument = (QueryArgument)queryArguments.get(index);
                    arguments.add(queryArgument.getKey());
                    if (queryArgument.getValue() != null) {
                        values.add(queryArgument.getValue());
                    }
                    if (queryArgument.getType() != null) {
                        types.add(queryArgument.getType());
                    }
                }
                query.setArguments(arguments);
                if (!types.isEmpty()) {
                    query.setArgumentTypes(types);
                }
                if (!values.isEmpty()) {
                    query.setArgumentValues(values);
                }
            }
        });
        argumentsMapping.setAttributeName("argumentsMapping");
        argumentsMapping.setXPath(getSecondaryNamespaceXPath() + "arguments/" + getSecondaryNamespaceXPath() + "argument");
View Full Code Here

   * @return the string of the JPQL query translated in SQL
   */
  private String rewriteEclipseLink(Query query) {
    EJBQueryImpl qi = (EJBQueryImpl) query;
    Session session = this.entityManager.unwrap(JpaEntityManager.class).getActiveSession();
    DatabaseQuery databaseQuery = (qi).getDatabaseQuery();
    databaseQuery.prepareCall(session, new DatabaseRecord());
    String sqlString = databaseQuery.getTranslatedSQLString(session,  new DatabaseRecord());
   
    //ADD THE ALIAS in the select statement (necessary for the temporary table construction.. ex for the worksheet)
    int fromPosition = sqlString.indexOf("FROM");
    StringBuffer sqlQuery2 = new StringBuffer();
    String SelectStatement = sqlString.substring(0,fromPosition-1);
View Full Code Here

                    }
                    else {
                        catalogPrefix = cat + ".";
                    }
                    call.setProcedureName(catalogPrefix + storedProcedure.getName());
                    DatabaseQuery dq = null;
                    DbStoredProcedureNameAndModel nameAndModel =
                        dbStoredProcedure2QueryName.get(storedProcedure);
                    String returnType = nameAndModel.procOpModel.getReturnType();
                    boolean hasResponse = returnType != null;
                    String typ = null;
                    ClassDescriptor xdesc = null;
                    if (hasResponse) {
                        int idx = 0;
                        int colonIdx = returnType.indexOf(":");
                        if (colonIdx == -1) {
                            idx = returnType.indexOf("}");
                        }
                        else {
                            idx = colonIdx;
                        }
                        if (idx > 0) {
                            typ = returnType.substring(idx+1);
                            for (XMLDescriptor xd : (List<XMLDescriptor>)(List)oxProject.getOrderedDescriptors()) {
                                if (xd.getSchemaReference() != null) {
                                    String context = xd.getSchemaReference().getSchemaContext();
                                    if (context.substring(1).equals(typ)) {
                                        xdesc = xd;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (hasResponse) {
                        if (nameAndModel.procOpModel.isCollection) {
                            dq = new DataReadQuery();
                        }
                        else {
                            dq = new ValueReadQuery();
                        }
                    }
                    else {
                        dq = new ValueReadQuery();
                    }
                    dq.bindAllParameters();
                    dq.setName(nameAndModel.name);
                    dq.setCall(call);

                    DatabaseType[] typesForMethod = procOpModel.getArgumentTypes().get(i);
                    for (int j=0, len=typesForMethod.length; j<len; j++) {
                        DbStoredArgument arg = storedProcedure.getArguments().get(j);
                        DatabaseType databaseType = typesForMethod[j];
                        InOut direction = arg.getInOut();
                        if (direction == OUT) {
                            call.addNamedOutputArgument(arg.getName(), databaseType);
                        }
                        else if (direction == IN) {
                            call.addNamedArgument(arg.getName(), databaseType);
                        }
                        else {
                            call.addNamedInOutputArgument(arg.getName(), databaseType);
                        }
                        if (direction == IN | direction == INOUT) {
                            if (xdesc != null) {
                                dq.addArgumentByTypeName(arg.getName(), xdesc.getJavaClassName());
                            }
                            else {
                                if (databaseType instanceof PLSQLCollection) {
                                    dq.addArgument(arg.getName(), Array.class);
                                }
                                else if (databaseType instanceof PLSQLrecord) {
                                    dq.addArgument(arg.getName(), Struct.class);
                                }
                                else {
                                    dq.addArgument(arg.getName(),
                                        JDBCTypes.getClassForCode(databaseType.getConversionCode()));
                                }
                            }
                        }
                    }
View Full Code Here

    public javax.persistence.Query createDescriptorNamedQuery(String queryName, Class descriptorClass, Vector argumentTypes){
        try {
            verifyOpen();
            ClassDescriptor descriptor = getServerSession().getDescriptor(descriptorClass);
            if (descriptor != null){
                DatabaseQuery query = descriptor.getQueryManager().getLocalQueryByArgumentTypes(queryName, argumentTypes);
                if (query != null){
                    return new EJBQueryImpl(query, this);
                }
            }
            return null;
View Full Code Here

     * return type.
     */
    public Query createNativeQuery(String sqlString, Class resultType){
        try {
            verifyOpen();
            DatabaseQuery query = createNativeQueryInternal(sqlString, resultType);
            return new EJBQueryImpl(query, this);
        } catch (RuntimeException e) {
            setRollbackOnly();
            throw e;
        }
View Full Code Here

     * This method is used to create a query using a EclipseLink Expression and the return type.
     */
    public javax.persistence.Query createQuery(Expression expression, Class resultType){
        try {
            verifyOpen();
            DatabaseQuery query = createQueryInternal(expression, resultType);
            return new EJBQueryImpl(query, this);
        } catch (RuntimeException e) {
            setRollbackOnly();
            throw e;
        }
View Full Code Here

                    }
                }
            List queries = session.getJPAQueries();
            for (Iterator iterator = queries.iterator(); iterator.hasNext();) {
                JPAQuery existingQuery = (JPAQuery)iterator.next();
                DatabaseQuery databaseQuery = existingQuery.processJPQLQuery(session);
                session.addQuery(databaseQuery.getName(), databaseQuery);
            }
            queries.clear();
            }
            return session;
        } catch (IllegalArgumentException illegalArgumentException) {
View Full Code Here

    }
   
   
    public DatabaseQuery processJPQLQuery(Session session){
        ClassLoader classloader = session.getDatasourcePlatform().getConversionManager().getLoader();
        DatabaseQuery ejbquery = EJBQueryImpl.buildEJBQLDatabaseQuery(
            this.getName(), jpqlString,  flushOnExecute, session, hints, classloader);
        ejbquery.setName(this.getName());
        return ejbquery;
    }
View Full Code Here

     * @exception  DatabaseException - an error has occurred on the database.
     * @exception  OptimisticLockException - an error has occurred using the optimistic lock feature.
     * @return - the result of executing the query.
     */
    public Object executeDatabaseQuery() throws DatabaseException, OptimisticLockException{
        DatabaseQuery ejbquery = processJPQLQuery(this.getSession());
        return ejbquery.executeDatabaseQuery();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.queries.DatabaseQuery

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.