~codescore-dev/codescore/version-1.0

« back to all changes in this revision

Viewing changes to src/net/launchpad/codescore/managers/PersonManager.java

  • Committer: Adam Cornett
  • Date: 2008-03-15 05:15:51 UTC
  • Revision ID: adam.cornett@gmail.com-20080315051551-p04pf7pglcguazgq
Massive updates to the admin side, added html loaders and pages for all major sections, began work on the tree for the school and coach views

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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>.
 
11
 */
 
12
 
 
13
package net.launchpad.codescore.managers;
 
14
 
 
15
import java.util.HashMap;
 
16
import java.util.List;
 
17
 
 
18
import org.apache.cayenne.ObjectContext;
 
19
import org.apache.cayenne.access.DataContext;
 
20
import org.apache.cayenne.query.NamedQuery;
 
21
 
 
22
import net.launchpad.codescore.dbo.Person;
 
23
 
 
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);
 
30
                if (l.size() < 1)
 
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);
 
35
        }
 
36
 
 
37
        public static Person getPersonByName(String name) {
 
38
                return getPersonByName(DataContext.createDataContext(), name);
 
39
        }
 
40
}