Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-03-13 15:08:19 +0000
committerEike Stepper2010-03-13 15:08:19 +0000
commit1e07fed44a31294864a19196af3d998abd249c91 (patch)
tree86678c335ed4ebed998e0508cf5efe31f5831569 /plugins/org.eclipse.net4j.db/src/org
parent86ce4f732d578de20b23dad2b737b513e31dc3e5 (diff)
downloadcdo-1e07fed44a31294864a19196af3d998abd249c91.tar.gz
cdo-1e07fed44a31294864a19196af3d998abd249c91.tar.xz
cdo-1e07fed44a31294864a19196af3d998abd249c91.zip
[256936] Support for Offline Mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256936
Diffstat (limited to 'plugins/org.eclipse.net4j.db/src/org')
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java73
1 files changed, 67 insertions, 6 deletions
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 fe73d4dcaa..9f33989f61 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
@@ -285,9 +285,48 @@ public final class DBUtil
}
}
- public static int selectMaximumInt(Connection connection, IDBField field) throws DBException
+ /**
+ * @since 3.0
+ */
+ public static int selectMinimumInt(Connection connection, IDBField field, String... where) throws DBException
+ {
+ Number number = getFunctionResult(connection, field, "MIN", where); //$NON-NLS-1$
+ if (number instanceof Integer)
+ {
+ return (Integer)number;
+ }
+ else if (number == null)
+ {
+ return 0;
+ }
+
+ throw new DBException("Not an integer number: " + number); //$NON-NLS-1$
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static long selectMinimumLong(Connection connection, IDBField field, String... where) throws DBException
+ {
+ Number number = getFunctionResult(connection, field, "MIN", where); //$NON-NLS-1$
+ if (number instanceof Long)
+ {
+ return (Long)number;
+ }
+ else if (number == null)
+ {
+ return 0L;
+ }
+
+ throw new DBException("Not a long number: " + number); //$NON-NLS-1$
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static int selectMaximumInt(Connection connection, IDBField field, String... where) throws DBException
{
- Number number = getMaximumNumber(connection, field);
+ Number number = getFunctionResult(connection, field, "MAX", where); //$NON-NLS-1$
if (number instanceof Integer)
{
return (Integer)number;
@@ -300,9 +339,12 @@ public final class DBUtil
throw new DBException("Not an integer number: " + number); //$NON-NLS-1$
}
- public static long selectMaximumLong(Connection connection, IDBField field) throws DBException
+ /**
+ * @since 3.0
+ */
+ public static long selectMaximumLong(Connection connection, IDBField field, String... where) throws DBException
{
- Number number = getMaximumNumber(connection, field);
+ Number number = getFunctionResult(connection, field, "MAX", where); //$NON-NLS-1$
if (number instanceof Long)
{
return (Long)number;
@@ -315,14 +357,33 @@ public final class DBUtil
throw new DBException("Not a long number: " + number); //$NON-NLS-1$
}
- private static Number getMaximumNumber(Connection connection, IDBField field) throws DBException
+ private static Number getFunctionResult(Connection connection, IDBField field, String function, String... where)
+ throws DBException
{
StringBuilder builder = new StringBuilder();
- builder.append("SELECT MAX("); //$NON-NLS-1$
+ builder.append("SELECT "); //$NON-NLS-1$
+ builder.append(function);
+ builder.append("("); //$NON-NLS-1$
builder.append(field);
builder.append(") FROM "); //$NON-NLS-1$
builder.append(field.getTable());
+ for (int i = 0; i < where.length; i++)
+ {
+ if (i == 0)
+ {
+ builder.append(" WHERE "); //$NON-NLS-1$
+ }
+ else
+ {
+ builder.append(" AND "); //$NON-NLS-1$
+ }
+
+ builder.append("("); //$NON-NLS-1$
+ builder.append(where[i]);
+ builder.append(")"); //$NON-NLS-1$
+ }
+
String sql = builder.toString();
trace(sql);
Statement statement = null;

Back to the top