下の1番目の例は、作業コードを示しています。私は作業コードをさらに進めてSQLをXMLファイルに保存したいと思っています。しかし、XMLファイルから読み込むと、SQL文をGStringとして扱うことはできません。ここでXMLファイルのエントリをGStringとして扱い、Groovyで「評価」する方法はありますか?
は実施例である:
private void testRefCursors(){
//object owner paramter
String owner = 'HR';
//Block of Oracle SQL to execute, returning 4 parameters
def sqlBlock =
"""
declare
type crsr is ref cursor;
tables crsr;
objects crsr;
begin
select count(*) into ${Sql.INTEGER} from all_tables where owner= ${owner} ;
open tables for select * from all_tables where owner= ${owner} ;
${Sql.resultSet OracleTypes.CURSOR} := tables;
select count(*) into ${Sql.INTEGER} from all_objects where owner= ${owner} ;
open objects for select * from all_objects where owner= ${owner};
${Sql.resultSet OracleTypes.CURSOR} := objects;
end;
"""
//note the order below, is the order of the 'types'
//in the SQL block used in the closure as parameters.
sqlSEDREF.call(sqlBlock){
t,user_tables,o,user_objects ->
println "found ${t} tables from a total of ${o} objects"
user_tables.eachRow(){x ->println "table:${x.table_name}"}
user_objects.eachRow(){println "object:${it.object_name}"}
}
}
今、私はXMLファイルからSQLのブロックを読み取るために例を変更すると、 、返されるエラーがSQL.call(GストリングのGストリングの実装を使用することができないの結果である
private void testRefCursors(){
//object owner paramter
String owner = 'HR';
def configFile = new File("config.xml");
config = new XmlSlurper().parse(configFile);
// FAILURE HERE -
GString sqlBlock = config.'sql-test-cursors'
//note the order below, is the order of the 'types'
//in the SQL block used in the closure as parameters.
sqlSEDREF.call(sqlBlock){
t,user_tables,o,user_objects ->
println "found ${t} tables from a total of ${o} objects"
user_tables.eachRow(){x ->println "table:${x.table_name}"}
user_objects.eachRow(){println "object:${it.object_name}"}
}
}
:私はどのように(またはそれが可能な場合)、Gストリングとしてその値を処理するために知っていません閉鎖):キャッチ
: groovy.lang.MissingMethodException: 方法の無 署名: (java.lang.Stringで、ツール:groovy.sql.Sql.call()は、引数の型のために適用可能である .UAT $ _testRefCursors_closure2)
私の現在の回避策は、おそらくCONFIG.groovyファイルを有することのconfig.xmlを有するから切り替えて.groovyファイルの代わりにXMLからGStringのを読み取ることです。任意の提案を大いに感謝します。
私はこの仕事を得ることができるかどうかがわかります。 http://groovy.codehaus.org/gapi/groovy/sql/Sql.html#call(groovy:私は、私が午前混乱が閉鎖を取るだけSQL.call方法は、Gストリングのバージョンであることだと思います。 lang.GString、%20groovy.lang.Closure) –
待機します。私はちょうどこのメソッドシグネチャに気づいた:call(String sql、List params、Closure closure) –