use of org.eclipse.persistence.internal.helper.NonSynchronizedVector 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;
}
use of org.eclipse.persistence.internal.helper.NonSynchronizedVector in project eclipselink by eclipse-ee4j.
the class DescriptorQueryManager method putCachedUpdateCalls.
/**
* INTERNAL:
* Cache a clone of the update SQL calls based on the updated fields.
* If the max size is reached, do not cache the call.
* The call's query must be dereferenced in order to allow the GC of a related session.
* PERF: Allow caching of the update SQL call to avoid regeneration.
*/
public void putCachedUpdateCalls(Vector updateFields, Vector updateCalls) {
Vector vectorToCache = updateCalls;
if (!updateCalls.isEmpty()) {
int updateCallsSize = updateCalls.size();
vectorToCache = new NonSynchronizedVector(updateCallsSize);
for (int i = 0; i < updateCallsSize; i++) {
DatasourceCall updateCall = (DatasourceCall) updateCalls.get(i);
// clone call and dereference query for DatasourceCall and EJBQLCall
DatasourceCall clonedUpdateCall = (DatasourceCall) updateCall.clone();
clonedUpdateCall.setQuery(null);
vectorToCache.add(clonedUpdateCall);
}
}
getCachedUpdateCalls().put(updateFields, vectorToCache);
}
use of org.eclipse.persistence.internal.helper.NonSynchronizedVector in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildInsertStatement.
/**
* Return the appropriate insert statement
*/
protected SQLInsertStatement buildInsertStatement(DatabaseTable table) {
SQLInsertStatement insertStatement = new SQLInsertStatement();
insertStatement.setTable(table);
insertStatement.setModifyRow(getModifyRow());
if (getDescriptor().hasReturningPolicies() && getDescriptor().getReturnFieldsToGenerateInsert() != null) {
// In case of RelationalDescriptor only return fields for current table must be used.
Vector<DatabaseField> returnFieldsForTable = new NonSynchronizedVector<>();
for (DatabaseField item : getDescriptor().getReturnFieldsToGenerateInsert()) {
if (table.equals(item.getTable())) {
returnFieldsForTable.add(item);
}
}
if (!returnFieldsForTable.isEmpty()) {
insertStatement.setReturnFields(getDescriptor().getReturnFieldsToGenerateInsert());
}
}
insertStatement.setHintString(getQuery().getHintString());
return insertStatement;
}
use of org.eclipse.persistence.internal.helper.NonSynchronizedVector in project eclipselink by eclipse-ee4j.
the class NojiTestSet method runQuery.
@SuppressWarnings("unchecked")
@Test
public void runQuery() {
DatabaseSession s = project.createDatabaseSession();
s.dontLogMessages();
s.login();
Vector queryArgs = new NonSynchronizedVector();
queryArgs.add("testsdfsdfasdfsdfsdfsdfsdfsdfdfsdfsdffds");
boolean worked = false;
String msg = null;
Object o = null;
try {
o = s.executeQuery("Noji", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation noji failed: " + msg, worked);
assertNotNull("result is supposed to be not-null", o);
Vector results = (Vector) o;
DatabaseRecord record = (DatabaseRecord) results.get(0);
BigDecimal x = (BigDecimal) record.get("X");
assertTrue("wrong x value", x.intValue() == 33);
s.logout();
}
use of org.eclipse.persistence.internal.helper.NonSynchronizedVector in project eclipselink by eclipse-ee4j.
the class Ni10TestSet method runQuery.
@SuppressWarnings("unchecked")
@Test
public void runQuery() {
DatabaseSession s = project.createDatabaseSession();
s.dontLogMessages();
s.login();
Vector queryArgs = new NonSynchronizedVector();
queryArgs.add(-1);
boolean worked = false;
String msg = null;
try {
s.executeQuery("Ni10", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation signtype_in_test failed: " + msg, worked);
// test data range: 2 should NOT work
queryArgs = new NonSynchronizedVector();
queryArgs.add(2);
worked = false;
msg = null;
try {
s.executeQuery("Ni10", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertFalse("invocation signtype_in_test with 2 worked: " + msg, worked);
// test data range: -2 should NOT work
queryArgs = new NonSynchronizedVector();
queryArgs.add(-2);
worked = false;
msg = null;
try {
s.executeQuery("Ni10", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertFalse("invocation signtype_in_test with -2 worked: " + msg, worked);
s.logout();
}
Aggregations