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) {
// If we catch a database exception as a result of executing a
// pessimistic locking query we need to ask the platform which
// JPA 2.0 locking exception we should throw. It will be either
// be a PessimisticLockException or a LockTimeoutException (if
// the query was executed using a wait timeout value)
if (this.lockMode != null && this.lockMode.name().contains(ObjectLevelReadQuery.PESSIMISTIC_)) {
// ask the platform if it is a lock timeout
if (session.getPlatform().isLockTimeoutException(e)) {
throw new LockTimeoutException(e);
} else {
throw new PessimisticLockException(e);
}
} else {