Class JDBCUserDAO
Implementazione JDBC del
UserDAO
, che gestisce le operazioni Dao sullo user.
Gli utenti sono salvati nella tabella User
, e rappresentati dal modello User
.
Tutte le interazioni con il database sono gestite tramite JdbcDAO
, con logging automatico via SystemLogger
.
-
Field Summary
Fields inherited from class it.unisa.diem.wordageddon_g16.db.JdbcDAO
connection
-
Constructor Summary
ConstructorsConstructorDescriptionJDBCUserDAO
(Connection connection) Costruisce un nuovoJDBCUserDAO
utilizzando la connessione specificata. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Elimina un utente dal database.void
Inserisce un nuovo utente nella tabellaUser
.boolean
isEmpty()
Verifica se la tabellaUser
è vuota.Recupera tutti gli utenti presenti nella tabellaUser
.Recupera un utente dal database in base al nome utente.void
Aggiorna le informazioni di un utente esistente.Methods inherited from class it.unisa.diem.wordageddon_g16.db.JdbcDAO
executeQuery, executeQuery, executeUpdate, isEmpty
-
Constructor Details
-
JDBCUserDAO
Costruisce un nuovoJDBCUserDAO
utilizzando la connessione specificata.- Parameters:
connection
- la connessione al database da utilizzare per le operazioni
-
-
Method Details
-
selectBy
Recupera un utente dal database in base al nome utente.- Specified by:
selectBy
in interfaceUserDAO
- Parameters:
username
- il nome dell’utente da cercare- Returns:
- un
Optional
contenente l’utente se trovato, altrimenti vuoto - Throws:
QueryFailedException
- se si verifica un errore durante l'esecuzione della query
-
selectAll
-
insert
Inserisce un nuovo utente nella tabellaUser
.Se l’utente esiste già (in base alla chiave primaria), l’inserimento viene ignorato.
- Specified by:
insert
in interfaceDAO<User>
- Parameters:
user
- l’oggettoUser
da inserire- Throws:
UpdateFailedException
- se si verifica un errore durante l'inserimento
-
update
-
delete
Elimina un utente dal database.L'eliminazione comporta anche la cancellazione automatica dei
GameReport
associati, grazie ai vincoli di integrità (ON DELETE CASCADE).- Specified by:
delete
in interfaceDAO<User>
- Parameters:
user
- l’oggettoUser
da eliminare- Throws:
UpdateFailedException
- se si verifica un errore durante la cancellazione
-
isEmpty
public boolean isEmpty()Verifica se la tabellaUser
è vuota.- Returns:
true
se non esiste alcun utente nel database, altrimentifalse
-