Mostrando las entradas con la etiqueta Oracle. Mostrar todas las entradas
Mostrando las entradas con la etiqueta Oracle. Mostrar todas las entradas

jueves, septiembre 02, 2010

java.io.IOException: JDT compilation error! WebLogic 10.3

Al desplegar un ear con un modulo EJB (3.0) en Weblogic (10.3.1 y 10.3.2, en Windows 7 con el JDK de cada instalación) obtenía el siguiente error:

Unable to deploy EJB: negocio-3.1.0.jar from negocio-3.1.0.jar:

There are 1 nested errors:

java.io.IOException: JDT compilation error!
at weblogic.ejb.container.ejbc.CompilerForJDT.compile(CompilerForJDT.java:66)
at weblogic.ejb.container.ejbc.EJBCompiler.doCompile(EJBCompiler.java:358)
at weblogic.ejb.container.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:556)

El problema era por un método sobre cargado:

boolean solicitarXxxYyyyObjeto(List listYyyyTO,
List listZzzzInstanciaTO);

Boolean solicitarXxxYyyyObjeto(
List listaZzzzInstanciaTO,
List listaYyyyTO) throws SeguridadException;

Elimine uno de los dos método tanto en la interfaz como en la implementación.
Y con eso la aplicación jalo.

martes, enero 02, 2007

LongRaw Datatype Oracle

      String query = "SELECT name,airline_logo FROM " +
"otn_airline_longraw WHERE code=?"
;

// Create a PreparedStatement object for executing the query
PreparedStatement pst = connection.prepareStatement(query);

// bind the parameter with code value
pst.setString(1,lcode);

// Obtain the result-set for the selected airline record
ResultSet result = pst.executeQuery();

// get user home folder name
userHome = System.getProperty("user.home");

