use of org.eclipse.persistence.queries.ObjectLevelReadQuery in project cuba by cuba-platform.
the class QueryImpl method preExecute.
protected void preExecute(JpaQuery jpaQuery) {
// copying behaviour of org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery()
DatabaseQuery elDbQuery = ((EJBQueryImpl) jpaQuery).getDatabaseQueryInternal();
boolean isObjectLevelReadQuery = elDbQuery.isObjectLevelReadQuery();
if (jpaQuery.getFlushMode() == FlushModeType.AUTO && (!isObjectLevelReadQuery || !((ObjectLevelReadQuery) elDbQuery).isReadOnly())) {
// flush is expected
entityChangedEventManager.beforeFlush(support.getInstances(entityManager));
support.processFlush(entityManager, true);
}
}
use of org.eclipse.persistence.queries.ObjectLevelReadQuery in project eclipselink by eclipse-ee4j.
the class QueryImpl method executeReadQuery.
/**
* Execute a ReadQuery by assigning the stored parameter values and running
* it in the database
*
* @return the results of the query execution
*/
protected Object executeReadQuery() {
List<Object> parameterValues = processParameters();
// TODO: the following performFlush() call is a temporary workaround for
// bug 4752493:
// CTS: INMEMORY QUERYING IN EJBQUERY BROKEN DUE TO CHANGE TO USE
// REPORTQUERY.
// Ideally we should only flush in case the selectionExpression can't be
// conformed in memory.
// There are two alternative ways to implement that:
// 1. Try running the query with conformInUOW flag first - if it fails
// with
// QueryException.cannotConformExpression then flush and run the query
// again -
// now without conforming.
// 2. Implement a new isComformable method on Expression which would
// determine whether the expression
// could be conformed in memory, flush only in case it returns false.
// Note that doesConform method currently implemented on Expression
// requires object(s) to be confirmed as parameter(s).
// The new isComformable method should not take any objects as
// parameters,
// it should return false if there could be such an object that
// passed to doesConform causes it to throw
// QueryException.cannotConformExpression -
// and true otherwise.
boolean shouldResetConformResultsInUnitOfWork = false;
DatabaseQuery query = getDatabaseQueryInternal();
boolean isObjectLevelReadQuery = query.isObjectLevelReadQuery();
if (isFlushModeAUTO() && (!isObjectLevelReadQuery || !((ObjectLevelReadQuery) query).isReadOnly())) {
performPreQueryFlush();
if (isObjectLevelReadQuery) {
if (((ObjectLevelReadQuery) query).shouldConformResultsInUnitOfWork()) {
cloneSharedQuery();
query = getDatabaseQueryInternal();
((ObjectLevelReadQuery) query).setCacheUsage(ObjectLevelReadQuery.UseDescriptorSetting);
shouldResetConformResultsInUnitOfWork = true;
}
}
}
// Set a pessimistic locking on the query if specified.
if (this.lockMode != null && !this.lockMode.equals(LockModeType.NONE)) {
// We need to throw TransactionRequiredException if there is no
// active transaction
this.entityManager.checkForTransaction(true);
// The lock mode setters and getters validate the query type
// so should be safe to make the casting.
cloneSharedQuery();
query = getDatabaseQueryInternal();
// we were unable to set the lock mode.
if (((ObjectLevelReadQuery) query).setLockModeType(lockMode.name(), (AbstractSession) getActiveSession())) {
throw new PersistenceException(ExceptionLocalization.buildMessage("ejb30-wrong-lock_called_without_version_locking-index", null));
}
}
Session session = getActiveSession();
try {
// in case it's a user-defined query
if (query.isUserDefined()) {
// and there is an active transaction
if (this.entityManager.checkForTransaction(false) != null) {
// verify whether uow has begun early transaction
if (session.isUnitOfWork() && !((UnitOfWorkImpl) session).wasTransactionBegunPrematurely()) {
// uow begins early transaction in case it hasn't
// already begun.
// TODO: This is not good, it means that no SQL queries
// can ever use the cache,
// using isUserDefined to mean an SQL query is also
// wrong.
((UnitOfWorkImpl) session).beginEarlyTransaction();
}
}
}
// Execute the query and return the result.
return session.executeQuery(query, parameterValues);
} catch (DatabaseException e) {
throw getDetailedException(e);
} catch (RuntimeException e) {
setRollbackOnly();
throw e;
} finally {
this.lockMode = null;
if (shouldResetConformResultsInUnitOfWork) {
((ObjectLevelReadQuery) query).conformResultsInUnitOfWork();
}
}
}
use of org.eclipse.persistence.queries.ObjectLevelReadQuery in project eclipselink by eclipse-ee4j.
the class EntityManagerFactoryImpl method addNamedQuery.
@Override
public void addNamedQuery(String name, Query query) {
QueryImpl queryImpl = query.unwrap(QueryImpl.class);
DatabaseQuery unwrapped = (DatabaseQuery) queryImpl.getDatabaseQueryInternal().clone();
if (queryImpl.lockMode != null) {
((ObjectLevelReadQuery) unwrapped).setLockModeType(queryImpl.lockMode.name(), getServerSession());
}
if (unwrapped.isReadQuery()) {
((ReadQuery) unwrapped).setInternalMax((queryImpl.getMaxResultsInternal()));
((ReadQuery) unwrapped).setFirstResult((queryImpl.getFirstResult()));
}
this.getServerSession().addQuery(name, unwrapped, true);
}
use of org.eclipse.persistence.queries.ObjectLevelReadQuery in project eclipselink by eclipse-ee4j.
the class JPQLParseTree method populateQuery.
/**
* Add all of the relevant query settings from an EJBQLParseTree to the given
* database query.
* @param query The query to populate
* @param session The session to use to information such as descriptors.
*/
public void populateQuery(DatabaseQuery query, AbstractSession session) {
if (query.isObjectLevelReadQuery()) {
ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery) query;
GenerationContext generationContext = buildContext(objectQuery, session);
populateReadQueryInternal(objectQuery, generationContext);
} else if (query.isUpdateAllQuery()) {
UpdateAllQuery updateQuery = (UpdateAllQuery) query;
GenerationContext generationContext = buildContext(updateQuery, session);
populateModifyQueryInternal(updateQuery, generationContext);
addUpdatesToQuery(updateQuery, generationContext);
} else if (query.isDeleteAllQuery()) {
DeleteAllQuery deleteQuery = (DeleteAllQuery) query;
GenerationContext generationContext = buildContext(deleteQuery, session);
populateModifyQueryInternal(deleteQuery, generationContext);
}
}
use of org.eclipse.persistence.queries.ObjectLevelReadQuery in project eclipselink by eclipse-ee4j.
the class IndirectionPolicy method mergeClientIntoServerValueHolder.
/**
* INTERNAL
* Replace the client value holder with the server value holder,
* after copying some of the settings from the client value holder.
*/
protected void mergeClientIntoServerValueHolder(RemoteValueHolder<?> serverValueHolder, MergeManager mergeManager) {
serverValueHolder.setMapping(this.mapping);
serverValueHolder.setSession(mergeManager.getSession());
if (this.mapping.isForeignReferenceMapping()) {
ObjectLevelReadQuery query = buildCascadeQuery(mergeManager);
serverValueHolder.setQuery(query);
}
}
Aggregations