Search in sources :

Example 1 with JPAQuery

use of org.eclipse.persistence.internal.jpa.JPAQuery in project eclipselink by eclipse-ee4j.

the class NamedPLSQLStoredProcedureQueryMetadata method process.

/**
 * INTERNAL:
 */
@Override
public void process(AbstractSession session) {
    // Build the stored procedure call.
    PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
    // Process the stored procedure parameters.
    for (PLSQLParameterMetadata parameter : m_parameters) {
        parameter.process(call, false);
    }
    // Process the procedure name.
    call.setProcedureName(m_procedureName);
    // Create a JPA query to store internally on the session.
    JPAQuery query = new JPAQuery(getName(), call, processQueryHints(session));
    // Process the result class.
    if (!getResultClass().isVoid()) {
        query.setResultClassName(getJavaClassName(getResultClass()));
    } else if (hasResultSetMapping(session)) {
        query.addResultSetMapping(getResultSetMapping());
    }
    addJPAQuery(query, session);
}
Also used : PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) JPAQuery(org.eclipse.persistence.internal.jpa.JPAQuery)

Example 2 with JPAQuery

use of org.eclipse.persistence.internal.jpa.JPAQuery in project eclipselink by eclipse-ee4j.

the class NamedStoredFunctionQueryMetadata method process.

/**
 * INTERNAL:
 */
@Override
public void process(AbstractSession session) {
    // Build the stored procedure call.
    StoredFunctionCall call = new StoredFunctionCall();
    // Process the stored procedure parameters.
    boolean callByIndex = callByIndex();
    for (StoredProcedureParameterMetadata parameter : getParameters()) {
        parameter.processArgument(call, callByIndex, -1);
    }
    if (getReturnParameter() != null) {
        getReturnParameter().processResult(call, -1);
    }
    // Process the procedure name.
    call.setProcedureName(getProcedureName());
    // Create a JPA query to store internally on the session.
    JPAQuery query = new JPAQuery(getName(), call, processQueryHints(session));
    // Process the result class.
    if (!getResultClass().isVoid()) {
        query.setResultClassName(getJavaClassName(getResultClass()));
    } else if (hasResultSetMapping(session)) {
        query.addResultSetMapping(getResultSetMapping());
    }
    addJPAQuery(query, session);
}
Also used : StoredFunctionCall(org.eclipse.persistence.queries.StoredFunctionCall) JPAQuery(org.eclipse.persistence.internal.jpa.JPAQuery)

Example 3 with JPAQuery

use of org.eclipse.persistence.internal.jpa.JPAQuery in project eclipselink by eclipse-ee4j.

the class NamedPLSQLStoredFunctionQueryMetadata method process.

/**
 * INTERNAL:
 */
@Override
public void process(AbstractSession session) {
    // Build the stored procedure call.
    PLSQLStoredFunctionCall call = new PLSQLStoredFunctionCall();
    // the rest of the args to ensure that it is set on the call first
    if (getReturnParameter() != null) {
        getReturnParameter().process(call, true);
    }
    // Process the stored procedure parameters.
    for (PLSQLParameterMetadata parameter : getParameters()) {
        parameter.process(call, false);
    }
    // Process the procedure name.
    call.setProcedureName(getProcedureName());
    // Create a JPA query to store internally on the session.
    JPAQuery query = new JPAQuery(getName(), call, processQueryHints(session));
    // Process the result class.
    if (!getResultClass().isVoid()) {
        query.setResultClassName(getJavaClassName(getResultClass()));
    } else if (hasResultSetMapping(session)) {
        query.addResultSetMapping(getResultSetMapping());
    }
    addJPAQuery(query, session);
}
Also used : PLSQLStoredFunctionCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredFunctionCall) JPAQuery(org.eclipse.persistence.internal.jpa.JPAQuery)

Example 4 with JPAQuery

use of org.eclipse.persistence.internal.jpa.JPAQuery in project eclipselink by eclipse-ee4j.

