コード例 #1
0
  public boolean ricavaUser(String username) throws DAOException {
    if (username != null) {

      try {
        Connection conn = dbAccess.getConnection();
        PreparedStatement stmt = conn.prepareStatement(SELECT_USER);
        stmt.setString(1, username);

        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
          closeAll(rs, stmt);
          dbAccess.closeConnection(conn);
          return true;
        } else {
          closeAll(rs, stmt);
          dbAccess.closeConnection(conn);
          return false;
        }

      } catch (SQLException e) {
        throw new DAOException("sql.login.exception.loginDAO", e);

      } catch (Exception e) {
        throw new DAOException("login.exception.loginDAO", e);
      }
    } else {
      throw new DAOException("invalid.object_username.loginDAO", null);
    }
  }
コード例 #2
0
  @Test
  public void testUpdate() {

    try {

      NotaB notaBU = new NotaB();
      notaBU.setDescrizione("asd2");

      boolean test = notaBDAO.update(conn, notaBU, notaB1);
      db.rollbackConnection(conn);

      assertTrue(test);

    } catch (DAOException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      fail(e.getMessage());
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 2

    try {

      notaBDAO.update(conn, new Allegato(), notaB1);
      fail();
    } catch (DAOException e) {

      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 3

    try {

      notaBDAO.update(conn, null, notaB1);
      fail();

    } catch (DAOException e) {
      // return;
      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #3
0
  public String ricavaPassword(String username) throws DAOException {

    if (username != null) {

      try {
        Connection conn = dbAccess.getConnection();
        PreparedStatement stmt = conn.prepareStatement(SELECT_PASS);
        stmt.setString(1, username);

        ResultSet rs = stmt.executeQuery();

        String pass = null;
        if (rs.next()) {
          pass = rs.getString(1);
          closeAll(rs, stmt);
          dbAccess.closeConnection(conn);
          return pass;
        } else {
          closeAll(rs, stmt);
          dbAccess.closeConnection(conn);
          return pass;
        }

      } catch (SQLException e) {
        throw new DAOException("sql.login.exception.loginDAO", e);

      } catch (Exception e) {
        throw new DAOException("login.exception.loginDAO", e);
      }
    } else {
      throw new DAOException("invalid.object_username.loginDAO", null);
    }
  }
コード例 #4
0
  @Test
  public void testFind() {
    try {

      RowSet rs = notaBDAO.find(notaB1, 2);
      try {

        boolean b = rs.next();

        assertTrue(b);

      } catch (SQLException e) {
        fail(e.getMessage());
      }

    } catch (DAOException e) {
      fail(e.getMessage());
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 2

    try {

      notaBDAO.find(new Allegato(), 2);
      fail();
    } catch (DAOException e) {

      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 3

    try {

      notaBDAO.find(null, 2);
      fail();
    } catch (DAOException e) {

      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #5
0
  @Before
  public void init() {

    notaBDAO = new NotaBDAO();

    try {
      db = new DBAccess();
      conn = db.getConnection();

      notaB1 = new NotaB();
      notaB1.setIdNotaB(1);
      notaB1.setDescrizione("asd");
      notaB1.setData(cd.getTime());
      notaB1.setIdStrumento(2);
      notaB1.setIdUtente(1);

      notaB2 = new NotaB();
      // notaB2.setIdNotaB(2);
      notaB2.setDescrizione("asd");
      // notaB2.setData(cd.getTime());
      notaB2.setIdStrumento(2);
      notaB2.setIdUtente(1);

    } catch (DBAccessException e) {
      fail(e.getMessage());
    }
  }
コード例 #6
0
  @Before
  public void init() {
    try {
      db = new DBAccess();
      conn = db.getConnection();
      allegato5 = new Allegato5();

      allegato5.setIdAllegato(1);
      allegato5.setSiglaLoop("PT900");
      allegato5.setServizio("a");
      allegato5.setSegnaliIngresso("b");
      allegato5.setUsciteTeoriche1("c");
      allegato5.setUsciteReali1("d");
      allegato5.setUsciteTeoriche2("e");
      allegato5.setUsciteReali2("f");
      allegato5.setCostruttori("g");
      allegato5.setTipi("h");
      allegato5.setCampi("i");
      allegato5.setNumSerie("l");
      allegato5.setCompilatoRapportoInefficienza(false);
      allegato5.setUdm("n");

      allegato5a = new Allegato5();
    } catch (DBAccessException e) {
      e.printStackTrace();
    }
  }
コード例 #7
0
  @Test
  public void testTransformStmt() {
    // PROVA UPDATE
    try {
      Allegato9 newAllegato9 = new Allegato9();
      newAllegato9.setAltro("campoi");

      String SET = sga9.transformStmt(newAllegato9, 1);
      String WHERE = sga9.transformStmt(allegato9, 2);

      String query = ALLEGATO9_UPDATE;

      query = query.replaceFirst(CHAR_AT, SET);
      query = query.replaceFirst(CHAR_AT, WHERE);

      Statement stmt = conn.createStatement();
      int count = stmt.executeUpdate(query);

      // PROVA FIND
      WHERE = sga9.transformStmt(newAllegato9, 2);

      query = ALLEGATO9_FIND_MAIN;
      query = query.replaceFirst(CHAR_AT, WHERE);

      ResultSet rs = stmt.executeQuery(query);
      rs.next();

      boolean test = rs.getString(17).equals(newAllegato9.getAltro());

      db.rollbackConnection(conn);
      assertTrue(test);
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
コード例 #8
0
  @Before
  public void init() {

    db = new DBAccess();
    try {
      conn = db.getConnection();
      sga9 = new StatementGenAllegato9();

      // DEVE CORRISPONDERE AD UNO VERO NEL DATABASE
      allegato9 = new Allegato9();
      allegato9.setIdAllegato(9);
      allegato9.setSigla("asd");
      allegato9.setMatricola("asd");
      allegato9.setCostruttore("asd");
      allegato9.setDn("asd");
      allegato9.setPn("asd");
      allegato9.setPesoKg(1);
      allegato9.setTaratura("asd");
      allegato9.setEnteCertificatore("asd");
      allegato9.setPrePopTest("asd");
      allegato9.setMolla(true);
      allegato9.setOtturatore(true);
      allegato9.setBoccaglio(true);
      allegato9.setSoffietto(true);
      allegato9.setDiscoGuidaStelo(true);
      allegato9.setPiattiPortaMolla(true);
      allegato9.setAltro("asd");
      allegato9.setLavorazioniParicolari("asd");
      allegato9.setUdm("asd");

    } catch (DBAccessException e) {

      e.printStackTrace();
    }
  }
コード例 #9
0
  @Test
  public void testGetPreparedStatement() {
    try {
      // testo il getPrearedStatement facendo una query di creazione
      // MANCA TESTO QUERY IN ALLEGATO5_CREATE
      stmt = conn.prepareStatement(ALLEGATO5_CREATE);
      Allegato5Assembler.getPreparedStatement(allegato5, stmt);
      stmt.executeUpdate();
      db.rollbackConnection(conn);

      stmt.close();
      db.closeConnection(conn);

    } catch (SQLException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      fail(e.getMessage());
    }
  }
コード例 #10
0
  @Test
  public void testRemove() {
    try {

      boolean res = notaBDAO.remove(conn, notaB1.getIdNotaB());

      db.rollbackConnection(conn);

      assertTrue(res);

    } catch (DBAccessException e) {
      fail(e.getMessage());
    } catch (DAOException e) {

      fail(e.getMessage());
    } finally {

      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #11
0
  @Test
  public void testGetInfoResultSet() {
    try {
      stmt = conn.prepareStatement(ALLEGATO5_FIND_BYPK);
      stmt.setInt(1, 6);
      ResultSet rs = stmt.executeQuery();
      rs.next();
      allegato5 = Allegato5Assembler.getInfo(rs);

      stmt.close();
      db.closeConnection(conn);

    } catch (SQLException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      fail(e.getMessage());
    }
  }
コード例 #12
0
  @Test
  public void testFindByAll() {
    try {

      RowSet rs = notaBDAO.findByAll();
      assertTrue(rs.next());

    } catch (DAOException e) {
      fail(e.getMessageKey());
    } catch (SQLException e) {
      fail(e.getMessage());
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #13
0
  @Test
  public void testGetInfoRowSet() {
    CachedRowSet rws;
    try {
      rws = new CachedRowSetImpl();

      rws.setCommand(ALLEGATO5_FIND_BYPK);
      rws.setInt(1, 6);
      rws.execute(conn);
      rws.next();
      allegato5 = Allegato5Assembler.getInfo(rws);
      rws.close();
      db.closeConnection(conn);

    } catch (SQLException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      fail(e.getMessage());
    }
  }
コード例 #14
0
  @Test
  public void testCreate() {
    try {
      notaB2.setData(cd.getTime());
      notaBDAO.create(conn, notaB2);
      String query = NOTA_B_FIND_BYPK;

      Statement stmt2 = conn.createStatement();
      ResultSet rs =
          stmt2.executeQuery(
              "SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'db_qualita' AND TABLE_NAME = 'nota_b'");
      rs.next();
      int id = rs.getInt(1);

      PreparedStatement stmt = conn.prepareStatement(query);
      stmt.setInt(1, id - 1);
      rs = stmt.executeQuery();

      rs.next();
      int a = rs.getInt(1);
      db.rollbackConnection(conn);
      assertTrue(rs.getInt(1) == (id - 1));

    } catch (DAOException e) {
      fail(e.getMessage());
    } catch (SQLException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      e.printStackTrace();
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 2 test null
    try {

      notaBDAO.create(null, notaB2);
      fail();
    } catch (DAOException e) {
      // return;

      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 3 test class exception
    try {

      notaBDAO.create(conn, new Allegato());
      fail();

    } catch (DAOException e) {
      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #15
0
 public LogInDAO() {
   dbAccess = dbAccess.getInstance();
 }