Added method to delete estate agents
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
parent
24e025c4d4
commit
200a28e23d
|
@ -101,6 +101,35 @@ public class ORM {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the given agent from the database.
|
||||||
|
*
|
||||||
|
* @param agent the agent that should be deleted
|
||||||
|
*/
|
||||||
|
public void delete(EstateAgent agent)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (agent.getId() == -1) {
|
||||||
|
System.err.println("This agent is not yet persisted to the dabase and cannot be deleted.");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// create query
|
||||||
|
String updateSQL = "DELETE FROM ESTATEAGENT WHERE ID = ?";
|
||||||
|
PreparedStatement pstmt = _connection.prepareStatement(updateSQL);
|
||||||
|
pstmt.setInt(1, agent.getId());
|
||||||
|
|
||||||
|
// execute query
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
pstmt.close();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (_agents.containsKey(agent.getId())) {
|
||||||
|
_agents.remove(agent.getId(), agent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persists the given agent.
|
* Persists the given agent.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue