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
|
@PersistenceContext(unitName="ToDoEJB3")
private EntityManager entityManager;
.....
public void create(String nom, String prenom, String commentaire,Date date,int priorite) {
long begin = System.currentTimeMillis();
if(priorite!=0){
Taches tache = new Taches(nom,prenom,commentaire, date);
try{
tache.setRefPriorite(entityManager.find(TachesPriorite.class, priorite));
entityManager.persist(tache);
System.out.println("Tache créée. nom:"+nom+" prenom:"+prenom+" commentaire:"+commentaire+" date:"+date);
}
catch(Exception e){
System.out.println("priorité inexistante ou null");
}
try{
Taches tache2 = new Taches(nom,prenom,commentaire, date);
tache2.setRefPriorite(entityManager.find(TachesPriorite.class, 10));
entityManager.persist(tache2);
System.out.println("Tache créée. nom:"+nom+" prenom:"+prenom+" commentaire:"+commentaire+" date:"+date);
}
catch(Exception e){
System.out.println("priorité inexistante ou null");
}
}
else{
System.out.println("Veuillez entrer une priorité");
}
long end = System.currentTimeMillis();
float time = ((float) (end-begin)) / 1000f;
System.out.println("[CREATE]Temps d execution :"+time +"ms");
} |
Partager