Java Code Examples for org.springframework.orm.hibernate4.HibernateTransactionManager

The following examples show how to use org.springframework.orm.hibernate4.HibernateTransactionManager. These examples are extracted from open source projects. 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 Project: onetwo   Source File: DbmMultipleDatasource.java    License: Apache License 2.0 5 votes vote down vote up
public DataSource getCurrentDatasource(){
	if(!masterSlave)
		return masterDatasource;
	
	SwitcherInfo switcher = contextHolder.getContextAttribute(SwitcherInfo.CURRENT_SWITCHER_INFO);
	DataSource ds = masterDatasource;
	if(switcher==null || StringUtils.isBlank(switcher.getCurrentSwitcherName())){
		return ds;
	}
	switch (switcher.getType()) {
	case TransactionManager:
		PlatformTransactionManager pt = (PlatformTransactionManager)Springs.getInstance().getBean(switcher.getCurrentSwitcherName());
		if(isHibernateTransactionManager(pt)){
			ds = ((HibernateTransactionManager)pt).getDataSource();
		}else if(DataSourceTransactionManager.class.isInstance(pt)){
			ds = ((DataSourceTransactionManager)pt).getDataSource();
		}else{
			throw new UnsupportedOperationException("TransactionManager: " + switcher.getCurrentSwitcherName());
		}
		break;

	default:
		String dsName = switcher.getCurrentSwitcherName();// + DATASOURCE_KEY;
		if(datasources.containsKey(dsName))
			ds = datasources.get(dsName);
		break;
	}
	return ds;
}
 
Example 2
@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
    HibernateTransactionManager txManager =  new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);
    return txManager;
}
 
Example 3
@Bean(name = "org.sakaiproject.sitestats.SiteStatsTransactionManager")
public PlatformTransactionManager getSiteStatsTransactionManager() throws IOException {
    if (siteStatsTransactionManager == null) {
        String whichDb = serverConfigurationService.getString("sitestats.db", "internal");
        if ("external".equals(whichDb)) {
            HibernateTransactionManager tx = new HibernateTransactionManager();
            tx.setSessionFactory(getSiteStatsSessionFactory());
            siteStatsTransactionManager = tx;
        } else {
            siteStatsTransactionManager = globalTransactionManager;
        }
    }
    return siteStatsTransactionManager;
}
 
Example 4
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager")
public PlatformTransactionManager transactionManager() throws IOException {
    if (platformTransactionManager == null) {
        if (sessionFactory == null) {
            sessionFactory();
        }
        HibernateTransactionManager txManager = new HibernateTransactionManager();
        txManager.setSessionFactory(sessionFactory);
        platformTransactionManager = txManager;
    }
    return platformTransactionManager;
}
 
Example 5
Source Project: zxl   Source File: MulCommonBaseServiceParser.java    License: Apache License 2.0 5 votes vote down vote up
private BeanDefinition buildHibernateTransactionManagerBeanDefinition(Element element, String name) {
	AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setAttribute(ID_ATTRIBUTE, name + HIBERNATE_TRANSACTION_MANAGER_SUFFIX);
	beanDefinition.setBeanClass(HibernateTransactionManager.class);
	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("sessionFactory", new RuntimeBeanReference(name + SESSION_FACTORY_SUFFIX));
	beanDefinition.setPropertyValues(propertyValues);
	return beanDefinition;
}
 
Example 6
@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
    HibernateTransactionManager txManager =  new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);
    return txManager;
}
 
Example 7
@Bean(name = "org.sakaiproject.sitestats.SiteStatsTransactionManager")
public PlatformTransactionManager getSiteStatsTransactionManager() throws IOException {
    if (siteStatsTransactionManager == null) {
        String whichDb = serverConfigurationService.getString("sitestats.db", "internal");
        if ("external".equals(whichDb)) {
            HibernateTransactionManager tx = new HibernateTransactionManager();
            tx.setSessionFactory(getSiteStatsSessionFactory());
            siteStatsTransactionManager = tx;
        } else {
            siteStatsTransactionManager = globalTransactionManager;
        }
    }
    return siteStatsTransactionManager;
}
 
Example 8
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager")
public PlatformTransactionManager transactionManager() throws IOException {
    if (platformTransactionManager == null) {
        if (sessionFactory == null) {
            sessionFactory();
        }
        HibernateTransactionManager txManager = new HibernateTransactionManager();
        txManager.setSessionFactory(sessionFactory);
        platformTransactionManager = txManager;
    }
    return platformTransactionManager;
}
 
