61.13. 動的な値での IN クエリーの使用
SQL producer では、IN 値が動的に計算される IN ステートメントで SQL クエリーを使用できます。たとえば、メッセージ本文やヘッダーなどから。
IN を使用するには、次のことが必要です。
-
パラメーター名の前に
in: -
パラメーターの前後に
( )を追加します
例はこれをよりよく説明しています。次のクエリーが使用されます。
-- this is a comment select * from projects where project in (:#in:names) order by id
-- this is a comment
select *
from projects
where project in (:#in:names)
order by id
次の経路で:
from("direct:query")
.to("sql:classpath:sql/selectProjectsIn.sql")
.to("log:query")
.to("mock:query");
from("direct:query")
.to("sql:classpath:sql/selectProjectsIn.sql")
.to("log:query")
.to("mock:query");
次に、IN クエリーは、次のような動的な値を持つキー名を持つヘッダーを使用できます。
クエリーは、外部化する代わりにエンドポイントで指定することもできます (外部化すると SQL クエリーの維持が容易になることに注意してください)。
from("direct:query")
.to("sql:select * from projects where project in (:#in:names) order by id")
.to("log:query")
.to("mock:query");
from("direct:query")
.to("sql:select * from projects where project in (:#in:names) order by id")
.to("log:query")
.to("mock:query");