01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/integration-support/src/java/org/sakaiproject/component/section/support/UserManagerHibernateImpl.java $
03: * $Id: UserManagerHibernateImpl.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.component.section.support;
21:
22: import java.sql.SQLException;
23:
24: import org.hibernate.HibernateException;
25: import org.hibernate.Query;
26: import org.hibernate.Session;
27:
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30: import org.sakaiproject.section.api.coursemanagement.User;
31: import org.sakaiproject.component.section.UserImpl;
32: import org.springframework.orm.hibernate3.HibernateCallback;
33: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
34:
35: public class UserManagerHibernateImpl extends HibernateDaoSupport
36: implements UserManager {
37: private static Log log = LogFactory
38: .getLog(UserManagerHibernateImpl.class);
39:
40: public User createUser(final String userUid,
41: final String displayName, final String sortName,
42: final String displayId) {
43:
44: if (log.isDebugEnabled())
45: log.debug("Creating a user named " + displayName
46: + " with uid=" + userUid);
47:
48: HibernateCallback hc = new HibernateCallback() {
49: public Object doInHibernate(Session session)
50: throws HibernateException, SQLException {
51: UserImpl user = new UserImpl(displayName, displayId,
52: sortName, userUid);
53: session.save(user);
54: return user;
55: }
56: };
57: return (User) getHibernateTemplate().execute(hc);
58: }
59:
60: public User findUser(final String userUid) {
61: HibernateCallback hc = new HibernateCallback() {
62: public Object doInHibernate(Session session)
63: throws HibernateException, SQLException {
64: Query q = session.getNamedQuery("findUser");
65: q.setParameter("userUid", userUid);
66: return q.uniqueResult();
67: }
68: };
69: return (User) getHibernateTemplate().execute(hc);
70: }
71:
72: }
|