Reformatted the codebase
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
parent
6e7c1ed8bd
commit
9366ab384e
|
@ -11,7 +11,8 @@ class FormUtil {
|
|||
/**
|
||||
* Reads a string from the console.
|
||||
*
|
||||
* @param label Label that is shown before the input
|
||||
* @param label
|
||||
* Label that is shown before the input
|
||||
* @return read string
|
||||
*/
|
||||
static String readString(String label) {
|
||||
|
@ -21,8 +22,10 @@ class FormUtil {
|
|||
/**
|
||||
* Reads a string from the console.
|
||||
*
|
||||
* @param label Label that is shown before the input
|
||||
* @param defaultValue the default value in case an empty input is provided
|
||||
* @param label
|
||||
* Label that is shown before the input
|
||||
* @param defaultValue
|
||||
* the default value in case an empty input is provided
|
||||
* @return read string
|
||||
*/
|
||||
static String readString(String label, String defaultValue) {
|
||||
|
@ -51,6 +54,7 @@ class FormUtil {
|
|||
password = String.valueOf(System.console().readPassword());
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a password from the console.
|
||||
*
|
||||
|
@ -64,7 +68,8 @@ class FormUtil {
|
|||
/**
|
||||
* Reads an integer from the console.
|
||||
*
|
||||
* @param label Label that is shown before the input
|
||||
* @param label
|
||||
* Label that is shown before the input
|
||||
* @return read integer
|
||||
*/
|
||||
static int readInt(String label) {
|
||||
|
@ -74,8 +79,10 @@ class FormUtil {
|
|||
/**
|
||||
* Reads an integer from the console.
|
||||
*
|
||||
* @param label Label that is shown before the input
|
||||
* @param defaultValue the default value
|
||||
* @param label
|
||||
* Label that is shown before the input
|
||||
* @param defaultValue
|
||||
* the default value
|
||||
* @return read integer
|
||||
*/
|
||||
static int readInt(String label, int defaultValue) {
|
||||
|
@ -83,7 +90,7 @@ class FormUtil {
|
|||
boolean finished = false;
|
||||
String defaultValueStr = defaultValue == -1 ? "" : String.valueOf(defaultValue);
|
||||
|
||||
while(!finished) {
|
||||
while (!finished) {
|
||||
String line = readString(label, defaultValueStr);
|
||||
|
||||
try {
|
||||
|
|
|
@ -48,23 +48,21 @@ public class Main {
|
|||
mainMenu.addEntry("Quit", QUIT);
|
||||
|
||||
// process input
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = mainMenu.show();
|
||||
|
||||
switch(response) {
|
||||
switch (response) {
|
||||
case MENU_AGENT:
|
||||
if (checkPassword()) {
|
||||
showEstateAgentMenu();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
System.out.println("The password was wrong.");
|
||||
}
|
||||
break;
|
||||
case MENU_ESTATES:
|
||||
if (loginEstateAgent()) {
|
||||
showEstateMenu();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
System.out.println("The username or password was wrong.");
|
||||
}
|
||||
break;
|
||||
|
@ -116,10 +114,10 @@ public class Main {
|
|||
estateMenu.addEntry("Back to the main menu", BACK);
|
||||
|
||||
// process input
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = estateMenu.show();
|
||||
|
||||
switch(response) {
|
||||
switch (response) {
|
||||
case NEW_ESTATE:
|
||||
newEstate();
|
||||
break;
|
||||
|
@ -156,8 +154,7 @@ public class Main {
|
|||
apartment.setBalcony(input.equals("Y") || input.equals("y"));
|
||||
input = FormUtil.readString("Built-in Kitchen(Y/N)");
|
||||
apartment.setBuiltinKitchen(input.equals("Y") || input.equals("y"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
House house = new House(estate);
|
||||
house.setPrice(FormUtil.readInt("Price"));
|
||||
house.setFloors(FormUtil.readInt("Floors"));
|
||||
|
@ -188,7 +185,7 @@ public class Main {
|
|||
listEstates.addEntry("Back to the Estate management menu", BACK);
|
||||
|
||||
// process input
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = listEstates.show();
|
||||
|
||||
switch (response) {
|
||||
|
@ -205,7 +202,8 @@ public class Main {
|
|||
/**
|
||||
* Shows a selected estate.
|
||||
*
|
||||
* @param id the id of the selected estate
|
||||
* @param id
|
||||
* the id of the selected estate
|
||||
*/
|
||||
private static void showEstate(int id) {
|
||||
Estate estate = _orm.getEstate(id);
|
||||
|
@ -222,7 +220,7 @@ public class Main {
|
|||
showEstateMenu.addEntry("Delete", DELETE);
|
||||
showEstateMenu.addEntry("Back to the list of estates", BACK);
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = showEstateMenu.show();
|
||||
|
||||
switch (response) {
|
||||
|
@ -241,7 +239,8 @@ public class Main {
|
|||
/**
|
||||
* Prints the estate details to command line.
|
||||
*
|
||||
* @param estate the estate from which the details should be printed to commandline
|
||||
* @param estate
|
||||
* the estate from which the details should be printed to commandline
|
||||
*/
|
||||
private static void printEstateDetails(Estate estate) {
|
||||
System.out.println("------------------");
|
||||
|
@ -257,8 +256,7 @@ public class Main {
|
|||
System.out.println("Price: " + house.getPrice());
|
||||
System.out.println("Floors: " + house.getFloors());
|
||||
System.out.println("Garden: " + (house.hasGarden() ? "yes" : "false"));
|
||||
}
|
||||
else if (estate instanceof Apartment) {
|
||||
} else if (estate instanceof Apartment) {
|
||||
Apartment apartment = (Apartment) estate;
|
||||
System.out.println("Floor: " + apartment.getFloor());
|
||||
System.out.println("Rooms: " + apartment.getRooms());
|
||||
|
@ -287,7 +285,8 @@ public class Main {
|
|||
/**
|
||||
* Modify estate.
|
||||
*
|
||||
* @param estate the modified estate
|
||||
* @param estate
|
||||
* the modified estate
|
||||
*/
|
||||
private static void modifyEstate(Estate estate) {
|
||||
System.out.println("Modify Estate");
|
||||
|
@ -306,16 +305,15 @@ public class Main {
|
|||
apartment.setFloor(FormUtil.readInt("Floor", apartment.getFloor()));
|
||||
apartment.setRooms(FormUtil.readInt("Rooms", apartment.getRooms()));
|
||||
apartment.setRent(FormUtil.readInt("Rent", apartment.getRent()));
|
||||
String input = FormUtil.readString("Balcony(Y/N)", apartment.hasBalcony()?"Y":"N");
|
||||
String input = FormUtil.readString("Balcony(Y/N)", apartment.hasBalcony() ? "Y" : "N");
|
||||
apartment.setBalcony(input.equals("Y") || input.equals("y"));
|
||||
input = FormUtil.readString("Built-in Kitchen(Y/N)", apartment.hasBuiltinKitchen()?"Y":"N");
|
||||
input = FormUtil.readString("Built-in Kitchen(Y/N)", apartment.hasBuiltinKitchen() ? "Y" : "N");
|
||||
apartment.setBuiltinKitchen(input.equals("Y") || input.equals("y"));
|
||||
}
|
||||
else if (estate instanceof House){
|
||||
} else if (estate instanceof House) {
|
||||
House house = (House) estate;
|
||||
house.setFloors(FormUtil.readInt("Floors", house.getFloors()));
|
||||
house.setPrice(FormUtil.readInt("Price", house.getPrice()));
|
||||
String input = FormUtil.readString("Garden(Y/N)", house.hasGarden()?"Y":"N");
|
||||
String input = FormUtil.readString("Garden(Y/N)", house.hasGarden() ? "Y" : "N");
|
||||
house.setGarden(input.equals("Y") || input.equals("y"));
|
||||
}
|
||||
|
||||
|
@ -328,7 +326,8 @@ public class Main {
|
|||
/**
|
||||
* Deletes an estate.
|
||||
*
|
||||
* @param estate the estate that should be deleted
|
||||
* @param estate
|
||||
* the estate that should be deleted
|
||||
*/
|
||||
private static void deleteEstate(Estate estate) {
|
||||
_orm.delete(estate);
|
||||
|
@ -351,10 +350,10 @@ public class Main {
|
|||
estateAgentMenu.addEntry("Back to the main menu", BACK);
|
||||
|
||||
// process input
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = estateAgentMenu.show();
|
||||
|
||||
switch(response) {
|
||||
switch (response) {
|
||||
case NEW_AGENT:
|
||||
newEstateAgent();
|
||||
break;
|
||||
|
@ -401,7 +400,7 @@ public class Main {
|
|||
listEstateAgents.addEntry("Back to the EstateAgent management menu", BACK);
|
||||
|
||||
// process input
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = listEstateAgents.show();
|
||||
|
||||
switch (response) {
|
||||
|
@ -417,7 +416,8 @@ public class Main {
|
|||
/**
|
||||
* Shows a selected estate agent.
|
||||
*
|
||||
* @param id the id of the selected agent
|
||||
* @param id
|
||||
* the id of the selected agent
|
||||
*/
|
||||
private static void showEstateAgent(int id) {
|
||||
EstateAgent agent = _orm.getAgent(id);
|
||||
|
@ -439,7 +439,7 @@ public class Main {
|
|||
showEstateAgentMenu.addEntry("Delete", DELETE);
|
||||
showEstateAgentMenu.addEntry("Back to the list of agents", BACK);
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = showEstateAgentMenu.show();
|
||||
|
||||
switch (response) {
|
||||
|
@ -458,7 +458,8 @@ public class Main {
|
|||
/**
|
||||
* Modify estate agent.
|
||||
*
|
||||
* @param agent the modified agent
|
||||
* @param agent
|
||||
* the modified agent
|
||||
*/
|
||||
private static void modifyEstateAgent(EstateAgent agent) {
|
||||
System.out.println("Modify EstateAgent");
|
||||
|
@ -483,7 +484,8 @@ public class Main {
|
|||
/**
|
||||
* Deletes an estate agent.
|
||||
*
|
||||
* @param agent the agent that should be deleted
|
||||
* @param agent
|
||||
* the agent that should be deleted
|
||||
*/
|
||||
private static void deleteEstateAgent(EstateAgent agent) {
|
||||
_orm.delete(agent);
|
||||
|
@ -502,16 +504,16 @@ public class Main {
|
|||
|
||||
// create menu
|
||||
Menu mainMenu = new Menu("Contract Management");
|
||||
mainMenu.addEntry("Insert person", INSERT_PERSON );
|
||||
mainMenu.addEntry("Insert person", INSERT_PERSON);
|
||||
mainMenu.addEntry("Create/Sign contract", CREATE_CONTRACT);
|
||||
mainMenu.addEntry("Contracts overview", OVERVIEW_CONTRACTS);
|
||||
mainMenu.addEntry("Back", BACK);
|
||||
|
||||
// process input
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = mainMenu.show();
|
||||
|
||||
switch(response) {
|
||||
switch (response) {
|
||||
case INSERT_PERSON:
|
||||
newPerson();
|
||||
break;
|
||||
|
@ -572,8 +574,7 @@ public class Main {
|
|||
long duration = endDate.getTime() - startDate.getTime();
|
||||
tenancyContract.setDuration(Duration.ofMillis(duration));
|
||||
tenancyContract.setAdditionalCost(FormUtil.readInt("Additional Costs"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
boolean housesAvailable = printListOfHouses();
|
||||
if (!housesAvailable) {
|
||||
System.out.println("No houses available to sell.");
|
||||
|
@ -654,7 +655,8 @@ public class Main {
|
|||
continue;
|
||||
}
|
||||
System.out.println("ID: " + apartment.getId() + "; Address: " + apartment.getStreet() + " "
|
||||
+ apartment.getStreetNumber() + ", " + apartment.getPostalCode() + " " + apartment.getCity());
|
||||
+ apartment.getStreetNumber() + ", " + apartment.getPostalCode() + " " +
|
||||
apartment.getCity());
|
||||
}
|
||||
System.out.println("------------------");
|
||||
|
||||
|
@ -678,7 +680,7 @@ public class Main {
|
|||
listContracts.addEntry("Back to the Contract management menu", BACK);
|
||||
|
||||
// process input
|
||||
while(true) {
|
||||
while (true) {
|
||||
int response = listContracts.show();
|
||||
|
||||
switch (response) {
|
||||
|
@ -694,7 +696,8 @@ public class Main {
|
|||
/**
|
||||
* Prints the contract details to command line.
|
||||
*
|
||||
* @param contract the contract from which the details should be printed to commandline
|
||||
* @param contract
|
||||
* the contract from which the details should be printed to commandline
|
||||
*/
|
||||
private static void printContractDetails(Contract contract) {
|
||||
System.out.println("------------------");
|
||||
|
@ -711,8 +714,7 @@ public class Main {
|
|||
estate = _orm.getEstate(purchaseContract.getHouse());
|
||||
System.out.println("House: " + estate.getStreet() + " " + estate.getStreetNumber() + ", "
|
||||
+ estate.getPostalCode() + " " + estate.getCity());
|
||||
}
|
||||
else if (contract instanceof TenancyContract) {
|
||||
} else if (contract instanceof TenancyContract) {
|
||||
TenancyContract tenancyContract = (TenancyContract) contract;
|
||||
Duration duration = tenancyContract.getDuration();
|
||||
System.out.println("Start Date: " + DateFormat.getInstance().format(tenancyContract.getStartDate()));
|
||||
|
@ -728,7 +730,8 @@ public class Main {
|
|||
/**
|
||||
* Shows a selected contract.
|
||||
*
|
||||
* @param id the id of the selected contract
|
||||
* @param id
|
||||
* the id of the selected contract
|
||||
*/
|
||||
private static void showContract(int id) {
|
||||
Contract contract = _orm.getContract(id);
|
||||
|
|
|
@ -7,17 +7,17 @@ import java.util.ArrayList;
|
|||
|
||||
/**
|
||||
* Small helper class for menus.
|
||||
*
|
||||
* <p>
|
||||
* First menu entries have to be created with addEntry. Afterwards the menu can be shown
|
||||
* on the console with show(). show() also returns the constant number of the selected menu entry.
|
||||
*
|
||||
* <p>
|
||||
* Example:
|
||||
* Menu m = new Menu("Main menu");
|
||||
* m.addEntry("Work hard", 0);
|
||||
* m.addEntry("Rest", 1);
|
||||
* m.addEntry("Go home", 2);
|
||||
* int chosenOption = m.show();
|
||||
*
|
||||
* <p>
|
||||
* This results in the following output on the console:
|
||||
* Main menu:
|
||||
* [1] Work hard
|
||||
|
@ -33,7 +33,8 @@ class Menu {
|
|||
/**
|
||||
* Initializes the menu object.
|
||||
*
|
||||
* @param title Title of the menu (e.g. "Main menu")
|
||||
* @param title
|
||||
* Title of the menu (e.g. "Main menu")
|
||||
*/
|
||||
Menu(String title) {
|
||||
super();
|
||||
|
@ -43,8 +44,10 @@ class Menu {
|
|||
/**
|
||||
* Adds a new menu entry
|
||||
*
|
||||
* @param label Name of the entry
|
||||
* @param returnValue constant number which is returned upon selection this entry
|
||||
* @param label
|
||||
* Name of the entry
|
||||
* @param returnValue
|
||||
* constant number which is returned upon selection this entry
|
||||
*/
|
||||
void addEntry(String label, int returnValue) {
|
||||
_labels.add(label);
|
||||
|
@ -61,10 +64,10 @@ class Menu {
|
|||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
while(selection == -1) {
|
||||
System.out.println(_title+":");
|
||||
while (selection == -1) {
|
||||
System.out.println(_title + ":");
|
||||
|
||||
for(int i = 0; i < _labels.size(); ++i) {
|
||||
for (int i = 0; i < _labels.size(); ++i) {
|
||||
System.out.println("[" + (i + 1) + "] " + _labels.get(i));
|
||||
}
|
||||
|
||||
|
@ -75,12 +78,12 @@ class Menu {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(selection < 1 || selection > _returnValues.size()) {
|
||||
if (selection < 1 || selection > _returnValues.size()) {
|
||||
System.err.println("Invalid input!");
|
||||
selection = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return _returnValues.get(selection-1);
|
||||
return _returnValues.get(selection - 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package de.dis2017.data;
|
||||
|
||||
public class Apartment extends Estate{
|
||||
public class Apartment extends Estate {
|
||||
private int floor;
|
||||
private int rent;
|
||||
private int rooms;
|
||||
private boolean balcony;
|
||||
private boolean builtinKitchen;
|
||||
|
||||
public Apartment(){
|
||||
public Apartment() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Apartment(Estate estate){
|
||||
public Apartment(Estate estate) {
|
||||
this.setId(estate.getId());
|
||||
this.setCity(estate.getCity());
|
||||
this.setPostalCode(estate.getPostalCode());
|
||||
|
@ -24,30 +24,39 @@ public class Apartment extends Estate{
|
|||
public int getFloor() {
|
||||
return floor;
|
||||
}
|
||||
|
||||
public void setFloor(int floor) {
|
||||
this.floor = floor;
|
||||
}
|
||||
|
||||
public int getRent() {
|
||||
return rent;
|
||||
}
|
||||
|
||||
public void setRent(int rent) {
|
||||
this.rent = rent;
|
||||
}
|
||||
|
||||
public int getRooms() {
|
||||
return rooms;
|
||||
}
|
||||
|
||||
public void setRooms(int rooms) {
|
||||
this.rooms = rooms;
|
||||
}
|
||||
|
||||
public boolean hasBalcony() {
|
||||
return balcony;
|
||||
}
|
||||
|
||||
public void setBalcony(boolean balcony) {
|
||||
this.balcony = balcony;
|
||||
}
|
||||
|
||||
public boolean hasBuiltinKitchen() {
|
||||
return builtinKitchen;
|
||||
}
|
||||
|
||||
public void setBuiltinKitchen(boolean builtinKitchen) {
|
||||
this.builtinKitchen = builtinKitchen;
|
||||
}
|
||||
|
|
|
@ -15,30 +15,39 @@ public class Contract {
|
|||
public int getEstate() {
|
||||
return estate;
|
||||
}
|
||||
|
||||
public void setEstate(int estate) {
|
||||
this.estate = estate;
|
||||
}
|
||||
|
||||
public int getContractNo() {
|
||||
return contractNo;
|
||||
}
|
||||
|
||||
public void setContractNo(int contractNo) {
|
||||
this.contractNo = contractNo;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public void setPlace(String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public int getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(int person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ public class House extends Estate {
|
|||
private int price;
|
||||
private boolean garden;
|
||||
|
||||
public House(){
|
||||
public House() {
|
||||
super();
|
||||
}
|
||||
|
||||
public House(Estate estate){
|
||||
public House(Estate estate) {
|
||||
this.setId(estate.getId());
|
||||
this.setCity(estate.getCity());
|
||||
this.setPostalCode(estate.getPostalCode());
|
||||
|
@ -22,18 +22,23 @@ public class House extends Estate {
|
|||
public int getFloors() {
|
||||
return floors;
|
||||
}
|
||||
|
||||
public void setFloors(int floors) {
|
||||
this.floors = floors;
|
||||
}
|
||||
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(int price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public boolean hasGarden() {
|
||||
return garden;
|
||||
}
|
||||
|
||||
public void setGarden(boolean garden) {
|
||||
this.garden = garden;
|
||||
}
|
||||
|
|
|
@ -7,22 +7,29 @@ public class Person {
|
|||
private String address;
|
||||
|
||||
public int getId() { return id; }
|
||||
|
||||
public void setId(int id) { this.id = id; }
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String adress) {
|
||||
this.address = adress;
|
||||
}
|
||||
|
|
|
@ -4,10 +4,11 @@ public class PurchaseContract extends Contract {
|
|||
private int noOfInstallments;
|
||||
private int interestRate;
|
||||
|
||||
public PurchaseContract(){
|
||||
public PurchaseContract() {
|
||||
super();
|
||||
}
|
||||
public PurchaseContract(Contract contract){
|
||||
|
||||
public PurchaseContract(Contract contract) {
|
||||
this.setContractNo(contract.getContractNo());
|
||||
this.setDate(contract.getDate());
|
||||
this.setPlace(contract.getPlace());
|
||||
|
|
|
@ -9,11 +9,11 @@ public class TenancyContract extends Contract {
|
|||
private Duration duration;
|
||||
private int additionalCost;
|
||||
|
||||
public TenancyContract(){
|
||||
public TenancyContract() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TenancyContract(Contract contract){
|
||||
public TenancyContract(Contract contract) {
|
||||
this.setContractNo(contract.getContractNo());
|
||||
this.setDate(contract.getDate());
|
||||
this.setPlace(contract.getPlace());
|
||||
|
|
|
@ -44,7 +44,7 @@ class DB2ConnectionManager {
|
|||
Class.forName("com.ibm.db2.jcc.DB2Driver");
|
||||
_con = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass);
|
||||
|
||||
} catch (IOException | ClassNotFoundException | SQLException | URISyntaxException e){
|
||||
} catch (IOException | ClassNotFoundException | SQLException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ public class ORM {
|
|||
/**
|
||||
* Loads all objects from the database and returns a list of them.
|
||||
*
|
||||
* @param objectType the type of objects to load
|
||||
* @param objectType
|
||||
* the type of objects to load
|
||||
* @return a list of objects
|
||||
*/
|
||||
public List<?> getAll(Type objectType) {
|
||||
|
@ -139,9 +140,12 @@ public class ORM {
|
|||
/**
|
||||
* Process a select all query for estates.
|
||||
*
|
||||
* @param rs the result set of such a query
|
||||
* @param rs
|
||||
* the result set of such a query
|
||||
* @return a list of estates
|
||||
* @throws SQLException when an error occurs during the rs.next call
|
||||
*
|
||||
* @throws SQLException
|
||||
* when an error occurs during the rs.next call
|
||||
*/
|
||||
private List<Estate> processEstates(ResultSet rs) throws SQLException {
|
||||
List<Estate> estates = new ArrayList<>();
|
||||
|
@ -165,10 +169,14 @@ public class ORM {
|
|||
/**
|
||||
* Process a select all query for houses.
|
||||
*
|
||||
* @param rs the result set of such a query
|
||||
* @param estates a list of estates
|
||||
* @param rs
|
||||
* the result set of such a query
|
||||
* @param estates
|
||||
* a list of estates
|
||||
* @return a list of houses
|
||||
* @throws SQLException when an error occurs during the rs.next call
|
||||
*
|
||||
* @throws SQLException
|
||||
* when an error occurs during the rs.next call
|
||||
*/
|
||||
private List<House> processHouses(ResultSet rs, List<?> estates) throws SQLException {
|
||||
List<House> houses = new ArrayList<>();
|
||||
|
@ -205,10 +213,14 @@ public class ORM {
|
|||
/**
|
||||
* Process a select all query for houses.
|
||||
*
|
||||
* @param rs the result set of such a query
|
||||
* @param estates a list of estates
|
||||
* @param rs
|
||||
* the result set of such a query
|
||||
* @param estates
|
||||
* a list of estates
|
||||
* @return a list of houses
|
||||
* @throws SQLException when an error occurs during the rs.next call
|
||||
*
|
||||
* @throws SQLException
|
||||
* when an error occurs during the rs.next call
|
||||
*/
|
||||
private List<Apartment> processApartments(ResultSet rs, List<?> estates) throws SQLException {
|
||||
List<Apartment> apartments = new ArrayList<>();
|
||||
|
@ -247,9 +259,12 @@ public class ORM {
|
|||
/**
|
||||
* Processes a select all query for estate agents.
|
||||
*
|
||||
* @param rs the result set of such a query
|
||||
* @param rs
|
||||
* the result set of such a query
|
||||
* @return a list of agents
|
||||
* @throws SQLException when an error occurs during the rs.next call
|
||||
*
|
||||
* @throws SQLException
|
||||
* when an error occurs during the rs.next call
|
||||
*/
|
||||
private List<EstateAgent> processAgents(ResultSet rs) throws SQLException {
|
||||
List<EstateAgent> agents = new ArrayList<>();
|
||||
|
@ -272,9 +287,12 @@ public class ORM {
|
|||
/**
|
||||
* Process a select all query for contracts.
|
||||
*
|
||||
* @param rs the result set of such a query
|
||||
* @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
|
||||
*
|
||||
* @throws SQLException
|
||||
* when an error occurs during the rs.next call
|
||||
*/
|
||||
private List<Contract> processContracts(ResultSet rs) throws SQLException {
|
||||
List<Contract> contracts = new ArrayList<>();
|
||||
|
@ -294,9 +312,12 @@ public class ORM {
|
|||
/**
|
||||
* Process a select all query for persons.
|
||||
*
|
||||
* @param rs the result set of such a query
|
||||
* @param rs
|
||||
* the result set of such a query
|
||||
* @return a list of persons
|
||||
* @throws SQLException when an error occurs during the rs.next call
|
||||
*
|
||||
* @throws SQLException
|
||||
* when an error occurs during the rs.next call
|
||||
*/
|
||||
private List<Person> processPersons(ResultSet rs) throws SQLException {
|
||||
List<Person> persons = new ArrayList<>();
|
||||
|
@ -317,7 +338,8 @@ public class ORM {
|
|||
/**
|
||||
* Loads the contract with the given ID from database and returns the corresponding object.
|
||||
*
|
||||
* @param ID the id of the contract to load
|
||||
* @param ID
|
||||
* the id of the contract to load
|
||||
* @return the Contract or null if there is no such object
|
||||
*/
|
||||
public Contract getContract(int ID) {
|
||||
|
@ -354,8 +376,7 @@ public class ORM {
|
|||
if (count == 1) {
|
||||
type = "TenancyContract";
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
type = "PurchaseContract";
|
||||
}
|
||||
rs.close();
|
||||
|
@ -414,7 +435,8 @@ public class ORM {
|
|||
/**
|
||||
* Loads the estate with the given ID from database and returns the corresponding object.
|
||||
*
|
||||
* @param ID the id of the estate to load
|
||||
* @param ID
|
||||
* the id of the estate to load
|
||||
* @return the Estate or null if there is no such object
|
||||
*/
|
||||
public Estate getEstate(int ID) {
|
||||
|
@ -447,8 +469,7 @@ public class ORM {
|
|||
if (count == 1) {
|
||||
type = "Apartment";
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
type = "House";
|
||||
}
|
||||
rs.close();
|
||||
|
@ -511,7 +532,8 @@ public class ORM {
|
|||
/**
|
||||
* Loads the estate agent with the given ID from database and returns the corresponding object.
|
||||
*
|
||||
* @param ID the ID of the agent to load
|
||||
* @param ID
|
||||
* the ID of the agent to load
|
||||
* @return the EstateAgent or null if there is no such agent
|
||||
*/
|
||||
public EstateAgent getAgent(int ID) {
|
||||
|
@ -536,7 +558,8 @@ public class ORM {
|
|||
/**
|
||||
* Loads the person with the given ID from database and returns the corresponding object.
|
||||
*
|
||||
* @param ID the ID of the person to load
|
||||
* @param ID
|
||||
* the ID of the person to load
|
||||
* @return the Person or null if there is no such agent
|
||||
*/
|
||||
public Person getPerson(int ID) {
|
||||
|
@ -576,7 +599,8 @@ public class ORM {
|
|||
/**
|
||||
* Loads the estate agent with the given username from database and returns the corresponding object,
|
||||
*
|
||||
* @param username the username of the estate agent
|
||||
* @param username
|
||||
* the username of the estate agent
|
||||
* @return the EstateAgent or null if there is no such agent
|
||||
*/
|
||||
public EstateAgent getAgent(String username) {
|
||||
|
@ -601,12 +625,12 @@ public class ORM {
|
|||
/**
|
||||
* Executes the given statement and returns an estate agent.
|
||||
*
|
||||
* @param pstmt the prepared statement with parameters already set
|
||||
* @param pstmt
|
||||
* the prepared statement with parameters already set
|
||||
* @return the EstateAgent or null
|
||||
*/
|
||||
@Nullable
|
||||
private EstateAgent getAgent(PreparedStatement pstmt)
|
||||
{
|
||||
private EstateAgent getAgent(PreparedStatement pstmt) {
|
||||
try {
|
||||
// execute query
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
|
@ -636,10 +660,10 @@ public class ORM {
|
|||
/**
|
||||
* Deletes the given agent from the database.
|
||||
*
|
||||
* @param agent the agent that should be deleted
|
||||
* @param agent
|
||||
* the agent that should be deleted
|
||||
*/
|
||||
public void delete(EstateAgent agent)
|
||||
{
|
||||
public void delete(EstateAgent agent) {
|
||||
if (agent.getId() == -1) {
|
||||
System.err.println("This agent is not yet persisted to the database and cannot be deleted.");
|
||||
return;
|
||||
|
@ -659,7 +683,8 @@ public class ORM {
|
|||
/**
|
||||
* Deletes an estate from the database.
|
||||
*
|
||||
* @param estate the estate to be deleted
|
||||
* @param estate
|
||||
* the estate to be deleted
|
||||
*/
|
||||
public void delete(Estate estate) {
|
||||
if (estate.getId() == -1) {
|
||||
|
@ -682,11 +707,12 @@ public class ORM {
|
|||
/**
|
||||
* Deletes an object from the database.
|
||||
*
|
||||
* @param sql the sql used for deletion
|
||||
* @param id the id of the object to be deleted
|
||||
* @param sql
|
||||
* the sql used for deletion
|
||||
* @param id
|
||||
* the id of the object to be deleted
|
||||
*/
|
||||
private void delete(String sql, int id)
|
||||
{
|
||||
private void delete(String sql, int id) {
|
||||
try {
|
||||
PreparedStatement pstmt = _connection.prepareStatement(sql);
|
||||
pstmt.setInt(1, id);
|
||||
|
@ -702,13 +728,14 @@ public class ORM {
|
|||
/**
|
||||
* Persists the given agent.
|
||||
*
|
||||
* @param agent the agent that should be persisted
|
||||
* @param agent
|
||||
* the agent that should be persisted
|
||||
*/
|
||||
public void persist(EstateAgent agent)
|
||||
{
|
||||
public void persist(EstateAgent agent) {
|
||||
try {
|
||||
if (agent.getId() == -1) {
|
||||
String insertSQL = "INSERT INTO ESTATEAGENT (name, address, login, password) VALUES (?, ?, ?, ?)";
|
||||
String insertSQL
|
||||
= "INSERT INTO ESTATEAGENT (name, address, login, password) VALUES (?, ?, ?, ?)";
|
||||
PreparedStatement pstmt = _connection.prepareStatement(insertSQL, Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
pstmt.setString(1, agent.getName());
|
||||
|
@ -751,10 +778,10 @@ public class ORM {
|
|||
/**
|
||||
* Persists the given estate.
|
||||
*
|
||||
* @param estate the estate that should be persisted
|
||||
* @param estate
|
||||
* the estate that should be persisted
|
||||
*/
|
||||
public void persist(Estate estate)
|
||||
{
|
||||
public void persist(Estate estate) {
|
||||
boolean changeFinished = false;
|
||||
try {
|
||||
_connection.setAutoCommit(false);
|
||||
|
@ -779,7 +806,8 @@ public class ORM {
|
|||
|
||||
if (estate instanceof House) {
|
||||
House house = (House) estate;
|
||||
String insertSQLHouse = "INSERT INTO HOUSE (ID, price, garden, floors) VALUES (?, ?, ?, ?)";
|
||||
String insertSQLHouse
|
||||
= "INSERT INTO HOUSE (ID, price, garden, floors) VALUES (?, ?, ?, ?)";
|
||||
PreparedStatement pstmtHouse = _connection.prepareStatement(insertSQLHouse);
|
||||
pstmtHouse.setInt(1, house.getId());
|
||||
pstmtHouse.setInt(2, house.getPrice());
|
||||
|
@ -790,10 +818,10 @@ public class ORM {
|
|||
pstmt.close();
|
||||
pstmtHouse.close();
|
||||
changeFinished = true;
|
||||
}
|
||||
else if (estate instanceof Apartment) {
|
||||
} else if (estate instanceof Apartment) {
|
||||
Apartment apartment = (Apartment) estate;
|
||||
String insertSQLApartment = "INSERT INTO APARTMENT (ID, floor, rent, rooms, balcony, builtInKitchen) " +
|
||||
String insertSQLApartment =
|
||||
"INSERT INTO APARTMENT (ID, floor, rent, rooms, balcony, builtInKitchen) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement pstmtApartment = _connection.prepareStatement(insertSQLApartment);
|
||||
pstmtApartment.setInt(1, apartment.getId());
|
||||
|
@ -823,7 +851,8 @@ public class ORM {
|
|||
|
||||
if (estate instanceof House) {
|
||||
House house = (House) estate;
|
||||
String updateSQLHouse = "UPDATE HOUSE SET floors = ?, garden = ?, price = ? WHERE ID = ?";
|
||||
String updateSQLHouse
|
||||
= "UPDATE HOUSE SET floors = ?, garden = ?, price = ? WHERE ID = ?";
|
||||
PreparedStatement pstmtHouse = _connection.prepareStatement(updateSQLHouse);
|
||||
pstmtHouse.setInt(1, house.getFloors());
|
||||
pstmtHouse.setInt(2, house.hasGarden() ? 1 : 0);
|
||||
|
@ -834,8 +863,7 @@ public class ORM {
|
|||
pstmt.close();
|
||||
pstmtHouse.close();
|
||||
changeFinished = true;
|
||||
}
|
||||
else if (estate instanceof Apartment) {
|
||||
} else if (estate instanceof Apartment) {
|
||||
Apartment apartment = (Apartment) estate;
|
||||
String updateSQLApartment = "UPDATE APARTMENT SET floor = ?, rent = ?, rooms = ?, " +
|
||||
"balcony = ?, builtInKitchen = ? WHERE ID = ?";
|
||||
|
@ -873,10 +901,10 @@ public class ORM {
|
|||
/**
|
||||
* Persists the given contract.
|
||||
*
|
||||
* @param contract the contract that should be persisted
|
||||
* @param contract
|
||||
* the contract that should be persisted
|
||||
*/
|
||||
public void persist(Contract contract)
|
||||
{
|
||||
public void persist(Contract contract) {
|
||||
boolean changeFinished = false;
|
||||
try {
|
||||
_connection.setAutoCommit(false);
|
||||
|
@ -907,7 +935,8 @@ public class ORM {
|
|||
pstmtPurchase.executeUpdate();
|
||||
pstmtPurchase.close();
|
||||
|
||||
String insertSQLSale = "INSERT INTO SALES (contractNumber, house, person) VALUES (?, ?, ?)";
|
||||
String insertSQLSale
|
||||
= "INSERT INTO SALES (contractNumber, house, person) VALUES (?, ?, ?)";
|
||||
PreparedStatement pstmtSale = _connection.prepareStatement(insertSQLSale);
|
||||
pstmtSale.setInt(1, purchaseContract.getContractNo());
|
||||
pstmtSale.setInt(2, purchaseContract.getHouse());
|
||||
|
@ -915,8 +944,7 @@ public class ORM {
|
|||
pstmtSale.executeUpdate();
|
||||
pstmtSale.close();
|
||||
changeFinished = true;
|
||||
}
|
||||
else if (contract instanceof TenancyContract) {
|
||||
} else if (contract instanceof TenancyContract) {
|
||||
TenancyContract tenancyContract = (TenancyContract) contract;
|
||||
String insertSQLTenancyContract = "INSERT INTO TENANCYCONTRACT " +
|
||||
"(contractNumber, startDate, duration, additionalCosts) " +
|
||||
|
@ -929,7 +957,8 @@ public class ORM {
|
|||
pstmtTenancy.executeUpdate();
|
||||
pstmtTenancy.close();
|
||||
|
||||
String insertSQLRental = "INSERT INTO RENTALS (contractNumber, apartment, person) VALUES (?, ?, ?)";
|
||||
String insertSQLRental
|
||||
= "INSERT INTO RENTALS (contractNumber, apartment, person) VALUES (?, ?, ?)";
|
||||
PreparedStatement pstmtRental = _connection.prepareStatement(insertSQLRental);
|
||||
pstmtRental.setInt(1, tenancyContract.getContractNo());
|
||||
pstmtRental.setInt(2, tenancyContract.getApartment());
|
||||
|
@ -961,10 +990,10 @@ public class ORM {
|
|||
/**
|
||||
* Persists the given person.
|
||||
*
|
||||
* @param person the person that should be persisted
|
||||
* @param person
|
||||
* the person that should be persisted
|
||||
*/
|
||||
public void persist(Person person)
|
||||
{
|
||||
public void persist(Person person) {
|
||||
try {
|
||||
if (person.getId() == -1) {
|
||||
String insertSQL = "INSERT INTO PERSON (firstName, name, address) VALUES (?, ?, ?)";
|
||||
|
|
Loading…
Reference in New Issue