List of usage examples for org.hibernate.cfg Configuration configure
public Configuration configure() throws HibernateException
From source file:raphdine.comptes.service.ServiceLocator.java
private ServiceLocator() { Configuration configuration = new Configuration(); configuration.addAnnotatedClass(Ecriture.class); if ("DESKTOP-M0G63FK".equals(System.getenv("COMPUTERNAME"))) { configuration.setProperty("hibernate.connection.url", "jdbc:h2:D:\\Dropbox\\Partage\\Didine\\Comptes\\Appli\\Data\\Comptes"); } else {// w w w . ja v a2 s. com configuration.setProperty("hibernate.connection.url", "jdbc:h2:N:\\raphiki\\Dropbox\\Partage\\Didine\\Comptes\\Appli\\Data\\Comptes"); } configuration.setProperty("connection.driver_class", "org.h2.Driver"); configuration.setProperty("dialect", "org.hibernate.dialect.H2Dialect"); configuration.setProperty("hibernate.default_schema", "ecritures"); configuration.setProperty("show_sql", "true"); configuration.configure(); ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()) .build(); sf = configuration.buildSessionFactory(sr); }
From source file:ResourcesPools.HibernateSessionManager.java
private static SessionFactory buildSessionFactory() { try {/*from ww w. j a v a 2 s .c o m*/ // Create the SessionFactory from hibernate.cfg.xml Configuration configuration = new Configuration(); configuration.configure(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); return new Configuration().configure().buildSessionFactory(serviceRegistry); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
From source file:ru.apertum.qsky.ejb.HibernateEJB.java
License:Open Source License
protected SessionFactory getFactory() { if (sessionFactory == null) { try {/*from www . j av a 2 s . co m*/ // Create the SessionFactory from standard (hibernate.cfg.xml) // config file. final Configuration configuration = new Configuration(); configuration.configure(); final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { // Log the exception. System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } return sessionFactory; }
From source file:Search.DeleteMov.java
protected int deleteMovie(String movname) { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); Session session = new Configuration().configure().buildSessionFactory(serviceRegistry).openSession(); Transaction tx = null;/* www. ja v a 2 s .c o m*/ try { tx = session.beginTransaction(); String hql = "DELETE FROM GS_Movie " + "WHERE name = :movname"; Query query = session.createQuery(hql); query.setParameter("movname", movname); result = query.executeUpdate(); System.out.println("Rows affected: " + result); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); return result; } }
From source file:Search.GetHistory.java
public static void listHistory() { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); Session session = new Configuration().configure().buildSessionFactory(serviceRegistry).openSession(); String date;/*from w ww .j a v a 2 s . co m*/ Transaction tx = null; try { tx = session.beginTransaction(); String qry1 = "select hr.date FROM GS_HistoryRes hr"; Query q1 = session.createQuery(qry1); List l1 = q1.list(); ListIterator li1 = l1.listIterator(); //System.out.println(l1); getCount = l1.size(); System.out.println(getCount); strHistory = new String[getCount * 4]; int counter = 0; int iter = 0; try { for (int i = 0; i < getCount; i++) { date = (String) li1.next().toString(); //System.out.println(date); String qry2 = "FROM GS_History h where h.date=:date"; Query q2 = session.createQuery(qry2); q2.setParameter("date", date); List l2 = q2.list(); for (Iterator iterator = l2.iterator(); iterator.hasNext();) { if (iter < 11) { GS_History movieaaa = (GS_History) iterator.next(); //strHistory[counter]=history.getDate()+","+history.getName()+","+history.getPlot()+","+history.getYear(); /* System.out.println(history.getDate()); System.out.println(history.getId()); System.out.println(history.getName()); System.out.println(history.getPlot()); System.out.println(history.getYear());*/ System.out.println(iter); switch (iter) { case 0: moviename1 = movieaaa.getName(); movieplot1 = movieaaa.getPlot(); movieyear1 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename1); System.out.println("Plot: " + movieplot1); System.out.println("Year: " + movieyear1); break; case 1: moviename2 = movieaaa.getName(); movieplot2 = movieaaa.getPlot(); movieyear2 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename2); System.out.println("Plot: " + movieplot2); System.out.println("Year: " + movieyear2); break; case 2: moviename3 = movieaaa.getName(); movieplot3 = movieaaa.getPlot(); movieyear3 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename3); System.out.println("Plot: " + movieplot3); System.out.println("Year: " + movieyear3); break; case 3: moviename4 = movieaaa.getName(); movieplot4 = movieaaa.getPlot(); movieyear4 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename4); System.out.println("Plot: " + movieplot4); System.out.println("Year: " + movieyear4); break; case 4: moviename11 = movieaaa.getName(); movieplot11 = movieaaa.getPlot(); movieyear11 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename11); System.out.println("Plot: " + movieplot11); System.out.println("Year: " + movieyear11); break; case 5: moviename21 = movieaaa.getName(); movieplot21 = movieaaa.getPlot(); movieyear21 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename21); System.out.println("Plot: " + movieplot21); System.out.println("Year: " + movieyear21); break; case 6: moviename31 = movieaaa.getName(); movieplot31 = movieaaa.getPlot(); movieyear31 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename31); System.out.println("Plot: " + movieplot31); System.out.println("Year: " + movieyear31); break; case 7: moviename41 = movieaaa.getName(); movieplot41 = movieaaa.getPlot(); movieyear41 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename41); System.out.println("Plot: " + movieplot41); System.out.println("Year: " + movieyear41); break; case 8: moviename12 = movieaaa.getName(); movieplot12 = movieaaa.getPlot(); movieyear12 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename12); System.out.println("Plot: " + movieplot12); System.out.println("Year: " + movieyear12); break; case 9: moviename22 = movieaaa.getName(); movieplot22 = movieaaa.getPlot(); movieyear22 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename22); System.out.println("Plot: " + movieplot22); System.out.println("Year: " + movieyear22); break; case 10: moviename32 = movieaaa.getName(); movieplot32 = movieaaa.getPlot(); movieyear32 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename32); System.out.println("Plot: " + movieplot32); System.out.println("Year: " + movieyear32); break; case 11: moviename42 = movieaaa.getName(); movieplot42 = movieaaa.getPlot(); movieyear42 = String.valueOf(movieaaa.getYear()); System.out.println("Rec Movie name: " + moviename42); System.out.println("Plot: " + movieplot42); System.out.println("Year: " + movieyear42); break; } } counter++; iter++; } } } catch (Exception e) { System.out.println(e); } } catch (Exception e) { System.out.println(e); } }
From source file:Search.GetMovies.java
public static void listMovies(String movname) { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); Session session = new Configuration().configure().buildSessionFactory(serviceRegistry).openSession(); /*double p1[]={0.1,0.2,0.3,0.4}; double p2[]={0.15,0.2,0.4,0.25};*/ Transaction tx = null;/*from www .j a v a2 s. c om*/ try { tx = session.beginTransaction(); System.out.println(movname); String qry = "select m.movid from GS_Movie m where m.name= :movname"; Query p1 = session.createQuery(qry); p1.setParameter("movname", movname); List p11 = p1.list(); try { //System.out.println(p11.iterator().next()); String movid = (String) p11.iterator().next(); //System.out.println(movid); Query qrya = session.createQuery("From GS_Movkld l where l.movid=:movid"); qrya.setParameter("movid", movid); List movies1 = qrya.list(); Iterator iterator1 = movies1.iterator(); GS_Movkld moviea = (GS_Movkld) iterator1.next(); ArrayList<Double> m1 = new ArrayList<Double>(); m1.add(moviea.getAction()); m1.add(moviea.getAdventure()); m1.add(moviea.getAnimation()); m1.add(moviea.getComedy()); m1.add(moviea.getCrime()); m1.add(moviea.getDrama()); //Query qry1=session.createQuery("From GS_Movkld"); // qry1.setParameter("movid", movid); Query qryb = session.createQuery("From GS_Movkld l where l.movid!=:movid"); qryb.setParameter("movid", movid); List movies = qryb.list(); int i = 0; HashMap<String, Double> map = new HashMap<String, Double>(); // ValueComparator bvc = new ValueComparator(map); // TreeMap<String,Double> sorted_map = new TreeMap<String,Double>(bvc); //System.out.println(movies); for (Iterator iterator = movies.iterator(); iterator.hasNext();) { GS_Movkld movie = (GS_Movkld) iterator.next(); ArrayList<Double> m2 = new ArrayList<>(); m2.add(movie.getAction()); m2.add(movie.getAdventure()); m2.add(movie.getAnimation()); m2.add(movie.getComedy()); m2.add(movie.getCrime()); m2.add(movie.getDrama()); double[] m11 = Doubles.toArray(m1); double[] m22 = Doubles.toArray(m2); //Double temp = KLDivergence.klDivergence(m11, m22); Double temp; if ((temp = KLDivergence.klDivergence(m11, m22)) <= 0.29999876) { /* System.out.println("Movie #" + i); System.out.println("Action: " + movie.getAction()); System.out.println("Comedy: " + movie.getComedy()); System.out.println("Drama: " + movie.getDrama()); i++;*/ map.put(movie.getMovid(), temp); } else { //System.out.println("Not recommended"); continue; } } ArrayList as = new ArrayList(map.entrySet()); Collections.sort(as, new Comparator() { public int compare(Object o1, Object o2) { Map.Entry e1 = (Map.Entry) o1; Map.Entry e2 = (Map.Entry) o2; Double first = (Double) e1.getValue(); Double second = (Double) e2.getValue(); return first.compareTo(second); } }); //List as1=as.subList(0, 5); Iterator j = as.iterator(); while (j.hasNext() && i < 5) { //System.out.println( (Map.Entry)j.next()); System.out.println(((Map.Entry) j.next()).getKey()); i++; } tx.commit(); } catch (NoSuchElementException nsee) { System.out.println("No Such Movie Found!!"); } // response.sendRedirect("localhost:8080/RecSysJava"); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } }
From source file:Search.UpdateMovie.java
private void updateMov(String name, String year, String plot, String dir, String prod, String movid, String cast, String genre) { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); Session session = new Configuration().configure().buildSessionFactory(serviceRegistry).openSession(); Transaction tx = null;//from w w w. j ava 2 s. com try { tx = session.beginTransaction(); String hql = "UPDATE GS_Movie m set m.year = :year, m.plot=:plot, m.cast=:cast, m.genre=:genre, m.director=:dir, m.producer=:prod " + "WHERE m.movid = :movid"; Query query = session.createQuery(hql); query.setParameter("year", year); query.setParameter("plot", plot); query.setParameter("cast", cast); query.setParameter("dir", dir); query.setParameter("prod", prod); query.setParameter("movid", movid); query.setParameter("genre", genre); int result = query.executeUpdate(); System.out.println("Rows affected: " + result); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } }
From source file:sk.fri.uniza.hibernate.Main.java
public static void main(String[] args) { Configuration conf = new Configuration(); conf.configure(); StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); SessionFactory buildSessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); Session session = buildSessionFactory.openSession(); session.beginTransaction();//from ww w.ja v a2s. co m Student student = new Student(new Date(), "Bod", 26); Lecturer lecturer = new Lecturer("KTK", "Martin", 27); Person person = new Person("Jozef", 35); session.save(person); session.save(student); session.save(lecturer); session.getTransaction().commit(); session.close(); StandardServiceRegistryBuilder.destroy(registry); }
From source file:smsims.db.DbOperation.java
private static SessionFactory configureSessionFactory() throws HibernateException { Configuration configuration = new Configuration(); configuration.configure(); Properties properties = configuration.getProperties(); serviceRegistry = new ServiceRegistryBuilder().applySettings(properties).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; }
From source file:sos.ftphistory.db.JadeHistorySelector.java
License:Apache License
private Session getSession() { Configuration configuration = new Configuration(); configuration.configure(); sessionFactory = configuration.buildSessionFactory(); Session session = sessionFactory.openSession(); sessionFactory.openSession();// www .j av a 2 s . co m return session; }