// 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) {
// 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();
// Set the lock mode (the session is passed in to do some validation
// checks)
// If the return value from the set returns true, it indicates that
// 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