@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); } }
private void updateCounter(int counter, Forma forma) throws SQLException { connection.update( "update " + tableName + " set counter =\" " + counter + "\"where idProjektu = \"" + forma.getTyp().name() + "\";"); }
private boolean checkIfExistsAndFillResultSet(Forma forma) throws SQLException { resultSet = connection.execQuery( "select * from " + tableName + " where idProjektu = \"" + forma.getTyp().name() + "\";"); return resultSet.next(); }
private void createNew(Forma forma) { connection.update( "insert into " + tableName + " (idProjektu) values(\"" + forma.getTyp().name() + "\" );"); }