1 20 package org.objectweb.jorm.facility.naming.longid; 21 22 import org.objectweb.jorm.api.PClassMapping; 23 import org.objectweb.jorm.api.PException; 24 import org.objectweb.jorm.facility.naming.generator.LongGenMgr; 25 import org.objectweb.jorm.facility.naming.generator.PLongGen; 26 27 36 public class CompositePLongGen implements PLongGen { 37 38 41 protected PLongGen objectIdGenerator; 42 43 46 protected long cid; 47 protected int cidSize; 48 49 public CompositePLongGen(PLongGen objectIdGenerator, long cid, int cidSize) { 50 this.objectIdGenerator = objectIdGenerator; 51 this.cid = cid; 52 this.cidSize = cidSize; 53 } 54 55 public long getCid() { 56 return cid; 57 } 58 59 62 65 public void init(String name, PClassMapping pcm, LongGenMgr mgr) throws PException { 66 objectIdGenerator.init(name, pcm, mgr); 67 } 68 69 72 public long genId() throws PException { 73 return genId(null); 74 } 75 76 80 public long genId(Object conn) throws PException { 81 long oid; 82 if (conn != null) { 83 oid = objectIdGenerator.genId(conn); 84 } else { 85 oid = objectIdGenerator.genId(); 86 } 87 return (cid << (LongIdManager.LONG_SIZE - cidSize)) + oid; 88 } 89 } 90 | Popular Tags |