if( result.next() ) {

// Fetch column values
name = result.getString(1); // Obtain the airline code

// append the file name with user home directory, file separator and
// file extension GIF
fullName = userHome+File.separator+name+".gif";

// LONGRAW data can be accessed in two ways:
// 1) By retrieving all the data at once (using getBytes method)
// 2) By using streams. The LONGRAW data is made available to the program
// as a stream, and the data can be retrieved chunk by chunk, which is
// more eficient in terms of memory usage
// In this sample we illustrate retrieval using streams method.
gifdata = result.getBinaryStream(2);
// create new file
File gifFile = new File(fullName);

// Write the byte array into a local file
FileOutputStream file= new
FileOutputStream(gifFile);

int chunk=0;
// write to the local file until image (LONGRAW) data is found
while( (chunk = gifdata.read()) != -1) {
file.write(chunk);
}

El ejemplo competo está acá [Cátalogo de ejemplos].
Creo que tiene las mejores practicas las clases:
Hace falta un finally para cerrar recursos.
Declarar como final algunos objetos.


martes, junio 20, 2006

Manejo de BLOB con Hibernate, Spring y Oracle

Clase Form
public class DocumentacionProbatoriaForm extends ValidatorForm{

/**
* Crea una instancia de clase DocumentacionProbatoriaForm.
*/
public DocumentacionProbatoriaForm() {
super();
// TODO Auto-generated constructor stub
}

/**
atributo para almacenar el rutaArchivo
*/
private String rutaArchivo;

/**
atributo para almacenar el archivo
*/
private FormFile archivo;

}// end class

Clase Action
public class DocumentacionProbatoriaMappingDispatchAction extends
MappingDispatchAction {


public ActionForward cargarDocumentoProbatorio(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {

if (logger.isInfoEnabled()) {
logger.info(" #### METODO: cargarDocumentoProbatorio");
}
DocumentacionProbatoriaForm forma = (DocumentacionProbatoriaForm) form;

FormFile docto = forma.getArchivo();


if (logger.isDebugEnabled()) {
logger.debug("size ::" + docto.getFileSize());
logger.debug("name ::" + docto.getFileName());
}//
DocumentacionProbatoriaVO vo = new DocumentacionProbatoriaVO();

vo.setCvePersona4modif(cvePersona4modif);
vo.setArchivo(docto.getFileData());


service = (DocumentacionProbatoriaService) super
.getBean("documentacionProbatoriaService");
// guardamos
vo = service.guardarDocumentacion(vo);
}//end method
}//end class


Implementación de la Clase de Servicio

public class DocumentacionProbatoriaServiceImpl implements
DocumentacionProbatoriaService {

private static Logger logger = Logger.getLogger(DocumentacionProbatoriaServiceImpl.class);

private DocProbatoriaModifDAO docProbatoriaModifDAO;

private FoliadorDAO foliadorDAO;

/**
* Crea una instancia de clase DocumentacionProbatoriaServiceImpl.
*/
public DocumentacionProbatoriaServiceImpl() {
super();
// TODO Auto-generated constructor stub
}

public DocumentacionProbatoriaVO guardarDocumentacion(
DocumentacionProbatoriaVO vo) throws BusinessException {

try {
Integer cveDocProbatoriaModif = this.foliadorDAO.getCveDocProbatoriaModif(vo.getCvePersona4modif());

DocProbatoriaModifPK pk = new DocProbatoriaModifPK();
pk.setCveDocProbatoriaModif(cveDocProbatoriaModif);
pk.setCvePersona4modif(vo.getCvePersona4modif());

DocProbatoriaModif docProba = new DocProbatoriaModif();
docProba.setComp_id(pk);
docProba.setDocProbatoria(this.creaBlob(vo.getArchivo()));
docProba.setDesDocProbatoria(vo.getDesDocProbatoria());
docProba.setDesNombreArchivo(vo.getNombreArchivo());

this.docProbatoriaModifDAO.insertar(docProba);

vo.setCveDocProbatoriaModif(cveDocProbatoriaModif);

// TODO Auto-generated method stub

}
catch (InfrastructureException e) {
logger.error(e.getMessage(), e);
}
return vo;
}

public DocumentacionProbatoriaVO recuperarDocumentacion(
DocumentacionProbatoriaVO vo) throws BusinessException {
try {
DocProbatoriaModifPK pk = new DocProbatoriaModifPK();
pk.setCveDocProbatoriaModif(vo.getCveDocProbatoriaModif());
pk.setCvePersona4modif(vo.getCvePersona4modif());
DocProbatoriaModif result= this.docProbatoriaModifDAO.findByPK(pk);
vo.setArchivo(this.toByteArray(result.getDocProbatoria()));
vo.setDesDocProbatoria(vo.getDesDocProbatoria());
vo.setNombreArchivo(result.getDesNombreArchivo());
return vo;
}
catch (InfrastructureException e) {
logger.error(e.getMessage(), e);
throw new BusinessException(e.getMessage(), e);
}
}


/**
* Recupera todos los documentos de una persona.
Recupera todos los datos excepto el BLOB.

* @param cvePersona4modif
* @return Lista con objetos DocumentacionProbatoriaVO.
* @throws BusinessException
*/
public List recuperaDocumentosXPersona(Integer cvePersona4modif) throws BusinessException{
List response = new ArrayList();

try {
if (logger.isDebugEnabled()){
logger.debug("cvePersona4modif :: " + cvePersona4modif);
}

final List temp = this.docProbatoriaModifDAO.recuperaListaDoctos( cvePersona4modif);
DocProbatoriaModif persitente = null;
DocumentacionProbatoriaVO vo = null;
if (temp!= null && !temp.isEmpty()){
final Iterator it = temp.iterator();
while(it.hasNext()) {
persitente =(DocProbatoriaModif) it.next();
vo = new DocumentacionProbatoriaVO();
vo.setArchivo(null);
vo.setCveDocProbatoriaModif(persitente.getComp_id().getCveDocProbatoriaModif());
vo.setCvePersona4modif(persitente.getComp_id().getCvePersona4modif());
vo.setDesDocProbatoria(persitente.getDesDocProbatoria());
vo.setNombreArchivo(persitente.getDesNombreArchivo());
if (logger.isDebugEnabled()){
logger.debug("DesNombreArchivo :: "
+ persitente.getDesNombreArchivo() + ", "
+ vo.getCveDocProbatoriaModif());
}
response.add(vo);
}
}

return response;
}
catch (InfrastructureException e) {
logger.error(e.getMessage(), e);
throw new BusinessException(e.getMessage(), e);
}
}

/**
* Elimina un documento.
* @param vo
* @throws BusinessException
*/
public void eliminarDocumento(DocumentacionProbatoriaVO vo) throws BusinessException{

try {
DocProbatoriaModifPK pk = new DocProbatoriaModifPK();



pk.setCveDocProbatoriaModif(vo.getCveDocProbatoriaModif());
pk.setCvePersona4modif(vo.getCvePersona4modif());

if (logger.isInfoEnabled()){
logger.info("pk :: " + GeneralSimeUtil.getObjectAsString(pk));
}

DocProbatoriaModif objetoPersistente = this.docProbatoriaModifDAO.findByPK(pk);

this.docProbatoriaModifDAO.eliminar(objetoPersistente);


if (logger.isDebugEnabled()) {
logger.debug("Eliminar [OK]");
}

}
catch (InfrastructureException e) {
logger.error(e.getMessage(), e);
throw new BusinessException(e.getMessage(), e);
}

}

/**
* Crea un BLob a apartir de un arrelog de bytes.
* @param input
* @return
*/
private Blob creaBlob(byte[] input){
return Hibernate.createBlob(input);
}


private byte[] toByteArray(Blob fromBlob) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
return toByteArrayImpl(fromBlob, baos);
}
catch (SQLException e) {
throw new RuntimeException(e);
}
catch (IOException e) {
throw new RuntimeException(e);
}
finally {
if (baos != null) {
try {
baos.close();
}
catch (IOException ex) {
}
}
}
}

private byte[] toByteArrayImpl(Blob fromBlob, ByteArrayOutputStream baos)
throws SQLException, IOException {
byte[] buf = new byte[4000];
InputStream is = fromBlob.getBinaryStream();
try {
for (;;) {
int dataSize = is.read(buf);

if (dataSize == -1)
break;
baos.write(buf, 0, dataSize);
}
}
finally {
if (is != null) {
try {
is.close();
}
catch (IOException ex) {
}
}
}
return baos.toByteArray();
}

/**
* Método que establece el valor del atributo docProbatoriaModifDAO.
*
* @param docProbatoriaModifDAO
* Valor a establecer en el atributo docProbatoriaModifDAO.
*/
public void setDocProbatoriaModifDAO(
DocProbatoriaModifDAO docProbatoriaModifDAO) {
this.docProbatoriaModifDAO = docProbatoriaModifDAO;
}

/**
* Método que establece el valor del atributo foliadorDAO.
*
* @param foliadorDAO
* Valor a establecer en el atributo foliadorDAO.
*/
public void setFoliadorDAO(FoliadorDAO foliadorDAO) {
this.foliadorDAO = foliadorDAO;
}

}//end class

