From ba2b51ed701397aba772d32a272e11283dd194df Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Thu, 17 Feb 2011 17:58:16 +0100 Subject: [PATCH] Rename RPC service classes from LibGlomService* to OnlineGlomService*. * src/main/java/org/glom/web/client/LayoutListDataProvider.java: Update references. * src/main/java/org/glom/web/client/OnlineGlom.java: Update references. * src/main/java/org/glom/web/client/OnlineGlomService.java: Rename from LibGlomServer.java. * src/main/java/org/glom/web/client/OnlineGlomServiceAsync.java: Rename from LibGlomServiceAsync.java. * src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java: Rename from LibGlomServiceImpl.java. * src/main/webapp/WEB-INF/web.xml: Update configuration. --- ChangeLog | 15 ++ .../glom/web/client/LayoutListDataProvider.java | 2 +- .../java/org/glom/web/client/LibGlomService.java | 38 ----- .../org/glom/web/client/LibGlomServiceAsync.java | 35 ---- src/main/java/org/glom/web/client/OnlineGlom.java | 4 +- .../org/glom/web/client/OnlineGlomService.java | 38 +++++ .../glom/web/client/OnlineGlomServiceAsync.java | 35 ++++ .../org/glom/web/server/LibGlomServiceImpl.java | 178 --------------------- .../org/glom/web/server/OnlineGlomServiceImpl.java | 178 +++++++++++++++++++++ src/main/webapp/WEB-INF/web.xml | 2 +- 10 files changed, 270 insertions(+), 255 deletions(-) delete mode 100644 src/main/java/org/glom/web/client/LibGlomService.java delete mode 100644 src/main/java/org/glom/web/client/LibGlomServiceAsync.java create mode 100644 src/main/java/org/glom/web/client/OnlineGlomService.java create mode 100644 src/main/java/org/glom/web/client/OnlineGlomServiceAsync.java delete mode 100644 src/main/java/org/glom/web/server/LibGlomServiceImpl.java create mode 100644 src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java diff --git a/ChangeLog b/ChangeLog index a321715..628c414 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2011-02-17 Ben Konrath + Rename RPC service classes from LibGlomService* to OnlineGlomService*. + + * src/main/java/org/glom/web/client/LayoutListDataProvider.java: Update + references. + * src/main/java/org/glom/web/client/OnlineGlom.java: Update references. + * src/main/java/org/glom/web/client/OnlineGlomService.java: Rename + from LibGlomServer.java. + * src/main/java/org/glom/web/client/OnlineGlomServiceAsync.java: + Rename from LibGlomServiceAsync.java. + * src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java: + Rename from LibGlomServiceImpl.java. + * src/main/webapp/WEB-INF/web.xml: Update configuration. + +2011-02-17 Ben Konrath + Update JDT settings. * .settings/org.eclipse.jdt.core.prefs: diff --git a/src/main/java/org/glom/web/client/LayoutListDataProvider.java b/src/main/java/org/glom/web/client/LayoutListDataProvider.java index 47522ec..12525dd 100644 --- a/src/main/java/org/glom/web/client/LayoutListDataProvider.java +++ b/src/main/java/org/glom/web/client/LayoutListDataProvider.java @@ -46,7 +46,7 @@ public class LayoutListDataProvider extends AsyncDataProvider { } }; - LibGlomServiceAsync.Util.getInstance().getTableData(start, length, OnlineGlom.getCurrentTableName(), callback); + OnlineGlomServiceAsync.Util.getInstance().getTableData(start, length, OnlineGlom.getCurrentTableName(), callback); } diff --git a/src/main/java/org/glom/web/client/LibGlomService.java b/src/main/java/org/glom/web/client/LibGlomService.java deleted file mode 100644 index d9e3411..0000000 --- a/src/main/java/org/glom/web/client/LibGlomService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Openismus GmbH - * - * This file is part of GWT-Glom. - * - * GWT-Glom is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GWT-Glom. If not, see . - */ - -package org.glom.web.client; - -import java.util.ArrayList; - -import org.glom.web.shared.GlomDocument; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - -@RemoteServiceRelativePath("libGlom") -public interface LibGlomService extends RemoteService { - - GlomDocument getGlomDocument(); - - String[] getLayoutListHeaders(String table); - - ArrayList getTableData(int start, int length, String table); - -} \ No newline at end of file diff --git a/src/main/java/org/glom/web/client/LibGlomServiceAsync.java b/src/main/java/org/glom/web/client/LibGlomServiceAsync.java deleted file mode 100644 index 755a521..0000000 --- a/src/main/java/org/glom/web/client/LibGlomServiceAsync.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.glom.web.client; - -import java.util.ArrayList; - -import org.glom.web.shared.GlomDocument; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -public interface LibGlomServiceAsync { - - void getGlomDocument(AsyncCallback callback); - - void getLayoutListHeaders(String table, AsyncCallback callback); - - void getTableData(int start, int length, String table, AsyncCallback> callback); - - /** - * Utility class to get the RPC Async interface from client-side code - */ - public static final class Util { - private static LibGlomServiceAsync instance; - - public static final LibGlomServiceAsync getInstance() { - if (instance == null) { - instance = (LibGlomServiceAsync) GWT.create(LibGlomService.class); - } - return instance; - } - - private Util() { - // Utility class should not be instanciated - } - } -} \ No newline at end of file diff --git a/src/main/java/org/glom/web/client/OnlineGlom.java b/src/main/java/org/glom/web/client/OnlineGlom.java index 62c58f0..f98c047 100644 --- a/src/main/java/org/glom/web/client/OnlineGlom.java +++ b/src/main/java/org/glom/web/client/OnlineGlom.java @@ -78,7 +78,7 @@ public class OnlineGlom implements EntryPoint { }; // make the call to get the filled in GlomDocument - LibGlomServiceAsync.Util.getInstance().getGlomDocument(callback); + OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(callback); } private void updateTable() { @@ -100,7 +100,7 @@ public class OnlineGlom implements EntryPoint { }; String selectedTable = dropBox.getValue(dropBox.getSelectedIndex()); - LibGlomServiceAsync.Util.getInstance().getLayoutListHeaders(selectedTable, callback); + OnlineGlomServiceAsync.Util.getInstance().getLayoutListHeaders(selectedTable, callback); } diff --git a/src/main/java/org/glom/web/client/OnlineGlomService.java b/src/main/java/org/glom/web/client/OnlineGlomService.java new file mode 100644 index 0000000..3694aa4 --- /dev/null +++ b/src/main/java/org/glom/web/client/OnlineGlomService.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010, 2011 Openismus GmbH + * + * This file is part of GWT-Glom. + * + * GWT-Glom is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GWT-Glom. If not, see . + */ + +package org.glom.web.client; + +import java.util.ArrayList; + +import org.glom.web.shared.GlomDocument; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +@RemoteServiceRelativePath("libGlom") +public interface OnlineGlomService extends RemoteService { + + GlomDocument getGlomDocument(); + + String[] getLayoutListHeaders(String table); + + ArrayList getTableData(int start, int length, String table); + +} \ No newline at end of file diff --git a/src/main/java/org/glom/web/client/OnlineGlomServiceAsync.java b/src/main/java/org/glom/web/client/OnlineGlomServiceAsync.java new file mode 100644 index 0000000..8fe085b --- /dev/null +++ b/src/main/java/org/glom/web/client/OnlineGlomServiceAsync.java @@ -0,0 +1,35 @@ +package org.glom.web.client; + +import java.util.ArrayList; + +import org.glom.web.shared.GlomDocument; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +public interface OnlineGlomServiceAsync { + + void getGlomDocument(AsyncCallback callback); + + void getLayoutListHeaders(String table, AsyncCallback callback); + + void getTableData(int start, int length, String table, AsyncCallback> callback); + + /** + * Utility class to get the RPC Async interface from client-side code + */ + public static final class Util { + private static OnlineGlomServiceAsync instance; + + public static final OnlineGlomServiceAsync getInstance() { + if (instance == null) { + instance = (OnlineGlomServiceAsync) GWT.create(OnlineGlomService.class); + } + return instance; + } + + private Util() { + // Utility class should not be instanciated + } + } +} \ No newline at end of file diff --git a/src/main/java/org/glom/web/server/LibGlomServiceImpl.java b/src/main/java/org/glom/web/server/LibGlomServiceImpl.java deleted file mode 100644 index 42f525d..0000000 --- a/src/main/java/org/glom/web/server/LibGlomServiceImpl.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Openismus GmbH - * - * This file is part of GWT-Glom. - * - * GWT-Glom is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GWT-Glom. If not, see . - */ - -package org.glom.web.server; - -import java.beans.PropertyVetoException; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; - -import org.glom.libglom.Document; -import org.glom.libglom.Field; -import org.glom.libglom.Glom; -import org.glom.libglom.LayoutFieldVector; -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.SortFieldPair; -import org.glom.libglom.StringVector; -import org.glom.libglom.SortClause; -import org.glom.web.client.LibGlomService; -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; -import com.mchange.v2.c3p0.DataSources; - -@SuppressWarnings("serial") -public class LibGlomServiceImpl extends RemoteServiceServlet implements LibGlomService { - private Document document; - ComboPooledDataSource cpds; - - // Called only when the servlet is stopped (the servlet container is stopped or restarted) - public LibGlomServiceImpl() { - Glom.libglom_init(); - document = new Document(); - // TODO hardcoded for now, need to figure out something for this - document.set_file_uri("file:///home/ben/music-collection.glom"); - int error = 0; - @SuppressWarnings("unused") - boolean retval = document.load(error); - // TODO handle error condition (also below) - - cpds = new ComboPooledDataSource(); - // load the jdbc driver - try { - cpds.setDriverClass("org.postgresql.Driver"); - } catch (PropertyVetoException e) { - // TODO log error, fatal error can't continue, user can be nofified when db access doesn't work - e.printStackTrace(); - } - - cpds.setJdbcUrl("jdbc:postgresql://" + document.get_connection_server() + "/" - + document.get_connection_database()); - // TODO figure out something for db user name and password - cpds.setUser("ben"); - 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 */ - 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."); - } - return (int) l; - } - - 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())) { - glomDocument.setDefaultTableIndex(i); - } - } - glomDocument.setTables(tables); - return glomDocument; - - } - - public String[] getLayoutListHeaders(String table) { - LayoutGroupVector layoutList = document.get_data_layout_groups("list", table); - LayoutItemVector layoutItems = layoutList.get(0).get_items(); - String[] headers = new String[safeLongToInt(layoutItems.size())]; - for (int i = 0; i < layoutItems.size(); i++) { - headers[i] = layoutItems.get(i).get_title_or_name(); - } - return headers; - } - - public ArrayList getTableData(int start, int length, String table) { - LayoutGroupVector layoutList = document.get_data_layout_groups("list", table); - LayoutItemVector layoutItems = layoutList.get(0).get_items(); - - LayoutFieldVector layoutFields = new LayoutFieldVector(); - SortClause sortClause = new SortClause(); - for (int i = 0; i < layoutItems.size(); i++) { - LayoutItem item = layoutItems.get(i); - LayoutItem_Field field = LayoutItem_Field.cast_dynamic(item); - if (field != null) { - layoutFields.add(field); - Field details = field.get_full_field_details(); - if (details != null && details.get_primary_key()) { - sortClause.addLast(new SortFieldPair(field, true)); // ascending - } - } - } - - ArrayList rowsList = new ArrayList(); - try { - Connection conn = cpds.getConnection(); - Statement st = conn.createStatement(); - - String query = Glom.build_sql_select_simple(table, layoutFields, sortClause); - ResultSet rs = st.executeQuery(query); - - while (rs.next()) { - String[] rowArray = new String[safeLongToInt(layoutItems.size())]; - for (int i = 0; i < layoutItems.size(); i++) { - rowArray[i] = rs.getString(i + 1); - } - rowsList.add(rowArray); - } - - rs.close(); - st.close(); - } catch (SQLException e) { - // TODO: log error, notify user of problem - e.printStackTrace(); - } - - return rowsList; - } - - // Called only when the servlet is stopped (the servlet container is stopped or restarted) - public void destroy() { - Glom.libglom_deinit(); - try { - DataSources.destroy(cpds); - } catch (SQLException e) { - // TODO log error, don't need to notify user because this is a clean up method - e.printStackTrace(); - } - } - -} diff --git a/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java b/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java new file mode 100644 index 0000000..9281beb --- /dev/null +++ b/src/main/java/org/glom/web/server/OnlineGlomServiceImpl.java @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2010, 2011 Openismus GmbH + * + * This file is part of GWT-Glom. + * + * GWT-Glom is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GWT-Glom. If not, see . + */ + +package org.glom.web.server; + +import java.beans.PropertyVetoException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +import org.glom.libglom.Document; +import org.glom.libglom.Field; +import org.glom.libglom.Glom; +import org.glom.libglom.LayoutFieldVector; +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.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; +import com.mchange.v2.c3p0.DataSources; + +@SuppressWarnings("serial") +public class OnlineGlomServiceImpl extends RemoteServiceServlet implements OnlineGlomService { + private Document document; + ComboPooledDataSource cpds; + + // Called only when the servlet is stopped (the servlet container is stopped or restarted) + public OnlineGlomServiceImpl() { + Glom.libglom_init(); + document = new Document(); + // TODO hardcoded for now, need to figure out something for this + document.set_file_uri("file:///home/ben/music-collection.glom"); + int error = 0; + @SuppressWarnings("unused") + boolean retval = document.load(error); + // TODO handle error condition (also below) + + cpds = new ComboPooledDataSource(); + // load the jdbc driver + try { + cpds.setDriverClass("org.postgresql.Driver"); + } catch (PropertyVetoException e) { + // TODO log error, fatal error can't continue, user can be nofified when db access doesn't work + e.printStackTrace(); + } + + cpds.setJdbcUrl("jdbc:postgresql://" + document.get_connection_server() + "/" + + document.get_connection_database()); + // TODO figure out something for db user name and password + cpds.setUser("ben"); + 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 */ + 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."); + } + return (int) l; + } + + 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())) { + glomDocument.setDefaultTableIndex(i); + } + } + glomDocument.setTables(tables); + return glomDocument; + + } + + public String[] getLayoutListHeaders(String table) { + LayoutGroupVector layoutList = document.get_data_layout_groups("list", table); + LayoutItemVector layoutItems = layoutList.get(0).get_items(); + String[] headers = new String[safeLongToInt(layoutItems.size())]; + for (int i = 0; i < layoutItems.size(); i++) { + headers[i] = layoutItems.get(i).get_title_or_name(); + } + return headers; + } + + public ArrayList getTableData(int start, int length, String table) { + LayoutGroupVector layoutList = document.get_data_layout_groups("list", table); + LayoutItemVector layoutItems = layoutList.get(0).get_items(); + + LayoutFieldVector layoutFields = new LayoutFieldVector(); + SortClause sortClause = new SortClause(); + for (int i = 0; i < layoutItems.size(); i++) { + LayoutItem item = layoutItems.get(i); + LayoutItem_Field field = LayoutItem_Field.cast_dynamic(item); + if (field != null) { + layoutFields.add(field); + Field details = field.get_full_field_details(); + if (details != null && details.get_primary_key()) { + sortClause.addLast(new SortFieldPair(field, true)); // ascending + } + } + } + + ArrayList rowsList = new ArrayList(); + try { + Connection conn = cpds.getConnection(); + Statement st = conn.createStatement(); + + String query = Glom.build_sql_select_simple(table, layoutFields, sortClause); + ResultSet rs = st.executeQuery(query); + + while (rs.next()) { + String[] rowArray = new String[safeLongToInt(layoutItems.size())]; + for (int i = 0; i < layoutItems.size(); i++) { + rowArray[i] = rs.getString(i + 1); + } + rowsList.add(rowArray); + } + + rs.close(); + st.close(); + } catch (SQLException e) { + // TODO: log error, notify user of problem + e.printStackTrace(); + } + + return rowsList; + } + + // Called only when the servlet is stopped (the servlet container is stopped or restarted) + public void destroy() { + Glom.libglom_deinit(); + try { + DataSources.destroy(cpds); + } catch (SQLException e) { + // TODO log error, don't need to notify user because this is a clean up method + e.printStackTrace(); + } + } + +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index e54f210..8275456 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -8,7 +8,7 @@ libGlomServlet - org.glom.web.server.LibGlomServiceImpl + org.glom.web.server.OnlineGlomServiceImpl -- 2.1.4