# HG changeset patch # User "jurzua " # Date 1426761993 -3600 # Node ID 5610250d021a6f2a634e25ff09a133ed613c45d2 # Parent 964fc53abeec693fa9f55e767c1246ac56832a39 SectionsIndex, we added a method to print the setting of the VM diff -r 964fc53abeec -r 5610250d021a src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java --- a/src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java Wed Mar 18 17:23:45 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java Thu Mar 19 11:46:33 2015 +0100 @@ -65,7 +65,7 @@ public void loadTransientData(){ try { DBSection section = DBService.getSectionWithContent(sectionId); - DBBook book = DBService.getBook(section.getBookId()); + DBBook book = DBService.getBookFromDB(section.getBookId()); this.sectionName = section.getName(); this.book = book; this.transientDataLoaded = true; diff -r 964fc53abeec -r 5610250d021a src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java --- a/src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java Wed Mar 18 17:23:45 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java Thu Mar 19 11:46:33 2015 +0100 @@ -22,7 +22,7 @@ if(sectionId != null){ DBSection section = DBService.getSectionWithContent(sectionId); if(section != null){ - DBBook book = DBService.getBook(section.getBookId()); + DBBook book = DBService.getBookFromDB(section.getBookId()); response.setContentType("application/json"); JSONObject json = new JSONObject(); diff -r 964fc53abeec -r 5610250d021a src/main/java/de/mpiwg/gazetteer/scripts/SectionsIndex.java --- a/src/main/java/de/mpiwg/gazetteer/scripts/SectionsIndex.java Wed Mar 18 17:23:45 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/scripts/SectionsIndex.java Thu Mar 19 11:46:33 2015 +0100 @@ -189,8 +189,34 @@ } + private static void printSetting(){ + + int mb = 1024*1024; + + //Getting the runtime reference from system + Runtime runtime = Runtime.getRuntime(); + + System.out.println("##### Heap utilization statistics [MB] #####"); + + //Print used memory + System.out.println("Used Memory:" + + (runtime.totalMemory() - runtime.freeMemory()) / mb); + + //Print free memory + System.out.println("Free Memory:" + + runtime.freeMemory() / mb); + + //Print total available memory + System.out.println("Total Memory:" + runtime.totalMemory() / mb); + + //Print Maximum available memory + System.out.println("Max Memory:" + runtime.maxMemory() / mb); + } + public static void main(String[] args){ + printSetting(); + String dbName = args[0]; String dbUser = args[1]; String dbPwd = args[2]; diff -r 964fc53abeec -r 5610250d021a src/main/java/de/mpiwg/gazetteer/utils/DBService.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Wed Mar 18 17:23:45 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Thu Mar 19 11:46:33 2015 +0100 @@ -8,7 +8,9 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; import org.hibernate.Query; @@ -31,6 +33,59 @@ static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/"; + private static DBService instance = null; + + public static DBService getInstance(){ + if(instance == null){ + instance = new DBService(); + } + return instance; + } + + private Map bookMap; + + public DBBook getBook(String id){ + return getBookMap().get(id); + } + + private Map getBookMap(){ + if(bookMap == null){ + try { + this.loadBookMap(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return this.bookMap; + } + + private void loadBookMap() throws SQLException{ + Long start = System.currentTimeMillis(); + Connection conn = null; + Statement stmt = null; + this.bookMap = new HashMap(); + + try { + String query = "SELECT * FROM books"; + logger.debug(query); + conn = getNewConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + + while(rs.next()){ + DBBook book = new DBBook(rs); + this.bookMap.put(book.getId(), book); + } + } catch (Exception e) { + e.printStackTrace(); + }finally{ + conn.close(); + } + + long end = System.currentTimeMillis(); + logger.debug("Time execution loading Book Map [ms]: " + (end - start)); + } + /** * This methods search from a list of terms. * Every term is considered a subsequence of whole section name. @@ -56,7 +111,6 @@ } query += "name like '%" + term + "%' "; } - //query += " limit 50"; try { Class.forName(JDBC_DRIVER); @@ -67,7 +121,8 @@ while (rs.next()) { DBSection section = new DBSection(rs); //DBBook book = getBook0(conn, section.getBookId()); - //section.setBook(book); + DBBook book = getInstance().getBook(section.getBookId()); + section.setBook(book); list.add(section); } rs.close(); @@ -78,7 +133,7 @@ } long end = System.currentTimeMillis(); - System.out.println("Time execution [ms]: " + (end - start)); + logger.debug("Time execution serching [ms]: " + (end - start)); return list; } @@ -173,7 +228,7 @@ String content = getContent(conn, bookId, startPage, endPage); response.setText(content); - DBBook book = getBook0(conn, bookId); + DBBook book = getBook0FromDB(conn, bookId); response.setBook(book); } @@ -225,15 +280,14 @@ } - public static DBBook getBook(String id) throws SQLException{ + public static DBBook getBookFromDB(String id) throws SQLException{ Connection conn = null; DBBook book = null; try { - Class.forName(JDBC_DRIVER); - + //Class.forName(JDBC_DRIVER); conn = getNewConnection(); - book = getBook0(conn, id); + book = getBook0FromDB(conn, id); } catch (Exception e) { e.printStackTrace(); } finally { @@ -242,7 +296,7 @@ return book; } - private static DBBook getBook0(Connection conn, String id) throws SQLException{ + private static DBBook getBook0FromDB(Connection conn, String id) throws SQLException{ DBBook book = null; String query = "SELECT * FROM books WHERE id = '" + id + "'"; diff -r 964fc53abeec -r 5610250d021a src/main/java/de/mpiwg/web/SearchBean.java --- a/src/main/java/de/mpiwg/web/SearchBean.java Wed Mar 18 17:23:45 2015 +0100 +++ b/src/main/java/de/mpiwg/web/SearchBean.java Thu Mar 19 11:46:33 2015 +0100 @@ -114,11 +114,12 @@ } for(DBSection section : this.currentSectionList){ + /* try { - section.setBook(DBService.getBook(section.getBookId())); + section.setBook(DBService.getInstance().getBook(section.getBookId())); } catch (SQLException e) { e.printStackTrace(); - } + }*/ section.setBranches(this.branchesMap.get(section.getId())); } }