当前位置: 首页>>代码示例>>Java>>正文


Java LocalSessionFactoryBean类代码示例

本文整理汇总了Java中org.springframework.orm.hibernate3.LocalSessionFactoryBean的典型用法代码示例。如果您正苦于以下问题:Java LocalSessionFactoryBean类的具体用法?Java LocalSessionFactoryBean怎么用?Java LocalSessionFactoryBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LocalSessionFactoryBean类属于org.springframework.orm.hibernate3包,在下文中一共展示了LocalSessionFactoryBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSessionFactoryBean

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
protected LocalSessionFactoryBean createSessionFactoryBean(Object testObject, OrmConfig entityManagerConfig) {
    // A custom subclass of spring's LocalSessionFactoryBean is used, to enable calling a custom config method
    UnitilsLocalSessionFactoryBean factoryBean = new UnitilsLocalSessionFactoryBean();
    factoryBean.setDataSource(getDataSource());
    factoryBean.setConfigurationClass(getConfigurationObjectClass());
    Resource[] hibernateConfigFiles = new Resource[entityManagerConfig.getConfigFiles().size()];
    int index = 0;
    for (String configFileName : entityManagerConfig.getConfigFiles()) {
        hibernateConfigFiles[index++] = new ClassPathResource(configFileName);
    }
    factoryBean.setConfigLocations(hibernateConfigFiles);

    // Enable invocation of custom config method
    factoryBean.setTestObject(testObject);
    factoryBean.setCustomConfigMethod(entityManagerConfig.getConfigMethod());

    // Build SessionFactory
    try {
        factoryBean.afterPropertiesSet();
    } catch (Exception e) {
        throw new UnitilsException("Error while processing " + LocalSessionFactoryBean.class.getSimpleName() + " configuration", e);
    }

    return factoryBean;
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:26,代码来源:HibernateSessionFactoryLoader.java

示例2: createHibernateSessionFactory

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
/**
 * Creates the Hibernate session factory.
 * 
 * @param repo  the component repository, only used to register secondary items like lifecycle, not null
 * @param dialect  the dialect instance, not null
 * @return the session factory, may be null
 */
protected SessionFactory createHibernateSessionFactory(ComponentRepository repo, DbDialect dialect) {
  if (getHibernateMappingFiles() == null) {
    return null; // Hibernate not required
  }
  LocalSessionFactoryBean factory = new LocalSessionFactoryBean();
  factory.setMappingResources(getHibernateMappingResources(repo));
  factory.setDataSource(getDataSource());
  Properties props = new Properties();
  props.setProperty("hibernate.dialect", dialect.getHibernateDialect().getClass().getName());
  props.setProperty("hibernate.show_sql", String.valueOf(isHibernateShowSql()));
  props.setProperty("hibernate.connection.release_mode", "on_close");
  if (isAllowHibernateThreadBoundSession()) {
    props.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
    props.setProperty(Environment.TRANSACTION_STRATEGY, "org.hibernate.transaction.JDBCTransactionFactory");
  }
  factory.setHibernateProperties(props);
  factory.setLobHandler(dialect.getLobHandler());
  try {
    factory.afterPropertiesSet();
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
  return factory.getObject();
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:32,代码来源:DbConnectorComponentFactory.java

示例3: EntityParser

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public EntityParser(
		Object entity,
		String[] properties,
		LocalSessionFactoryBean sessionFactoryBean) {
	this.sessionFactoryBean = sessionFactoryBean;
	this.entity = entity;
	this.properties = properties;
	this.pc = extractPersistentClass(entity.getClass().getName());
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:10,代码来源:EntityParser.java

示例4: getConfiguredPersistenceUnit

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public ConfiguredOrmPersistenceUnit<SessionFactory, Configuration> getConfiguredPersistenceUnit(Object testObject) {
    LocalSessionFactoryBean factoryBean = getSessionFactoryBean(testObject);
    SessionFactory entityManagerFactory = (SessionFactory) factoryBean.getObject();
    Configuration hibernateConfiguration = factoryBean.getConfiguration();

    return new ConfiguredOrmPersistenceUnit<SessionFactory, Configuration>(entityManagerFactory, hibernateConfiguration);
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:8,代码来源:HibernateSpringSupport.java

示例5: getSessionFactoryBean

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
/**
 * @param testObject The test instance, not null
 * @return Instance of {@link LocalSessionFactoryBean} that wraps the configuration of hibernate in spring
 */
protected LocalSessionFactoryBean getSessionFactoryBean(Object testObject) {
    if (!getSpringModule().isApplicationContextConfiguredFor(testObject)) {
        return null;
    }
    Collection<?> entityManagerFactoryBeans = getSpringModule().getApplicationContext(testObject).getBeansOfType(LocalSessionFactoryBean.class).values();
    if (entityManagerFactoryBeans.size() == 0) {
        return null;
    }
    return (LocalSessionFactoryBean) entityManagerFactoryBeans.iterator().next();
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:15,代码来源:HibernateSpringSupport.java

示例6: main

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public static void main(String[] args)
{
	FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext(
		"database/spring/applicationContext.xml");

	LocalSessionFactoryBean sessionFactory = (LocalSessionFactoryBean) appContext
		.getBean("&sessionFactory", LocalSessionFactoryBean.class);

	sessionFactory.createDatabaseSchema();
}
 
开发者ID:mtpettyp,项目名称:openreports,代码行数:11,代码来源:SchemaExporter.java

示例7: main

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public static void main(String[] args)
{
	FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext(
			"database/spring/applicationContext.xml");
	
	LocalSessionFactoryBean sessionFactory = (LocalSessionFactoryBean) appContext
			.getBean("&sessionFactory", LocalSessionFactoryBean.class);
	
	sessionFactory.updateDatabaseSchema();	
}
 
开发者ID:mtpettyp,项目名称:openreports,代码行数:11,代码来源:SchemaUpdater.java

示例8: setLocalSessionFactory

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public void setLocalSessionFactory(LocalSessionFactoryBean localSessionFactory)
{
    this.localSessionFactory = localSessionFactory;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:5,代码来源:ScriptExecutorImpl.java

示例9: getLocalSessionFactory

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public LocalSessionFactoryBean getLocalSessionFactory()
{
    return localSessionFactory;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:5,代码来源:ScriptExecutorImpl.java

示例10: setLocalSessionFactory

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public void setLocalSessionFactory(LocalSessionFactoryBean localSessionFactory)
{
    this.cfg = localSessionFactory.getConfiguration();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:5,代码来源:DataSourceCheck.java

示例11: setSessionFactoryBean

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
@Autowired
public void setSessionFactoryBean(LocalSessionFactoryBean sessionFactoryBean) {
	this.sessionFactoryBean = sessionFactoryBean;
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:5,代码来源:HibernateActionLogger.java

示例12: getSessionFactoryByDsName

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public synchronized static SessionFactory getSessionFactoryByDsName(String dataSourceName) {
    Map map = (Map) SessionContext.getAttributeForServletContext(SESSIONFACTORY);
    if (map == null) {
        SessionContext.setAttributeForServletContext(SESSIONFACTORY, new HashMap());
        map = (Map) SessionContext.getAttributeForServletContext(SESSIONFACTORY);
    }
    SessionFactory sessionFactory = (SessionFactory) map.get(dataSourceName);
    if (sessionFactory == null) {
        try {
            DocumentBuilderFactory dbf = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();
            DocumentBuilder db = dbf.newDocumentBuilder();
            db.setEntityResolver(new EntityResolver() {
                public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException {
                    InputSource inputsource = new InputSource();
                    inputsource.setByteStream(XmlBeanFactory.class.getResource("spring-beans.dtd").openStream());
                    return inputsource;
                }
            });
            String path = ServerBeanFactoryUtils.getApplicationContext().getServletContext().getRealPath("");
            String initParameter = ServerBeanFactoryUtils.getApplicationContext().getServletContext().getInitParameter("contextConfigLocation");
            String res[] = initParameter.split(" ");
            for(String r : res) {
                if(r.contains("applicationContext")){
                    path = path + r;
                    break;
                }
            }
            Document doc = db.parse(path);
            NodeList list = (NodeList) doc.getElementsByTagName("list");
            NodeList values = ((Element) list.item(0)).getElementsByTagName("value");
            String[] hbm = new String[values.getLength()];
            for (int i = 0; i < hbm.length; i++) {
                hbm[i] = values.item(i).getFirstChild().getNodeValue();
            }

            LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
            bean.setDataSource(DataSourceUtils.findDataSource(dataSourceName));
            bean.setMappingResources(hbm);
            Properties porp = new Properties();
            porp.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
            porp.setProperty("hibernate.show_sql", "true");
            porp.setProperty("hibernate.generate_statistics", "ture");
            bean.setHibernateProperties(porp);
            bean.afterPropertiesSet();
            sessionFactory = (SessionFactory) bean.getObject();
            map.put(dataSourceName,sessionFactory);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return sessionFactory;
}
 
开发者ID:jialiuyang,项目名称:appBack,代码行数:53,代码来源:SessionFactoryCache.java

示例13: getConfiguredOrmPersistenceUnit

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public ConfiguredOrmPersistenceUnit<SessionFactory, Configuration> getConfiguredOrmPersistenceUnit(Object testObject, OrmConfig entityManagerConfig) {
    LocalSessionFactoryBean factoryBean = createSessionFactoryBean(testObject, entityManagerConfig);
    SessionFactory entityManagerFactory = (SessionFactory) factoryBean.getObject();
    Configuration hibernateConfiguration = factoryBean.getConfiguration();
    return new ConfiguredOrmPersistenceUnit<SessionFactory, Configuration>(entityManagerFactory, hibernateConfiguration);
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:7,代码来源:HibernateSessionFactoryLoader.java

示例14: getHibernateFactoryBean

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public LocalSessionFactoryBean getHibernateFactoryBean() {
  return _hibernateFactoryBean;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:4,代码来源:DbConnectorFactoryBean.java

示例15: setHibernateFactoryBean

import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public void setHibernateFactoryBean(LocalSessionFactoryBean hibernateFactoryBean) {
  _hibernateFactoryBean = hibernateFactoryBean;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:4,代码来源:DbConnectorFactoryBean.java


注:本文中的org.springframework.orm.hibernate3.LocalSessionFactoryBean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。