[DS-633] NPE when deleting object returned by EPerson.findAll()

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5241 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Wood
2010-08-05 19:56:37 +00:00
parent 52fec66c47
commit fe57901b96
2 changed files with 15 additions and 11 deletions

View File

@@ -145,9 +145,9 @@ public class EPerson extends DSpaceObject
} }
/** /**
* Find the eperson by their email address * Find the eperson by their email address.
* *
* @return EPerson * @return EPerson, or {@code null} if none such exists.
*/ */
public static EPerson findByEmail(Context context, String email) public static EPerson findByEmail(Context context, String email)
throws SQLException, AuthorizeException throws SQLException, AuthorizeException
@@ -157,7 +157,7 @@ public class EPerson extends DSpaceObject
return null; return null;
} }
// All email addresses are stored as lowercase, so ensure that the email address is lowercased for the lookup // All email addresses are stored as lower case, so ensure that the email address is lowercased for the lookup
TableRow row = DatabaseManager.findByUnique(context, "eperson", TableRow row = DatabaseManager.findByUnique(context, "eperson",
"email", email.toLowerCase()); "email", email.toLowerCase());
@@ -183,7 +183,7 @@ public class EPerson extends DSpaceObject
} }
/** /**
* Find the eperson by their netid * Find the eperson by their netid.
* *
* @param context * @param context
* DSpace context * DSpace context
@@ -223,7 +223,7 @@ public class EPerson extends DSpaceObject
} }
/** /**
* Find the epeople that match the search query across firstname, lastname or email * Find the epeople that match the search query across firstname, lastname or email.
* *
* @param context * @param context
* DSpace context * DSpace context
@@ -317,7 +317,8 @@ public class EPerson extends DSpaceObject
paramArr = new Object[] {int_param,params,params,params,offset}; paramArr = new Object[] {int_param,params,params,params,offset};
// Get all the epeople that match the query // Get all the epeople that match the query
TableRowIterator rows = DatabaseManager.query(context, dbquery, paramArr); TableRowIterator rows = DatabaseManager.queryTable(context, "eperson",
dbquery, paramArr);
try try
{ {
List<TableRow> epeopleRows = rows.toList(); List<TableRow> epeopleRows = rows.toList();
@@ -434,9 +435,9 @@ public class EPerson extends DSpaceObject
s = "lastname"; s = "lastname";
} }
// NOTE: The use of 's' in the order by clause can not cause an sql // NOTE: The use of 's' in the order by clause can not cause an SQL
// injection because the string is derived from constant values above. // injection because the string is derived from constant values above.
TableRowIterator rows = DatabaseManager.query(context, TableRowIterator rows = DatabaseManager.queryTable(context, "eperson",
"SELECT * FROM eperson ORDER BY "+s); "SELECT * FROM eperson ORDER BY "+s);
try try
@@ -915,7 +916,7 @@ public class EPerson extends DSpaceObject
Vector<String> tableList = new Vector<String>(); Vector<String> tableList = new Vector<String>();
// check for eperson in item table // check for eperson in item table
TableRowIterator tri = DatabaseManager.query(myContext, TableRowIterator tri = DatabaseManager.queryTable(myContext, "item",
"SELECT * from item where submitter_id= ? ", "SELECT * from item where submitter_id= ? ",
getID()); getID());
@@ -934,7 +935,7 @@ public class EPerson extends DSpaceObject
} }
// check for eperson in workflowitem table // check for eperson in workflowitem table
tri = DatabaseManager.query(myContext, tri = DatabaseManager.queryTable(myContext, "workflowitem",
"SELECT * from workflowitem where owner= ? ", "SELECT * from workflowitem where owner= ? ",
getID()); getID());
@@ -953,7 +954,7 @@ public class EPerson extends DSpaceObject
} }
// check for eperson in tasklistitem table // check for eperson in tasklistitem table
tri = DatabaseManager.query(myContext, tri = DatabaseManager.queryTable(myContext, "tasklistitem",
"SELECT * from tasklistitem where eperson_id= ? ", "SELECT * from tasklistitem where eperson_id= ? ",
getID()); getID());

View File

@@ -797,6 +797,9 @@ public class DatabaseManager
*/ */
public static int delete(Context context, TableRow row) throws SQLException public static int delete(Context context, TableRow row) throws SQLException
{ {
if (null == row.getTable())
throw new IllegalArgumentException("Row not associated with a table");
String pk = getPrimaryKeyColumn(row); String pk = getPrimaryKeyColumn(row);
if (row.isColumnNull(pk)) if (row.isColumnNull(pk))