the class NamedStoredProcedureQueryMetadata method process.

/**
 * INTERNAL:
 */
@Override
public void process(AbstractSession session) {
    // Build the stored procedure call.
    StoredProcedureCall call = new StoredProcedureCall();
    // Process the stored procedure parameters.
    int index = 1;
    boolean callByIndex = callByIndex();
    boolean hasOutParameters = false;
    for (StoredProcedureParameterMetadata parameter : m_parameters) {
        parameter.processArgument(call, callByIndex, index);
        index++;
        // procedure does not return a result set.
        if (parameter.isOutParameter()) {
            hasOutParameters = true;
        }
    }
    // Process the procedure name.
    call.setProcedureName(m_procedureName);
    // Process the returns result set.
    call.setReturnsResultSet(returnsResultSet(hasOutParameters));
    // Process the multiple result sets.
    call.setHasMultipleResultSets(hasMultipleResultSets());
    // Create a JPA query to store internally on the session.
    JPAQuery query = new JPAQuery(getName(), call, processQueryHints(session));
    if (!m_resultClasses.isEmpty()) {
        // Process the multiple result classes.
        for (MetadataClass resultClass : m_resultClasses) {
            query.addResultClassNames(getJavaClassName(resultClass));
        }
    } else if (!m_resultSetMappings.isEmpty()) {
        // Process the multiple result set mapping.
        query.setResultSetMappings(m_resultSetMappings);
    } else {
        // Legacy support (EclipseLink @NamedStoreProcedureQuery).
        if (!getResultClass().isVoid()) {
            query.setResultClassName(getJavaClassName(getResultClass()));
        } else if (hasResultSetMapping(session)) {
            query.addResultSetMapping(getResultSetMapping());
        }
    }
    addJPAQuery(query, session);
}
Also used : MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall) JPAQuery(org.eclipse.persistence.internal.jpa.JPAQuery)

Example 5 with JPAQuery

use of org.eclipse.persistence.internal.jpa.JPAQuery in project eclipselink by eclipse-ee4j.

the class DeleteOperation method invoke.

/**
 * Execute <code>DELETE</code> operation on the database
 * @param   xrService parent <code>XRService</code> that owns this <code>Operation</code>
 * @param   invocation contains runtime argument values to be bound to the list of
 *          {@link Parameter}'s.
 * @return  result - can be <code>null</code> if the underlying <code>DELETE</code> operation on the
 *          database does not return a value
 *
 * @see  Operation
 */
@SuppressWarnings("rawtypes")
@Override
public Object invoke(XRServiceAdapter xrService, Invocation invocation) {
    DatabaseQuery query = classDescriptor.getQueryManager().getQuery(getFindByPKQuery());
    // 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<String> queryArguments = query.getArguments();
        int queryArgumentsSize = queryArguments.size();
        Vector<Object> executeArguments = new NonSynchronizedVector<>();
        for (int i = 0; i < queryArgumentsSize; i++) {
            String argName = 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;
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) JPAQuery(org.eclipse.persistence.internal.jpa.JPAQuery) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) Vector(java.util.Vector)

Aggregations

JPAQuery (org.eclipse.persistence.internal.jpa.JPAQuery)9 Vector (java.util.Vector)2 ConstructorQueryMappings (org.eclipse.persistence.internal.jpa.jpql.ConstructorQueryMappings)2 JPQLQueryHelper (org.eclipse.persistence.internal.jpa.jpql.JPQLQueryHelper)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 Blob (java.sql.Blob)1 Date (java.sql.Date)1 SQLException (java.sql.SQLException)1 SQLXML (java.sql.SQLXML)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 DatasourceCall (org.eclipse.persistence.internal.databaseaccess.DatasourceCall)1 OutputParameterForCallableStatement (org.eclipse.persistence.internal.databaseaccess.OutputParameterForCallableStatement)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)1 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1