List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:appHibernateSebastianLeonte.Main.java
public static void consulta() { SessionFactory session = SessionFactoryUtil.getSessionFactory(); Session s = session.openSession();//from ww w . ja v a2s.co m Transaction transaction = s.beginTransaction(); System.out.println("Modificando"); Vuelos vuelo = new Vuelos(); Query q = s.createQuery("from Vuelos where Destino='BARCELONA' or Destino='MADRID'"); List<Vuelos> listaVuelo = q.list(); Iterator<Vuelos> iter = listaVuelo.iterator(); while (iter.hasNext()) { vuelo = (Vuelos) iter.next(); System.out.println("PROCEDENCIA: " + vuelo.getProcedencia() + "\t"); System.out.println("DESTINO: " + vuelo.getDestino() + "\t"); System.out.println("HORA DE SALIDA: " + vuelo.getHoraSalida()); } s.close(); session.close(); }
From source file:arche.modifChangeImpact.ModifChangeImpactRFView.java
License:Open Source License
private void stopReasoningFramework() { try {/* www . j a va 2s.co m*/ rf.stop(); // Close Hibernate SessionFactory sf = ArchECoreDataProvider.getSessionFactory(); if (sf != null) sf.close(); } catch (ArchEException e) { e.printStackTrace(); } }
From source file:basedistribuida.connection.Connection.java
public static void dispose(SessionFactory sessionFactory) { sessionFactory.close(); }
From source file:br.com.caelum.vraptor.hibernate.SessionFactoryCreator.java
License:Open Source License
public void destroy(@Disposes SessionFactory sessionFactory) { LOGGER.debug("destroying session factory"); sessionFactory.close(); }
From source file:br.com.machina.verbum.Main.java
License:Apache License
private static void addAdministratorUser() { AnnotationConfiguration configuration = new AnnotationConfiguration(); configuration.configure();//from w w w.ja va2s . c om SessionFactory sessionFactory = configuration.buildSessionFactory(); Session session = null; Transaction transaction = null; try { session = sessionFactory.openSession(); transaction = session.beginTransaction(); User user = new User(); user.setName(ask("Please type your name:")); user.setLogin(ask("Please type your login:")); final String password = ask("Please type your password:"); user.setEmail(ask("Please type your e-mail:")); Sha1PasswordEncrypter encrypter = new Sha1PasswordEncrypter(); user.setPassword(encrypter.encrypt(password)); user.setAdministrator(true); session.save(user); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); } finally { if (session != null) { session.close(); } sessionFactory.close(); } }
From source file:br.com.sgejs.database.ConexaoBanco.java
public void fechaConexao(@Disposes SessionFactory factory) { factory.close(); }
From source file:br.udesc.ceplan.prog3.hibernate.ExemploHibernate.java
/** * @param args the command line arguments */// ww w. ja va2 s . c o m public static void main(String[] args) throws Exception { SessionFactory sessFact = NewHibernateUtil.getSessionFactory(); Session session = sessFact.getCurrentSession(); org.hibernate.Transaction tr = session.beginTransaction(); Employee emp; emp = new Employee(); emp.setEmpName("TESTE 01"); emp.setEmpMobileNos("11111111111"); emp.setEmpAddress("ENDEREO TESTE 01"); session.save(emp); emp = new Employee(); emp.setEmpName("TESTE 02"); emp.setEmpMobileNos("22222222222"); emp.setEmpAddress("ENDEREO TESTE 02"); session.save(emp); emp = new Employee(); emp.setEmpName("TESTE 03"); emp.setEmpMobileNos("333333333333"); emp.setEmpAddress("ENDEREO TESTE 03"); session.save(emp); tr.commit(); System.out.println("Successfully inserted"); printData(); sessFact.close(); }
From source file:com.akatkar.winerydemoproject.Application.java
public static void main(String[] args) { System.out.println("running ..."); SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try {/* www . j a va 2 s. c o m*/ } finally { session.close(); sessionFactory.close(); } }
From source file:com.akursat.ws.UserServiceImpl.java
@Override public String find(String username) { Transaction trns = null;/*from w w w . j a v a 2 s. c o m*/ SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try { trns = session.beginTransaction(); Query query = session.createQuery("from Users where username=:username_param") .setParameter("username_param", username); List<Users> users = query.list(); if (users.isEmpty()) { return "Empty"; } else if (users.size() == 1) { return users.get(0).getEmail() + users.get(0).getBirthday() + users.get(0).getSex(); } session.getTransaction().commit(); sessionFactory.close(); } catch (RuntimeException e) { if (trns != null) { trns.rollback(); } e.printStackTrace(); } finally { session.flush(); session.close(); } return ""; }
From source file:com.autobizlogic.abl.logic.dynamic.Deployer.java
License:Open Source License
/** * Deploy a jar into a database for use by DatabaseClassManager. * @param props Should contain the required parameters: * <ul>//from w ww. j ava2s . co m * <li>either HIB_CFG_FILE (Hibernate config file path as a string) or * HIB_CFG as a Hibernate Configuration object * <li>PROJECT_NAME: the name of the project to deploy to (will be created if it does not exist) * <li>JAR_FILE_NAME: the path of the jar file to deploy, as a String * <li>EFFECTIVE_DATE: the date/time at which the new logic classes should take effect, * as a java.util.Date (optional) * </ul> * @return Null if everything went OK, otherwise a reason for the failure */ public static String deploy(Properties props) { Logger root = Logger.getRootLogger(); root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN))); Logger.getLogger("org.hibernate").setLevel(Level.WARN); Logger.getLogger("org.hibernate.tool.hbm2ddl").setLevel(Level.DEBUG); Logger.getLogger("org.hibernate.SQL").setLevel(Level.DEBUG); Logger.getLogger("org.hibernate.transaction").setLevel(Level.DEBUG); Configuration config; if (props.get(HIB_CFG) == null) { config = new Configuration(); File cfgFile = new File((String) props.get(HIB_CFG_FILE)); config.configure(cfgFile); } else config = (Configuration) props.get(HIB_CFG); if (config.getClassMapping(Project.class.getName()) == null) { config.addAnnotatedClass(Project.class); config.addAnnotatedClass(LogicFile.class); config.addAnnotatedClass(LogicFileLog.class); } SessionFactory sessFact = config.buildSessionFactory(); Session session = sessFact.getCurrentSession(); Transaction tx = session.beginTransaction(); Query query = session.createQuery("from Project where name = :name").setString("name", (String) props.get(PROJECT_NAME)); Project project = (Project) query.uniqueResult(); if (project == null) { project = new Project(); project.setName((String) props.get(PROJECT_NAME)); session.save(project); } LogicFile logicFile = new LogicFile(); String fileName = (String) props.get(JAR_FILE_NAME); String shortFileName = fileName; if (fileName.length() > 300) shortFileName = fileName.substring(0, 300); logicFile.setName(shortFileName); logicFile.setCreationDate(new Timestamp(System.currentTimeMillis())); File jarFile = new File((String) props.get(JAR_FILE_NAME)); try { FileInputStream inStr = new FileInputStream(fileName); Blob blob = session.getLobHelper().createBlob(inStr, jarFile.length()); logicFile.setContent(blob); } catch (Exception ex) { throw new RuntimeException("Error while storing jar file into database", ex); } Date effDate = (Date) props.get(EFFECTIVE_DATE); logicFile.setEffectiveDate(new Timestamp(effDate.getTime())); logicFile.setProject(project); session.save(logicFile); tx.commit(); sessFact.close(); return null; }