1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public void createrectif(Long npch,Integer montant)
{ EntityManager em = getEntityManager();
List<Operation> oper= em.createQuery("select object(o) from Operation as o where (o.npch=:n)")
.setParameter("n",operation.getNpch()).getResultList();
if(!oper.isEmpty())
{
montantfromquery=oper.get(0).getMontant();
operation.setNpch(npch);
operation.setCodActiv(oper.get(0).getCodActiv());
operation.setCodCaisse(oper.get(0).getCodCaisse());
operation.setCodTransac(oper.get(0).getCodTransac());
operation.setDateOp(oper.get(0).getDateOp());
operation.setDateVersm(oper.get(0).getDateVersm());
operation.setImpAnal(oper.get(0).getImpAnal());
operation.setImpBudi(oper.get(0).getImpBudi());
operation.setMatriculeAgent(oper.get(0).getMatriculeAgent());
operation.setMoisPaie(oper.get(0).getMoisPaie());
operation.setMontantht(oper.get(0).getMontantht());
operation.setNpch(oper.get(0).getNpch());
operation.setNumMandat(oper.get(0).getNumMandat());
//***montant soit =(-op.getMontant)soit = nouveau montant
operation.setMontant(montant);
}
}
public String recherche() {
EntityManager em = getEntityManager();
try{
//====================================
utx.begin();
createrectif(operation.getNpch(),operation.getMontant());
n=montantfromquery;
createrectif(operation.getNpch(),-n);
em.persist(operation);
utx.commit();
} catch (Exception ex) {
try {
ensureAddErrorMessage(ex, "A persistence error occurred.");
utx.rollback();
} catch (Exception e) {
e.printStackTrace();
ensureAddErrorMessage(e, "An error occurred attempting to roll back the transaction.");
}
//return null;
}finally{em.close();}
return listSetup();
} |
Partager