Exemplo n.º 1
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String op = request.getParameter("op");
    HttpSession session = request.getSession(true);

    Categoria c = new Categoria();
    dao.Dao<Categoria> daoC = new Dao<Categoria>(Categoria.class);
    if (op.equals("Salvar")) {
      c.setNome(request.getParameter("nomeCategoria"));
      daoC.insert(c);

      response.sendRedirect("categoria.jsp");
    }
    if (op.equals("Gerenciar")) {
      session.setAttribute("nomeBusca", "nao");
      response.sendRedirect("GerenciaCategoria.jsp");
    }
    if (op.equalsIgnoreCase("Buscar")) {
      session.setAttribute("nomeBusca", request.getParameter("nomeBusca"));
      response.sendRedirect("GerenciaCategoria.jsp");
    }
    if (op.equals("Atualizar")) {
      c = (Categoria) session.getAttribute("categoria");
      c.setNome(request.getParameter("nomeC"));
      daoC.update(c);
      session.removeAttribute("categoria");
      response.sendRedirect("GerenciaCategoria.jsp");
    }
    if (op.equalsIgnoreCase("OK")) {
      session.removeAttribute("remover");
      response.sendRedirect("GerenciaCategoria.jsp");
    }
  }
  protected int getLastId() throws DaoException {
    if (dao.size() == 0) {
      return 0;
    }

    return ((TaskModel) dao.getAll().get(dao.size() - 1)).getId();
  }
Exemplo n.º 3
0
  public static void main(String args[]) throws Exception {

    // Instantiate our DAO and get connection
    Dao dao = new Dao();
    Connection conn = dao.getConnection();

    // Prepare a callable statement
    // NOTE:  Curly brackets aka braces are required for the call builder
    // to work correctly.  Otherwise it'll actually just treat it as a
    // PreparedStatement, which may or may not be what you want!
    String s1 = "{CALL ADD_SERVICE(?,?,?)}";
    CallableStatement cs = conn.prepareCall(s1);

    // Set variables the usual way
    cs.setString(1, "DUB");
    cs.setString(2, "EWR");
    cs.setString(3, "A380");

    // Execute it
    cs.execute();

    // Get the result set (as usual)
    ResultSet rs = cs.getResultSet();

    // Go to the first result (the only one!) which came from the SELECT
    // statement in the procedure.
    rs.next();

    // Print the flight number to the screen
    System.out.println("New flight number is " + rs.getInt("flightNumber"));
  }
Exemplo n.º 4
0
  public static void main(String[] args) {

    //		StartUpService.startUpData();
    Service.sortTrailerArrival();
    for (Trailer trailer : Dao.getTrailer()) {
      Service.setSubOrderEarliestLoadingTime(trailer);
    }
    StartUpService.sortSubOrdersDao();
    Service.createLoadingBaySchedule(Dao.getSubOrders());
    trailerView = new TrailerView();
    loadingBayView = new LoadingBayView();
    externalSystemView = new ExternalSystemView();
  }
Exemplo n.º 5
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String s1 = request.getParameter("s1");
    // String pass2=request.getParameter("pass2");
    HttpSession session = request.getSession();

    String uname = (String) session.getAttribute("uname");
    Model m = new Model();

    m.setS1(s1);
    //	m.setUname(uname);

    String sql = "delete from register where username=?";
    boolean st = Dao.DeleteUser(m, sql);

    if (st) {
      String msg1 = "Password Changed Successfully.. Login with your new Password";
      request.setAttribute("msg", msg1);
      getServletContext().getRequestDispatcher("/AdminMain.jsp").forward(request, response);

    } else {
      String msg1 = "Password Not Changed";
      request.setAttribute("msg", msg1);
      getServletContext().getRequestDispatcher("/AdminLogin.jsp").forward(request, response);
    }
  }
Exemplo n.º 6
0
 /**
  * Fills a model in the TrailerView dialog.
  *
  * @param trailerState the trailer state that is represented by each model. For example,
  *     TrailerState.LOADING will fill the LoadingModel.
  */
 public static void fillModel(TrailerState trailerState) {
   DefaultListModel<Trailer> model = null;
   switch (trailerState) {
     case ARRIVED:
       model = ReadyModel;
       break;
     case BEING_LOADED:
       model = LoadingModel;
       break;
     case DEPARTED:
       model = DepartedModel;
       break;
     case ENROUTE:
       model = EnRouteModel;
       break;
     case LOADED:
       model = LoadedModel;
       break;
     default:
       break;
   }
   if (model != null) {
     model.clear();
     for (Trailer trailer : Dao.getTrailer()) {
       if (trailer.getTrailerState() == trailerState) {
         model.addElement(trailer);
       }
     }
   }
 }
