Example usage for org.hibernate.cfg Configuration getProperties

List of usage examples for org.hibernate.cfg Configuration getProperties

Introduction

In this page you can find the example usage for org.hibernate.cfg Configuration getProperties.

Prototype

public Properties getProperties() 

Source Link

Document

Get all properties

Usage

From source file:servlet.FindSC.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   www .  j  av a  2 s  .c  o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet FindSC</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet FindSC at " + request.getContextPath() + "</h1>");

        // No try catch, I suppose the connexion will be okey...
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties());
        SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
        Session session = sessionFactory.openSession();
        try {
            String sc_name = '%' + request.getParameter("sc_name").trim() + '%';
            Criteria crit = session.createCriteria(Sr.class);
            crit.add(Restrictions.like("scName", sc_name));
            Iterator it = crit.list().iterator();
            Set<Sr> srs = new HashSet();
            while (it.hasNext()) {
                srs.add((Sr) it.next());
            }
            request.setAttribute("srs", srs);
            session.close();
            getServletConfig().getServletContext().getRequestDispatcher("/FindSC.jsp").forward(request,
                    response);
        } catch (HibernateException he) {
            out.println(he.getMessage() + "<br/>");
            session.close();
        }

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:servlet.NewQoso.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w ww  .  ja v a 2 s  . c om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet NewQoso</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet NewQoso at " + request.getContextPath() + "</h1>");

        // No try catch, I suppose the connexion will be okey...
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties());
        SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
        Session session = sessionFactory.openSession();
        Transaction trans = session.beginTransaction();

        try {

            Qoso qoso = new Qoso();

            session.persist(qoso);
            trans.commit();
            session.close();
            out.println("The creation of this Quality of Service Offered has succeded !!<br/>");
        } catch (HibernateException he) {
            out.println(he.getMessage() + "<br/>");
            //out.println(he.getCause() + "<br/>");
            out.println("The creation of this Quality of Service Offered has failed...<br/>");
            trans.rollback();
            session.close();
        }

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:servlet.NewS.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w w w .j a  va 2s . c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet NewS</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet NewS at " + request.getContextPath() + "</h1>");

        // No try catch, I suppose the connexion will be okey...
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties());
        SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
        Session session = sessionFactory.openSession();
        Transaction trans = session.beginTransaction();

        try {
            //String id = request.getParameter("s_id").trim();
            String name = request.getParameter("s_name").trim();

            Query query = session.createQuery("from data.S s where s.name = :aName");
            query.setParameter("aName", name);
            if ((S) query.uniqueResult() != null) {
                throw new HibernateException(new Throwable("This Service name already exists"));
            }

            S s = new S();
            s.setName(name);

            session.persist(s);
            trans.commit();
            session.close();
            out.println("The creation of this Service has succeded !!<br/>");
        } catch (HibernateException he) {
            out.println(he.getMessage() + "<br/>");
            //out.println(he.getCause() + "<br/>");
            out.println("The creation of this Service has failed...<br/>");
            trans.rollback();
            session.close();
        }
        out.println("</body>");
        out.println("</html>");
    }
}

