01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-api/api/src/java/org/sakaiproject/metaobj/shared/IdGenerator.java $
03: * $Id: IdGenerator.java 9469 2006-05-15 14:52:05Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
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.metaobj.shared;
21:
22: import java.io.Serializable;
23:
24: import org.hibernate.HibernateException;
25: import org.hibernate.engine.SessionImplementor;
26: import org.hibernate.id.IdentifierGenerator;
27: import org.sakaiproject.component.cover.ComponentManager;
28: import org.sakaiproject.metaobj.shared.mgt.IdManager;
29:
30: /**
31: * creates unique identifiers for hibernate
32: */
33: public class IdGenerator implements IdentifierGenerator {
34:
35: private static IdManager idManager;
36:
37: public IdGenerator() {
38: }
39:
40: public Serializable generate(SessionImplementor arg0, Object arg1)
41: throws HibernateException {
42: return getIdManager().createId();
43: }
44:
45: protected IdManager getIdManager() {
46: if (idManager == null) {
47: idManager = (IdManager) ComponentManager.getInstance().get(
48: "idManager");
49: }
50: return idManager;
51: }
52:
53: }
|