本文整理汇总了Java中net.sf.hibernate.SessionFactory类的典型用法代码示例。如果您正苦于以下问题:Java SessionFactory类的具体用法?Java SessionFactory怎么用?Java SessionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SessionFactory类属于net.sf.hibernate包,在下文中一共展示了SessionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
/**
* Specify the underlying <tt>SessionFactory</tt>, by passing a JNDI name.
* The <tt>accessMode</tt> is ignored by Hibernate.
* @see org.odmg.Database#open(String, int)
*/
public void open(String name, int accessMode) throws ODMGException {
try {
new Configuration().configure();
}
catch (HibernateException he) {
throw new ODMGException( he.getMessage() );
}
sessionFactory = (SessionFactory) SessionFactoryObjectFactory.getNamedInstance(name);
if (sessionFactory==null) throw new ODMGException("No SessionFactory was associated with the given JDNI name");
/*try {
sessionFactory = (SessionFactory) NamingHelper.getInitialContext( Environment.getProperties() ).lookup(name);
}
catch (NamingException ne) {
throw new ODMGException( ne.getMessage() );
}*/
}
示例2: hibernateInit
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
@Ignore
@Test
public void hibernateInit() throws Exception
{
Database.init();
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
// Filter-time code (H3SessionAjaxFilter)
transaction.commit();
// Shutdown code, when do we need to do this?
sessionFactory.close();
}
示例3: initSessionFactory
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
private static SessionFactory initSessionFactory(String fileName){
SessionFactory sf = null;
try{
/**
* We will use this commented out the style for creating sessionfactory
*/
//URL url = ClassLoader.getSystemResource(fileName);
//String file_name = url.getFile();
//File f = new File(file_name);
//File f = new File("config/myfile.cfg.xml");
//sf = new Configuration().configure(f).buildSessionFactory();
sf = new Configuration().configure().buildSessionFactory();
if(sf!=null){
System.out.println("Message from ApplicationSessionFactory: Got Session !");
}else{
System.out.println("Message from ApplicationSessionFactory: could not get Session !");
}
}catch(Exception ex){
ex.printStackTrace();
}
return sf;
}
示例4: initSessionFactory
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
private static SessionFactory initSessionFactory(String fileName){
SessionFactory sf = null;
try{
/**
* We will use this commented out the style for creating sessionfactory
*/
File f = new File(fileName);
//File f = new File("config/myfile.cfg.xml");
sf = new Configuration().configure(f).buildSessionFactory();
//sf = new Configuration().configure().buildSessionFactory();
}catch(Exception ex){
ex.printStackTrace();
}
return sf;
}
示例5: initSessionFactory
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
private static SessionFactory initSessionFactory(String fileName){
SessionFactory sf = null;
try{
/**
* We will use this commented out the style for creating sessionfactory
*/
File f = new File(fileName);
//File f = new File("config/myfile.cfg.xml");
sf = new Configuration().configure(f).buildSessionFactory();
//sf = new Configuration().configure().buildSessionFactory();
}catch(Exception ex){
ex.printStackTrace();
}
return sf;
}
示例6: buildSessionFactory
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
/**
* Instantiate a new <tt>SessionFactory</tt>, using the properties and
* mappings in this configuration. The <tt>SessionFactory</tt> will be
* immutable, so changes made to the <tt>Configuration</tt> after
* building the <tt>SessionFactory</tt> will not affect it.
*
* @see net.sf.hibernate.SessionFactory
* @return a new factory for <tt>Session</tt>s
*/
public SessionFactory buildSessionFactory() throws HibernateException {
secondPassCompile();
validate();
Environment.verifyProperties(properties);
Properties copy = new Properties();
copy.putAll(properties);
Settings settings = buildSettings();
configureCaches(settings);
return new SessionFactoryImpl(this, settings);
}
示例7: getImpl
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
private synchronized SessionFactory getImpl() {
if (impl==null) {
try {
impl = service.buildSessionFactory();
}
catch (Exception e) {
throw new LazyInitializationException(e);
}
}
return impl;
}
示例8: stop
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
public void stop() {
log.info("stopping service");
try {
InitialContext context = NamingHelper.getInitialContext( getProperties() );
( (SessionFactory) context.lookup(boundName) ).close();
//context.unbind(boundName);
}
catch (Exception e) {
log.warn("exception while stopping service", e);
}
}
示例9: addInstance
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
public static void addInstance(String uid, String name, SessionFactory instance, Properties properties) {
log.debug("registered: " + uid + " (" + ( (name==null) ? "unnamed" : name ) + ')');
INSTANCES.put(uid, instance);
if (name!=null) NAMED_INSTANCES.put(name, instance);
//must add to JNDI _after_ adding to HashMaps, because some JNDI servers use serialization
if (name==null) {
log.info("Not binding factory to JNDI, no JNDI name configured");
}
else {
log.info("Factory name: " + name);
try {
Context ctx = NamingHelper.getInitialContext(properties);
NamingHelper.bind(ctx, name, instance);
log.info("Bound factory to JNDI name: " + name);
( (EventContext) ctx ).addNamingListener(name, EventContext.OBJECT_SCOPE, LISTENER);
}
catch (InvalidNameException ine) {
log.error("Invalid JNDI name: " + name, ine);
}
catch (NamingException ne) {
log.warn("Could not bind factory to JNDI", ne);
}
catch(ClassCastException cce) {
log.warn("InitialContext did not implement EventContext");
}
}
}
示例10: getSessionFactory
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
/**
* Returns session factory
*
* @return session factory
*/
public SessionFactory getSessionFactory() {
if (sessionFactory == null) {
sessionFactory = ServiceManager.getInstance().getConfigurationService().getSessionFactory();
}
return sessionFactory;
}
示例11: getSession
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
protected Session getSession() {
SessionFactory sf = null;
try {
sf = HibernateLocator.getSessionFactory();
Session sessio = sf.openSession();
return sessio;
} catch (HibernateException e) {
throw new EJBException(e);
}finally{
sf = null;
}
}
示例12: init
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
/**
* This method will read configuration file from classpath
* and get the name of the hibernate configuration file.
* Once we know the name of the hibernate config file then
* this method will build the sessionFactory and put in Hashtable.
*
*/
private static void init(){
ApplicationConfiguration ac = ApplicationConfiguration.getInstance();
applicationName = ac.getProperty("applicationName");
String hibernate_config_file_name = ac.getProperty("hibernateConfigFileName");
SessionFactory sf = initSessionFactory(hibernate_config_file_name);
factories.put(applicationName,sf);
}
示例13: init
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
/**
* This method will read configuration file from classpath
* and get the name of the hibernate configuration file.
* Once we know the name of the hibernate config file then
* this method will build the sessionFactory and put in Hashtable.
*
*/
private static void init(){
applicationName="xyz";
String fileName ="";
try{
URL url = ClassLoader.getSystemResource("hibernate.cfg.xml");
fileName = url.getFile();
}catch(Exception ex){
ex.printStackTrace();
}
SessionFactory sf = initSessionFactory(fileName);
factories.put(applicationName,sf);
}
示例14: buildSessionFactory
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
SessionFactory buildSessionFactory() throws HibernateException {
log.info( "starting service at JNDI name: " + boundName );
log.info( "service properties: " + properties );
return getConfiguration().buildSessionFactory();
}
示例15: getSessionFactory
import net.sf.hibernate.SessionFactory; //导入依赖的package包/类
SessionFactory getSessionFactory() {
return sessionFactory;
}