fixes bug#8905
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@68122 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
0de782b500
commit
418e1c2c3f
|
@ -6,9 +6,9 @@ import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
|
||||||
/**
|
/**
|
||||||
* Classe que trata a geração do ID da tabela Aidf.
|
* Classe que trata a geração do ID da tabela Aidf.
|
||||||
*
|
*
|
||||||
|
@ -21,7 +21,9 @@ import org.hibernate.engine.SessionImplementor;
|
||||||
public class IdAidfStore {
|
public class IdAidfStore {
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(IdAidfStore.class);
|
private static Logger log = Logger.getLogger(IdAidfStore.class);
|
||||||
|
|
||||||
|
private static final String LIMITE_ID_AIDF = "LIMITE_ID_AIDF";
|
||||||
|
|
||||||
private static IdAidfStore INSTANCE = new IdAidfStore();
|
private static IdAidfStore INSTANCE = new IdAidfStore();
|
||||||
|
|
||||||
private int indiceAtual = 1;
|
private int indiceAtual = 1;
|
||||||
|
@ -34,10 +36,55 @@ public class IdAidfStore {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buscar novo limite de aidf.
|
||||||
|
*
|
||||||
|
* Por padrão é 999. Com o intuito de ativar de forma gradual, foi criado uma constante para essa função
|
||||||
|
* @param connection
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int buscarLimiteAidf(Connection connection){
|
||||||
|
int qtdMaxima = 999;
|
||||||
|
PreparedStatement ps;
|
||||||
|
|
||||||
|
log.info("buscando constante limite aidf ...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
ps = connection.prepareStatement("select VALORCONSTANTE from constante where NOMBCONSTANTE = :1");
|
||||||
|
ps.setString(1, LIMITE_ID_AIDF);
|
||||||
|
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()){
|
||||||
|
|
||||||
|
String tmp = rs.getString("VALORCONSTANTE");
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(tmp)){
|
||||||
|
qtdMaxima = Integer.parseInt(tmp);
|
||||||
|
|
||||||
|
log.info(String.format("constante encontrada : %s",tmp));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
log.info("constante não parametrizada");
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
|
||||||
|
}catch(Throwable e){
|
||||||
|
log.error("erro buscar constante",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return qtdMaxima;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized Serializable getNextId(Connection connection) throws HibernateException {
|
public synchronized Serializable getNextId(Connection connection) throws HibernateException {
|
||||||
|
|
||||||
int qtdMaxima = 999;
|
int qtdMaxima = this.buscarLimiteAidf(connection);
|
||||||
|
|
||||||
|
log.info(String.format("qtdMaxima:%s",qtdMaxima));
|
||||||
|
|
||||||
long idEncontrado = -1;
|
long idEncontrado = -1;
|
||||||
|
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
|
|
Loading…
Reference in New Issue