本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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);
}