Source Code Cross Referenced for CourseManagerHibernateImpl.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » component » section » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.component.section 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/standalone/src/java/org/sakaiproject/component/section/CourseManagerHibernateImpl.java $
003:         * $Id: CourseManagerHibernateImpl.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.component.section;
021:
022:        import java.sql.SQLException;
023:        import java.util.HashSet;
024:        import java.util.Iterator;
025:        import java.util.Set;
026:
027:        import org.hibernate.HibernateException;
028:        import org.hibernate.Query;
029:        import org.hibernate.Session;
030:
031:        import org.apache.commons.logging.Log;
032:        import org.apache.commons.logging.LogFactory;
033:        import org.sakaiproject.id.api.IdManager;
034:        import org.sakaiproject.section.api.CourseManager;
035:        import org.sakaiproject.section.api.coursemanagement.Course;
036:        import org.sakaiproject.section.api.coursemanagement.ParticipationRecord;
037:        import org.sakaiproject.section.api.coursemanagement.User;
038:        import org.springframework.orm.hibernate3.HibernateCallback;
039:        import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
040:
041:        /**
042:         * Hibernate implementation of CourseManager.  Useful for loading data in standalone mode.
043:         * 
044:         * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
045:         *
046:         */
047:        public class CourseManagerHibernateImpl extends HibernateDaoSupport
048:                implements  CourseManager {
049:
050:            private static final Log log = LogFactory
051:                    .getLog(CourseManagerHibernateImpl.class);
052:
053:            protected IdManager uuidManager;
054:
055:            public Course createCourse(final String siteContext,
056:                    final String title, final boolean selfRegAllowed,
057:                    final boolean selfSwitchingAllowed,
058:                    final boolean externallyManaged) {
059:
060:                if (log.isDebugEnabled())
061:                    log.debug("Creating a new course offering named " + title);
062:
063:                HibernateCallback hc = new HibernateCallback() {
064:                    public Object doInHibernate(Session session)
065:                            throws HibernateException, SQLException {
066:                        CourseImpl course = new CourseImpl();
067:                        course.setExternallyManaged(externallyManaged);
068:                        course.setSelfRegistrationAllowed(selfRegAllowed);
069:                        course.setSelfSwitchingAllowed(selfSwitchingAllowed);
070:                        course.setSiteContext(siteContext);
071:                        course.setTitle(title);
072:                        course.setUuid(uuidManager.createUuid());
073:                        session.save(course);
074:                        return course;
075:                    };
076:                };
077:
078:                return (Course) getHibernateTemplate().execute(hc);
079:            }
080:
081:            public boolean courseExists(final String siteContext) {
082:                HibernateCallback hc = new HibernateCallback() {
083:                    public Object doInHibernate(Session session)
084:                            throws HibernateException, SQLException {
085:                        Query q = session
086:                                .getNamedQuery("loadCourseBySiteContext");
087:                        q.setParameter("siteContext", siteContext);
088:                        return q.uniqueResult();
089:                    };
090:                };
091:
092:                return getHibernateTemplate().execute(hc) != null;
093:            }
094:
095:            public ParticipationRecord addInstructor(final User user,
096:                    final Course course) {
097:                HibernateCallback hc = new HibernateCallback() {
098:                    public Object doInHibernate(Session session)
099:                            throws HibernateException, SQLException {
100:                        InstructorRecordImpl pr = new InstructorRecordImpl(
101:                                course, user);
102:                        pr.setUuid(uuidManager.createUuid());
103:                        session.save(pr);
104:                        return pr;
105:                    }
106:                };
107:                return (ParticipationRecord) getHibernateTemplate().execute(hc);
108:            }
109:
110:            public ParticipationRecord addEnrollment(final User user,
111:                    final Course course) {
112:                HibernateCallback hc = new HibernateCallback() {
113:                    public Object doInHibernate(Session session)
114:                            throws HibernateException, SQLException {
115:                        EnrollmentRecordImpl enr = new EnrollmentRecordImpl(
116:                                course, "enrolled", user);
117:                        enr.setUuid(uuidManager.createUuid());
118:                        session.save(enr);
119:                        return enr;
120:                    }
121:                };
122:                return (ParticipationRecord) getHibernateTemplate().execute(hc);
123:            }
124:
125:            public ParticipationRecord addTA(final User user,
126:                    final Course course) {
127:                HibernateCallback hc = new HibernateCallback() {
128:                    public Object doInHibernate(Session session)
129:                            throws HibernateException, SQLException {
130:                        TeachingAssistantRecordImpl ta = new TeachingAssistantRecordImpl(
131:                                course, user);
132:                        ta.setUuid(uuidManager.createUuid());
133:                        session.save(ta);
134:                        return ta;
135:                    }
136:                };
137:                return (ParticipationRecord) getHibernateTemplate().execute(hc);
138:            }
139:
140:            public void removeCourseMembership(final String userUid,
141:                    final Course course) {
142:                HibernateCallback hc = new HibernateCallback() {
143:                    public Object doInHibernate(Session session)
144:                            throws HibernateException, SQLException {
145:                        Query q = session
146:                                .getNamedQuery("loadSiteParticipation");
147:                        q.setParameter("siteContext", course.getSiteContext());
148:                        q.setParameter("userUid", userUid);
149:                        Object result = q.uniqueResult();
150:                        if (result != null) {
151:                            session.delete(result);
152:                            if (log.isInfoEnabled())
153:                                log.info("Site membership for " + userUid
154:                                        + " in course " + course
155:                                        + " has been deleted");
156:                        } else {
157:                            if (log.isInfoEnabled())
158:                                log.info("Could not find membership for "
159:                                        + userUid + " in course " + course);
160:                        }
161:                        return null;
162:                    }
163:                };
164:                getHibernateTemplate().execute(hc);
165:
166:                // Make sure we remove any orphaned section memberships
167:                removeOrphans(course.getSiteContext());
168:
169:            }
170:
171:            /**
172:             * @inheritDoc
173:             */
174:            public void removeOrphans(final String siteContext) {
175:                final Set userUids = getSiteMemberIds(siteContext);
176:                if (userUids == null || userUids.isEmpty()) {
177:                    return;
178:                }
179:                HibernateCallback hc = new HibernateCallback() {
180:                    public Object doInHibernate(Session session)
181:                            throws HibernateException, SQLException {
182:                        Query q = session
183:                                .getNamedQuery("findOrphanedSectionMemberships");
184:                        q.setParameter("siteContext", siteContext);
185:                        q.setParameterList("userUids", userUids);
186:                        int deleted = 0;
187:                        for (Iterator iter = q.iterate(); iter.hasNext(); deleted++) {
188:                            session.delete(iter.next());
189:                        }
190:                        if (log.isInfoEnabled())
191:                            log.info(deleted + " section memberships deleted");
192:                        return null;
193:                    }
194:                };
195:                getHibernateTemplate().execute(hc);
196:            }
197:
198:            /**
199:             * Gets only the user IDs of the site members
200:             * 
201:             * @param siteContext
202:             * @return
203:             */
204:            private Set getSiteMemberIds(final String siteContext) {
205:                HibernateCallback hc = new HibernateCallback() {
206:                    public Object doInHibernate(Session session)
207:                            throws HibernateException, SQLException {
208:                        Query q = session
209:                                .getNamedQuery("findSiteMemberUserUids");
210:                        q.setParameter("siteContext", siteContext);
211:                        return new HashSet(q.list());
212:                    };
213:                };
214:
215:                return (Set) getHibernateTemplate().execute(hc);
216:            }
217:
218:            // Dependency injection
219:
220:            public void setUuidManager(IdManager uuidManager) {
221:                this.uuidManager = uuidManager;
222:            }
223:
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.