Actually, Java.wrap wants the recv parameter to be JavaUtilities, so you'd
need to do something like this:
return Java.wrap(recv.getRuntime().getModule("JavaUtilities"),
JavaObject.wrap(recv.getRuntime(),c.prepareStatement(sql.toString())));
You could also call Java.java_to_ruby, but it adds a lot of overhead that is
unnecessary in this case -- it will unwrap the JavaObject, do a lot of type
checking (in JavaUtil.convertJavaToRuby), and in this case just rewrap it in
a JavaObject. (We should probably have Java-facing versions of some of
these methods that avoid unnecessary wrapping-unwrapping.)
return Java.java_to_ruby(recv,
JavaObject.wrap(recv.getRuntime(),c.prepareStatement(sql.toString())),
Block.NULL_BLOCK);
-Bill
On 5/2/07, Bill Dortch <[EMAIL PROTECTED]> wrote:
I haven't tried this (yet, will shortly), but I think what you need to do
is:
return Java.wrap(recv,JavaObject.wrap(
recv.getRuntime(),c.prepareStatement(sql.toString())))
Otherwise you're just returning a raw JavaObject, with no proxy (hence no
methods).
On 5/2/07, Ola Bini <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm investigating something that looks like a slight problem with the
> new JI, or with me. Basically, this code in standard JRuby Java:
> public static IRubyObject prepareStatement(IRubyObject recv,
> IRubyObject sql) throws SQLException {
> Connection c = (Connection)recv.dataGetStruct();
> return JavaObject.wrap(recv.getRuntime(),
> c.prepareStatement(sql.toString()));
> }
>
> is bound to the method "ps" on a connection object in AR-JDBC. Now, in
> AR-JDBC, the Oracle adapter have this code:
>
> @stmts ||= {}
> @stmts[sql] ||= @connection.ps(sql)
> stmt = @stmts[sql]
> stmt.setLong(1,id)
> stmt.executeUpdate
>
> the problem here is that it fails. On setLong. If I replace it with
> setInt, it doesn't work either. Both of these methods ARE there. The
> error message looks like this:
>
> NoMethodError: undefined method `setLong' for
> [EMAIL PROTECTED]:Java::JavaObject
>
> Bill, am I doing something wrong? Is the wrap-method outdated (and if
> so, we have major code to rewrite)?
>
> Cheers
>
> --
> Ola Bini (http://ola-bini.blogspot.com )
> JvYAML, RbYAML, JRuby and Jatha contributor
> System Developer, Karolinska Institutet (http://www.ki.se)
> OLogix Consulting (http://www.ologix.com )
>
> "Yields falsehood when quined" yields falsehood when quined.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
>
>