1 package org.apache.ojb.tools.mapping.reversedb; 2 3 17 18 import java.util.HashMap ; 19 20 26 public class IdGeneratorSingleton 27 { 28 private static IdGeneratorSingleton singleton = new IdGeneratorSingleton(); 29 30 31 32 private HashMap hmIds = new HashMap (); 33 34 private IdGeneratorSingleton () 35 { 36 } 37 38 private int _getId(String type, String instance) 39 { 40 HashMap hmTypeId = (HashMap )hmIds.get(type); 41 if (hmTypeId == null) 42 { 43 hmTypeId = new HashMap (); 44 hmIds.put(type, hmTypeId); 45 } 46 Integer storedId = (Integer )hmTypeId.get(instance); 47 int id; 48 if (storedId == null) 49 { 50 id = 0; 51 } 52 else id = storedId.intValue()+1; 53 hmTypeId.put(instance, new Integer (id)); 54 return id; 55 } 56 57 public static int getId(String type, String instance) 58 { 59 return singleton._getId (type, instance); 60 } 61 } 62 63 64 121 | Popular Tags |