1 package org.hibernate.id; 3 4 import java.net.InetAddress ; 5 import org.hibernate.util.BytesHelper; 6 7 15 16 public abstract class AbstractUUIDGenerator implements IdentifierGenerator { 17 18 private static final int IP; 19 static { 20 int ipadd; 21 try { 22 ipadd = BytesHelper.toInt( InetAddress.getLocalHost().getAddress() ); 23 } 24 catch (Exception e) { 25 ipadd = 0; 26 } 27 IP = ipadd; 28 } 29 private static short counter = (short) 0; 30 private static final int JVM = (int) ( System.currentTimeMillis() >>> 8 ); 31 32 public AbstractUUIDGenerator() { 33 } 34 35 39 protected int getJVM() { 40 return JVM; 41 } 42 43 47 protected short getCount() { 48 synchronized(AbstractUUIDGenerator.class) { 49 if (counter<0) counter=0; 50 return counter++; 51 } 52 } 53 54 57 protected int getIP() { 58 return IP; 59 } 60 61 64 protected short getHiTime() { 65 return (short) ( System.currentTimeMillis() >>> 32 ); 66 } 67 protected int getLoTime() { 68 return (int) System.currentTimeMillis(); 69 } 70 71 72 } 73 74 75 76 77 78 | Popular Tags |