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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations