package org.jbpm.pvm.internal.id; import org.hibernate.Query; import org.hibernate.Session; import org.jbpm.api.cmd.Command; import org.jbpm.api.cmd.Environment; public class AcquireDbidBlockCmd implements Command { private static final long serialVersionUID = 1L; long blocksize; public AcquireDbidBlockCmd(long blocksize) { this.blocksize = blocksize; } public Long execute(Environment environment) throws Exception { Session session = (Session)environment.get(Session.class); Session newsession = session.getSessionFactory().openSession(); newsession.beginTransaction(); PropertyImpl property = (PropertyImpl)newsession.createQuery("select property from " + PropertyImpl.class.getName() + " as property " + "where property.key = '" + "next.dbid" + "'").uniqueResult(); String nextIdText = property.getValue(); Long nextId = new Long(nextIdText); property.setValue(Long.toString(nextId.longValue() + this.blocksize)); newsession.update(property); newsession.flush(); newsession.getTransaction().commit(); newsession.close(); newsession = null; return nextId; } }