1 30 31 34 package com.nightlabs.ipanema.idgenerator; 35 36 import javax.jdo.JDOObjectNotFoundException; 37 import javax.jdo.PersistenceManager; 38 39 42 public class IDGeneratorAssistant 43 { 44 public static synchronized int generateIDInt(PersistenceManager pm, String key) 45 { 46 IDStoreInt idStore; 47 pm.getExtent(IDStoreInt.class, true); 48 try 49 { 50 idStore = (IDStoreInt) pm.getObjectById(IDStoreIntID.create(key), true); 51 idStore.increment(); 52 } catch (JDOObjectNotFoundException x) { 53 idStore = new IDStoreInt(key); 54 pm.makePersistent(idStore); 55 } 56 return idStore.getLastID(); 57 } 58 59 public static synchronized long generateIDLong(PersistenceManager pm, String key) 60 { 61 IDStoreLong idStore; 62 pm.getExtent(IDStoreLong.class, true); 63 try 64 { 65 idStore = (IDStoreLong) pm.getObjectById(IDStoreLongID.create(key), true); 66 idStore.increment(); 67 } catch (JDOObjectNotFoundException x) { 68 idStore = new IDStoreLong(key); 69 pm.makePersistent(idStore); 70 } 71 return idStore.getLastID(); 72 } 73 } 74 | Popular Tags |