Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2016-01-22 23:49:38 -0500
committerEike Stepper2016-01-22 23:49:38 -0500
commitc5c0e6edbb86fd299b3a9d8d7c19ab0561bb3558 (patch)
treef6eecba0fa9a9e981a81da122ea7cde544b8edee
parentfbcdb8d712255477e9ab4864ba7d2feec08d838d (diff)
downloadcdo-c5c0e6edbb86fd299b3a9d8d7c19ab0561bb3558.tar.gz
cdo-c5c0e6edbb86fd299b3a9d8d7c19ab0561bb3558.tar.xz
cdo-c5c0e6edbb86fd299b3a9d8d7c19ab0561bb3558.zip
[486409] Provide table and row statistics on DBBrowserPage
https://bugs.eclipse.org/bugs/show_bug.cgi?id=486409
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBBrowserPage.java41
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerBrowser.java18
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java44
3 files changed, 100 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBBrowserPage.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBBrowserPage.java
index c6c320218a..fd98134d25 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBBrowserPage.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBBrowserPage.java
@@ -85,6 +85,10 @@ public class DBBrowserPage extends AbstractPage
protected String showTables(CDOServerBrowser browser, PrintStream pout, Connection connection, String repo)
{
String table = browser.getParam("table");
+ boolean used = browser.isParam("used");
+
+ int totalRows = 0;
+ int usedTables = 0;
List<String> allTableNames = DBUtil.getAllTableNames(connection, repo);
for (String tableName : allTableNames)
@@ -95,14 +99,47 @@ public class DBBrowserPage extends AbstractPage
}
String label = browser.escape(tableName)/* .toLowerCase() */;
+
+ int rowCount = DBUtil.getRowCount(connection, tableName);
+ if (rowCount > 0)
+ {
+ // label += " (" + rowCount + ")";
+ totalRows += rowCount;
+ ++usedTables;
+ }
+ else if (used)
+ {
+ continue;
+ }
+
if (tableName.equals(table))
{
- pout.print("<b>" + label + "</b><br>\r\n");
+ pout.print("<b>" + label + "</b>");
}
else
{
- pout.print(browser.href(label, getName(), "table", tableName, "order", null, "direction", null) + "<br>\r\n");
+ pout.print(browser.href(label, getName(), "table", tableName, "order", null, "direction", null));
}
+
+ if (rowCount > 0)
+ {
+ pout.print(" (" + rowCount + ")");
+ }
+
+ pout.print("<br>\r\n");
+ }
+
+ if (totalRows != 0)
+ {
+ int totalTables = allTableNames.size();
+ int emptyTables = totalTables - usedTables;
+
+ pout.print("<br>" + totalTables + " tables total\r\n");
+ pout.print("<br>" + usedTables + " tables used (" + totalRows + " rows)\r\n");
+ pout.print("<br>" + emptyTables + " tables empty\r\n");
+ pout.print("<br>"
+ + browser.href(used ? "Show empty tables" : "Hide empty tables", getName(), "used", String.valueOf(!used))
+ + "<br>\r\n");
}
return table;
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerBrowser.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerBrowser.java
index e9395aa534..9078cf4b5c 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerBrowser.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerBrowser.java
@@ -208,7 +208,14 @@ public class CDOServerBrowser extends Worker
if (param.length() != 0)
{
String[] keyValue = param.split("=");
- map.put(keyValue[0], keyValue[1]);
+ if (keyValue.length == 1)
+ {
+ map.put(keyValue[0], "true");
+ }
+ else
+ {
+ map.put(keyValue[0], keyValue[1]);
+ }
}
}
}
@@ -231,6 +238,15 @@ public class CDOServerBrowser extends Worker
return map.get(key);
}
+ /**
+ * @since 4.5
+ */
+ public boolean isParam(String key)
+ {
+ Map<String, String> map = params.get();
+ return "true".equalsIgnoreCase(map.get(key));
+ }
+
public String href(String label, String resource, String... params)
{
Map<String, String> map = new HashMap<String, String>(this.params.get());
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
index 5d10a50a9f..647f1efe56 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
@@ -1099,6 +1099,50 @@ public final class DBUtil
}
}
+ /**
+ * Returns the number of rows contained in the given table.
+ *
+ * @since 4.5
+ */
+ public static int getRowCount(Connection connection, String tableName) throws DBException
+ {
+ String sql = trace("SELECT COUNT(*) FROM " + tableName);
+ Statement statement = null;
+ ResultSet resultSet = null;
+
+ try
+ {
+ statement = connection.createStatement();
+
+ try
+ {
+ resultSet = statement.executeQuery(sql);
+ if (!resultSet.next())
+ {
+ return -1;
+ }
+
+ return resultSet.getInt(1);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(resultSet);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(statement);
+ }
+ }
+
private static void reset(ResultSet resultSet) throws DBException
{
try

Back to the top