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


Java LocalSessionFactoryBean.getObject方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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


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