Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/library/assistant/database/DatabaseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void inflateDB() {
List<String> tableData = new ArrayList<>();
try {
Set<String> loadedTables = getDBTables();
System.out.println("Already loaded tables " + loadedTables);
LOGGER.log(Level.INFO, "Already loaded tables {}", loadedTables);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(DatabaseHandler.class.getClass().getResourceAsStream("/resources/database/tables.xml"));
Expand All @@ -71,15 +71,15 @@ private static void inflateDB() {
}
}
if (tableData.isEmpty()) {
System.out.println("Tables are already loaded");
LOGGER.log(Level.INFO, "Tables are already loaded");
}
else {
System.out.println("Inflating new tables.");
LOGGER.log(Level.INFO, "Inflating new tables.");
createTables(tableData);
}
}
catch (Exception ex) {
LOGGER.log(Level.ERROR, "{}", ex);
LOGGER.log(Level.ERROR, "Exception occurred", ex);
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ public ResultSet execQuery(String query) {
result = stmt.executeQuery(query);
}
catch (SQLException ex) {
System.out.println("Exception at execQuery:dataHandler" + ex.getLocalizedMessage());
LOGGER.log(Level.ERROR, "Exception at execQuery:dataHandler", ex);
return null;
}
finally {
Expand All @@ -131,7 +131,7 @@ public boolean execAction(String qu) {
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error:" + ex.getMessage(), "Error Occured", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception at execQuery:dataHandler" + ex.getLocalizedMessage());
LOGGER.log(Level.ERROR, "Exception at execQuery:dataHandler", ex);
return false;
}
finally {
Expand All @@ -149,7 +149,7 @@ public boolean deleteBook(Book book) {
}
}
catch (SQLException ex) {
LOGGER.log(Level.ERROR, "{}", ex);
LOGGER.log(Level.ERROR, "Exception occurred", ex);
}
return false;
}
Expand All @@ -162,12 +162,12 @@ public boolean isBookAlreadyIssued(Book book) {
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
int count = rs.getInt(1);
System.out.println(count);
LOGGER.log(Level.INFO, "Book issue count: {}", count);
return (count > 0);
}
}
catch (SQLException ex) {
LOGGER.log(Level.ERROR, "{}", ex);
LOGGER.log(Level.ERROR, "Exception occurred", ex);
}
return false;
}
Expand All @@ -183,7 +183,7 @@ public boolean deleteMember(MemberListController.Member member) {
}
}
catch (SQLException ex) {
LOGGER.log(Level.ERROR, "{}", ex);
LOGGER.log(Level.ERROR, "Exception occurred", ex);
}
return false;
}
Expand All @@ -196,12 +196,12 @@ public boolean isMemberHasAnyBooks(MemberListController.Member member) {
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
int count = rs.getInt(1);
System.out.println(count);
LOGGER.log(Level.INFO, "Member issue count: {}", count);
return (count > 0);
}
}
catch (SQLException ex) {
LOGGER.log(Level.ERROR, "{}", ex);
LOGGER.log(Level.ERROR, "Exception occurred", ex);
}
return false;
}
Expand All @@ -218,7 +218,7 @@ public boolean updateBook(Book book) {
return (res > 0);
}
catch (SQLException ex) {
LOGGER.log(Level.ERROR, "{}", ex);
LOGGER.log(Level.ERROR, "Exception occurred", ex);
}
return false;
}
Expand All @@ -235,7 +235,7 @@ public boolean updateMember(MemberListController.Member member) {
return (res > 0);
}
catch (SQLException ex) {
LOGGER.log(Level.ERROR, "{}", ex);
LOGGER.log(Level.ERROR, "Exception occurred", ex);
}
return false;
}
Expand All @@ -261,7 +261,7 @@ public ObservableList<PieChart.Data> getBookGraphStatistics() {
}
}
catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.ERROR, "Exception occurred", e);
}
return data;
}
Expand All @@ -283,7 +283,7 @@ public ObservableList<PieChart.Data> getMemberGraphStatistics() {
}
}
catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.ERROR, "Exception occurred", e);
}
return data;
}
Expand All @@ -292,7 +292,7 @@ private static void createTables(List<String> tableData) throws SQLException {
Statement statement = conn.createStatement();
statement.closeOnCompletion();
for (String command : tableData) {
System.out.println(command);
LOGGER.log(Level.INFO, "Executing SQL command: {}", command);
statement.addBatch(command);
}
statement.executeBatch();
Expand Down