From 21a56e8b3c65f18bab1fecb090232d09461d17f4 Mon Sep 17 00:00:00 2001 From: Peter Breton Date: Thu, 30 May 2002 15:53:38 +0000 Subject: [PATCH] Support long datatype (getLongColumn, setColumn) git-svn-id: http://scm.dspace.org/svn/repo/trunk@56 9c30dcfa-912a-0410-8fc2-9e0234be79fd --- .../org/dspace/storage/rdbms/TableRow.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/dspace/src/org/dspace/storage/rdbms/TableRow.java b/dspace/src/org/dspace/storage/rdbms/TableRow.java index ea1f146a74..20c9c7ba60 100644 --- a/dspace/src/org/dspace/storage/rdbms/TableRow.java +++ b/dspace/src/org/dspace/storage/rdbms/TableRow.java @@ -150,6 +150,36 @@ public class TableRow return ((Integer) value).intValue(); } + /** + * Return the long value of column. + * + * If the column's type is not an long, or the column does not + * exist, an IllegalArgumentException is thrown. + * + * @param - The name of the column. + * @return - the long value of the column, or -1 if the column + * is an SQL null. + */ + public long getLongColumn(String column) + { + if (! hasColumn(column)) + throw new IllegalArgumentException("No such column " + column); + + String name = canonicalize(column); + + if (isColumnNull(name)) + return -1; + + Object value = data.get(name); + + if (value == null) + throw new IllegalArgumentException("Column " + column + " not present"); + if (!(value instanceof Long)) + throw new IllegalArgumentException("Value is not an long"); + + return ((Long) value).longValue(); + } + /** * Return the String value of column. * @@ -304,6 +334,22 @@ public class TableRow data.put(canonicalize(column), new Integer(i)); } + /** + * Set COLUMN to the long l. + * + * If the column does not exist, an IllegalArgumentException is thrown. + * + * @param column - The name of the column. + * @param l - The long value + */ + public void setColumn(String column, long l) + { + if (! hasColumn(column)) + throw new IllegalArgumentException("No such column " + column); + + data.put(canonicalize(column), new Long(l)); + } + /** * Set COLUMN to the date d. If the date is null, the column is * set to NULL as well.