1 28 29 package com.caucho.amber.idgen; 30 31 import com.caucho.amber.manager.AmberConnection; 32 import com.caucho.util.L10N; 33 import com.caucho.util.Log; 34 35 import java.sql.SQLException ; 36 import java.util.logging.Logger ; 37 38 41 abstract public class IdGenerator { 42 private static final L10N L = new L10N(IdGenerator.class); 43 private static final Logger log = Log.open(IdGenerator.class); 44 45 private long _next; 46 private int _remaining; 47 48 private int _groupSize = 50; 49 50 53 public int getGroupSize() 54 { 55 return _groupSize; 56 } 57 58 61 public void setGroupSize(int groupSize) 62 { 63 _groupSize = groupSize; 64 } 65 66 69 public long allocate(AmberConnection aConn) 70 throws SQLException 71 { 72 synchronized (this) { 73 if (_remaining <= 0) { 74 _next = allocateGroup(aConn); 75 _remaining += getGroupSize(); 76 } 77 78 long value = _next; 79 _next++; 80 _remaining--; 81 82 return value; 83 } 84 } 85 86 89 abstract public long allocateGroup(AmberConnection aConn) 90 throws SQLException ; 91 } 92 | Popular Tags |