Example 9
Source Project: blog   Source File: GreetingServiceConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager(
		SessionFactory sessionFactory) {
	HibernateTransactionManager htm = new HibernateTransactionManager();
	htm.setSessionFactory(sessionFactory);
	return htm;
}
 
Example 10
Source Project: blog   Source File: GreetingServiceConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager(
		SessionFactory sessionFactory) {
	HibernateTransactionManager htm = new HibernateTransactionManager();
	htm.setSessionFactory(sessionFactory);
	return htm;
}
 
Example 11
Source Project: tutorials   Source File: PersistenceConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager() {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory().getObject());

    return txManager;
}
 
Example 12
Source Project: tutorials   Source File: Cause5NonTransientConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager() {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory().getObject());

    return txManager;
}
 
Example 13
Source Project: tutorials   Source File: Cause4NonTransientConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager() {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory().getObject());

    return txManager;
}
 
Example 14
Source Project: tutorials   Source File: Cause1NonTransientConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager() {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory().getObject());

    return txManager;
}
 
Example 15
Source Project: tutorials   Source File: Cause1PersistenceConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager() {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory().getObject());

    return txManager;
}
 
Example 16
Source Project: tutorials   Source File: Cause2PersistenceConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager() {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory().getObject());

    return txManager;
}
 
Example 17
Source Project: tutorials   Source File: Cause3PersistenceConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public HibernateTransactionManager transactionManager() {
    final HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory().getObject());

    return txManager;
}
 
Example 18
Source Project: quickperf   Source File: SpringConfig.java    License: 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;
}
 
Example 19
Source Project: Project   Source File: RepositoryTestConfig.java    License: Apache License 2.0 4 votes vote down vote up
public PlatformTransactionManager annotationDrivenTransactionManager() {
  System.out.println(sessionFactory);
  HibernateTransactionManager transactionManager = new HibernateTransactionManager();
  transactionManager.setSessionFactory(sessionFactory);
  return transactionManager;
}
 
Example 20
Source Project: onetwo   Source File: DbmMultipleDatasource.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isHibernateTransactionManager(PlatformTransactionManager pt){
	if(!ClassUtils.isPresent("org.hibernate.SessionFactory", ClassUtils.getDefaultClassLoader())){
		return false;
	}
	return HibernateTransactionManager.class.isInstance(pt);
}
 
Example 21
Source Project: sakai   Source File: HelpManagerImpl.java    License: Educational Community License v2.0 4 votes vote down vote up
/**
 * @param txManager The txManager to set.
 */
public void setTxManager(HibernateTransactionManager txManager)
{
	this.txManager = txManager;
}
 
Example 22
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager")
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
    HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);
    return txManager;
}
 
Example 23
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager")
public PlatformTransactionManager transactionManager(SessionFactory sessionFactory) {
    HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);
    return txManager;
}
 
Example 24
Source Project: sakai   Source File: HelpManagerImpl.java    License: Educational Community License v2.0 4 votes vote down vote up
/**
 * @param txManager The txManager to set.
 */
public void setTxManager(HibernateTransactionManager txManager)
{
	this.txManager = txManager;
}
 
Example 25
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager")
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
    HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);
    return txManager;
}
 
Example 26
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager")
public PlatformTransactionManager transactionManager(SessionFactory sessionFactory) {
    HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(sessionFactory);
    return txManager;
}
 
Example 27
Source Project: tutorials   Source File: PersistenceConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public PlatformTransactionManager hibernateTransactionManager() {
    final HibernateTransactionManager transactionManager = new HibernateTransactionManager();
    transactionManager.setSessionFactory(sessionFactory().getObject());
    return transactionManager;
}
 
Example 28
Source Project: tutorials   Source File: PersistenceTestConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public PlatformTransactionManager hibernateTransactionManager() {
    final HibernateTransactionManager transactionManager = new HibernateTransactionManager();
    transactionManager.setSessionFactory(sessionFactory().getObject());
    return transactionManager;
}
 
Example 29
Source Project: spring4-sandbox   Source File: HibernateConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() {
	return new HibernateTransactionManager(sessionFactory());
}
 
Example 30
Source Project: OpERP   Source File: DbTestContext.java    License: MIT License 4 votes vote down vote up
/**
 * 
 * This is setting up the hibernate transaction manager
 * 
 */
@Bean
public HibernateTransactionManager hibernateTransactionManager(
		SessionFactory sessionFactory) {
	return new HibernateTransactionManager(sessionFactory);
}