Package org.myphotodiary.model

Examples of org.myphotodiary.model.SessionConfiguration


      return;
    }

    EntityManager em = ModelFactory.getEntityManager();
    EntityTransaction tx = null;
    SessionConfiguration sessionConfig = null;
    try {
      tx = em.getTransaction();
      tx.begin();

      // Get the directory description data from database
      sessionConfig = em.createQuery(
          "select config from SessionConfiguration config where config.user = ?1 and config.pwd = ?2", SessionConfiguration.class)
          .setParameter(1, user).setParameter(2, pwd).getSingleResult();

    } catch (Exception ex) {
      sessionConfig = new SessionConfiguration(user, pwd);
      em.persist(sessionConfig);
      getServletContext().log("No configuration data for: " + user + ". Set default configuration", ex);
    }
    finally {
      // Reply the Json response
View Full Code Here


   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    getServletContext().log("-> SessionConfigurationSvr.doPost()\nParameters= " + request.getParameterMap().toString());
    // Extract request parameters
    SessionConfiguration newConfig = null;
    try {
      newConfig = SessionConfiguration.decode(request.getInputStream());
    }
    catch (Exception ex) {
      getServletContext().log("Cannot decode POSTed configuration parameters", ex);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // Persist the session configuration into database
    EntityManager em = ModelFactory.getEntityManager();
    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();
      SessionConfiguration oldConfig = null;
      // search if old configuration exists, or create it
      try {
        TypedQuery<SessionConfiguration> query = em.createQuery(
            "select config from SessionConfiguration config where config.user = ?1 and config.pwd = ?2", SessionConfiguration.class)
            .setParameter(1, newConfig.getUser()).setParameter(2, newConfig.getPwd());
        oldConfig = query.getSingleResult();
        oldConfig.update(newConfig);
        em.merge(oldConfig);
      } catch (NoResultException ex) {
        getServletContext().log("No directory data for: " + newConfig.getUser(), ex);
        em.persist(newConfig);
      }
View Full Code Here

TOP

Related Classes of org.myphotodiary.model.SessionConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.