Beispiel #1
0
 @Override
 @SuppressWarnings({"ThrowableInstanceNeverThrown"})
 public int executeUpdate() {
   try {
     if (!entityManager.isTransactionInProgress()) {
       entityManager.throwPersistenceException(
           new TransactionRequiredException("Executing an update/delete query"));
       return 0;
     }
     return internalExecuteUpdate();
   } catch (QueryExecutionRequestException he) {
     throw new IllegalStateException(he);
   } catch (TypeMismatchException e) {
     throw new IllegalArgumentException(e);
   } catch (HibernateException he) {
     entityManager.throwPersistenceException(he);
     return 0;
   }
 }
  @Override
  public BaseQueryImpl setParameter(int position, Calendar value, TemporalType temporalType) {
    checkOpen(true);

    try {
      findParameterRegistration(position).bindValue(value, temporalType);
    } catch (QueryParameterException e) {
      throw new IllegalArgumentException(e);
    } catch (HibernateException he) {
      throw entityManager.convert(he);
    }

    return this;
  }
  @Override
  public <T> BaseQueryImpl setParameter(Parameter<T> param, T value) {
    checkOpen(true);

    try {
      findParameterRegistration(param).bindValue(value);
    } catch (QueryParameterException e) {
      throw new IllegalArgumentException(e);
    } catch (HibernateException he) {
      throw entityManager.convert(he);
    }

    return this;
  }
  @Override
  @SuppressWarnings("unchecked")
  public BaseQueryImpl setParameter(String name, Object value) {
    checkOpen(true);

    try {
      findParameterRegistration(name).bindValue(value);
    } catch (QueryParameterException e) {
      throw new IllegalArgumentException(e);
    } catch (HibernateException he) {
      throw entityManager.convert(he);
    }

    return this;
  }
  @Override
  public BaseQueryImpl setParameter(int position, Date value, TemporalType temporalType) {
    checkOpen(true);

    try {
      findParameterRegistration(position).bindValue(value, temporalType);
    } catch (ParameterStrategyException e) {
      throw new IllegalArgumentException("Invalid mix of named and positional parameters", e);
    } catch (NoSuchParameterException e) {
      throw new IllegalArgumentException(e.getMessage(), e);
    } catch (QueryParameterException e) {
      throw new IllegalArgumentException(e);
    } catch (HibernateException he) {
      throw entityManager.convert(he);
    }

    return this;
  }
 protected void checkOpen(boolean markForRollbackIfClosed) {
   entityManager.checkOpen(markForRollbackIfClosed);
 }
 @Override
 public FlushModeType getFlushMode() {
   checkOpen(false);
   return jpaFlushMode != null ? jpaFlushMode : entityManager.getFlushMode();
 }
  @Override
  @SuppressWarnings({"deprecation"})
  public BaseQueryImpl setHint(String hintName, Object value) {
    checkOpen(true);
    boolean applied = false;
    try {
      if (HINT_TIMEOUT.equals(hintName)) {
        applied = applyTimeoutHint(ConfigurationHelper.getInteger(value));
      } else if (SPEC_HINT_TIMEOUT.equals(hintName)) {
        // convert milliseconds to seconds
        int timeout =
            (int) Math.round(ConfigurationHelper.getInteger(value).doubleValue() / 1000.0);
        applied = applyTimeoutHint(timeout);
      } else if (AvailableSettings.LOCK_TIMEOUT.equals(hintName)) {
        applied = applyLockTimeoutHint(ConfigurationHelper.getInteger(value));
      } else if (HINT_COMMENT.equals(hintName)) {
        applied = applyCommentHint((String) value);
      } else if (HINT_FETCH_SIZE.equals(hintName)) {
        applied = applyFetchSizeHint(ConfigurationHelper.getInteger(value));
      } else if (HINT_CACHEABLE.equals(hintName)) {
        applied = applyCacheableHint(ConfigurationHelper.getBoolean(value));
      } else if (HINT_CACHE_REGION.equals(hintName)) {
        applied = applyCacheRegionHint((String) value);
      } else if (HINT_READONLY.equals(hintName)) {
        applied = applyReadOnlyHint(ConfigurationHelper.getBoolean(value));
      } else if (HINT_CACHE_MODE.equals(hintName)) {
        applied = applyCacheModeHint(ConfigurationHelper.getCacheMode(value));
      } else if (HINT_FLUSH_MODE.equals(hintName)) {
        applied = applyFlushModeHint(ConfigurationHelper.getFlushMode(value));
      } else if (AvailableSettings.SHARED_CACHE_RETRIEVE_MODE.equals(hintName)) {
        final CacheRetrieveMode retrieveMode = (CacheRetrieveMode) value;

        CacheStoreMode storeMode =
            hints != null
                ? (CacheStoreMode) hints.get(AvailableSettings.SHARED_CACHE_STORE_MODE)
                : null;
        if (storeMode == null) {
          storeMode =
              (CacheStoreMode)
                  entityManager.getProperties().get(AvailableSettings.SHARED_CACHE_STORE_MODE);
        }
        applied = applyCacheModeHint(CacheModeHelper.interpretCacheMode(storeMode, retrieveMode));
      } else if (AvailableSettings.SHARED_CACHE_STORE_MODE.equals(hintName)) {
        final CacheStoreMode storeMode = (CacheStoreMode) value;

        CacheRetrieveMode retrieveMode =
            hints != null
                ? (CacheRetrieveMode) hints.get(AvailableSettings.SHARED_CACHE_RETRIEVE_MODE)
                : null;
        if (retrieveMode == null) {
          retrieveMode =
              (CacheRetrieveMode)
                  entityManager.getProperties().get(AvailableSettings.SHARED_CACHE_RETRIEVE_MODE);
        }
        applied = applyCacheModeHint(CacheModeHelper.interpretCacheMode(storeMode, retrieveMode));
      } else if (hintName.startsWith(AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE)) {
        if (canApplyAliasSpecificLockModeHints()) {
          // extract the alias
          final String alias =
              hintName.substring(AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE.length() + 1);
          // determine the LockMode
          try {
            final LockMode lockMode = LockModeTypeHelper.interpretLockMode(value);
            applyAliasSpecificLockModeHint(alias, lockMode);
          } catch (Exception e) {
            LOG.unableToDetermineLockModeValue(hintName, value);
            applied = false;
          }
        } else {
          applied = false;
        }
      } else {
        LOG.ignoringUnrecognizedQueryHint(hintName);
      }
    } catch (ClassCastException e) {
      throw new IllegalArgumentException("Value for hint");
    }

    if (applied) {
      if (hints == null) {
        hints = new HashMap<String, Object>();
      }
      hints.put(hintName, value);
    } else {
      LOG.debugf("Skipping unsupported query hint [%s]", hintName);
    }

    return this;
  }
Beispiel #9
0
 @Override
 public FlushModeType getFlushMode() {
   return jpaFlushMode != null ? jpaFlushMode : entityManager.getFlushMode();
 }