use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method setPasswordCustomer.
@Override
public void setPasswordCustomer(String username, String newPassword) throws CriticalError, ClientNotExist {
log.debug("SQL Public setPasswordCustomer: Customer: " + username + " sets password.");
if (!isCustomerExist(username)) {
log.debug("SQL Public setPasswordCustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
// START transaction
connectionStartTransaction();
//Write part of transaction
//updating password
assignPasswordToRegisteredClient(new CustomersTable(), username, newPassword);
log.debug("SQL Public setPasswordCustomer: Success setting password for username: " + username);
// END transaction
connectionCommitTransaction();
} catch (SQLDatabaseException e) {
connectionRollbackTransaction();
throw e;
} finally {
connectionEndTransaction();
}
}
use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method removeWorker.
@Override
public void removeWorker(Integer sessionID, String username) throws CriticalError, ClientNotExist, ClientNotConnected {
log.debug("SQL Public removeWorker: Remove worker with username: " + username);
validateSessionEstablished(sessionID);
if (!isWorkerExist(username)) {
log.debug("SQL Public removeWorker: no such worker with username: " + username);
throw new ClientNotExist();
}
//validate not deleting the admin
if (getWorkerTypeByUsername(username) == CLIENT_TYPE.MANAGER) {
log.debug("SQL Public removeWorker: cant remove the manager!");
throw new CriticalError();
}
try {
// START transaction
connectionStartTransaction();
//Read part of transaction
Integer workerSessionID = getSessionByUsernameOfRegisteredClient(new WorkersTable(), username);
//Write part of transaction
if (workerSessionID != null) {
log.debug("SQL Public removeWorker: user " + username + " connected! doing logout first");
logoutAsWorker(workerSessionID, username);
}
log.debug("SQL Public removeWorker: remove user " + username + " from workers table");
removeRegisteredClient(new WorkersTable(), username);
log.debug("SQL Public removeWorker: Success removing username: " + username);
// END transaction
connectionCommitTransaction();
} catch (SQLDatabaseException e) {
log.debug("SQL Public removeCustomer: known error occured:" + e.getMessage());
connectionRollbackTransaction();
throw e;
} catch (SQLException e) {
log.fatal("SQL Public removeCustomer: SQL error occured:" + e.getMessage());
connectionRollbackTransaction();
throw new CriticalError();
} finally {
connectionEndTransaction();
}
}
Aggregations