List of usage examples for org.hibernate.cfg Configuration buildSessionFactory
public SessionFactory buildSessionFactory() throws HibernateException
From source file:com.oracle.coherence.hibernate.cachestore.HibernateCacheLoader.java
License:CDDL license
/** * Constructor which accepts an entityName and a Hibernate configuration * resource. The current implementation instantiates a SessionFactory per * instance (implying one instance per CacheStore-backed NamedCache). * * @param sEntityName Hibernate entity (i.e. the HQL table name) * @param sResource Hibernate config classpath resource (e.g. hibernate.cfg.xml) *///from w ww. j a v a 2s .co m public HibernateCacheLoader(String sEntityName, String sResource) { m_sEntityName = sEntityName; /* If we start caching these we need to be aware that the resource may be relative (and so we should not key the cache by resource name). */ Configuration configuration = new Configuration(); configuration.configure(sResource); m_sessionFactory = configuration.buildSessionFactory(); }
From source file:com.oracle.coherence.hibernate.cachestore.HibernateCacheLoader.java
License:CDDL license
/** * Constructor which accepts an entityName and a Hibernate configuration * resource. The current implementation instantiates a SessionFactory per * instance (implying one instance per CacheStore-backed NamedCache). * * @param sEntityName Hibernate entity (i.e. the HQL table name) * @param configurationFile Hibernate config file (e.g. hibernate.cfg.xml) */// w w w.j a v a2 s. c o m public HibernateCacheLoader(String sEntityName, File configurationFile) { m_sEntityName = sEntityName; /* If we start caching these we should cache by canonical file name. */ Configuration configuration = new Configuration(); configuration.configure(configurationFile); m_sessionFactory = configuration.buildSessionFactory(); }
From source file:com.ordecon.schmoo.Communication.java
License:Creative Commons License
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException { PropertyConfigurator.configure("log4j.cfg"); Logger log = Logger.getLogger(Communication.class); log.info("Schmoo Server starting..."); Configuration configuration = new Configuration().configure(new File("hibernate.cfg.xml")); SessionFactory sf = configuration.buildSessionFactory(); Class c = Class.forName("com.ordecon.schmoo.smsc.modules.http.HTTPConnector"); Connector con = (Connector) c.newInstance(); //con.$sendTestMessage(); Session s = sf.openSession();/* w ww .ja v a 2s . c o m*/ ModuleTemplate ct = (ModuleTemplate) s.load(ModuleTemplate.class, 1); log.info(ct); for (Object o : ct.getParameters()) { ModuleParameterTemplate parameterTemplate = (ModuleParameterTemplate) o; log.info(parameterTemplate); } }
From source file:com.payment.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { HttpSession session = request.getSession(); Calendar cal = Calendar.getInstance(); String month = new SimpleDateFormat("MMM").format(cal.getTime()); String concept = request.getParameter("concept"); String flat = (String) session.getAttribute("flat"); // String month = request.getParameter("month"); int amount = Integer.parseInt(request.getParameter("amount")); Pay pay = new Pay(); pay.setAmount(amount);//from w w w. j ava 2 s .c o m pay.setConcept(concept); pay.setFlat(flat); pay.setMonth(month); String email = (String) session.getAttribute("email"); paymentmail pxx = new paymentmail(); int n = pxx.send(email, amount, month); if (n == 0) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file SessionFactory factory = cfg.buildSessionFactory(); Session session1 = factory.openSession(); Transaction t = session1.beginTransaction(); session1.persist(pay); t.commit(); session1.close(); request.setAttribute("success", "suc"); RequestDispatcher rd = request.getRequestDispatcher("account.jsp"); rd.forward(request, response); } else { request.setAttribute("success", "err"); RequestDispatcher rd = request.getRequestDispatcher("account.jsp"); rd.forward(request, response); } } catch (Exception e) { } }
From source file:com.persistent.cloudninja.utils.SessionFactoryConfigurer.java
License:Apache License
public SessionFactory createSessionFactoryForTenant(String tenantDB) { TenantDataConnectionEntity dataConnectionEntity = tenantDataConnectionDao.find(tenantDB.substring(4)); StringBuffer strBufServerURL = new StringBuffer("jdbc:sqlserver://"); strBufServerURL.append(dataConnectionEntity.getServer()); strBufServerURL.append(";databaseName="); strBufServerURL.append(tenantDB);/*from w ww. j a va 2 s . c o m*/ strBufServerURL.append(";"); String userName = dataConnectionEntity.getUser(); String password = dataConnectionEntity.getPassword(); Configuration cfg = new Configuration(); cfg.addClass(TaskList.class); cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect"); cfg.setProperty("hibernate.show_sql", "true"); cfg.setProperty("hibernate.hbm2ddl.auto", "update"); cfg.setProperty("hibernate.connection.driver_class", driverClassName); cfg.setProperty("hibernate.connection.url", strBufServerURL.toString()); cfg.setProperty("hibernate.connection.username", userName); cfg.setProperty("hibernate.connection.password", password); return cfg.buildSessionFactory(); }
From source file:com.plexobject.testplayer.dao.hibernate.HibernateUtil.java
License:Open Source License
/** * Rebuild the SessionFactory with the given Hibernate Configuration. * <p>// www . jav a2 s .c o m * HibernateUtil does not configure() the given Configuration object, * it directly calls buildSessionFactory(). This method also closes * the old static variable SessionFactory before, if it is still open. * * @param cfg */ public static void rebuildSessionFactory(Configuration cfg) { log.debug("Rebuilding the SessionFactory from given Configuration"); if (sessionFactory != null && !sessionFactory.isClosed()) sessionFactory.close(); if (cfg.getProperty(Environment.SESSION_FACTORY_NAME) != null) { log.debug("Managing SessionFactory in JNDI"); cfg.buildSessionFactory(); } else { log.debug("Holding SessionFactory in static variable"); sessionFactory = cfg.buildSessionFactory(); } configuration = cfg; }
From source file:com.quix.aia.cn.imo.database.HibernateFactory.java
License:Open Source License
public static SessionFactory buildSessionFactory() throws HibernateException { if (sessionFactory != null) { closeFactory();//from www. j a va 2 s. c o m } Configuration configuration = new Configuration(); configuration.configure(); sessionFactory = configuration.buildSessionFactory(); return sessionFactory; }
From source file:com.r573.enfili.common.resource.db.hibernate.HibernateManager.java
License:Apache License
public static void init(Configuration configuration) { sessionFactory = configuration.buildSessionFactory(); }
From source file:com.rapid.develop.core.system.dal.SessionFactoryBuilder.java
License:Apache License
/** * System.//from w w w . ja v a2s . c o m * * <p>Javassit??</p> * * @return SessionFactory */ public synchronized SessionFactory getEntitySessionFactory() { if (this.entitySessionFactory == null) { URL url = SessionFactoryBuilder.class.getResource(AppConfigure.HIBERNATE_CFG_XML); Configuration configuration = new Configuration().configure(url); AppConfigure appConfigure = AppConfigure.loadConfig(); for (String key : appConfigure.getConfigurationValues().keySet()) { configuration.setProperty(key, appConfigure.getConfigurationValues().get(key)); } configuration.setProperty("hibernate.hbm2ddl.auto", "create"); configuration.addAnnotatedClass(Application.class); configuration.addAnnotatedClass(AppPlugin.class); configuration.addAnnotatedClass(AppPluginConfig.class); configuration.addAnnotatedClass(AppRestService.class); configuration.addAnnotatedClass(AppServiceClass.class); configuration.addAnnotatedClass(EntityDefination.class); configuration.addAnnotatedClass(FieldDefination.class); entitySessionFactory = configuration.buildSessionFactory(); } return this.entitySessionFactory; }
From source file:com.rdsic.pcm.common.HibernateUtil.java
private static void initSessionFactory(String cfgFile) { if (sessionFactory == null) { try {//from ww w . j av a2 s. c o m System.out.println("Loading hibernate configuration..."); org.hibernate.cfg.Configuration hconfig = new org.hibernate.cfg.Configuration().configure(cfgFile); hconfig.setProperty("hibernate.connection.driver_class", Configuration.getString(Constant.CONFIG_KEY.PCM_DB_DRIVER)); hconfig.setProperty("hibernate.connection.url", Configuration.getString(Constant.CONFIG_KEY.PCM_DB_URL)); hconfig.setProperty("hibernate.connection.username", Configuration.getString(Constant.CONFIG_KEY.PCM_DB_USER)); hconfig.setProperty("hibernate.connection.password", Configuration.getString(Constant.CONFIG_KEY.PCM_DB_PASSWORD)); sessionFactory = hconfig.buildSessionFactory(); System.out.println("Hibernate load completed..."); } catch (Throwable ex) { log.error("Initial SessionFactory creation failed.", ex); throw new ExceptionInInitializerError(ex); } } }