コード例 #1
0
  @Override
  public void uzyjForme(Forma forma) throws NoItemFound, ItemUsed {

    try {
      if (checkIfExistsAndFillResultSet(forma)) {
        int counter = getCounter();
        if (counter > 0) {
          updateCounter(counter - 1, forma);
        } else {
          throw new ItemUsed(forma.toString());
        }
      } else {
        throw new NoItemFound(forma.toString());
      }
    } catch (SQLException ex) {
      Logger.getLogger(FormaRepositoryDBImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
コード例 #2
0
 private void updateCounter(int counter, Forma forma) throws SQLException {
   connection.update(
       "update "
           + tableName
           + "  set counter =\" "
           + counter
           + "\"where idProjektu = \""
           + forma.getTyp().name()
           + "\";");
 }
コード例 #3
0
  private boolean checkIfExistsAndFillResultSet(Forma forma) throws SQLException {
    resultSet =
        connection.execQuery(
            "select * from "
                + tableName
                + " where idProjektu = \""
                + forma.getTyp().name()
                + "\";");

    return resultSet.next();
  }
コード例 #4
0
 private void createNew(Forma forma) {
   connection.update(
       "insert into " + tableName + " (idProjektu) values(\"" + forma.getTyp().name() + "\" );");
 }