Added ability to retrieve list of contracts
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
parent
fb777a5bfc
commit
e5350da142
|
@ -1,9 +1,6 @@
|
||||||
package de.dis2017.data.db;
|
package de.dis2017.data.db;
|
||||||
|
|
||||||
import de.dis2017.data.Apartment;
|
import de.dis2017.data.*;
|
||||||
import de.dis2017.data.Estate;
|
|
||||||
import de.dis2017.data.EstateAgent;
|
|
||||||
import de.dis2017.data.House;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
@ -55,6 +52,9 @@ public class ORM {
|
||||||
case ESTATE:
|
case ESTATE:
|
||||||
objects = processEstates(rs);
|
objects = processEstates(rs);
|
||||||
break;
|
break;
|
||||||
|
case CONTRACT:
|
||||||
|
objects = processContracts(rs);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
|
@ -116,6 +116,28 @@ public class ORM {
|
||||||
return agents;
|
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.
|
* Loads the estate with the given ID from database and returns the corresponding object.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue