use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method getQuery.
/**
* INTERNAL:
* Return the query from the session 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.
*
* @param shouldSearchParent indicates whether parent should be searched if query not found.
* @see #getQuery(String, List)
*/
public DatabaseQuery getQuery(String name, Vector arguments, boolean shouldSearchParent) {
List<DatabaseQuery> queries = getQueries().get(name);
if ((queries != null) && !queries.isEmpty()) {
// 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 = new Vector(argumentTypesSize);
for (int i = 0; i < argumentTypesSize; i++) {
argumentTypes.addElement(arguments.elementAt(i).getClass());
}
for (DatabaseQuery query : queries) {
if (Helper.areTypesAssignable(argumentTypes, query.getArgumentTypes())) {
return query;
}
}
}
if (shouldSearchParent) {
AbstractSession parent = getParent();
if (parent != null) {
return parent.getQuery(name, arguments, true);
}
}
return null;
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method executeQuery.
/**
* PUBLIC:
* Execute the pre-defined query by name and return the result.
* Queries can be pre-defined and named to allow for their reuse.
* The class is the descriptor in which the query was pre-defined.
*
* @see DescriptorQueryManager#addQuery(String, DatabaseQuery)
*/
public Object executeQuery(String queryName, Class<?> domainClass, Vector argumentValues) throws DatabaseException {
ClassDescriptor descriptor = getDescriptor(domainClass);
if (descriptor == null) {
throw QueryException.descriptorIsMissingForNamedQuery(domainClass, queryName);
}
DatabaseQuery query = descriptor.getQueryManager().getQuery(queryName, argumentValues);
if (query == null) {
throw QueryException.queryNotDefined(queryName, domainClass);
}
return executeQuery(query, argumentValues);
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method addQuery.
/**
* INTERNAL:
* Add the query to the session queries.
*/
protected synchronized void addQuery(DatabaseQuery query, boolean nameMustBeUnique) {
List<DatabaseQuery> queriesByName = getQueries().get(query.getName());
if (queriesByName == null) {
// lazily create Vector in Hashtable.
queriesByName = new ArrayList<>();
getQueries().put(query.getName(), queriesByName);
}
if (nameMustBeUnique) {
// JPA addNamedQuery
if (queriesByName.size() <= 1) {
queriesByName.clear();
} else {
throw new IllegalStateException(ExceptionLocalization.buildMessage("argument_keyed_named_query_with_JPA", new Object[] { query.getName() }));
}
} else {
// Check that we do not already have a query that matched it
for (Iterator<DatabaseQuery> enumtr = queriesByName.iterator(); enumtr.hasNext(); ) {
DatabaseQuery existingQuery = enumtr.next();
if (Helper.areTypesAssignable(query.getArgumentTypes(), existingQuery.getArgumentTypes())) {
throw ValidationException.existingQueryTypeConflict(query, existingQuery);
}
}
}
queriesByName.add(query);
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method postAcquireConnection.
/**
* INTERNAL:
* This method rises appropriate for the session event(s)
* right after connection is acquired.
*/
public void postAcquireConnection(Accessor accessor) {
if (getProject().hasVPDIdentifier(this)) {
if (getPlatform().supportsVPD()) {
DatabaseQuery query = getPlatform().getVPDSetIdentifierQuery(getProject().getVPDIdentifier());
List argValues = new ArrayList();
query.addArgument(getProject().getVPDIdentifier());
argValues.add(getProperty(getProject().getVPDIdentifier()));
executeQuery(query, argValues);
} else {
throw ValidationException.vpdNotSupported(getPlatform().getClass().getName());
}
}
if (this.eventManager != null) {
this.eventManager.postAcquireConnection(accessor);
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class TransporterHelper method read.
public static org.eclipse.persistence.internal.sessions.remote.Transporter read(org.omg.CORBA.portable.InputStream istream) {
org.eclipse.persistence.internal.sessions.remote.Transporter value = new org.eclipse.persistence.internal.sessions.remote.Transporter();
int length = istream.read_long();
byte[] bytes = new byte[length];
istream.read_octet_array(bytes, 0, length);
java.io.ByteArrayInputStream byteIn = new java.io.ByteArrayInputStream(bytes);
Object anObject = null;
Map descriptors = null;
DatabaseQuery query = null;
if (bytes.length == 0) {
return null;
}
try {
java.io.ObjectInputStream objectIn = new java.io.ObjectInputStream(byteIn);
anObject = objectIn.readObject();
descriptors = (Map) objectIn.readObject();
query = (DatabaseQuery) objectIn.readObject();
} catch (Exception exception) {
exception.printStackTrace();
}
value.object = anObject;
value.wasOperationSuccessful = istream.read_boolean();
value.setQuery(query);
value.setObjectDescriptors(descriptors);
return value;
}
Aggregations