ajuste (fixes bug 5878 )
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@40043 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
411ca73c96
commit
04dca61e2c
|
@ -0,0 +1,73 @@
|
||||||
|
package com.rjconsultores.ventaboletos.entidad;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.engine.SessionImplementor;
|
||||||
|
import org.hibernate.id.Configurable;
|
||||||
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
||||||
|
|
||||||
|
public class CustomIdGenerator implements IdentifierGenerator, Configurable {
|
||||||
|
|
||||||
|
private String seqName;
|
||||||
|
private Integer tamanho;
|
||||||
|
|
||||||
|
public Serializable generate(SessionImplementor session, Object object)
|
||||||
|
throws HibernateException {
|
||||||
|
|
||||||
|
Connection connection = session.connection();
|
||||||
|
try {
|
||||||
|
|
||||||
|
PreparedStatement ps = connection
|
||||||
|
.prepareStatement("SELECT " + seqName + ".NEXTVAL AS NEXTVAL FROM DUAL");
|
||||||
|
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
Integer id = rs.getInt("NEXTVAL");
|
||||||
|
String newValue = id.toString();
|
||||||
|
if (ApplicationProperties.getInstance().habilitarCustomSequence()) {
|
||||||
|
newValue = "1" + (StringUtils.leftPad(id.toString(), tamanho, "0"));
|
||||||
|
}
|
||||||
|
return Integer.valueOf(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(org.hibernate.type.Type arg0, Properties arg1, Dialect arg2) throws MappingException {
|
||||||
|
setTamanho(Integer.valueOf(arg1.getProperty("tamanho")));
|
||||||
|
setSeqName(arg1.getProperty("seqName"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTamanho() {
|
||||||
|
return tamanho;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTamanho(Integer tamanho) {
|
||||||
|
this.tamanho = tamanho;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeqName() {
|
||||||
|
return seqName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeqName(String seqName) {
|
||||||
|
this.seqName = seqName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,6 +16,9 @@ import javax.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
import org.hibernate.annotations.Parameter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@SequenceGenerator(name = "FOLIO_PREIMPRESO_SEQ", sequenceName = "FOLIO_PREIMPRESO_SEQ", allocationSize = 1)
|
@SequenceGenerator(name = "FOLIO_PREIMPRESO_SEQ", sequenceName = "FOLIO_PREIMPRESO_SEQ", allocationSize = 1)
|
||||||
@Table(name = "FOLIO_PREIMPRESO")
|
@Table(name = "FOLIO_PREIMPRESO")
|
||||||
|
@ -24,6 +27,11 @@ public class FolioPreimpreso implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@Id
|
@Id
|
||||||
@Basic(optional = false)
|
@Basic(optional = false)
|
||||||
|
@GenericGenerator(name = "FOLIO_PREIMPRESO_SEQ", strategy = "com.rjconsultores.ventaboletos.entidad.CustomIdGenerator" ,
|
||||||
|
parameters = {
|
||||||
|
@Parameter(name="tamanho", value="8"),
|
||||||
|
@Parameter(name="seqName", value="FOLIO_PREIMPRESO_SEQ")
|
||||||
|
} )
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "FOLIO_PREIMPRESO_SEQ")
|
@GeneratedValue(strategy = GenerationType.AUTO, generator = "FOLIO_PREIMPRESO_SEQ")
|
||||||
@Column(name = "FOLIOPREIMPRESO_ID")
|
@Column(name = "FOLIOPREIMPRESO_ID")
|
||||||
private Integer foliopreimpresoId;
|
private Integer foliopreimpresoId;
|
||||||
|
|
|
@ -132,4 +132,9 @@ public class ApplicationProperties {
|
||||||
return property.equals("1");
|
return property.equals("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean habilitarCustomSequence() {
|
||||||
|
String property = p.getProperty("custom.sequence", "0");
|
||||||
|
return property.equals("1");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue