Package org.hibernate

Examples of org.hibernate.Transaction


   * @throws PersistenceManagerException in case of any problems.
   */
  public void deleteItem(ItemIF item)
    throws PersistenceManagerException {

    Transaction tx = null;
    try {
      final Session session = HibernateUtil.openSession();
      tx = session.beginTransaction();

      // Create item object and save to database
      deleteItem(item, session);

      tx.commit();
      item.setId(-1);
    } catch (Exception e) {
      if (tx != null) {
        try {
          tx.rollback();
        } catch (HibernateException e1) {
          // We can do nothing here.
        }
      }

View Full Code Here


   * @throws PersistenceManagerException in case of any problems.
   */
  private void saveCreatedItem(ChannelIF channel, final ItemIF item)
    throws PersistenceManagerException {

    Transaction tx = null;
    try {
      final Session session = HibernateUtil.openSession();
      tx = session.beginTransaction();

      // Save item to database
      HibernateUtil.lock(channel, session);
      createItem(item, channel, session);

      tx.commit();
    } catch (Exception e) {
      if (tx != null) {
        try {
          tx.rollback();
        } catch (HibernateException e1) {
          // We can do nothing here.
        }
      }

View Full Code Here

  }
 
  protected DBTransaction beginDbTransaction() {
    if (trxWrapper == null || trxWrapper.isCommitted()) {
      try {
        Transaction trx = hibernateSession.beginTransaction();
        trxWrapper = new DBTransaction(trx);
        return trxWrapper;
      } catch (HibernateException e) {
        throw new DBRuntimeException("DBSession - could not begin DBTransaction", e);
      }
View Full Code Here

   *
   */
  public void fill() throws JRException
  {
    Session session = createSession();
    Transaction transaction = session.beginTransaction();

    Map params = getParameters(session);
   
    File[] files =
      new File[]{
        new File("build/reports/AddressesReport.jasper"),
        new File("build/reports/HibernateQueryReport.jasper")
      };
    for(int i = 0; i < files.length; i++)
    {
      File reportFile = files[i];
      long start = System.currentTimeMillis();
      JasperFillManager.fillReportToFile(reportFile.getAbsolutePath(), params);
      System.err.println("Report : " + reportFile + ". Filling time : " + (System.currentTimeMillis() - start));
    }
   
    transaction.rollback();
    session.close();
  }
View Full Code Here

  public void deleteTestDataAndCloseSession() {
    session.clear();
    if ( session.getTransaction().isActive() ) {
      session.getTransaction().rollback();
    }
    Transaction transaction = session.beginTransaction();

    Novel novel = (Novel) session.get( Novel.class, "novel-1" );
    if ( novel != null ) {
      session.delete( novel );
    }

    Animal animal = (Animal) session.get( Animal.class, "animal-1" );
    if ( animal != null ) {
      session.delete( animal );
    }

    animal = (Animal) session.get( Animal.class, "animal-2" );
    if ( animal != null ) {
      session.delete( animal );
    }

    Zoo zoo = (Zoo) session.get( Zoo.class, "zoo-1" );
    if ( zoo != null ) {
      session.delete( zoo );
    }

    Contributor contributor = (Contributor) session.get( Contributor.class, "contributor-1" );
    if ( contributor != null ) {
      session.delete( contributor );
    }

    contributor = (Contributor) session.get( Contributor.class, "contributor-2" );
    if ( contributor != null ) {
      session.delete( contributor );
    }

    Project project = (Project) session.get( Project.class, "project-1" );
    if ( project != null ) {
      session.delete( project );
    }

    project = (Project) session.get( Project.class, "project-2" );
    if ( project != null ) {
      session.delete( project );
    }

    project = (Project) session.get( Project.class, "project-3" );
    if ( project != null ) {
      session.delete( project );
    }

    ProjectGroup projectGroup = (ProjectGroup) session.get( ProjectGroup.class, "project-group-1" );
    if ( projectGroup != null ) {
      session.delete( projectGroup );
    }

    transaction.commit();
    session.close();
  }
View Full Code Here

    Novel novel = createAndPersistNovel();

    String newRevision = doConcurrentUpdateToNovel();
    assertThat( newRevision ).isNotEqualTo( novel.get_rev() );

    Transaction transaction = session.beginTransaction();
    novel.setDescription( "Description 2" );
    transaction.commit();
  }
View Full Code Here

  @Test(expected = StaleObjectStateException.class)
  public void updateAfterConcurrentDeletionShouldCauseException() throws Exception {
    createAndPersistNovel();
    session.clear();

    Transaction transaction = session.beginTransaction();

    Novel novel = (Novel) session.get( Novel.class, "novel-1" );
    concurrentlyDeleteNovel();
    novel.setPosition( 2 );

    transaction.commit();
  }
View Full Code Here

  public void deletionAfterConcurrentModificationShouldCauseException() throws Exception {
    Novel novel = createAndPersistNovel();

    doConcurrentUpdateToNovel();

    Transaction transaction = session.beginTransaction();
    session.delete( novel );
    transaction.commit();
  }
View Full Code Here

    session.delete( novel );
    transaction.commit();
  }

  private Novel createAndPersistNovel() {
    Transaction transaction = session.beginTransaction();

    Novel novel = createNovel();

    assertThat( novel.get_rev() ).isNull();
    session.persist( novel );
    transaction.commit();
    assertThat( novel.get_rev() ).isNotNull();
    return novel;
  }
View Full Code Here

      @Override
      public String call() throws Exception {
        Session session = openSession();

        Transaction transaction = session.beginTransaction();
        final Novel novel = (Novel) session.get( Novel.class, "novel-1" );
        novel.setDescription( "Description 2" );
        transaction.commit();

        return novel.get_rev();
      }
    } ).get();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.Transaction

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.