-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to save BFile thorugh Hibernate
PostPosted: Thu Jun 07, 2007 5:49 pm 
Newbie

Joined: Thu Jun 07, 2007 5:47 pm
Posts: 3
Please let me know if anyone knows How to save BFILE through hibernate. Quick reply is greatly appreciated.

Thanks
Kumar.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 9:55 am 
Newbie

Joined: Thu Jun 07, 2007 5:47 pm
Posts: 3
Here is the sample UserType clas i am using to get BFILE from database. But when i am trying to get BILE from database... i am not getting data, Any one knows how to get BFILE data from database.

package com.ameripath.shared.apptier.hibernate;

import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.jdbc.OracleConnection;
import oracle.jdbc.driver.OracleTypes;
import oracle.sql.BFILE;
import oracle.sql.BLOB;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

public final class BFileType implements UserType {

private static final int BFILE_TYPE = OracleTypes.BFILE;
private static final Class RETURNED_CLASS = BFILE.class;

public int[] sqlTypes() {
return new int[]{BFILE_TYPE};
}

public Class returnedClass() {
return byte[].class;
}

public boolean equals(Object x, Object y) throws HibernateException {
return (x == y)
|| (x != null && y != null && java.util.Arrays.equals(
(byte[]) x, (byte[]) y));
}

public boolean isMutable() {
return false;
}

public int hashCode(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return 0;
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner)throws HibernateException, SQLException {
BFILE file = (BFILE) rs.getObject(names[0]);
if (file != null && file.getBytes()!= null){
return file.getBytes();
}else{
return null;
}


}

public void nullSafeSet(PreparedStatement st, Object value, int index)throws HibernateException, SQLException {
if (value == null)
st.setObject(index, null);
else{
BFILE file = new BFILE((OracleConnection)((org.jboss.resource.adapter.jdbc.WrappedConnection) st.getConnection()).getUnderlyingConnection(),(byte[]) value);
st.setBytes(index,file.getBytes());
}
}

public Object deepCopy(Object value)
{
if (value == null) return null;

byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);

return result;
}

public Serializable disassemble(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 9:56 am 
Newbie

Joined: Thu Jun 07, 2007 5:47 pm
Posts: 3
Here is the sample UserType clas i am using to get BFILE from database. But when i am trying to get BILE from database... i am not getting data, Any one knows how to get BFILE data from database.

package com.ameripath.shared.apptier.hibernate;

import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.jdbc.OracleConnection;
import oracle.jdbc.driver.OracleTypes;
import oracle.sql.BFILE;
import oracle.sql.BLOB;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

public final class BFileType implements UserType {

private static final int BFILE_TYPE = OracleTypes.BFILE;
private static final Class RETURNED_CLASS = BFILE.class;

public int[] sqlTypes() {
return new int[]{BFILE_TYPE};
}

public Class returnedClass() {
return byte[].class;
}

public boolean equals(Object x, Object y) throws HibernateException {
return (x == y)
|| (x != null && y != null && java.util.Arrays.equals(
(byte[]) x, (byte[]) y));
}

public boolean isMutable() {
return false;
}

public int hashCode(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return 0;
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner)throws HibernateException, SQLException {
BFILE file = (BFILE) rs.getObject(names[0]);
if (file != null && file.getBytes()!= null){
return file.getBytes();
}else{
return null;
}


}

public void nullSafeSet(PreparedStatement st, Object value, int index)throws HibernateException, SQLException {
if (value == null)
st.setObject(index, null);
else{
BFILE file = new BFILE((OracleConnection)((org.jboss.resource.adapter.jdbc.WrappedConnection) st.getConnection()).getUnderlyingConnection(),(byte[]) value);
st.setBytes(index,file.getBytes());
}
}

public Object deepCopy(Object value)
{
if (value == null) return null;

byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);

return result;
}

public Serializable disassemble(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
// TODO Auto-generated method stub
return null;
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.