1 25 package org.jresearch.gossip.dao.drivers.keygen; 26 27 import java.sql.Connection ; 28 import java.sql.SQLException ; 29 import java.util.Collections ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 39 public class HighLowKeyGenerator implements KeyGenerator { 40 44 Map keys = Collections.synchronizedMap(new HashMap ()); 45 46 57 public Object generateKey(String [] primaryKeyName, Connection connection) 58 throws SQLException { 59 final String tableName = primaryKeyName[0]; 60 61 KeyKeeper keyKeeper; 62 synchronized (keys) { 63 keyKeeper = (KeyKeeper) keys.get(tableName); 64 if (keyKeeper == null) { 65 keyKeeper = new KeyKeeper(tableName, primaryKeyName); 66 keys.put(tableName, keyKeeper); 67 } 68 } 69 return keyKeeper.nextKey(connection); 70 } 71 72 75 public boolean isBeforeInsert() { 76 return true; 77 } 78 } 79 | Popular Tags |