/**
   * 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;
  }
Пример #2
0
 /** {@inheritDoc} */
 @Nullable
 @Override
 public <V> V addMetaIfAbsent(String name, V val) {
   return tx.addMeta(name, val);
 }
Пример #3
0
 /** {@inheritDoc} */
 @Override
 public <V> V addMeta(String name, V val) {
   return tx.addMeta(name, val);
 }