Exemplo n.º 7
0
  private String sustraerInformacionNodo(CliGol cliGol, Node nodo) {

    String[] excluye = {
      "CLI_ID",
      "CLI_SAP",
      "CliApePat",
      "CliApeMat",
      "CliNom",
      "CLI_FEC_NAC",
      "CLI_DOM_CAL",
      "CLI_DOM_NUM_EXT",
      "CLI_DOM_NUM_INT",
      "CLI_DOM_COL",
      "CLI_POS_ID",
      "CliGolP1",
      "CliGolP8",
      "CliGolP10",
      "CliGolP11",
      "CliGolP15",
      "CliGolP17",
      "CliGolP18",
      "CliGolP25",
      "CliGolResAct",
      "CliGolNumTar",
      "CliGolCtaChe",
      "CliGolCrePer",
      "CliGolCreAut",
      "CliGolCreHip",
      "CliGolOtrCre",
      "CliBurMens",
      "PagRnt",
      "CliGolBurCre",
      "CliBurValr",
      "CliGolIng",
      "CliGolImpRen"
    };

    NodeList variables = nodo.getChildNodes();

    LinkedHashMap[] mapas = obtenerMapeos(cliGol, variables, excluye);

    Dao dao = new Dao();
    Object[] descripciones = dao.ObtenLista(mapas[0], Arrays.asList(excluye));

    // <variable,puntos>,descripciones
    return unirMapeos(mapas[1], descripciones);
  }
Exemplo n.º 8
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String op = request.getParameter("op");
    int id = Integer.parseInt(request.getParameter("id"));
    dao.Dao<Categoria> daoC = new Dao<Categoria>(Categoria.class);
    HttpSession session = request.getSession(true);
    dao.Dao<Livro> daoL = new Dao<Livro>(Livro.class);
    if (op.equalsIgnoreCase("Atualizar")) {
      Categoria c = (Categoria) daoC.get(id);
      session.setAttribute("categoria", c);
    }
    if (op.equals("Remover")) {
      Categoria c = (Categoria) daoC.get(id);
      String nome = c.getNome();
      List<Livro> livro = daoL.list();
      boolean ok = true;
      for (Livro l : livro) {
        if (l.getCategoria().getNome().equals(nome)) {
          ok = false;
          break;
        }
      }
      if (ok == true) {
        daoC.remove(id);
        session.setAttribute("remover", "sim");
      } else {
        session.setAttribute("remover", "nao");
      }
    }

    response.sendRedirect("GerenciaCategoria.jsp");
  }
Exemplo n.º 9
0
 public static void createWestStrings() {
   String st = new String("aaa");
   Dao.addWest(st);
   st = new String("bbb");
   Dao.addWest(st);
   st = new String("ccc");
   Dao.addWest(st);
   st = new String("ddd");
   Dao.addWest(st);
   st = new String("eee");
   Dao.addWest(st);
   st = new String("fff");
   Dao.addWest(st);
   st = new String("ggg");
   Dao.addWest(st);
   st = new String("hhh");
   Dao.addWest(st);
   st = new String("iii");
   Dao.addWest(st);
   st = new String("jjj");
   Dao.addWest(st);
 }
Exemplo n.º 10
0
 public static void createEastStrings() {
   String st = new String("000");
   Dao.addEast(st);
   st = new String("001");
   Dao.addEast(st);
   st = new String("002");
   Dao.addEast(st);
   st = new String("003");
   Dao.addEast(st);
   st = new String("004");
   Dao.addEast(st);
   st = new String("005");
   Dao.addEast(st);
   st = new String("006");
   Dao.addEast(st);
   st = new String("007");
   Dao.addEast(st);
   st = new String("008");
   Dao.addEast(st);
   st = new String("009");
   Dao.addEast(st);
 }
