diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/H2ChannelMessageStoreQueryProvider.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/H2ChannelMessageStoreQueryProvider.java new file mode 100644 index 0000000000..f16eb201a6 --- /dev/null +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/channel/H2ChannelMessageStoreQueryProvider.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.jdbc.store.channel; + +/** + * @author Gunnar Hillert + * @author Artem Bilan + * @author Manuel Jordan + * @since 4.3 + * + */ +public class H2ChannelMessageStoreQueryProvider extends AbstractChannelMessageStoreQueryProvider { + + @Override + public String getCreateMessageQuery() { + return "INSERT into %PREFIX%CHANNEL_MESSAGE(MESSAGE_ID, GROUP_KEY, REGION, CREATED_DATE, MESSAGE_PRIORITY, " + + "MESSAGE_SEQUENCE, MESSAGE_BYTES) " + + "values (?, ?, ?, ?, ?, NEXT VALUE FOR %PREFIX%MESSAGE_SEQ, ?)"; + } + + @Override + public String getPollFromGroupExcludeIdsQuery() { + return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; + } + + @Override + public String getPollFromGroupQuery() { + return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + "order by CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; + } + + @Override + public String getPriorityPollFromGroupExcludeIdsQuery() { + return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + "and %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID not in (:message_ids) " + + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; + } + + @Override + public String getPriorityPollFromGroupQuery() { + return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES " + + "from %PREFIX%CHANNEL_MESSAGE " + + "where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " + + "order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1"; + } + +} diff --git a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-drop-h2.sql b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-drop-h2.sql new file mode 100644 index 0000000000..257045f2f4 --- /dev/null +++ b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-drop-h2.sql @@ -0,0 +1,4 @@ +DROP TABLE INT_CHANNEL_MESSAGE; +DROP INDEX INT_CHANNEL_MSG_DATE_IDX; +DROP INDEX INT_CHANNEL_MSG_PRIORITY_IDX; +DROP SEQUENCE INT_MESSAGE_SEQ; diff --git a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-h2.sql b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-h2.sql new file mode 100644 index 0000000000..0223a63928 --- /dev/null +++ b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-h2.sql @@ -0,0 +1,15 @@ +CREATE TABLE INT_CHANNEL_MESSAGE ( + MESSAGE_ID CHAR(36) NOT NULL, + GROUP_KEY CHAR(36) NOT NULL, + CREATED_DATE BIGINT NOT NULL, + MESSAGE_PRIORITY INT, + MESSAGE_SEQUENCE BIGINT NOT NULL, + MESSAGE_BYTES LONGVARBINARY, + REGION VARCHAR(100) NOT NULL, + constraint INT_CHANNEL_MESSAGE_PK primary key (GROUP_KEY, MESSAGE_ID, REGION) +); + +CREATE INDEX INT_CHANNEL_MSG_DATE_IDX ON INT_CHANNEL_MESSAGE (CREATED_DATE, MESSAGE_SEQUENCE); +CREATE INDEX INT_CHANNEL_MSG_PRIORITY_IDX ON INT_CHANNEL_MESSAGE (MESSAGE_PRIORITY DESC, CREATED_DATE, MESSAGE_SEQUENCE); + +CREATE SEQUENCE INT_MESSAGE_SEQ START WITH 1 INCREMENT BY 1; diff --git a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-postgresql.sql b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-postgresql.sql index c255a3dd82..35c6f19e25 100644 --- a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-postgresql.sql +++ b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/store/channel/schema-postgresql.sql @@ -13,5 +13,3 @@ CREATE TABLE INT_CHANNEL_MESSAGE ( CREATE INDEX INT_CHANNEL_MSG_DATE_IDX ON INT_CHANNEL_MESSAGE USING btree (CREATED_DATE, MESSAGE_SEQUENCE); CREATE INDEX INT_CHANNEL_MSG_PRIORITY_IDX ON INT_CHANNEL_MESSAGE USING btree (MESSAGE_PRIORITY DESC, CREATED_DATE, MESSAGE_SEQUENCE); - - diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DataSource-h2-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DataSource-h2-context.xml new file mode 100644 index 0000000000..05a29239be --- /dev/null +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DataSource-h2-context.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2JdbcChannelMessageStoreTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2JdbcChannelMessageStoreTests-context.xml new file mode 100644 index 0000000000..e47f85d05f --- /dev/null +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2JdbcChannelMessageStoreTests-context.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2JdbcChannelMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2JdbcChannelMessageStoreTests.java new file mode 100644 index 0000000000..c71cfc2345 --- /dev/null +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2JdbcChannelMessageStoreTests.java @@ -0,0 +1,26 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.jdbc.store.channel; + +/** + * @author Gunnar Hillert + * @author Manuel Jordan + * @since 4.3 + */ +public class H2JdbcChannelMessageStoreTests extends AbstractJdbcChannelMessageStoreTests { + +} diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests-context.xml new file mode 100644 index 0000000000..d644c3c3e7 --- /dev/null +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests-context.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests.java new file mode 100644 index 0000000000..eb34757f4f --- /dev/null +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.jdbc.store.channel; + +import org.junit.Rule; + +import org.springframework.integration.test.support.LongRunningIntegrationTest; + +/** + * + * @author Gunnar Hillert + * @author Artem Bilan + * @author Manuel Jordan + * @since 4.3 + */ +public class H2TxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests { + + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + +} diff --git a/src/reference/asciidoc/jdbc.adoc b/src/reference/asciidoc/jdbc.adoc index 6df71a4e84..6519cdb638 100644 --- a/src/reference/asciidoc/jdbc.adoc +++ b/src/reference/asciidoc/jdbc.adoc @@ -358,7 +358,7 @@ This `channelMessageStoreQueryProvider` provides the SQL queries and Spring Inte * MySQL * Oracle * Derby - +* H2 If your database is not listed, you can easily extend the `AbstractChannelMessageStoreQueryProvider` class and provide your own custom queries. diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index baf9e88b5d..efd765e11f 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -260,3 +260,8 @@ See <> for more information. The `WireTap` `ChannelInterceptor` now can accept a `channelName` which is resolved to the target `MessageChannel` later, during the first active interceptor operation. See <> for more information. + +==== ChannelMessageStoreQueryProvider + +The `ChannelMessageStoreQueryProvider` now supports H2 database. +See <> for more information.