From 0920024e3b0ccae42e180e5d432714f013fd4eb3 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Mon, 24 Jun 2013 15:37:57 +0000 Subject: QPID-4837 : [Java Broker] add ability to use connection pool for JDBC store git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1496099 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/bonecp/BoneCPConnectionProvider.java | 59 ++++++++++++++++++++++ .../bonecp/BoneCPConnectionProviderFactory.java | 42 +++++++++++++++ ...pid.server.plugin.JDBCConnectionProviderFactory | 19 +++++++ 3 files changed, 120 insertions(+) create mode 100644 qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java create mode 100644 qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java create mode 100644 qpid/java/broker-plugins/jdbc-provider-bone/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.JDBCConnectionProviderFactory (limited to 'qpid/java/broker-plugins') diff --git a/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java new file mode 100644 index 0000000000..7545b84611 --- /dev/null +++ b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java @@ -0,0 +1,59 @@ +/* + * + * 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.qpid.server.store.jdbc.bonecp; + +import com.jolbox.bonecp.BoneCP; +import com.jolbox.bonecp.BoneCPConfig; +import java.sql.Connection; +import java.sql.SQLException; +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.store.jdbc.ConnectionProvider; + +public class BoneCPConnectionProvider implements ConnectionProvider +{ + public static final int DEFAULT_MIN_CONNECTIONS_PER_PARTITION = 5; + public static final int DEFAULT_MAX_CONNECTIONS_PER_PARTITION = 10; + public static final int DEFAULT_PARTITION_COUNT = 4; + private final BoneCP _connectionPool; + + public BoneCPConnectionProvider(String connectionUrl, Configuration storeConfiguration) throws SQLException + { + BoneCPConfig config = new BoneCPConfig(); + config.setJdbcUrl(connectionUrl); + + config.setMinConnectionsPerPartition(storeConfiguration.getInteger("minConnectionsPerPartition", DEFAULT_MIN_CONNECTIONS_PER_PARTITION)); + config.setMaxConnectionsPerPartition(storeConfiguration.getInteger("maxConnectionsPerPartition", DEFAULT_MAX_CONNECTIONS_PER_PARTITION)); + config.setPartitionCount(storeConfiguration.getInteger("partitionCount",DEFAULT_PARTITION_COUNT)); + _connectionPool = new BoneCP(config); + } + + @Override + public Connection getConnection() throws SQLException + { + return _connectionPool.getConnection(); + } + + @Override + public void close() throws SQLException + { + _connectionPool.shutdown(); + } +} diff --git a/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java new file mode 100644 index 0000000000..71c59c7772 --- /dev/null +++ b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java @@ -0,0 +1,42 @@ +/* + * + * 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.qpid.server.store.jdbc.bonecp; + +import java.sql.SQLException; +import org.apache.commons.configuration.Configuration; +import org.apache.qpid.server.plugin.JDBCConnectionProviderFactory; +import org.apache.qpid.server.store.jdbc.ConnectionProvider; + +public class BoneCPConnectionProviderFactory implements JDBCConnectionProviderFactory +{ + @Override + public String getType() + { + return "BONECP"; + } + + @Override + public ConnectionProvider getConnectionProvider(String connectionUrl, Configuration storeConfiguration) + throws SQLException + { + return new BoneCPConnectionProvider(connectionUrl, storeConfiguration); + } +} diff --git a/qpid/java/broker-plugins/jdbc-provider-bone/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.JDBCConnectionProviderFactory b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.JDBCConnectionProviderFactory new file mode 100644 index 0000000000..70157b44c3 --- /dev/null +++ b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.JDBCConnectionProviderFactory @@ -0,0 +1,19 @@ +# +# 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. +# +org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory -- cgit v1.2.1