Exemplo n.º 11
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession();
    session.setAttribute("msg", "");

    String uname = request.getParameter("uname");
    String pass = request.getParameter("pass");
    String repass = request.getParameter("repass");
    // String customerid = request.getParameter("customerid");
    String fname = request.getParameter("fname");
    String lname = request.getParameter("lname");
    String gender = request.getParameter("gender");
    String dob = request.getParameter("dob");
    // String nation = request.getParameter("nation");
    String state = request.getParameter("state");
    String district = request.getParameter("district");
    String addr = request.getParameter("addr");
    String pincode = request.getParameter("pincode");
    String distributer = request.getParameter("distributer");
    String aadharno = request.getParameter("aadharno");
    String mobileno = request.getParameter("mobileno");
    String stdcode = request.getParameter("stdcode");
    String telephone = request.getParameter("telephone");
    String email = request.getParameter("email");
    String question = request.getParameter("question");
    String answer = request.getParameter("answer");

    if (uname.equals(null)
        || uname.equals("")
        || pass.equals(null)
        || pass.equals("")
        || fname.equals(null)
        || fname.equals("")
        || lname.equals(null)
        || lname.equals("")
        || gender.equals(null)
        || gender.equals("")
        || dob.equals(null)
        || dob.equals("")
        || state.equals(null)
        || state.equals("")
        || district.equals(null)
        || district.equals("")
        || distributer.equals(null)
        || distributer.equals("")
        || pincode.equals(null)
        || pincode.equals("")
        || addr.equals(null)
        || addr.equals("")
        || aadharno.equals(null)
        || aadharno.equals("")
        || mobileno.equals(null)
        || mobileno.equals("")
        || stdcode.equals(null)
        || stdcode.equals("")
        || telephone.equals(null)
        || telephone.equals("")
        || email.equals(null)
        || email.equals("")
        || question.equals(null)
        || question.equals("")
        || answer.equals(null)
        || answer.equals("")) {

      session.setAttribute("msg", "All Fields are mandatory");
      getServletContext().getRequestDispatcher("/Register.jsp").forward(request, response);
    } else if (!pass.equals(repass)) {
      session.setAttribute("msg", "Password and Reenter passwords must be same");
      getServletContext().getRequestDispatcher("/Register.jsp").forward(request, response);
    } else {
      Model m = new Model();
      m.setUname(uname);
      m.setPass(pass);
      //			m.setRepass(repass);
      m.setFname(fname);
      m.setLname(lname);
      m.setAddr(addr);
      m.setGender(gender);
      m.setDistributer(distributer);
      m.setDistrict(district);
      m.setDob(dob);
      m.setEmail(email);
      m.setPincode(pincode);
      m.setState(state);
      m.setMobileno(mobileno);
      //			m.setNationality(nation);
      m.setAadharno(aadharno);
      m.setTelephone(telephone);
      m.setStdcode(stdcode);
      m.setQuestion(question);
      m.setAnswer(answer);

      // String sql = "insert into REGISTERATION values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      String sql =
          "insert into REGISTER (USERNAME,PASSWORD,FIRSTNAME,LASTNAME,GENDER,DOB,STATE,DISTRICT,ADDRESS,PINCODE,DISTRIBUTER,AADHARNO,MOBILENO,STDCODE,TELEPHONE,EMAIL,QUESTION,ANSWER) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

      int i = Dao.register(m, sql);
      if (i > 0) {
        System.out.println("Success");

        session.setAttribute("usernameRegister", uname);
        session.setAttribute("password", pass);
        session.setAttribute("fname", fname);
        session.setAttribute("lname", lname);
        session.setAttribute("gender", gender);
        session.setAttribute("dob", dob);
        session.setAttribute("state", state);
        session.setAttribute("district", district);
        session.setAttribute("addr", addr);
        session.setAttribute("pincode", pincode);
        session.setAttribute("distributer", distributer);
        session.setAttribute("aadharno", aadharno);
        session.setAttribute("mobileno", mobileno);
        session.setAttribute("stdcode", stdcode);
        session.setAttribute("telephone", telephone);
        session.setAttribute("email", email);
        session.setAttribute("question", question);
        session.setAttribute("answer", answer);

        getServletContext().getRequestDispatcher("/RegisterSuccess.jsp").forward(request, response);
      }
    }
  }
