本文整理汇总了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;
}
示例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();
}
示例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());
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例8: setLocalSessionFactory
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public void setLocalSessionFactory(LocalSessionFactoryBean localSessionFactory)
{
this.localSessionFactory = localSessionFactory;
}
示例9: getLocalSessionFactory
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public LocalSessionFactoryBean getLocalSessionFactory()
{
return localSessionFactory;
}
示例10: setLocalSessionFactory
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public void setLocalSessionFactory(LocalSessionFactoryBean localSessionFactory)
{
this.cfg = localSessionFactory.getConfiguration();
}
示例11: setSessionFactoryBean
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
@Autowired
public void setSessionFactoryBean(LocalSessionFactoryBean sessionFactoryBean) {
this.sessionFactoryBean = sessionFactoryBean;
}
示例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;
}
示例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);
}
示例14: getHibernateFactoryBean
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public LocalSessionFactoryBean getHibernateFactoryBean() {
return _hibernateFactoryBean;
}
示例15: setHibernateFactoryBean
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; //导入依赖的package包/类
public void setHibernateFactoryBean(LocalSessionFactoryBean hibernateFactoryBean) {
_hibernateFactoryBean = hibernateFactoryBean;
}