Added ability to retrieve list of contracts

Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
Jim Martens 2017-04-24 13:46:00 +02:00
parent fb777a5bfc
commit e5350da142
1 changed files with 26 additions and 4 deletions

View File

@ -1,9 +1,6 @@
package de.dis2017.data.db;
import de.dis2017.data.Apartment;
import de.dis2017.data.Estate;
import de.dis2017.data.EstateAgent;
import de.dis2017.data.House;
import de.dis2017.data.*;
import org.jetbrains.annotations.Nullable;
import java.sql.*;
@ -55,6 +52,9 @@ public class ORM {
case ESTATE:
objects = processEstates(rs);
break;
case CONTRACT:
objects = processContracts(rs);
break;
}
rs.close();
pstmt.close();
@ -116,6 +116,28 @@ public class ORM {
return agents;
}
/**
* Process a select all query for contracts.
*
* @param rs the result set of such a query
* @return a list of contracts
* @throws SQLException when an error occurs during the rs.next call
*/
private List<Contract> processContracts(ResultSet rs) throws SQLException {
List<Contract> contracts = new ArrayList<>();
while (rs.next()) {
Contract contract = new Contract();
contract.setContractNo(rs.getInt("contractNumber"));
contract.setPlace(rs.getString("place"));
contract.setDate(rs.getString("date"));
contracts.add(contract);
}
return contracts;
}
/**
* Loads the estate with the given ID from database and returns the corresponding object.
*