Exemplo n.º 12
0
  @Test
  public void populaTabela() {
    Dao dao = new Dao();

    Departamento dep1 = new Departamento();
    Departamento dep2 = new Departamento();

    dep1.setNomeDepartamento("A");
    dep2.setNomeDepartamento("B");

    Empregado emp1 = new Empregado();
    Empregado emp2 = new Empregado();
    Empregado emp3 = new Empregado();

    emp1.setNomeEmpregado("rafael");
    emp1.setNumeroDependentes(3);
    emp1.setSalario(1000);
    emp1.setDepartamento(dep2);
    emp1.setIdEmpregado(1);

    emp2.setNomeEmpregado("fogel");
    emp2.setNumeroDependentes(1);
    emp2.setSalario(3000);
    emp2.setDepartamento(dep1);
    emp2.setIdEmpregado(2);

    emp3.setNomeEmpregado("rafael fogel");
    emp3.setNumeroDependentes(5);
    emp3.setSalario(3000);
    emp3.setDepartamento(dep2);
    emp3.setIdEmpregado(3);

    Ferias fef1 = new Ferias();
    Ferias fef2 = new Ferias();

    fef1.setAno(2012);
    fef1.setMes(12);
    fef1.setEmpregado(emp1);

    fef2.setAno(2000);
    fef2.setMes(12);
    fef2.setEmpregado(emp2);

    List<Ferias> ferias1 = new ArrayList<Ferias>();
    List<Ferias> ferias2 = new ArrayList<Ferias>();

    ferias1.add(fef1);
    ferias2.add(fef2);

    emp1.setFerias(ferias1);
    emp2.setFerias(ferias2);

    Projeto pro1 = new Projeto();
    Projeto pro2 = new Projeto();
    Projeto pro3 = new Projeto();

    dao.save(dep1);
    dao.save(dep2);
    dao.save(emp1);
    dao.save(emp2);
    dao.save(emp3);

    // --------------------------------------------------

    List<Empregado> empregados1 = new ArrayList<Empregado>();
    List<Empregado> empregados2 = new ArrayList<Empregado>();
    List<Empregado> empregados3 = new ArrayList<Empregado>();

    empregados1.add(emp1);
    empregados1.add(emp2);

    empregados2.add(emp3);
    empregados2.add(emp1);

    pro1.setIdProjeto(1);
    pro1.setNomeProjeto("P1");
    pro1.setEmpregados(empregados1);

    pro2.setIdProjeto(2);
    pro2.setNomeProjeto("P2");
    pro2.setEmpregados(empregados2);

    pro3.setIdProjeto(3);
    pro3.setNomeProjeto("P3");
    pro3.setEmpregados(empregados3);

    dao.save(pro1);
    dao.save(pro2);
    dao.save(pro3);
  }
Exemplo n.º 13
0
 public static void main(String[] args) {
   ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
   Dao dao = (Dao) context.getBean("DaoImpl");
   User user = new User("test", "test", "test");
   dao.save(user);
 }
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // 文字化けのおまじない
    response.setContentType("application/json; charset=UTF-8");

    String battleClickJson = (String) request.getParameter("battleClickBean");
    System.out.println(battleClickJson);

    // デバッグ用にプレイヤとゲームを勝手に入力
    // request.getSession().setAttribute("playerID", 1);
    // request.getSession().setAttribute("gameID", 1);
    // ここまで

    BattleClickBean battleClickBean = JSON.decode(battleClickJson, BattleClickBean.class);
    System.out.println(battleClickBean.getTurnTotalTime());

    // セッションからゲームIDを取得
    GAMEID gameID = new GAMEID((int) request.getSession().getAttribute("GAMEID"));
    // セッションからクリックしたプレイヤーを取得
    ClickPlayerID clickPlayerID =
        new ClickPlayerID((int) request.getSession().getAttribute("PLAYERID"));
    // マス情報を取得
    MASSID massID = new MASSID(battleClickBean.getClickObjectNumber());
    System.out.println(massID);
    // クリックしたものが何かを判別(マス or アイテム or スキル)
    ClickObjectTypeEnum objectType = battleClickBean.getClickObjectType();
    // GAMEID gameID = new GAMEID(battleClickBean.getGameObjectNumber())
    // ---------------------------------------------------------------------------
    Connection con = null;
    try {
      // objectTypeに応じたクリック時処理へ、@return = ClickResultBean
      con = Dao.getConnection();

      ClickResultBean clickResultBean =
          objectType.clickAction(
              massID, gameID, battleClickBean.getTurnTotalTime(), clickPlayerID, con);

      MASSLIST massList = clickResultBean.getMASSLIST();
      List<Mass> list = massList.get();

      MassStateBean massStateBean = new MassStateBean();

      for (Mass ms : list) {
        int massId = ms.getMASSID().get();
        // String url = MassTypeEnum.MASSTYPE0.url;
        String url = ms.getMassState().url;
        MassUpdateBean massUpdateBean = new MassUpdateBean(massId, url);

        // デバック用--------------------------------------------------
        System.out.println(massUpdateBean.getMassNumber());
        System.out.println(massUpdateBean.getUrl());

        massStateBean.addMassUpdateBean(massUpdateBean);
      }

      //			Boolean isFinish = clickResultBean.getISFINISH().get();
      //			if (isFinish) {
      //				String massClickBean = JSON.encode(massStateBean);
      //
      //				System.out.println(massClickBean);
      //				PrintWriter out = response.getWriter();
      //				out.println(massClickBean);
      //
      //			} else {
      massStateBean.setIsFinished(clickResultBean.getISFINISH().get());

      PLAYERID playerID = new PLAYERID((int) request.getSession().getAttribute("PLAYERID"));
      ChangeTurnPlayerService ctps = new ChangeTurnPlayerService(con);
      massStateBean.setIsMyTurn(
          ctps.checkTurnPlayer(
                  new GAMEID((int) request.getSession().getAttribute("GAMEID")), playerID)
              .getIsMyTurn());

      // クイズをbeanに追加
      if (clickResultBean.getQuiz() != null) {
        QuizBean qbean = new QuizBean();
        qbean.setDescription(clickResultBean.getQuiz().getDESCRIPTION().get());
        qbean.setAnswer(clickResultBean.getQuiz().getANSWER());

        massStateBean.setQuizBean(qbean);
      }

      // アイテムをbeanに追加
      if (clickResultBean.getItem() != null) {
        ItemBean ibean = new ItemBean();
        ibean.setItemEnum(clickResultBean.getItem().getITEMENUM());

        ibean.setItemName(clickResultBean.getItem().getITEMNAME().get());
        massStateBean.setItemBean(ibean);
      }

      // プレイヤのアイテム、スキル情報をbeanに追加
      if (clickResultBean.getMyPlayer() != null) {
        Player myPlayer = clickResultBean.getMyPlayer();

        PlayerBean pbean = new PlayerBean();
        pbean.setCoolTime(myPlayer.getCOOLTIME().get());
        // set itemURL

        if (myPlayer.getITEMID().get() != 0)
          pbean.setItemURL(ItemEnum.getItemEnum(myPlayer.getITEMID().get()).getItemURL());

        massStateBean.setMyPlayerBean(pbean);
      }
      if (clickResultBean.getEnemyPlayer() != null) {
        Player enemyPlayer = clickResultBean.getEnemyPlayer();
        PlayerBean pbean = new PlayerBean();
        pbean.setCoolTime(enemyPlayer.getCOOLTIME().get());
        // set itemURL

        if (enemyPlayer.getITEMID().get() != 0)
          pbean.setItemURL(ItemEnum.getItemEnum(enemyPlayer.getITEMID().get()).getItemURL());

        massStateBean.setEnemyPlayerBean(pbean);
      }

      String massClickBean = JSON.encode(massStateBean);

      System.out.println(massClickBean);
      PrintWriter out = response.getWriter();
      out.println(massClickBean);

      return;
      //			}

      // int winPlayerId =
      // clickResultBean.getWinPlayerID().get();//勝ったプレイヤーID
      // int losePlayerId =
      // clickResultBean.getLosePlayerID().get();//負けたプレイヤーID
      //
      // Player player = new Player();
      // int playerId = player.getPLAYERID().get();//
      //
      // if (playerId == winPlayerId) {
      // // 勝側のサーブレットに勝ったプレイヤーIDを渡す
      // request.getSession().setAttribute("winPlayerID", winPlayerId);
      // RequestDispatcher disp =
      // request.getRequestDispatcher("/WinPlayerServlet");
      // disp.forward(request, response);
      // } else if (playerId == losePlayerId) {
      // // 負側のサーブレットに負けたプレイヤーIDを渡す
      // request.getSession().setAttribute("losePlayerID", losePlayerId);
      // RequestDispatcher disp =
      // request.getRequestDispatcher("/LosePlayerServlet");
      // disp.forward(request, response);
      // }

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      try {
        if (con != null && con.isClosed()) {
          throw new RuntimeException("すでにコネクションが閉じています。ロールバックができません。");
        }
        if (con != null) con.rollback();
      } catch (SQLException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
      }
      throw new RuntimeException(e);
    } catch (SQLException e) {
      e.printStackTrace();
      try {
        if (con != null && con.isClosed()) {
          throw new RuntimeException("すでにコネクションが閉じています。ロールバックができません。");
        }
        if (con != null) con.rollback();
      } catch (SQLException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
      }
      throw new RuntimeException(e);
    } catch (Throwable e) {
      e.printStackTrace();
      throw e;
    } finally {
      try {
        con.close();
      } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
      }
    }
  }
Exemplo n.º 15
0
 private static void conectar() {
   Dao dao = new Dao() {};
   dao.getConnection();
 }