oracle11g - Casting java.sql.Connection to oracle.jdbc.OracleConnection results in compilation error -



oracle11g - Casting java.sql.Connection to oracle.jdbc.OracleConnection results in compilation error -

i cast java.sql.connection oracle.jdbc.oracleconnection in order bind info on array query.

when seek next on scala 2.10, bonecp 0.8.0 , slick 2.0.0:

import com.jolbox.bonecp.connectionhandle import oracle.jdbc.oracleconnection def failswithcompilationerror() = { database.fordatasource(ds).withdyntransaction { val connection = dynamicsession.conn.asinstanceof[connectionhandle].getinternalconnection println(connection.unwrap(classof[oracleconnection])) // when uncommenting next 2 lines compilation error "error while loading aqmessage, class file '.../ojdbc6.jar(oracle/jdbc/aq/aqmessage.class)' broken" occur // val oracleconnection: oracleconnection = connection.unwrap(classof[oracleconnection]) // println(oracleconnection) } }

and uncomment 2 lines assignment val of type oracleconnection , printlna compilation failure

[error] error while loading aqmessage, class file '.../ojdbc6.jar(oracle/jdbc/aq/aqmessage.class)' broken occur.

i verified ojdbc6.jar should not corrupted downloading newer version oracle.

it seems problem scala compiler.

as embedded functionality depended on oracle.jdbc.oracleconnection plain old java class, built separate .jar , linked scala code things started roll.

here's how got work:

oraclearray.java package my.application.oracle.collections; import oracle.jdbc.oracleconnection; import oracle.jdbc.oraclepreparedstatement; import oracle.sql.array; import scala.long; import scala.tuple2; import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import java.util.arraylist; import java.util.list; /* wraps usage of oracle arrays since casting java.sql.connection oracle.jdbc.connection not compile on scala. */ public class oraclearray { public static list<tuple2<long, long>> fetchassetsbyids(list ids, connection connection) throws sqlexception { oracleconnection oracleconnection = (oracleconnection) connection; array oraclearray = oracleconnection.createarray("my_array_sql_type", ids.toarray()); string sql = "select a.id, a.value" + "from asset " + "where a.id in (select column_value table(?))"; preparedstatement statement = oracleconnection.preparestatement(sql); seek { oraclepreparedstatement oraclepreparedstatement = (oraclepreparedstatement) statement; oraclepreparedstatement.setarray(1, oraclearray); resultset resultset = oraclepreparedstatement.executequery(); seek { arraylist<tuple2<long, long>> resulttuples = new arraylist<>(); while (resultset.next()) { long id = resultset.getlong(1); long value = resultset.getlong(2); resulttuples.add(new tuple2(id, value)); } homecoming resulttuples; } { resultset.close(); } } { statement.close(); } } } datauser.scala package my.application import my.application.oracle.collections.oraclearray import scala.slick.driver.jdbcdriver.backend.database import database.dynamicsession import com.jolbox.bonecp.connectionhandle import java.sql.connection import collection.javaconversions._ /* uses bonecp , slick connect database , relays java.sql.connection oraclearray in order run operations utilize oracle arrays */ object datauser { def dosomethingwithassets(ids: seq[long]): unit = { database.fordatasource(ds).withdyntransaction { val connection: connection = dynamicsession.conn.asinstanceof[connectionhandle].getinternalconnection val assets: seq[(long, long)] = oraclearray.fetchassetsbyids(ids, connection) println(assets) } } }

oracle11g slick scala-2.10 bonecp

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -