Package org.hibernate.classic

Examples of org.hibernate.classic.Session


  /**
   * {@inheritDoc}
   */
  public final Session currentSession() throws HibernateException {
    Session current = existingSession( factory );
    if (current == null) {
      current = buildOrObtainSession();
      // register a cleanup synch
      current.getTransaction().registerSynchronization( buildCleanupSynch() );
      // wrap the session in the transaction-protection proxy
      if ( needsWrapping( current ) ) {
        current = wrap( current );
      }
      // then bind it
View Full Code Here


    return factory.getSettings().getConnectionReleaseMode();
  }

  protected Session wrap(Session session) {
    TransactionProtectionWrapper wrapper = new TransactionProtectionWrapper( session );
    Session wrapped = ( Session ) Proxy.newProxyInstance(
        Session.class.getClassLoader(),
            SESS_PROXY_INTERFACES,
            wrapper
      );
    // yick!  need this for proper serialization/deserialization handling...
View Full Code Here

    cleanupAnyOrphanedSession( factory );
    doBind( session, factory );
  }

  private static void cleanupAnyOrphanedSession(SessionFactory factory) {
    Session orphan = doUnbind( factory, false );
    if ( orphan != null ) {
      log.warn( "Already session bound on call to bind(); make sure you clean up your sessions!" );
      try {
        if ( orphan.getTransaction() != null && orphan.getTransaction().isActive() ) {
          try {
            orphan.getTransaction().rollback();
          }
          catch( Throwable t ) {
            log.debug( "Unable to rollback transaction for orphaned session", t );
          }
        }
        orphan.close();
      }
      catch( Throwable t ) {
        log.debug( "Unable to close orphaned session", t );
      }
    }
View Full Code Here

    sessionMap.put( factory, session );
  }

  private static Session doUnbind(SessionFactory factory, boolean releaseMapIfEmpty) {
    Map sessionMap = sessionMap();
    Session session = null;
    if ( sessionMap != null ) {
      session = ( Session ) sessionMap.remove( factory );
      if ( releaseMapIfEmpty && sessionMap.isEmpty() ) {
        context.set( null );
      }
View Full Code Here

   */
  public SectionStatus setCompleted (User person, ContentLoc loc, boolean complete) {
    ISIXmlSection sec = loc.getSection().getSectionAncestor();
    if (sec == null)
      return null;
    Session s = Databinder.getHibernateSession();
    SectionStatus stat = getSectionStatus(person, sec);
    if (stat == null) {
      stat = new SectionStatus(person, new ContentLoc(sec).getLocation(), complete);
      s.save(stat);
    } else {
      stat.setCompleted(complete);
    }
    // If there are no response groups, automatically mark as Reviewed
    if (!sec.hasResponseGroup()) {
View Full Code Here

  public void adjustMessageCount (User student, ContentLoc loc, Role role, int amount) {
    ISIXmlSection sec = loc.getSection().getSectionAncestor();
    if (sec == null) {
      throw new IllegalArgumentException("Content Location not valid");
    }
    Session s = Databinder.getHibernateSession();
    SectionStatus stat = getSectionStatus(student, sec);
    if (stat == null) {
      stat = new SectionStatus(student, new ContentLoc(sec).getLocation(), false);
      s.save(stat);
    }
    if (role.equals(Role.STUDENT))
      stat.setUnreadStudentMessages(stat.getUnreadStudentMessages() + amount);
    else
      stat.setUnreadTeacherMessages(stat.getUnreadTeacherMessages() + amount);
View Full Code Here

 
  /* (non-Javadoc)
   * @see org.cast.isi.service.IQuestionService#createQuestion(org.cast.cwm.data.models.UserModel, java.lang.String, java.lang.String)
   */
  public void createQuestion(UserModel mOwner, String text, String pageName) {
    Session session = Databinder.getHibernateSession();
    Question question = new Question(text, mOwner.getObject(), null);
    ISIPrompt prompt = new ISIPrompt(PromptType.MY_QUESTIONS);
    if (mOwner != null) {
      prompt.setTargetUser(mOwner.getObject());
      eventService.saveEvent("question:create", text, pageName);
    }
    session.save(prompt)
    question.setPrompt(prompt);
    session.save(question);
    cwmService.flushChanges();
  }
View Full Code Here

  /**
   * @see CurrentSessionContext#currentSession
   */
  public Session currentSession() {
    Session current = existingSession( factory );
    if ( current == null ) {
      throw new HibernateException( "No session currently bound to execution context" );
    }
    return current;
  }
View Full Code Here

   *
   * @param factory The factory for which to unbind the current session.
   * @return The bound session if one, else null.
   */
  public static Session unbind(SessionFactory factory) {
    Session existing = null;
    Map sessionMap = sessionMap();
    if ( sessionMap != null ) {
      existing = ( Session ) sessionMap.remove( factory );
      doCleanup();
    }
View Full Code Here

    }
    catch ( Throwable t ) {
      throw new HibernateException( "Problem locating/validating JTA transaction", t );
    }

    Session currentSession = ( Session ) currentSessionMap.get( txn );

    if ( currentSession == null ) {
      currentSession = buildOrObtainSession();

      try {
        txn.registerSynchronization( buildCleanupSynch( txn ) );
      }
      catch ( Throwable t ) {
        try {
          currentSession.close();
        }
        catch ( Throwable ignore ) {
          log.debug( "Unable to release generated current-session on failed synch registration", ignore );
        }
        throw new HibernateException( "Unable to register cleanup Synchronization with TransactionManager" );
View Full Code Here

TOP

Related Classes of org.hibernate.classic.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.