ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yu, Jack" <Jack...@fmr.com>
Subject RE: How to pass Array as parameter?
Date Wed, 03 Oct 2007 21:27:14 GMT
One minor change to the sample code, I have to use inner most delegate
connection. So it is:


 public void setParameter(ParameterSetter setter, Object parameter)
throws SQLException {
		if (parameter instanceof DBArray) {
			DBArray arr = (DBArray)parameter;
			Statement stmt = setter.getPreparedStatement();
			Connection conn = stmt.getConnection();
			if (conn instanceof DelegatingConnection) {
				DelegatingConnection dcon =
(DelegatingConnection) conn;
				conn = dcon.getInnermostDelegate();
			}
			ArrayDescriptor  desc = new ArrayDescriptor
(arr.getSqlType(), conn);
			
			/* arr.getData's type is SQLData[] */
			parameter = new ARRAY(desc, conn,
arr.getData());
			 
		}
		setter.setObject(parameter);
	}

-----Original Message-----
From: Yu, Jack 
Sent: Wednesday, October 03, 2007 5:11 PM
To: user-java@ibatis.apache.org
Subject: How to pass Array as parameter?

I would need to pass Array in the call, but I couldn't find out feasible
way to wrap around my objects to java.sql.Array.

In Oracle, it appears I could use "ARRAY" to create, but ARRAY object
need ArrayDescriptor which requires access to Connection object, which I
am not sure how to get in the ibatis environment.

I am trying to play around the setParameter in TypeHandlerCallback
interface, here is what I come out. It works in Oracle environment, but
I would like to get some feedback before I check in the code.

Thanks.

	public void setParameter(ParameterSetter setter, Object
parameter) throws SQLException {
		if (parameter instanceof DBArray) {
			DBArray arr = (DBArray)parameter;
			// convert SQLData[] to Array
			Statement stmt = setter.getPreparedStatement();
			Connection conn = stmt.getConnection();
			ArrayDescriptor  desc = new ArrayDescriptor
(arr.getSqlType(), conn);
			
			parameter = new ARRAY(desc, conn,
arr.getData());
			 
		}
		setter.setObject(parameter);
	}



Mime
View raw message