1 23 24 package org.objectweb.jorm.facility.naming.generator; 25 26 import org.objectweb.jorm.api.PAccessor; 27 import org.objectweb.jorm.api.PBinding; 28 import org.objectweb.jorm.api.PClassMapping; 29 import org.objectweb.jorm.api.PException; 30 import org.objectweb.jorm.naming.api.PName; 31 32 37 public abstract class LongGenIncr 38 implements PLongGen, PAccessor, LongGenIncrAccessor, PBinding { 39 private LongGenIncrMgr mgr; 40 44 private long nextId = 0; 45 46 48 55 public void init(String name, PClassMapping pcm, LongGenMgr mgr) 56 throws PException { 57 this.mgr = (LongGenIncrMgr) mgr; 58 init(pcm); 60 PName lgpn = pcm.getPBinder().decodeString(name); 62 Object conn = mgr.getPMapper().getConnection(); 63 try { 64 this.bind(lgpn); 65 if (exist(conn)) { 66 read(conn, this); 67 } else { 68 export(conn, name); 70 write(conn, this); 71 } 72 } catch (PException pe) { 73 mgr.getPMapper().closeConnection(conn); 74 throw pe; 75 } 76 mgr.getPMapper().closeConnection(conn); 77 } 78 79 83 public synchronized long genId() throws PException { 84 Object conn = mgr.getPMapper().getConnection(); 85 try { 86 return genId(conn); 87 } finally { 88 mgr.getPMapper().closeConnection(conn); 89 } 90 } 91 92 public long genId(Object conn) throws PException { 93 nextId++; 94 write(conn, this); 95 return nextId - 1; 96 } 97 98 100 105 public Object getMemoryInstance() { 106 return this; 107 } 108 109 111 114 public long paGetNextId() { 115 return nextId; 116 } 117 118 121 public void paSetNextId(long val) { 122 nextId = val; 123 } 124 } 125 | Popular Tags |