/**
 *
 */
package brn.distsim.ormapper.class2hbm;

import java.io.Serializable;

import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.IdentifierGenerator;

/**
 * @author kurth
 *
 */
public class IdGenerator implements IdentifierGenerator {

//  protected int simulationId;

  private static int nextId = 0;

  private static int simulationId = 0;

  public static void setSimulationId(int id) {
    simulationId = id;
  }

  public IdGenerator() {
//    this.simulationId = 0;
//    this.nextId = 1;
  }

  /* (non-Javadoc)
   * @see org.hibernate.id.IdentifierGenerator#generate(org.hibernate.engine.SessionImplementor, java.lang.Object)
   */
  public synchronized Serializable generate(SessionImplementor arg0, Object arg1)
      throws HibernateException {
    long id = ((long)simulationId << (long)Integer.SIZE) + (long)(++nextId);
    return new Long(id);
  }

}
