List of usage examples for org.springframework.orm.hibernate5 HibernateTransactionManager HibernateTransactionManager
public HibernateTransactionManager(SessionFactory sessionFactory)
From source file:org.projectforge.framework.persistence.history.HibernateSearchReindexer.java
@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: @Override/* w ww . jav a 2 s .c o m*/ public Object doInTransaction(final TransactionStatus status) { try { hibernate.execute(new HibernateCallback() { @Override 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; } }); }
From source file:org.projectforge.framework.persistence.xstream.HibernateXmlConverter.java
/** * 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 untersttzt. * //from w w w .j ava2s . c o m * @param writer Ziel fr die XML-Datei. * @param includeHistory bei false werden die History Eintrge 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() { @Override public Object doInTransaction(final TransactionStatus status) { hibernate.execute(new HibernateCallback() { @Override public Object doInHibernate(final Session session) throws HibernateException { writeObjects(writer, includeHistory, session, preserveIds); status.setRollbackOnly(); return null; } }); return null; } }); }