浏览代码

Ajout méthode utilitaire pour la recherche

Arthur Brandao 5 年之前
父节点
当前提交
69dd4793f8
共有 3 个文件被更改,包括 54 次插入3 次删除
  1. 3 3
      src/db/table/EspaceTable.java
  2. 16 0
      src/db/table/UsagerTable.java
  3. 35 0
      src/db/table/VilleTable.java

+ 3 - 3
src/db/table/EspaceTable.java

@@ -25,11 +25,11 @@ public class EspaceTable extends Table<Espace>{
 	}
 	
 	public Optional<Espace> findByLibelle(String lib) {
-		Espace e = getByLibelle(lib);
-		if (e == null) {
+		Espace obj = getByLibelle(lib);
+		if (obj == null) {
 			return Optional.empty();
 		}
-		return Optional.of(e);
+		return Optional.of(obj);
 	}
 	
 	public static EspaceTable getInstance() {

+ 16 - 0
src/db/table/UsagerTable.java

@@ -17,6 +17,22 @@ public class UsagerTable extends Table<Usager> {
 	private UsagerTable() {
 		// Private constructor for singleton
 	}
+	
+	public Usager getByCode(String code) {
+		List<Usager> list = getByField("CODE", code);
+		if(list.isEmpty()) {
+			return null;
+		}
+		return list.get(0);
+	}
+	
+	public Optional<Usager> findByCodePostal(String code) {
+		Usager obj = getByCode(code);
+		if (obj == null) {
+			return Optional.empty();
+		}
+		return Optional.of(obj);
+	}
 
 	@Override
 	public Usager getById(long id) {

+ 35 - 0
src/db/table/VilleTable.java

@@ -1,5 +1,8 @@
 package db.table;
 
+import java.util.List;
+import java.util.Optional;
+
 import db.Table;
 import db.annotation.DbTable;
 import entity.Ville;
@@ -13,6 +16,38 @@ public class VilleTable extends Table<Ville> {
 		// Private constructor for singleton
 	}
 	
+	public Ville getByLibelle(String lib) {
+		List<Ville> list = getByField("LIBELLE", lib);
+		if(list.isEmpty()) {
+			return null;
+		}
+		return list.get(0);
+	}
+	
+	public Optional<Ville> findByLibelle(String lib) {
+		Ville obj = getByLibelle(lib);
+		if (obj == null) {
+			return Optional.empty();
+		}
+		return Optional.of(obj);
+	}
+	
+	public Ville getByCodePostal(String cp) {
+		List<Ville> list = getByField("CODEPOSTAL", cp);
+		if(list.isEmpty()) {
+			return null;
+		}
+		return list.get(0);
+	}
+	
+	public Optional<Ville> findByCodePostal(String cp) {
+		Ville obj = getByCodePostal(cp);
+		if (obj == null) {
+			return Optional.empty();
+		}
+		return Optional.of(obj);
+	}
+	
 	public static VilleTable getInstance() {
 		if(instance == null) {
 			instance = new VilleTable();