use of org.hibernate.SessionFactory in project spring-framework by spring-projects.
the class OpenSessionInterceptor method invoke.
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
SessionFactory sf = getSessionFactory();
if (!TransactionSynchronizationManager.hasResource(sf)) {
// New Session to be bound for the current method's scope...
Session session = openSession();
try {
TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
return invocation.proceed();
} finally {
SessionFactoryUtils.closeSession(session);
TransactionSynchronizationManager.unbindResource(sf);
}
} else {
// Pre-bound Session found -> simply proceed.
return invocation.proceed();
}
}
use of org.hibernate.SessionFactory in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method readDetailsFromConnection.
private void readDetailsFromConnection(RepositoryDiag diag, final SqlRepositoryConfiguration config) {
final List<LabeledString> details = diag.getAdditionalDetails();
Session session = baseHelper.getSessionFactory().openSession();
try {
session.beginTransaction();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
details.add(new LabeledString(DETAILS_TRANSACTION_ISOLATION, getTransactionIsolation(connection, config)));
Properties info = connection.getClientInfo();
if (info == null) {
return;
}
for (String name : info.stringPropertyNames()) {
details.add(new LabeledString(DETAILS_CLIENT_INFO + name, info.getProperty(name)));
}
}
});
session.getTransaction().commit();
SessionFactory sessionFactory = baseHelper.getSessionFactory();
if (!(sessionFactory instanceof SessionFactoryImpl)) {
return;
}
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) sessionFactory;
// we try to override configuration which was read from sql repo configuration with
// real configuration from session factory
String dialect = sessionFactoryImpl.getDialect() != null ? sessionFactoryImpl.getDialect().getClass().getName() : null;
details.add(new LabeledString(DETAILS_HIBERNATE_DIALECT, dialect));
} catch (Throwable th) {
//nowhere to report error (no operation result available)
session.getTransaction().rollback();
} finally {
baseHelper.cleanupSessionAndResult(session, null);
}
}
use of org.hibernate.SessionFactory in project dhis2-core by dhis2.
the class DhisTest method bindSession.
/**
* Binds a Hibernate Session to the current thread.
*/
private void bindSession() {
SessionFactory sessionFactory = (SessionFactory) getBean("sessionFactory");
Session session = sessionFactory.openSession();
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
}
use of org.hibernate.SessionFactory in project uPortal by Jasig.
the class PortalRawEventsAggregatorImpl method evictAggregates.
@AggrEventsTransactional
@Override
public void evictAggregates(Map<Class<?>, Collection<Serializable>> entitiesToEvict) {
int evictedEntities = 0;
int evictedCollections = 0;
final Session session = getEntityManager().unwrap(Session.class);
final SessionFactory sessionFactory = session.getSessionFactory();
final Cache cache = sessionFactory.getCache();
for (final Entry<Class<?>, Collection<Serializable>> evictedEntityEntry : entitiesToEvict.entrySet()) {
final Class<?> entityClass = evictedEntityEntry.getKey();
final List<String> collectionRoles = getCollectionRoles(sessionFactory, entityClass);
for (final Serializable id : evictedEntityEntry.getValue()) {
cache.evictEntity(entityClass, id);
evictedEntities++;
for (final String collectionRole : collectionRoles) {
cache.evictCollection(collectionRole, id);
evictedCollections++;
}
}
}
logger.debug("Evicted {} entities and {} collections from hibernate caches", evictedEntities, evictedCollections);
}
use of org.hibernate.SessionFactory in project ignite by apache.
the class CacheHibernateStoreSessionListenerSelfTest method sessionListenerFactory.
/**
* {@inheritDoc}
*/
@Override
protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
return new Factory<CacheStoreSessionListener>() {
@Override
public CacheStoreSessionListener create() {
CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
SessionFactory sesFactory = new Configuration().setProperty("hibernate.connection.url", URL).addAnnotatedClass(Table1.class).addAnnotatedClass(Table2.class).buildSessionFactory();
lsnr.setSessionFactory(sesFactory);
return lsnr;
}
};
}
Aggregations