* @throws NetworkException Wird geworfen, wenn die Verbindung zum Server fehlgeschlagen ist.
*/
public void login(final LoginRequest lr) throws LoginFailedException, NetworkException {
try {
logger.info("Trying to login at the server with user " + lr.email + "...");
Employee e = netControl.login(lr);
logger.info("...successful logged in");
employee = e;
logins.put(lr, e.getId());
loginData = lr;
writeIDs();
} catch (DBDirtyException ex) {
try {
logger.info("Database is dirty - cleaning and the retrying...");
ClientDB cdb = new ClientDB(ex.getId());
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", Employee.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", Project.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", Department.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", WorkPackage.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", EmployeeProjectRelation.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", EmployeeWorkPackageRelation.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", WorkPackageDependsRelation.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", Task.getTableName()));
cdb.execute(SQLFormatter.generateQuery("DELETE FROM %s", Duration.getTableName()));
} catch (SQLException ex1) {
logger.warning("Failed reading the database!", ex1);
} catch (IOException ex1) {
logger.warning("Reading the database file failed!", ex1);
}
login(lr);
} catch (NetworkException ex) {
if (logins.containsKey(lr)) {
loginData = lr;
try {
long id = logins.get(lr);
ClientDB cdb = new ClientDB(id);
ResultSet rs = cdb.query(SQLFormatter.generateQuery("SELECT * FROM %s WHERE id = %d", Employee.getTableName(), id));
if (!rs.next()) {
logger.warning("The login is known but not available in the local database. Raise an error to refetch from server.");
rs.close();
throw ex;
}
employee = new Employee(null, rs);
rs.close();
} catch (SQLException ex1) {
logger.warning("Failed reading the database!", ex1);
throw ex;
} catch (IOException ex1) {