From 186564f18995d28150c8382a6cce64b0706b7662 Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Fri, 18 Feb 2011 13:00:38 +0100 Subject: [PATCH] Use String arrays instead of GlomTable objects in GlomDocument GWT-RPC object. This is a small performance boost. I'll use GlomTable to get the required layoutlist information. * src/main/java/org/glom/web/client/OnlineGlom.java: * src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java: * src/main/java/org/glom/web/shared/GlomDocument.java: --- ChangeLog | 11 ++++++ src/main/java/org/glom/web/client/OnlineGlom.java | 8 ++-- .../org/glom/web/server/OnlineGlomServiceImpl.java | 43 +++++++++++---------- .../java/org/glom/web/shared/GlomDocument.java | 44 +++++++++++----------- 4 files changed, 60 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index d15d649..8533fb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-02-18 Ben Konrath + Use String arrays instead of GlomTable objects in GlomDocument GWT-RPC object. + + This is a small performance boost. I'll use GlomTable to get the required + layoutlist information. + + * src/main/java/org/glom/web/client/OnlineGlom.java: + * src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java: + * src/main/java/org/glom/web/shared/GlomDocument.java: + +2011-02-18 Ben Konrath + Add option to turn off formatting in JDT formatter preferences. * .settings/org.eclipse.jdt.core.prefs: diff --git a/src/main/java/org/glom/web/client/OnlineGlom.java b/src/main/java/org/glom/web/client/OnlineGlom.java index e2c037f..ba305ce 100644 --- a/src/main/java/org/glom/web/client/OnlineGlom.java +++ b/src/main/java/org/glom/web/client/OnlineGlom.java @@ -20,7 +20,6 @@ package org.glom.web.client; import org.glom.web.shared.GlomDocument; -import org.glom.web.shared.GlomTable; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.event.dom.client.ChangeEvent; @@ -67,9 +66,10 @@ public class OnlineGlom implements EntryPoint { } public void onSuccess(GlomDocument result) { - GlomTable[] tables = result.getTables(); - for (int i = 0; i < tables.length; i++) { - dropBox.addItem(tables[i].getTitle(), tables[i].getName()); + String[] tableNames = result.getTableNames(); + String[] tableTitles = result.getTableTitles(); + for (int i = 0; i < tableNames.length; i++) { + dropBox.addItem(tableTitles[i], tableNames[i]); } dropBox.setSelectedIndex(result.getDefaultTableIndex()); documentName = result.getTitle(); diff --git a/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java b/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java index 9281beb..3c099ab 100644 --- a/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java +++ b/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java @@ -34,12 +34,11 @@ import org.glom.libglom.LayoutGroupVector; import org.glom.libglom.LayoutItem; import org.glom.libglom.LayoutItemVector; import org.glom.libglom.LayoutItem_Field; +import org.glom.libglom.SortClause; import org.glom.libglom.SortFieldPair; import org.glom.libglom.StringVector; -import org.glom.libglom.SortClause; import org.glom.web.client.OnlineGlomService; import org.glom.web.shared.GlomDocument; -import org.glom.web.shared.GlomTable; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.mchange.v2.c3p0.ComboPooledDataSource; @@ -77,8 +76,10 @@ public class OnlineGlomServiceImpl extends RemoteServiceServlet implements Onlin cpds.setPassword("ChangeMe"); // of course it's not the password I'm using on my server } - /* FIXME I think Swig is generating long on 64-bit machines and int on 32-bit machines - need to keep this constant - * http://stackoverflow.com/questions /1590831/safely-casting-long-to-int-in-java */ + /* + * FIXME I think Swig is generating long on 64-bit machines and int on 32-bit machines - need to keep this constant + * http://stackoverflow.com/questions/1590831/safely-casting-long-to-int-in-java + */ public static int safeLongToInt(long l) { if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw new IllegalArgumentException(l + " cannot be cast to int without changing its value."); @@ -89,25 +90,29 @@ public class OnlineGlomServiceImpl extends RemoteServiceServlet implements Onlin public GlomDocument getGlomDocument() { GlomDocument glomDocument = new GlomDocument(); - // set visible title - glomDocument.setTitle(document.get_database_title()); - - // set array of GlomTables and the default table index - StringVector tableNames = document.get_table_names(); - GlomTable[] tables = new GlomTable[safeLongToInt(tableNames.size())]; - for (int i = 0; i < tableNames.size(); i++) { - String tableName = tableNames.get(i); - GlomTable glomTable = new GlomTable(); - glomTable.setName(tableName); - glomTable.setTitle(document.get_table_title(tableName)); - tables[i] = glomTable; - if (tableName.equals(document.get_default_table())) { + // get arrays of table names and titles, and find the default table index + StringVector tablesVec = document.get_table_names(); + int numTables = safeLongToInt(tablesVec.size()); + String[] tableNames = new String[numTables]; + String[] tableTitles = new String[numTables]; + boolean foundDefaultTable = false; + for (int i = 0; i < numTables; i++) { + String tableName = tablesVec.get(i); + tableNames[i] = tableName; + // JNI is "expensive", the comparison will only be called if we haven't already found the default table + if (!foundDefaultTable && tableName.equals(document.get_default_table())) { glomDocument.setDefaultTableIndex(i); + foundDefaultTable = true; } + tableTitles[i] = document.get_table_title(tableName); } - glomDocument.setTables(tables); - return glomDocument; + // set everything we need + glomDocument.setTableNames(tableNames); + glomDocument.setTableTitles(tableTitles); + glomDocument.setTitle(document.get_database_title()); + + return glomDocument; } public String[] getLayoutListHeaders(String table) { diff --git a/src/main/java/org/glom/web/shared/GlomDocument.java b/src/main/java/org/glom/web/shared/GlomDocument.java index 1db3629..9d9ebe6 100644 --- a/src/main/java/org/glom/web/shared/GlomDocument.java +++ b/src/main/java/org/glom/web/shared/GlomDocument.java @@ -24,33 +24,31 @@ import java.io.Serializable; @SuppressWarnings("serial") public class GlomDocument implements Serializable { private String title; - private int defaultTable; - private GlomTable[] tables; + // could consider a LinkedHashMap if we need to support adding or removing tables + // order must be consistent between these two arrays + private String[] tableNames; + private String[] tableTitles; + private int defaultTableIndex; public GlomDocument() { + new GlomDocument("", new String[] {}, new String[] {}, 0); } - public String getTitle() { - return title; + public GlomDocument(String title, String[] tableNames, String[] tableTitles, int defaultTableIndex) { + this.title = title; + this.tableNames = tableNames; + this.tableTitles = tableTitles; + this.defaultTableIndex = defaultTableIndex; } - public void setTitle(String name) { - this.title = name; - } - - public int getDefaultTableIndex() { - return defaultTable; - } - - public void setDefaultTableIndex(int defaultTable) { - this.defaultTable = defaultTable; - } - - public void setTables(GlomTable[] tables) { - this.tables = tables; - } - - public GlomTable[] getTables() { - return tables; - } + // @formatter:off + public String getTitle() { return title; } + public void setTitle(String name) { this.title = name; } + public int getDefaultTableIndex() { return defaultTableIndex; } + public void setDefaultTableIndex(int defaultTable) { this.defaultTableIndex = defaultTable; } + public String[] getTableNames() { return tableNames; } + public void setTableNames(String[] tableNames) { this.tableNames = tableNames; } + public void setTableTitles(String[] tableTitles) { this.tableTitles = tableTitles; } + public String[] getTableTitles() { return tableTitles; } + // @formatter:on } -- 2.1.4