Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.activemq.store.jdbc.adapter;

import org.apache.activemq.store.jdbc.Statements;

/**
*
* @org.apache.xbean.XBean element="h2-jdbc-adapter"
*/
public class H2JDBCAdapter extends BytesJDBCAdapter {

@Override
public void setStatements(Statements statements) {
statements.setBinaryDataType("BLOB");
super.setStatements(statements);
}

@Override
public String limitQuery(String query) {
return query + " LIMIT " + getMaxRows();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You 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.
## ---------------------------------------------------------------------------
class=org.apache.activemq.store.jdbc.adapter.H2JDBCAdapter
6 changes: 6 additions & 0 deletions activemq-unit-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,29 @@
import org.apache.activemq.broker.BrokerTest;
import org.apache.derby.jdbc.EmbeddedDataSource;

import javax.sql.DataSource;

public class JDBCStoreBrokerTest extends BrokerTest {

protected void configureJDBCPersistenceAdapter(JDBCPersistenceAdapter jdbc, final String name) throws Exception {

}

@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = new BrokerService();
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
var jdbc = new JDBCPersistenceAdapter();
configureJDBCPersistenceAdapter(jdbc, "JDBCStoreBrokerTest");
jdbc.deleteAllMessages();
broker.setPersistenceAdapter(jdbc);
return broker;
}

protected BrokerService x_createRestartedBroker() throws Exception {
BrokerService broker = new BrokerService();
broker.setPersistenceAdapter(new JDBCPersistenceAdapter());
var jdbc = new JDBCPersistenceAdapter();
configureJDBCPersistenceAdapter(jdbc, "JDBCStoreBrokerTest");
broker.setPersistenceAdapter(jdbc);
return broker;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.activemq.store.jdbc.h2;

import javax.sql.DataSource;
import org.h2.jdbcx.JdbcDataSource;

import java.io.IOException;

public class H2DB {

public static DataSource createDataSource(String db) throws IOException {
var ds = new JdbcDataSource();
ds.setURL(createURL(db));
ds.setUser(getUser());
ds.setPassword(getPassword());
return ds;
}

public static String createURL(String db) {
return "jdbc:h2:./target/h2-db/" + db + "/" + db + "-h2.db;DB_CLOSE_DELAY=-1";
}

public static String getUser() {
return "sa";
}

public static String getPassword() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.activemq.store.jdbc.h2;

import junit.framework.Test;
import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
import org.apache.activemq.store.jdbc.JDBCStoreBrokerTest;
import org.apache.activemq.store.jdbc.adapter.H2JDBCAdapter;

import javax.sql.DataSource;

public class H2JDBCStoreBrokerTest extends JDBCStoreBrokerTest {

@Override
protected void configureJDBCPersistenceAdapter(final JDBCPersistenceAdapter jdbc, String dbname) throws Exception {
jdbc.setDataSource(H2DB.createDataSource("H2JDBCStoreBrokerTest"));
jdbc.setAdapter(new H2JDBCAdapter());
}

public static Test suite() {
return suite(H2JDBCStoreBrokerTest.class);
}
}
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<jmock-version>2.13.1</jmock-version>
<jolokia-version>2.4.3</jolokia-version>
<junit-version>4.13.2</junit-version>
<h2-version>2.4.240</h2-version>
<hamcrest-version>1.3</hamcrest-version>
<karaf-version>4.3.7</karaf-version>
<log4j-version>2.25.3</log4j-version>
Expand Down Expand Up @@ -766,6 +767,12 @@
<version>${org-apache-derby-version}</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2-version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
Expand Down