From source file:servlet.NewSC.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w  ww . j a  v a 2 s .  c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet NewSC</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet NewSC at " + request.getContextPath() + "</h1>");

        // No try catch, I suppose the connexion will be okey...
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties());
        SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
        Session session = sessionFactory.openSession();
        Transaction trans = session.beginTransaction();

        try {
            //String id = request.getParameter("sc_id").trim();
            String name = request.getParameter("sc_name").trim();

            Query query = session.createQuery("from data.Sc sc where sc.name = :aName");
            query.setParameter("aName", name);
            if ((Sc) query.uniqueResult() != null) {
                throw new HibernateException(new Throwable("This Service Capability name already exists"));
            }

            Sc sc = new Sc();
            sc.setName(name);

            /*
             if (!id.equals("")) {
             try {
             int newId = Integer.valueOf(id);                                                
             // Search if this id isn't already used
             Query query = session.createQuery("from data.Sc sc where sc.id = :anId");
             query.setParameter("anId", newId);                                               
             if ((Sc) query.uniqueResult() == null) {
             // This id doesn't exist yet
             sc.setId(newId);                            
             } else {
             throw new HibernateException(new Throwable("This ID already exist"));
             }
             } catch (NumberFormatException ne) {
             throw new HibernateException(new Throwable("This ID isn't an integer"));
             }
             }
             */
            session.persist(sc);
            trans.commit();
            session.close();
            out.println("The creation has succeded !!<br/>");
        } catch (HibernateException he) {
            out.println(he.getMessage() + "<br/>");
            //out.println(he.getCause() + "<br/>");
            out.println("The creation has failed...<br/>");
            trans.rollback();
            session.close();
        }

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:servlet.NewSP.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w ww . j ava 2s. co m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet NewSP</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet NewSP at " + request.getContextPath() + "</h1>");

        // No try catch, I suppose the connexion will be okey...
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties());
        SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
        Session session = sessionFactory.openSession();
        Transaction trans = session.beginTransaction();

        try {

            Sp sp = new Sp();

            session.persist(sp);
            trans.commit();
            session.close();
            out.println("The creation of this Service P ?? has succeded !!<br/>");
        } catch (HibernateException he) {
            out.println(he.getMessage() + "<br/>");
            //out.println(he.getCause() + "<br/>");
            out.println("The creation of this Service P ?? has failed...<br/>");
            trans.rollback();
            session.close();
        }

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:servlet.NewSR.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w ww  .j  a  v  a  2 s  .  c  o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet page1</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet page1 at " + request.getContextPath() + "</h1>");

        try {
            Configuration configuration = new Configuration();
            configuration.configure("hibernate.cfg.xml");
            StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                    .applySettings(configuration.getProperties());
            SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
            Session session = sessionFactory.openSession();
            Transaction trans = session.beginTransaction();

            Query query = session.createQuery("from data.Sc sc where sc.id = :anId");
            query.setParameter("anId", Integer.valueOf(request.getParameter("sc_id")));
            Sc sc = (Sc) query.uniqueResult();
            if (sc == null) {
                throw new HibernateException(new Throwable("The SC_ID doesn't exist"));
            }

            query = session.createQuery("from data.S s where s.id = :anId");
            query.setParameter("anId", Integer.valueOf(request.getParameter("s_id")));
            S s = (S) query.uniqueResult();
            if (sc == null) {
                throw new HibernateException(new Throwable("The S_ID doesn't exist"));
            }

            query = session.createQuery("from data.Sp sp where sp.id = :anId");
            query.setParameter("anId", Integer.valueOf(request.getParameter("sp_id")));
            Sp sp = (Sp) query.uniqueResult();
            if (sp == null) {
                throw new HibernateException(new Throwable("The SP_ID doesn't exist"));
            }

            query = session.createQuery("from data.Qoso qoso where qoso.id = :anId");
            query.setParameter("anId", Integer.valueOf(request.getParameter("qoso_id")));
            Qoso qoso = (Qoso) query.uniqueResult();
            if (qoso == null) {
                throw new HibernateException(new Throwable("The Qoso_ID doesn't exist"));
            }

            Sr sr = new Sr(qoso, s, sc, sp, sc.getName(), s.getName(), request.getParameter("statut"));
            session.persist(sr);
            trans.commit();
            session.close();
            out.println("The creation of this Service Registery has succeded !!<br/>");
        } catch (HibernateException he) {
            out.println(he.getMessage() + "<br/>");
            out.println("The creation of this Service Registery has failed...<br/>");
        }

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:servlet.UpdateSRStatut.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  ww  w .  ja v  a  2s. c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet UpdateSRStatut</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet UpdateSRStatut at " + request.getContextPath() + "</h1>");

        // No try catch, I suppose the connexion will be okey...
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties());
        SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
        Session session = sessionFactory.openSession();
        Transaction trans = session.beginTransaction();

        try {
            int sr_id;
            try {
                sr_id = Integer.valueOf(request.getParameter("sr_id"));
            } catch (NumberFormatException ne) {
                throw new HibernateException(new Throwable("The SR ID isn't a number"));
            }
            Query query = session.createQuery("from data.Sr sr where sr.id = :anId");
            query.setParameter("anId", sr_id);
            Sr sr = (Sr) query.uniqueResult();
            if (sr == null) {
                throw new HibernateException(new Throwable("The SR ID doesn't exist"));
            }
            sr.setStatus(request.getParameter("statut"));
            session.persist(sr);
            trans.commit();
            session.close();
            out.println("The update of the statut has succeded !!<br/>");
        } catch (HibernateException he) {
            out.println(he.getMessage() + "<br/>");
            out.println("The update of the statut has failed...<br/>");
            trans.rollback();
            session.close();
        }

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:SfUtil.SfUtil.java

public SessionFactory SfUtil() {
    Configuration config = new Configuration().configure("hibernate.cfg.xml");
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
            .applySettings(config.getProperties());

    SessionFactory sf = config.buildSessionFactory(builder.build());

    return sf;/*  ww  w.j  av a  2s .  co  m*/
}

From source file:sk.cagani.stuba.bpbp.serverApp.DatabaseConnector.java

public DatabaseConnector() {
    Configuration configuration = new Configuration();
    configuration.configure("hibernate.cfg.xml");
    configuration.addJar(new File("/home/debian/BPbp/target/lib/BPbpDatabaseMapper-1.0.jar"));
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
            .applySettings(configuration.getProperties());
    sessionFactory = configuration.buildSessionFactory(ssrb.build());
    stats = sessionFactory.getStatistics();
    stats.setStatisticsEnabled(true);//from   w  ww .j a v a 2s .co  m
}

From source file:smsims.db.DbOperation.java

private static SessionFactory configureSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration();
    configuration.configure();// w w  w  . j  av a 2  s . co m

    Properties properties = configuration.getProperties();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(properties).buildServiceRegistry();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    return sessionFactory;
}