org.springframework.orm.hibernate3.HibernateTransactionManager Java Examples

The following examples show how to use org.springframework.orm.hibernate3.HibernateTransactionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateXmlConverter.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Schreibt alle Objekte der Datenbank in den angegebenen Writer.<br/>
 * <b>Warnung!</b> Bei der Serialisierung von Collections wird derzeit nur {@link java.util.Set} sauber unterstützt.
 * @param writer Ziel für die XML-Datei.
 * @param includeHistory bei false werden die History Einträge nicht geschrieben
 * @param preserveIds If true, the object ids will be preserved, otherwise new ids will be assigned through xstream.
 */
public void dumpDatabaseToXml(final Writer writer, final boolean includeHistory, final boolean preserveIds)
{
  final TransactionTemplate tx = new TransactionTemplate(new HibernateTransactionManager(hibernate.getSessionFactory()));
  tx.execute(new TransactionCallback() {
    public Object doInTransaction(final TransactionStatus status)
    {
      hibernate.execute(new HibernateCallback() {
        public Object doInHibernate(final Session session) throws HibernateException
        {
          writeObjects(writer, includeHistory, session, preserveIds);
          status.setRollbackOnly();
          return null;
        }
      });
      return null;
    }
  });
}
 
Example #2
Source File: HibernateSearchReindexer.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked"})
private void reindex(final Class< ? > clazz, final ReindexSettings settings, final StringBuffer buf)
{
  // PF-378: Performance of run of full re-indexing the data-base is very slow for large data-bases
  // Single transactions needed, otherwise the full run will be very slow for large data-bases.
  final TransactionTemplate tx = new TransactionTemplate(new HibernateTransactionManager(hibernate.getSessionFactory()));
  tx.execute(new TransactionCallback() {
    // The call-back is needed, otherwise a lot of transactions are left open until last run is completed:
    public Object doInTransaction(final TransactionStatus status)
    {
      try {
        hibernate.execute(new HibernateCallback() {
          public Object doInHibernate(final Session session) throws HibernateException
          {
            databaseDao.reindex(clazz, settings, buf);
            status.setRollbackOnly();
            return null;
          }
        });
      } catch (final Exception ex) {
        buf.append(" (an error occured, see log file for further information.), ");
        log.error("While rebuilding data-base-search-index for '" + clazz.getName() + "': " + ex.getMessage(), ex);
      }
      return null;
    }
  });
}
 
Example #3
Source File: PersistenceConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
@Autowired
public HibernateTransactionManager transactionManager(final SessionFactory sessionFactory) {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);

    return txManager;
}
 
Example #4
Source File: PersistenceConfigHibernate3.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
@Autowired
public HibernateTransactionManager transactionManager(final SessionFactory sessionFactory) {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);

    return txManager;
}
 
Example #5
Source File: SpringConfig.java    From quickperf with Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager hibernateTransactionManager(LocalSessionFactoryBean sessionFactory) {
    HibernateTransactionManager transactionManager = new HibernateTransactionManager();
    transactionManager.setSessionFactory(sessionFactory.getObject());
    return transactionManager;
}