/**
   * Gets Hibernate session.
   *
   * @param tx Cache transaction.
   * @return Session.
   */
  Session session(@Nullable GridCacheTx tx) {
    Session ses;

    if (tx != null) {
      ses = tx.meta(ATTR_SES);

      if (ses == null) {
        ses = sesFactory.openSession();

        ses.beginTransaction();

        // Store session in transaction metadata, so it can be accessed
        // for other operations on the same transaction.
        tx.addMeta(ATTR_SES, ses);

        if (log.isDebugEnabled())
          log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]");
      }
    } else {
      ses = sesFactory.openSession();

      ses.beginTransaction();
    }

    return ses;
  }
    /** {@inheritDoc} */
    @Override
    public Integer call() throws Exception {
      GridCacheTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ);

      try {
        GridCacheCountDownLatchValue latchVal = latchView.get(key);

        if (latchVal == null) {
          if (log.isDebugEnabled())
            log.debug("Failed to find count down latch with given name: " + name);

          assert cnt == 0;

          return cnt;
        }

        int retVal;

        if (val > 0) {
          retVal = latchVal.get() - val;

          if (retVal < 0) retVal = 0;
        } else retVal = 0;

        latchVal.set(retVal);

        latchView.put(key, latchVal);

        tx.commit();

        return retVal;
      } finally {
        tx.end();
      }
    }
  /** {@inheritDoc} */
  @Override
  public void txEnd(GridCacheTx tx, boolean commit) throws GridException {
    init();

    Session ses = tx.removeMeta(ATTR_SES);

    if (ses != null) {
      Transaction hTx = ses.getTransaction();

      if (hTx != null) {
        try {
          if (commit) {
            ses.flush();

            hTx.commit();
          } else hTx.rollback();

          if (log.isDebugEnabled())
            log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
        } catch (HibernateException e) {
          throw new GridException(
              "Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e);
        } finally {
          ses.close();
        }
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void rollback() throws GridException {
    enter();

    try {
      tx.rollback();
    } finally {
      leave();
    }
  }
  /** {@inheritDoc} */
  @Override
  public GridFuture<GridCacheTx> commitAsync() {
    enter();

    try {
      return tx.commitAsync();
    } finally {
      leave();
    }
  }
  /** {@inheritDoc} */
  @Override
  public void end() throws GridException {
    enter();

    try {
      tx.end();
    } finally {
      leave();
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean isRollbackOnly() {
    enter();

    try {
      return tx.isRollbackOnly();
    } finally {
      leave();
    }
  }
 /** {@inheritDoc} */
 @Override
 public <V> Map<String, V> allMeta() {
   return tx.allMeta();
 }
 /** {@inheritDoc} */
 @Override
 public long timeout(long timeout) {
   return tx.timeout(timeout);
 }
示例#10
0
 /** {@inheritDoc} */
 @Override
 public GridCacheTxConcurrency concurrency() {
   return tx.concurrency();
 }
示例#11
0
 /** {@inheritDoc} */
 @Override
 public long startTime() {
   return tx.startTime();
 }
示例#12
0
 /** {@inheritDoc} */
 @Override
 public UUID nodeId() {
   return tx.nodeId();
 }
示例#13
0
 /** {@inheritDoc} */
 @Override
 public <V> boolean replaceMeta(String name, V curVal, V newVal) {
   return tx.replaceMeta(name, curVal, newVal);
 }
示例#14
0
 /** {@inheritDoc} */
 @Override
 public <V> V addMeta(String name, V val) {
   return tx.addMeta(name, val);
 }
示例#15
0
 /** {@inheritDoc} */
 @Override
 public void copyMeta(Map<String, ?> data) {
   tx.copyMeta(data);
 }
示例#16
0
 /** {@inheritDoc} */
 @Override
 public void copyMeta(GridMetadataAware from) {
   tx.copyMeta(from);
 }
示例#17
0
 /** {@inheritDoc} */
 @Override
 public boolean hasMeta(String name) {
   return tx.hasMeta(name);
 }
示例#18
0
 /** {@inheritDoc} */
 @Override
 public <V> V putMetaIfAbsent(String name, V val) {
   return tx.putMetaIfAbsent(name, val);
 }
示例#19
0
 /** {@inheritDoc} */
 @Override
 public <V> boolean hasMeta(String name, V val) {
   return tx.hasMeta(name, val);
 }
示例#20
0
 /** {@inheritDoc} */
 @Override
 public <V> V putMetaIfAbsent(String name, Callable<V> c) {
   return tx.putMetaIfAbsent(name, c);
 }
示例#21
0
 /** {@inheritDoc} */
 @Override
 public UUID xid() {
   return tx.xid();
 }
示例#22
0
 /** {@inheritDoc} */
 @Nullable
 @Override
 public <V> V addMetaIfAbsent(String name, V val) {
   return tx.addMeta(name, val);
 }
示例#23
0
 /** {@inheritDoc} */
 @Override
 public long threadId() {
   return tx.threadId();
 }
示例#24
0
 /** {@inheritDoc} */
 @Override
 public <V> V addMetaIfAbsent(String name, @Nullable Callable<V> c) {
   return tx.addMetaIfAbsent(name, c);
 }
示例#25
0
 /** {@inheritDoc} */
 @Override
 public GridCacheTxIsolation isolation() {
   return tx.isolation();
 }
示例#26
0
 /** {@inheritDoc} */
 @Override
 public long timeout() {
   return tx.timeout();
 }
示例#27
0
 /** {@inheritDoc} */
 @Override
 public boolean isInvalidate() {
   return tx.isInvalidate();
 }
示例#28
0
 /** {@inheritDoc} */
 @Override
 public <V> boolean removeMeta(String name, V val) {
   return tx.removeMeta(name, val);
 }
示例#29
0
 /** {@inheritDoc} */
 @SuppressWarnings({"RedundantTypeArguments"})
 @Override
 public <V> V removeMeta(String name) {
   return tx.<V>removeMeta(name);
 }
示例#30
0
 /** {@inheritDoc} */
 @Override
 public GridCacheTxState state() {
   return tx.state();
 }