KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > facility > naming > generator > LongGenIncrMgr


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.facility.naming.generator;
25
26 import org.objectweb.jorm.api.PClassMapping;
27 import org.objectweb.jorm.api.PException;
28 import org.objectweb.jorm.api.PMapper;
29 import org.objectweb.jorm.api.PMapCluster;
30 import org.objectweb.jorm.facility.naming.basidir.BasidBinder;
31 import org.objectweb.jorm.naming.api.PBinder;
32 import org.objectweb.jorm.naming.api.PNamingContext;
33
34 /**
35  * Manages LongGenIncr long generators. It is extended by the LongGenIncrMapping
36  * JORM-generated class.
37  * @author P. Dechamboux
38  */

39 public abstract class LongGenIncrMgr implements LongGenMgr, PClassMapping {
40     public final String JavaDoc CNLONGGENINCR = "org.objectweb.jorm.facility.naming.generator.LongGenIncr";
41
42     // IMPLEMENTATION OF METHODS FROM THE LongGenMgr INTERFACE
43

44     /**
45      * Initializes a long generator manager by mapping relevant classes
46      * to the given mapper, and setting relevant initial persistent
47      * information.
48      */

49     public void init(PMapper pm, byte clact) throws PException {
50         // LongGenIncr initialization
51
PClassMapping pcm = pm.lookup(CNLONGGENINCR);
52         if (pcm != null)
53             throw new PException("LongGenIncr already mapped with this mapper.");
54         // Perform mapping only if it has not been already done
55
PBinder lgmbinder = new BasidBinder(PNamingContext.CTSTRING);
56         setPBinder(lgmbinder);
57         lgmbinder.setPClassMapping(this);
58         pm.map(this);
59         PMapCluster cl = pm.getPMapCluster(this.getClassName());
60         if (cl == null) {
61             throw new PException("No meta-information cluster defined: not correctly mapped.");
62         }
63         switch (clact) {
64         case PClassMapping.CREATE_STRUCTURE_IF_NEEDED:
65             cl.createMappingStructures(false);
66             break;
67         case PClassMapping.CLEANUP_REMOVEALL:
68             cl.deleteMappingStructures();
69             cl.createMappingStructures(false);
70             break;
71         case PClassMapping.CLEANUP_REMOVEDATA:
72             cl.deleteData();
73             break;
74         case PClassMapping.CLEANUP_DONOTHING:
75             break;
76         }
77     }
78
79     /**
80      * Retrieves a long generator with the given name. If it does not
81      * exist, creates it.
82      */

83     public LongGen getLongGen(String JavaDoc lgname) throws PException {
84         return getLongGen(lgname, null);
85     }
86     
87     /**
88      * Retrieves a long generator with the given name. If it does not
89      * exist, creates it.
90      */

91     public LongGen getLongGen(String JavaDoc lgname, Object JavaDoc _conn) throws PException {
92         Object JavaDoc conn = _conn;
93         if (_conn == null) {
94             conn = getPMapper().getConnection();
95         }
96         PLongGen res;
97         try {
98             res = (PLongGen) Class.forName(
99                     CNLONGGENINCR + PMapper.PBINDINGAPPENDER)
100                     .newInstance();
101         } catch (Exception JavaDoc e) {
102             throw new PException(e, "Cannot create LongGenIncr (probably a ClassLoader problem).");
103         }
104         res.init(lgname, this, this);
105         if (_conn == null) {
106             getPMapper().closeConnection(conn);
107         }
108         return res;
109     }
110 }
111
Popular Tags