2
* Copyright (C) 2008 Adam Cornett This program is free software; you can
3
* redistribute it and/or modify it under the terms of the GNU General Public
4
* License as published by the Free Software Foundation; either version 3 of the
5
* License, or (at your option) any later version. This program is distributed
6
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
* See the GNU General Public License for more details. You should have received
9
* a copy of the GNU General Public License along with this program; if not, see
10
* <http://www.gnu.org/licenses>.
13
package net.launchpad.codescore.managers;
15
import java.util.HashMap;
16
import java.util.List;
18
import org.apache.cayenne.ObjectContext;
19
import org.apache.cayenne.access.DataContext;
20
import org.apache.cayenne.query.NamedQuery;
22
import net.launchpad.codescore.dbo.Person;
24
public class PersonManager {
25
public static Person getPersonByName(ObjectContext oc, String name) {
26
HashMap<String, Object> params = new HashMap<String, Object>();
27
params.put("n", name);
28
NamedQuery personByName = new NamedQuery("person_by_name", params);
29
List l = oc.performQuery(personByName);
31
throw new RuntimeException("Couldn't find person " + name);
32
else if (l.size() > 1)
33
throw new RuntimeException("Multiple choices");
34
return (Person) l.get(0);
37
public static Person getPersonByName(String name) {
38
return getPersonByName(DataContext.createDataContext(), name);