Clase DAO
public class DocProbatoriaModifDAOImpl extends DAOSimeBaseImpl implements DocProbatoriaModifDAO {

/**
* Crea una instancia de clase DocProbatoriaModifDAOImpl.
*/
public DocProbatoriaModifDAOImpl() {
super();
// TODO Auto-generated constructor stub
}

public DocProbatoriaModif findByPK(DocProbatoriaModifPK pk) throws InfrastructureException {
return (DocProbatoriaModif) super.getHibernateTemplate().load(DocProbatoriaModif.class, pk);
}
public List recuperaListaDoctos(Integer cvePersona4modif) throws InfrastructureException{
List response = new ArrayList();

StringBuffer query = new StringBuffer();
query.append(" from DocProbatoriaModif as obj");
query.append(" where obj.comp_id.cvePersona4modif = ");
query.append(cvePersona4modif);

response = super.getHibernateTemplate().find(query.toString());

if (logger.isDebugEnabled()){
logger.debug("query :: " + query);
logger.debug("response.size() :: " + response.size());
}

return response;
}
}//end class

Clase VO
public class DocumentacionProbatoriaVO extends GenericSimeVO {

/**
*
*/
private static final long serialVersionUID = 1L;
private java.lang.Integer cvePersona4modif;
private java.lang.Integer cveDocProbatoriaModif;
/**
* Representación en un arreglo de bytes del archivo
*/
private byte[] archivo;
private java.lang.String nombreArchivo;
private java.lang.String desDocProbatoria;
}//end class

Clase de mapeo de HB:

public abstract class BaseDocProbatoriaModif implements Serializable {

// primary key
private mx.net.vlad.integracion.hbm.DocProbatoriaModifPK comp_id;

// fields
private java.sql.Blob docProbatoria;
private java.lang.String desDocProbatoria;
private java.lang.String desNombreArchivo;
}//end class




Nota
La clases de tipo bean obviamente tienen sus métodos get&set.
La clases que considero más importante y por lo tanto la he puesto intacta es el servicio, ya que hace la transformación del arreglo de bytes al objeto BLOB y viceversa.
La configuración de Spring no tiene nada de especial es por ello que no la pongo.


jueves, octubre 20, 2005

Tablas con nombre mafufos en Oracle

Hice unos cambios en mi BD de oracle y me genero tablas con nombre mafufos como BIN$4vcvloiRRxWzgEV2Xum/KA==$0 , las cual no permitian que me conectara con una herramienta que genera los hbm y las classes java, lo elimine con:
purge recyclebin
Salu2!

martes, octubre 18, 2005

Sequences Oracle

DROP SEQUENCE nombre_del_sequence;

CREATE SEQUENCE nombre_del_sequence
START WITH 1
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOORDER;