use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class DescriptorQueryManager method getQuery.
/**
* PUBLIC:
* Return the query from the set of pre-defined queries with the given name and argument types.
* This allows for common queries to be pre-defined, reused and executed by name.
* This method should be used if the Session has multiple queries with the same name but
* different arguments.
* If only one query exists, it will be returned regardless of the arguments.
* If multiple queries exist, the first query that has corresponding argument types will be returned
*
* @see #getQuery(String)
*/
public DatabaseQuery getQuery(String name, Vector arguments) {
DatabaseQuery query = getLocalQuery(name, arguments);
// found in parents, return null.
if (query == null) {
DatabaseQuery parentQuery = getQueryFromParent(name, arguments);
if ((parentQuery != null) && parentQuery.isReadQuery()) {
parentQuery = (DatabaseQuery) parentQuery.clone();
((ObjectLevelReadQuery) parentQuery).setReferenceClass(this.descriptor.getJavaClass());
addQuery(name, parentQuery);
}
return parentQuery;
}
return query;
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class DescriptorQueryManager method clone.
/**
* INTERNAL:
* Clone the query manager
*/
@Override
public Object clone() {
DescriptorQueryManager manager = null;
try {
manager = (DescriptorQueryManager) super.clone();
} catch (Exception exception) {
throw new AssertionError(exception);
}
// Bug 3037701 - clone the queries
// bug5677655
manager.setQueries(new LinkedHashMap<>(getQueries().size()));
Iterator<List<DatabaseQuery>> iterator = queries.values().iterator();
while (iterator.hasNext()) {
Iterator<DatabaseQuery> queriesForKey = iterator.next().iterator();
while (queriesForKey.hasNext()) {
DatabaseQuery initialQuery = queriesForKey.next();
DatabaseQuery clonedQuery = (DatabaseQuery) initialQuery.clone();
clonedQuery.setDescriptor(manager.getDescriptor());
manager.addQuery(clonedQuery);
}
}
manager.setDoesExistQuery((DoesExistQuery) getDoesExistQuery().clone());
if (getReadAllQuery() != null) {
manager.setReadAllQuery((ReadAllQuery) getReadAllQuery().clone());
}
if (getReadObjectQuery() != null) {
manager.setReadObjectQuery((ReadObjectQuery) getReadObjectQuery().clone());
}
if (getUpdateQuery() != null) {
manager.setUpdateQuery((UpdateObjectQuery) getUpdateQuery().clone());
}
if (getInsertQuery() != null) {
manager.setInsertQuery((InsertObjectQuery) getInsertQuery().clone());
}
if (getDeleteQuery() != null) {
manager.setDeleteQuery((DeleteObjectQuery) getDeleteQuery().clone());
}
return manager;
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class RemoteSessionController method executeNamedQuery.
/**
* A named query after serialization is executed locally.
*/
public Transporter executeNamedQuery(Transporter nameTransporter, Transporter classTransporter, Transporter argumentsTransporter) {
Transporter transporter = new Transporter();
try {
Object result;
DatabaseQuery query;
// Clear the unit of work, as the client unit of work may have been cleared.
this.unitOfWork = null;
AbstractSession executionSession = getExecutionSession();
if (classTransporter.getObject() == null) {
result = executionSession.executeQuery((String) nameTransporter.getObject(), (Vector) argumentsTransporter.getObject());
query = executionSession.getQuery((String) nameTransporter.getObject());
} else {
result = executionSession.executeQuery((String) nameTransporter.getObject(), (Class) classTransporter.getObject(), (Vector) argumentsTransporter.getObject());
query = executionSession.getDescriptor((Class) classTransporter.getObject()).getQueryManager().getQuery((String) nameTransporter.getObject());
}
transporter.setQuery(query);
transporter.setObjectDescriptors(query.replaceValueHoldersIn(result, this));
transporter.setObject(result);
} catch (RuntimeException exception) {
transporter.setException(exception);
}
transporter.prepare(this.session);
return transporter;
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class DescriptorQueryManager method getLocalQuery.
/**
* INTENAL:
* Return the query from the set of pre-defined queries with the given name and argument types.
* This allows for common queries to be pre-defined, reused and executed by name.
* Only returns those queries locally defined, not superclass's queries
* If only one query exists, it will be returned regardless of the arguments.
* If multiple queries exist, the first query that has corresponding argument types will be returned
*
* @see #getQuery(String)
*/
public DatabaseQuery getLocalQuery(String name, Vector arguments) {
List<DatabaseQuery> queries = getQueries().get(name);
if (queries == null) {
return null;
}
// Short circuit the simple, most common case of only one query.
if (queries.size() == 1) {
return queries.get(0);
}
// CR#3754; Predrag; mar 19/2002;
// We allow multiple named queries with the same name but
// different argument set; we can have only one query with
// no arguments; Vector queries is not sorted;
// When asked for the query with no parameters the
// old version did return the first query - wrong:
// return (DatabaseQuery) queries.firstElement();
int argumentTypesSize = 0;
if (arguments != null) {
argumentTypesSize = arguments.size();
}
Vector argumentTypes = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(argumentTypesSize);
for (int i = 0; i < argumentTypesSize; i++) {
argumentTypes.addElement(arguments.elementAt(i).getClass());
}
return getLocalQueryByArgumentTypes(name, argumentTypes);
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class DescriptorQueryManager method initialize.
/**
* INTERNAL:
* Post initialize the mappings
*/
public void initialize(AbstractSession session) {
this.initializeQueryTimeout(session);
if (getDescriptor().isAggregateDescriptor()) {
return;
}
if (getMultipleTableJoinExpression() != null) {
// Combine new multiple table expression to additional join expression
setAdditionalJoinExpression(getMultipleTableJoinExpression().and(getAdditionalJoinExpression()));
}
if (getDescriptor().isAggregateCollectionDescriptor()) {
return;
}
// Configure default query cache for all named queries.
QueryResultsCachePolicy defaultQueryCachePolicy = session.getProject().getDefaultQueryResultsCachePolicy();
if (defaultQueryCachePolicy != null && !getDescriptor().getCachePolicy().isIsolated()) {
for (List<DatabaseQuery> queries : getQueries().values()) {
for (DatabaseQuery query : queries) {
if (query.isReadQuery()) {
ReadQuery readQuery = (ReadQuery) query;
if (!readQuery.shouldCacheQueryResults()) {
readQuery.setQueryResultsCachePolicy(defaultQueryCachePolicy.clone());
}
}
}
}
}
getDescriptor().initialize(this, session);
}
Aggregations