76 lines
2.5 KiB
Plaintext
Executable File
76 lines
2.5 KiB
Plaintext
Executable File
package com.fp.sessionbeans.helper;
|
|
|
|
import javax.naming.InitialContext;
|
|
|
|
import com.fp.common.properties.PropertiesHandler;
|
|
import com.fp.persistence.commondb.PersistenceManager;
|
|
import com.fp.persistence.commondb.data.SessionData;
|
|
import com.fp.persistence.commondb.data.ThreadFacade;
|
|
import com.fp.sessionbeans.ejb.interfaces.SequenceBeanLocal;
|
|
|
|
/**
|
|
* Calse que se encarga de entregar el consecutivo de una secuencia dado un codigo de sequencia. Ejemplo Codigo dde
|
|
* secuencia, PERSONCODE, entrega el siguiente numero de persona.
|
|
*
|
|
* @author Jorge Vaca
|
|
* @version 2.1
|
|
*/
|
|
public class Sequence {
|
|
|
|
private Long nextvalue;
|
|
|
|
/**
|
|
* Metodo que entrega el numero de solicitud, para el usuario.
|
|
*
|
|
* @param pQueryRequest Datos del request.
|
|
* @throws Exception
|
|
*/
|
|
synchronized public Long getNextValue(String pSequenceCode) throws Exception {
|
|
SessionData sd = ThreadFacade.getSessionData();
|
|
if (sd.isEjb()) {
|
|
return this.getNextValueJta(pSequenceCode);
|
|
}
|
|
this.getNextValueNonJta(pSequenceCode);
|
|
return Long.valueOf(this.nextvalue.toString());
|
|
}
|
|
|
|
/**
|
|
* Metodo que entrega el numero de solicitud, para el usuario.
|
|
*
|
|
* @param pQueryRequest Datos del request.
|
|
* @throws Exception
|
|
*/
|
|
public Long getNextValueJta(String pSequenceCode) throws Exception {
|
|
SequenceBeanLocal local = null;
|
|
try {
|
|
PropertiesHandler ph = new PropertiesHandler("fb-facade");
|
|
InitialContext ctx = new InitialContext();
|
|
local = (SequenceBeanLocal) ctx.lookup(ph.getStringValue("ear") + "SequenceBean/local");
|
|
Long sec = local.getNextValueJta(PersistenceManager.getInstance().createEntityManagerLocal(), pSequenceCode);
|
|
return sec;
|
|
} catch (Exception exp) {
|
|
throw exp;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Metodo que entrega el numero de solicitud, para el usuario.
|
|
*
|
|
* @param pQueryRequest Datos del request.
|
|
* @throws Exception
|
|
*/
|
|
private void getNextValueNonJta(String pSequenceCode) throws Exception {
|
|
SequenceThread st = new SequenceThread(this, ThreadFacade.getSessionData().getCompany(), pSequenceCode);
|
|
st.start();
|
|
st.join();
|
|
}
|
|
|
|
public void setNextvalue(Long nextvalue) {
|
|
this.nextvalue = nextvalue;
|
|
}
|
|
|
|
public Long getNextvalue() {
|
|
return this.nextvalue;
|
|
}
|
|
}
|