Search in sources :

Example 66 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class JPAQuery method processSQLQuery.

/**
 * INTERNAL:
 * Convert the SQL string into a DatabaseQuery.
 */
public DatabaseQuery processSQLQuery(Session session) {
    DatabaseQuery query = null;
    ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader();
    if (resultClassName != null) {
        Class<?> clazz = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(resultClassName);
        query = EJBQueryImpl.buildSQLDatabaseQuery(clazz, sqlString, hints, loader, (AbstractSession) session);
    } else if (resultSetMappingNames != null) {
        query = EJBQueryImpl.buildSQLDatabaseQuery(resultSetMappingNames.get(0), sqlString, hints, loader, (AbstractSession) session);
    } else {
        // Neither a resultClass or resultSetMapping is specified so place in a temp query on the session
        query = EJBQueryImpl.buildSQLDatabaseQuery(sqlString, hints, loader, (AbstractSession) session);
    }
    query.setName(this.getName());
    return query;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 67 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class JPAQuery method prepare.

/**
 * INTERNAL:
 * Generate the DatabaseQuery query from the JPA named query.
 */
@Override
public void prepare() {
    DatabaseQuery query = null;
    ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader();
    if (isSQLQuery()) {
        query = processSQLQuery(getSession());
    } else if (isJPQLQuery()) {
        query = processJPQLQuery(getSession());
    } else if (call != null) {
        query = processStoredProcedureQuery(getSession());
        if (call.hasParameters()) {
            // convert the type in the parameters;  query.convertClassNamesToClasses does not cascade to the call
            for (Object value : call.getParameters()) {
                if (value instanceof Object[]) {
                    // must be inout type, and the out portion is a DatabaseField
                    ((DatabaseField) ((Object[]) value)[1]).convertClassNamesToClasses(loader);
                    value = ((Object[]) value)[0];
                }
                if (value instanceof DatabaseField) {
                    ((DatabaseField) value).convertClassNamesToClasses(loader);
                }
            }
        }
    }
    // Make sure all class names have been converted.
    query.convertClassNamesToClasses(loader);
    setDatabaseQuery(query);
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField)

Example 68 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class StoredProcedureQueryImpl method buildResultSetMappingNameQuery.

/**
 * Build a ResultSetMappingQuery from a sql result set mapping name and a
 * stored procedure call.
 *
 * This is called from a named stored procedure that employs result set
 * mapping name(s) which should be available from the session.
 */
public static DatabaseQuery buildResultSetMappingNameQuery(List<String> resultSetMappingNames, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) {
    // apply any query hints
    DatabaseQuery hintQuery = applyHints(hints, buildResultSetMappingNameQuery(resultSetMappingNames, call), classLoader, session);
    // apply any query arguments
    applyArguments(call, hintQuery);
    return hintQuery;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery)

Example 69 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class StoredProcedureQueryImpl method buildStoredProcedureQuery.

/**
 * Build a ReadAllQuery from a class and stored procedure call.
 */
public static DatabaseQuery buildStoredProcedureQuery(Class<?> resultClass, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) {
    DatabaseQuery query = new ReadAllQuery(resultClass);
    query.setCall(call);
    query.setIsUserDefined(true);
    // apply any query hints
    query = applyHints(hints, query, classLoader, session);
    // apply any query arguments
    applyArguments(call, query);
    return query;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery)

Example 70 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class StoredProcedureQueryImpl method buildStoredProcedureQuery.

/**
 * Build a ResultSetMappingQuery from a sql result set mapping name and a
 * stored procedure call.
 */
public static DatabaseQuery buildStoredProcedureQuery(String sqlResultSetMappingName, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) {
    ResultSetMappingQuery query = new ResultSetMappingQuery();
    query.setSQLResultSetMappingName(sqlResultSetMappingName);
    query.setCall(call);
    query.setIsUserDefined(true);
    // apply any query hints
    DatabaseQuery hintQuery = applyHints(hints, query, classLoader, session);
    // apply any query arguments
    applyArguments(call, hintQuery);
    return hintQuery;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) ResultSetMappingQuery(org.eclipse.persistence.queries.ResultSetMappingQuery)

Aggregations

DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)86 ArrayList (java.util.ArrayList)18 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)15 List (java.util.List)14 Vector (java.util.Vector)12 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)12 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)12 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)8 EntityManager (jakarta.persistence.EntityManager)6 HashMap (java.util.HashMap)6 QName (javax.xml.namespace.QName)6 EJBQueryImpl (org.eclipse.persistence.internal.jpa.EJBQueryImpl)6 PersistenceContext (org.eclipse.persistence.jpa.rs.PersistenceContext)6 DataReadQuery (org.eclipse.persistence.queries.DataReadQuery)6 Session (org.eclipse.persistence.sessions.Session)6 Test (org.junit.Test)6 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)5 ReadQuery (org.eclipse.persistence.queries.ReadQuery)5 ReportQuery (org.eclipse.persistence.queries.ReportQuery)5 PersistenceException (jakarta.persistence.PersistenceException)4