EspaceTable.java 812 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package db.table;
  2. import java.util.List;
  3. import java.util.Optional;
  4. import db.Table;
  5. import db.annotation.DbTable;
  6. import entity.Espace;
  7. @DbTable(name = "Espace", entity = Espace.class)
  8. public class EspaceTable extends Table<Espace>{
  9. private static EspaceTable instance;
  10. private EspaceTable() {
  11. // Private constructor for singleton
  12. }
  13. public Espace getByLibelle(String lib) {
  14. List<Espace> list = getByField("LIBELLE", lib);
  15. if(list.isEmpty()) {
  16. return null;
  17. }
  18. return list.get(0);
  19. }
  20. public Optional<Espace> findByLibelle(String lib) {
  21. Espace obj = getByLibelle(lib);
  22. if (obj == null) {
  23. return Optional.empty();
  24. }
  25. return Optional.of(obj);
  26. }
  27. public static EspaceTable getInstance() {
  28. if(instance == null) {
  29. instance = new EspaceTable();
  30. }
  31. return instance;
  32. }
  33. }