搜索

此内容没有您所选择的语言版本。

Chapter 20. JoSQL

download PDF

Overview

The JoSQL (SQL for Java objects) language enables you to evaluate predicates and expressions in Apache Camel. JoSQL employs a SQL-like query syntax to perform selection and ordering operations on data from in-memory Java objects—however, JoSQL is not a database. In the JoSQL syntax, each Java object instance is treated like a table row and each object method is treated like a column name. Using this syntax, it is possible to construct powerful statements for extracting and compiling data from collections of Java objects. For details, see http://josql.sourceforge.net/.

Adding the JoSQL module

To use JoSQL in your routes you need to add a dependency on camel-josql to your project as shown in Example 20.1, “Adding the camel-josql dependency”.

Example 20.1. Adding the camel-josql dependency

<!-- Maven POM File -->
...
<dependencies>
  ...
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-josql</artifactId>
    <version>${camel-version}</version>
  </dependency>
  ...
</dependencies>

Static import

To use the sql() static method in your application code, include the following import statement in your Java source files:
import static org.apache.camel.builder.sql.SqlBuilder.sql;

Variables

Table 20.1, “SQL variables” lists the variables that are accessible when using JoSQL.
Table 20.1. SQL variables
NameTypeDescription
exchangeorg.apache.camel.ExchangeThe current Exchange
inorg.apache.camel.MessageThe IN message
outorg.apache.camel.MessageThe OUT message
propertyObjectthe Exchange property whose key is property
headerObjectthe IN message header whose key is header
variableObjectthe variable whose key is variable

Example

Example 20.2, “Route using JoSQL” shows a route that uses JoSQL.

Example 20.2. Route using JoSQL

<camelContext>
  <route>
    <from uri="direct:start"/>
    <setBody>
      <language language="sql">select * from MyType</language>
    </setBody>
    <to uri="seda:regularQueue"/>
  </route>
</camelContext>
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.