1 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 39 public abstract class LongGenIncrMgr implements LongGenMgr, PClassMapping { 40 public final String CNLONGGENINCR = "org.objectweb.jorm.facility.naming.generator.LongGenIncr"; 41 42 44 49 public void init(PMapper pm, byte clact) throws PException { 50 PClassMapping pcm = pm.lookup(CNLONGGENINCR); 52 if (pcm != null) 53 throw new PException("LongGenIncr already mapped with this mapper."); 54 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 83 public LongGen getLongGen(String lgname) throws PException { 84 return getLongGen(lgname, null); 85 } 86 87 91 public LongGen getLongGen(String lgname, Object _conn) throws PException { 92 Object 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 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 |