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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
public class Famille implements Serializable{
// Champ
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long code;
@Column(nullable = false)
@Version
private int version;
@Column(length = 150, nullable = false)
private String libelle;
@Column(length = 10, nullable = false)
private String porte;
@Column(length = 10, nullable = false)
private String ilot;
//@ManyToOne()
//@JoinColumn(name = "STRUCTURE", insertable = false, updatable = false)
//private Structure structure ;
@Column(length = 10, nullable = false)
private String lot;
// Méthodes
public Famille(){
}
// toString
public String toString() {
return String.format("P[%d,%d,%s,%s,%s,%s]",getVersion(), getCode(), getLibelle(),getPorte(),getLot(),getIlot());//,getStructure().getCode());
}
public Long getCode() {
return code;
}
public void setCode(Long code) {
this.code = code;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public String getPorte() {
return porte;
}
public void setPorte(String porte) {
this.porte = porte;
}
public String getLot() {
return lot;
}
public void setLot(String lot) {
this.lot = lot;
}
public String getIlot() {
return ilot;
}
public void setIlot(String ilot) {
this.ilot = ilot;
}
//public Structure getStructure() {
// return structure;
//}
//public void setStructure(Structure structure) {
// this.structure = structure;
//}
}
public class Personne implements Serializable {
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long matricule;
@Column(nullable = false)
@Version
private int version;
@Column(length = 30, nullable = false)
private String nom;
@Column(length = 150, nullable = false)
private String prenom;
@Column(nullable = false)
@Temporal(TemporalType.DATE)
private Date datenais;
@Column(length = 100)
private String profession;
@Column(length = 30)
private String rang;
@Column(length = 10)
private String cell1;
@Column(length = 10)
private String cell2;
@Column(length = 10)
private String cell3;
@Column(length = 20)
private String type;
@Column(length = 1)
private String sexe;
@Column(nullable = false)
private boolean marie;
@Column(nullable = true)
private int nbenfants;
@Column(length = 20)
private String photo;
//private Blob photo;
// relation principale Personne (one) -> Adresse (one)
// impl�ment�e par la cl� �trang�re Personne(adresse_id) -> Adresse
// cascade insertion Personne -> insertion Adresse
// cascade maj Personne -> maj Adresse
// cascade suppression Personne -> suppression Adresse
// une Personne doit avoir 1 Adresse (nullable=false)
// 1 Adresse n'appartient qu'� 1 personne (unique=true)
@OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumn(name = "adresse", unique = true, insertable = false) //, nullable = false)
private Adresse adresse;
// relation Personne (many) -> Activite (many) via une table de jointure PersonneActivite
// PersonneActivite5(PERSONNE_ID) est cl� �tang�re sur Personne(id)
// PersonneActivite5(ACTIVITE_ID) est cl� �tang�re sur Activite(id)
// plus de cascade sur les activit�s
// @ManyToMany(cascade={CascadeType.PERSIST})
@ManyToMany()
@JoinTable(name = "PersonneActivite", joinColumns = @JoinColumn(name = "personne"), inverseJoinColumns = @JoinColumn(name = "activite"))
private Set<Activite> activites = new HashSet<Activite>();
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "famille", insertable = false, updatable = true)
private Famille famille ;
//@OneToOne(mappedBy = "personne", fetch=FetchType.LAZY)
//private Occupation occupation;
// constructeurs
public Personne() {
}
public Personne(String nom, String prenom, Date datenaissance, boolean marie, int nbenfants) {
setNom(nom);
setPrenom(prenom);
setDatenaissance(datenaissance);
setMarie(marie);
setNbenfants(nbenfants);
}
public Personne(String nom, String prenom, Date datenaissance,String profession,String rang,String sexe,
boolean marie, int nbenfants,String photo,String cell1,String cell2,String cell3) {
setNom(nom);
setPrenom(prenom);
setDatenaissance(datenaissance);
setProfession(profession);
setRang(rang);
setSexe(sexe);
setMarie(marie);
setNbenfants(nbenfants);
setPhoto(photo);
setCell1(cell1);
setCell2(cell2);
setCell3(cell3);
}
public Personne(String nom, String prenom, String datenaissance,String profession,String rang,String sexe,
boolean marie, int nbenfants,String photo,String cell1,String cell2,String cell3){
setNom(nom);
setPrenom(prenom);
try{
setDatenaissance(new SimpleDateFormat("dd/MM/yyyy").parse(datenaissance));
} catch(java.text.ParseException e){
System.out.println("Error :"+ e.getMessage());
}
setProfession(profession);
setRang(rang);
setSexe(sexe);
setMarie(marie);
setNbenfants(nbenfants);
setPhoto(photo);
setCell1(cell1);
setCell2(cell2);
setCell3(cell3);
}
// toString
public String toString() {
return String.format("P[%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%d,%d,%d]", getVersion(),getMatricule(), getNom(), getPrenom(),
new SimpleDateFormat("dd/MM/yyyy").format(getDatenaissance()),getSexe(),getProfession(),getRang(),getCell(),isMarie(),getType(),getNbenfants(),getAdresse().getId(),
getFamille().getCode());
}
// getters and setters
public Long getMatricule() {
return matricule;
}
public void setMatricule(Long matricule) {
this.matricule = matricule;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public Date getDatenaissance() {
return datenais;
}
public void setDatenaissance(Date datenais) {
this.datenais = datenais;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
public String getRang() {
return rang;
}
public void setRang(String rang) {
this.rang = rang;
}
public String getSexe() {
return sexe;
}
public void setSexe(String sexe) {
this.sexe = sexe;
}
public String getCell() {
return String.format("P[%s,%s,%s]", cell1, cell2, cell3);
}
public String getCell1() {
return cell1;
}
public String getCell2() {
return cell2;
}
public String getCell3() {
return cell3;
}
public void setCell1(String cell) {
this.cell1 = cell;
}
public void setCell2(String cell) {
this.cell2 = cell;
}
public void setCell3(String cell) {
this.cell3 = cell;
}
public void setCell(String cell) {
if (cell1 == null) {
this.cell1 = cell;
}
else if (cell2 == null){
this.cell2 = cell;
}
else {
this.cell3 = cell;
}
}
public boolean isMarie() {
return marie;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public void setMarie(boolean marie) {
this.marie = marie;
}
public int getNbenfants() {
return nbenfants;
}
public void setNbenfants(int nbenfants) {
this.nbenfants = nbenfants;
}
public Adresse getAdresse() {
return adresse;
}
public void setAdresse(Adresse adresse) {
this.adresse = adresse;
}
public Set<Activite> getActivites() {
return activites;
}
public void setActivites(Set<Activite> activites) {
this.activites = activites;
}
public Famille getFamille() {
return famille;
}
public void setFamille(Famille famille) {
this.famille = famille;
}
//public Occupation getOccupation() {
// return occupation;
//}
//public void setOccupation(Occupation occupation) {
// this.occupation = occupation;
//}
} |