use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class JPQLQueryHelper method getConstructorQueryMappings.
/**
* Retrieves the class names and the attribute names mapped to their types that are used in the
* constructor expressions defined in the <code><b>SELECT</b></code> clause.
* <br>
* For instance, from the following JPQL query:
* <br>
* <pre><code> SELECT new test.example.Employee(e.name, e.id),
* new test.example.Address(a.zipcode)
* FROM Employee e, Address a</code></pre>
* <br>
* The return object is
* <pre><code> |- test.example.Employee
* |- |- name : String
* |- |- id : int
* |- test.example.Address
* |- zipcode : int</code></pre>
*
* @param session The {@link AbstractSession} is used to retrieve the mappings used in the
* constructor items
* @return The holder of the result
*/
public List<ConstructorQueryMappings> getConstructorQueryMappings(AbstractSession session) {
List<ConstructorQueryMappings> allMappings = new LinkedList<>();
for (DatabaseQuery query : session.getJPAQueries()) {
ConstructorQueryMappings mappings = getConstructorQueryMappings(session, query);
allMappings.add(mappings);
}
return allMappings;
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method processJPAQuery.
/**
* INTERNAL:
* Process the JPA named query into an EclipseLink Session query. This
* method is called after descriptor initialization.
*/
protected void processJPAQuery(DatabaseQuery jpaQuery) {
// They need to be initialized after login, as the database platform must be known.
try {
jpaQuery.prepareInternal(this);
} catch (RuntimeException re) {
// will be thrown at runtime if a user attempts to use it.
if (!tolerateInvalidJPQL) {
throw re;
}
}
DatabaseQuery databaseQuery = (DatabaseQuery) jpaQuery.getProperty("databasequery");
databaseQuery = (databaseQuery == null) ? jpaQuery : databaseQuery;
// this should be true but for backward compatibility it
addQuery(databaseQuery, false);
// is set to false.
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method copyDescriptorNamedQueries.
/**
* INTERNAL:
* This method will be used to copy all EclipseLink named queries defined in descriptors into the session.
* @param allowSameQueryNameDiffArgsCopyToSession if the value is true, it allow
* multiple queries of the same name but different arguments to be copied to the session.
*/
public void copyDescriptorNamedQueries(boolean allowSameQueryNameDiffArgsCopyToSession) {
for (ClassDescriptor descriptor : getProject().getOrderedDescriptors()) {
Map<String, List<DatabaseQuery>> queries = descriptor.getQueryManager().getQueries();
if ((queries != null) && (queries.size() > 0)) {
for (Iterator<Map.Entry<String, List<DatabaseQuery>>> keyValueItr = queries.entrySet().iterator(); keyValueItr.hasNext(); ) {
Map.Entry<String, List<DatabaseQuery>> entry = keyValueItr.next();
List<DatabaseQuery> thisQueries = entry.getValue();
if ((thisQueries != null) && (thisQueries.size() > 0)) {
for (Iterator<DatabaseQuery> thisQueriesItr = thisQueries.iterator(); thisQueriesItr.hasNext(); ) {
DatabaseQuery queryToBeAdded = thisQueriesItr.next();
if (allowSameQueryNameDiffArgsCopyToSession) {
addQuery(queryToBeAdded, false);
} else {
if (getQuery(queryToBeAdded.getName()) == null) {
addQuery(queryToBeAdded, false);
} else {
log(SessionLog.WARNING, SessionLog.PROPERTIES, "descriptor_named_query_cannot_be_added", new Object[] { queryToBeAdded, queryToBeAdded.getName(), queryToBeAdded.getArgumentTypes() });
}
}
}
}
}
}
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method updateTablePerTenantDescriptors.
/**
* INTERNAL:
* Set the table per tenant. This should be called per client session after
* the start of a transaction. From JPA this method is called on the entity
* manager by setting the multitenant table per tenant property.
*/
public void updateTablePerTenantDescriptors(String property, Object value) {
// When all the table per tenant descriptors are set, we should initialize them.
boolean shouldInitializeDescriptors = hasTablePerTenantDescriptors();
for (ClassDescriptor descriptor : getTablePerTenantDescriptors()) {
TablePerMultitenantPolicy policy = (TablePerMultitenantPolicy) descriptor.getMultitenantPolicy();
if ((!policy.hasContextTenant()) && policy.usesContextProperty(property)) {
policy.setContextTenant((String) value);
}
shouldInitializeDescriptors = shouldInitializeDescriptors && policy.hasContextTenant();
}
if (shouldInitializeDescriptors) {
// descriptors, we can go through the initialization phases safely.
try {
// First initialize basic properties (things that do not depend on anything else)
for (ClassDescriptor descriptor : tablePerTenantDescriptors) {
descriptor.preInitialize(this);
}
// Second initialize basic mappings
for (ClassDescriptor descriptor : tablePerTenantDescriptors) {
descriptor.initialize(this);
}
// Third initialize child dependencies
for (ClassDescriptor descriptor : tablePerTenantDescriptors) {
descriptor.postInitialize(this);
}
if (getIntegrityChecker().hasErrors()) {
handleSevere(new IntegrityException(getIntegrityChecker()));
}
} finally {
clearIntegrityChecker();
}
getCommitManager().initializeCommitOrder();
// once all the descriptors have been initialized.
if (hasTablePerTenantQueries()) {
for (DatabaseQuery query : getTablePerTenantQueries()) {
processJPAQuery(query);
}
}
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method preReleaseConnection.
/**
* INTERNAL:
* This method rises appropriate for the session event(s)
* right before the connection is released.
*/
public void preReleaseConnection(Accessor accessor) {
if (getProject().hasVPDIdentifier(this)) {
if (getPlatform().supportsVPD()) {
DatabaseQuery query = getPlatform().getVPDClearIdentifierQuery(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.preReleaseConnection(accessor);
}
}
Aggregations