Repository: logging-log4j2
Updated Branches:
  refs/heads/master bb6fcd09e -> 639f093b8


[LOG4J2-2186] Add a JDBC ConnectionSource that provides pooling through
Apache Commons DBCP 2.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/639f093b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/639f093b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/639f093b

Branch: refs/heads/master
Commit: 639f093b8103df2c2eda8d62fd12d7619d98ac04
Parents: bb6fcd0
Author: Gary Gregory <[email protected]>
Authored: Thu Jan 18 20:54:47 2018 -0700
Committer: Gary Gregory <[email protected]>
Committed: Thu Jan 18 20:54:47 2018 -0700

----------------------------------------------------------------------
 log4j-jdbc-dbcp2/pom.xml                        | 170 +++++++++++++++++++
 .../db/jdbc/PoolingDriverConnectionSource.java  | 155 +++++++++++++++++
 log4j-jdbc-dbcp2/src/site/manual/index.md       |  35 ++++
 log4j-jdbc-dbcp2/src/site/site.xml              |  52 ++++++
 .../jdbc/PoolingDriverConnectionSourceTest.java |  96 +++++++++++
 pom.xml                                         |   1 +
 src/changes/changes.xml                         |   3 +
 src/site/xdoc/manual/appenders.xml              |  28 ++-
 8 files changed, 537 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/log4j-jdbc-dbcp2/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-jdbc-dbcp2/pom.xml b/log4j-jdbc-dbcp2/pom.xml
new file mode 100644
index 0000000..18e0e86
--- /dev/null
+++ b/log4j-jdbc-dbcp2/pom.xml
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ 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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <parent>
+    <groupId>org.apache.logging.log4j</groupId>
+    <artifactId>log4j</artifactId>
+    <version>2.10.1-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>log4j-jdbc-dbcp2</artifactId>
+  <name>Apache Log4j JDBC DBCP 2</name>
+  <description>
+    Connection source for the JDBC Appender using on Apache Commons DBCP 2.
+  </description>
+  <properties>
+    <log4jParentDir>${basedir}/..</log4jParentDir>
+    <docLabel>Log4j JDBC DBCP 2 Documentation</docLabel>
+    <projectDir>/log4j-jdbc-dbcp2</projectDir>
+    <module.name>org.apache.logging.log4j.jdbc.dbcp2</module.name>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-dbcp2</artifactId>
+      <version>2.2.0</version>
+    </dependency>
+    <!-- Test Dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>com.h2database</groupId>
+      <artifactId>h2</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            
<Fragment-Host>org.apache.logging.log4j.core.appender.db.jdbc</Fragment-Host>
+            <Export-Package>*</Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <version>${changes.plugin.version}</version>
+        <reportSets>
+          <reportSet>
+            <reports>
+              <report>changes-report</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+        <configuration>
+          <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate>
+          <useJql>true</useJql>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>${checkstyle.plugin.version}</version>
+        <configuration>
+          
<!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation>
 -->
+          <configLocation>${log4jParentDir}/checkstyle.xml</configLocation>
+          
<suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation>
+          <enableRulesSummary>false</enableRulesSummary>
+          <propertyExpansion>basedir=${basedir}</propertyExpansion>
+          
<propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>${javadoc.plugin.version}</version>
+        <configuration>
+          <bottom><![CDATA[<p align="center">Copyright &#169; 
{inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br />
+            Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather 
logo, the Apache Logging project logo,
+            and the Apache Log4j logo are trademarks of The Apache Software 
Foundation.</p>]]></bottom>
+          <!-- module link generation is completely broken in the javadoc 
plugin for a multi-module non-aggregating project -->
+          <detectOfflineLinks>false</detectOfflineLinks>
+          <linksource>true</linksource>
+        </configuration>
+        <reportSets>
+          <reportSet>
+            <id>non-aggregate</id>
+            <reports>
+              <report>javadoc</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>findbugs-maven-plugin</artifactId>
+        <version>${findbugs.plugin.version}</version>
+        <configuration>
+          <fork>true</fork>
+          <jvmArgs>-Duser.language=en</jvmArgs>
+          <threshold>Normal</threshold>
+          <effort>Default</effort>
+          
<excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jxr-plugin</artifactId>
+        <version>${jxr.plugin.version}</version>
+        <reportSets>
+          <reportSet>
+            <id>non-aggregate</id>
+            <reports>
+              <report>jxr</report>
+            </reports>
+          </reportSet>
+          <reportSet>
+            <id>aggregate</id>
+            <reports>
+              <report>aggregate</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <version>${pmd.plugin.version}</version>
+        <configuration>
+          <targetJdk>${maven.compiler.target}</targetJdk>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSource.java
----------------------------------------------------------------------
diff --git 
a/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSource.java
 
b/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSource.java
new file mode 100644
index 0000000..80adbb3
--- /dev/null
+++ 
b/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSource.java
@@ -0,0 +1,155 @@
+/*
+ * 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.logging.log4j.core.appender.db.jdbc;
+
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.commons.dbcp2.ConnectionFactory;
+import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp2.PoolableConnection;
+import org.apache.commons.dbcp2.PoolableConnectionFactory;
+import org.apache.commons.dbcp2.PoolingDriver;
+import org.apache.commons.pool2.ObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.logging.log4j.core.Core;
+import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+
+/**
+ * A {@link ConnectionSource} that uses a JDBC connection string, a user name, 
and a password to call
+ * {@link DriverManager#getConnection(String, String, String)}. The 
connections are served from an
+ * <a href="http://commons.apache.org/proper/commons-dbcp/";>Apache Commons 
DBCP</a> pooling driver.
+ */
+@Plugin(name = "PoolingDriver", category = Core.CATEGORY_NAME, elementType = 
"connectionSource", printObject = true)
+public final class PoolingDriverConnectionSource extends 
DriverManagerConnectionSource {
+
+    /**
+     * Builds PoolingDriverConnectionSource instances.
+     *
+     * @param <B>
+     *            This builder type or a subclass.
+     */
+    public static class Builder<B extends Builder<B>>
+            extends DriverManagerConnectionSource.Builder<B, 
PoolingDriverConnectionSource> {
+
+        public static final String DEFAULT_POOL_NAME = "example";
+        private String poolName = DEFAULT_POOL_NAME;
+
+        @Override
+        public PoolingDriverConnectionSource build() {
+            try {
+                return new PoolingDriverConnectionSource(getDriverClassName(), 
getConnectionString(), getUserName(),
+                        getPassword(), getProperties(), poolName);
+            } catch (final SQLException e) {
+                getLogger().error("Exception constructing {} for {}", 
PoolingDriverConnectionSource.class,
+                        getConnectionString(), e);
+                return null;
+            }
+        }
+
+        public B setPoolName(final String poolName) {
+            this.poolName = poolName;
+            return asBuilder();
+        }
+    }
+
+    public static final String URL_PREFIX = "jdbc:apache:commons:dbcp:";
+
+    // This method is not named newBuilder() to make the compiler happy.
+    @PluginBuilderFactory
+    public static <B extends Builder<B>> B 
newPoolingDriverConnectionSourceBuilder() {
+        return new Builder<B>().asBuilder();
+    }
+
+    private final String poolingDriverClassName = 
"org.apache.commons.dbcp2.PoolingDriver";
+
+    private final String poolName;
+
+    public PoolingDriverConnectionSource(final String driverClassName, final 
String connectionString,
+            final char[] userName, final char[] password, final Property[] 
properties, final String poolName)
+            throws SQLException {
+        super(driverClassName, connectionString, URL_PREFIX + poolName, 
userName, password, properties);
+        this.poolName = poolName;
+        setupDriver(connectionString);
+    }
+
+    @Override
+    public String getActualConnectionString() {
+        // TODO Auto-generated method stub
+        return super.getActualConnectionString();
+    }
+
+    private PoolingDriver getPoolingDriver() throws SQLException {
+        final PoolingDriver driver = (PoolingDriver) 
DriverManager.getDriver(URL_PREFIX);
+        if (driver == null) {
+            getLogger().error("No JDBC driver for {}", URL_PREFIX);
+        }
+        return driver;
+    }
+
+    private void setupDriver(final String connectionString) throws 
SQLException {
+        //
+        // First, we'll create a ConnectionFactory that the
+        // pool will use to create Connections.
+        // We'll use the DriverManagerConnectionFactory,
+        // using the connect string passed in the command line
+        // arguments.
+        //
+        final ConnectionFactory connectionFactory = new 
DriverManagerConnectionFactory(connectionString, null);
+
+        //
+        // Next, we'll create the PoolableConnectionFactory, which wraps
+        // the "real" Connections created by the ConnectionFactory with
+        // the classes that implement the pooling functionality.
+        //
+        final PoolableConnectionFactory poolableConnectionFactory = new 
PoolableConnectionFactory(connectionFactory,
+                null);
+
+        //
+        // Now we'll need a ObjectPool that serves as the
+        // actual pool of connections.
+        //
+        // We'll use a GenericObjectPool instance, although
+        // any ObjectPool implementation will suffice.
+        //
+        @SuppressWarnings("resource")
+        // This GenericObjectPool will be closed on shutown
+        final ObjectPool<PoolableConnection> connectionPool = new 
GenericObjectPool<>(poolableConnectionFactory);
+
+        // Set the factory's pool property to the owning pool
+        poolableConnectionFactory.setPool(connectionPool);
+
+        loadDriver(poolingDriverClassName);
+        final PoolingDriver driver = getPoolingDriver();
+        if (driver != null) {
+            driver.registerPool(poolName, connectionPool);
+        }
+        //
+        // Now we can just use the connect string 
"jdbc:apache:commons:dbcp:example"
+        // to access our pool of Connections.
+        //
+    }
+
+    public void shutdownDriver() throws SQLException {
+        final PoolingDriver driver = getPoolingDriver();
+        if (driver != null) {
+            driver.closePool(poolName);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/log4j-jdbc-dbcp2/src/site/manual/index.md
----------------------------------------------------------------------
diff --git a/log4j-jdbc-dbcp2/src/site/manual/index.md 
b/log4j-jdbc-dbcp2/src/site/manual/index.md
new file mode 100644
index 0000000..b7fb5a5
--- /dev/null
+++ b/log4j-jdbc-dbcp2/src/site/manual/index.md
@@ -0,0 +1,35 @@
+<!-- vim: set syn=markdown : -->
+<!--
+    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.
+-->
+
+# Log4j 2 JDBC Connection Source with Apache Commons DBCP 2
+
+This module adds a connection source for JDBC Appenders. The 
PoolingDriverConnectionSource 
+provides connection pooling through Apache Commons DBCP 2. 
+
+## Requirements
+
+This module was introduced in Log4j 2.11.0 and requires Apache Commons DBCP 2 
to provide
+connection pooling.
+
+Some features may require optional
+[dependencies](../runtime-dependencies.html). These dependencies are specified 
in the
+documentation for those features.
+
+Some Log4j features require external dependencies.
+See the [Dependency Tree](dependencies.html#Dependency_Tree)
+for the exact list of JAR files needed for these features.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/log4j-jdbc-dbcp2/src/site/site.xml
----------------------------------------------------------------------
diff --git a/log4j-jdbc-dbcp2/src/site/site.xml 
b/log4j-jdbc-dbcp2/src/site/site.xml
new file mode 100644
index 0000000..6d4cddc
--- /dev/null
+++ b/log4j-jdbc-dbcp2/src/site/site.xml
@@ -0,0 +1,52 @@
+<!--
+ 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.
+
+-->
+<project name="Log4j Core"
+         xmlns="http://maven.apache.org/DECORATION/1.4.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 
http://maven.apache.org/xsd/decoration-1.4.0.xsd";>
+  <body>
+    <links>
+      <item name="Apache" href="http://www.apache.org/"; />
+      <item name="Logging Services" href="http://logging.apache.org/"/>
+      <item name="Log4j" href="../index.html"/>
+    </links>
+
+    <!-- Component-specific reports -->
+    <menu ref="reports"/>
+
+       <!-- Overall Project Info -->
+    <menu name="Log4j Project Information" img="icon-info-sign">
+      <item name="Dependencies" href="../dependencies.html" />
+      <item name="Dependency Convergence" 
href="../dependency-convergence.html" />
+      <item name="Dependency Management" href="../dependency-management.html" 
/>
+      <item name="Project Team" href="../team-list.html" />
+      <item name="Mailing Lists" href="../mail-lists.html" />
+      <item name="Issue Tracking" href="../issue-tracking.html" />
+      <item name="Project License" href="../license.html" />
+      <item name="Source Repository" href="../source-repository.html" />
+      <item name="Project Summary" href="../project-summary.html" />
+    </menu>
+
+    <menu name="Log4j Project Reports" img="icon-cog">
+      <item name="Changes Report" href="../changes-report.html" />
+      <item name="JIRA Report" href="../jira-report.html" />
+      <item name="Surefire Report" href="../surefire-report.html" />
+      <item name="RAT Report" href="../rat-report.html" />
+    </menu>
+  </body>
+</project>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSourceTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSourceTest.java
 
b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSourceTest.java
new file mode 100644
index 0000000..2b7b886
--- /dev/null
+++ 
b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/PoolingDriverConnectionSourceTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.logging.log4j.core.appender.db.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.logging.log4j.core.config.Property;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PoolingDriverConnectionSourceTest {
+
+    @Test
+    public void testH2Properties() throws SQLException {
+        final Property[] properties = new Property[] {
+                // @formatter:off
+                Property.createProperty("username", 
JdbcH2TestHelper.USER_NAME),
+                Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
+                // @formatter:on
+        };
+        // @formatter:off
+        final PoolingDriverConnectionSource source = 
PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+            .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+            .setProperties(properties)
+            .build();
+        // @formatter:on
+        try (Connection conn = source.getConnection()) {
+            Assert.assertFalse(conn.isClosed());
+        }
+    }
+
+    @Test
+    public void testH2PropertiesAndPoolName() throws SQLException {
+        final Property[] properties = new Property[] {
+                // @formatter:off
+                Property.createProperty("username", 
JdbcH2TestHelper.USER_NAME),
+                Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
+                // @formatter:on
+        };
+        // @formatter:off
+        final PoolingDriverConnectionSource source = 
PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+            .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+            .setProperties(properties)
+            .setPoolName("MyPoolName")
+            .build();
+        // @formatter:on
+        try (Connection conn = source.getConnection()) {
+            Assert.assertFalse(conn.isClosed());
+        }
+    }
+
+    @Test
+    public void testH2UserAndPassword() throws SQLException {
+        // @formatter:off
+        final PoolingDriverConnectionSource source = 
PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+            .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+            .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
+            .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
+            .build();
+        // @formatter:on
+        try (Connection conn = source.getConnection()) {
+            Assert.assertFalse(conn.isClosed());
+        }
+    }
+
+    @Test
+    public void testH2UserPasswordAndPoolName() throws SQLException {
+        // @formatter:off
+        final PoolingDriverConnectionSource source = 
PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+            .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+            .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
+            .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
+            .setPoolName("MyPoolName")
+            .build();
+        // @formatter:on
+        try (Connection conn = source.getConnection()) {
+            Assert.assertFalse(conn.isClosed());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 31195f2..f1027f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1320,6 +1320,7 @@
     <module>log4j-jmx-gui</module>
     <module>log4j-samples</module>
     <module>log4j-bom</module>
+    <module>log4j-jdbc-dbcp2</module>
     <module>log4j-couchdb</module>
     <module>log4j-mongodb</module>
     <module>log4j-cassandra</module>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3ca94e4..6398bb0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -104,6 +104,9 @@
       <action issue="LOG4J2-2198" dev="ggregory" type="update">
         Update MongoDB dependencies from classic to modern.
       </action>
+      <action issue="LOG4J2-2186" dev="ggregory" type="add">
+        Add a JDBC ConnectionSource that provides pooling through Apache 
Commons DBCP 2.
+      </action>
     </release>
     <release version="2.10.0" date="2017-11-18" description="GA Release 
2.10.0">
       <action issue="LOG4J2-2120" dev="mikes" type="add" due-to="Carter 
Douglas Kozak ">

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/639f093b/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml 
b/src/site/xdoc/manual/appenders.xml
index c62a284..4f106df 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -1070,9 +1070,10 @@ CREATE TABLE logs (
           <p>When configuring the JDBCAppender, you must specify a 
<code>ConnectionSource</code> implementation from
             which the Appender gets JDBC connections. You must use exactly one 
of the following nested elements:</p>
           <ul>
-            <li><a 
href="#JDBCDataSource"><code>&lt;DataSource&gt;</code></a></li>
-            <li><a 
href="#JDBCConnectionFactory"><code>&lt;ConnectionFactory&gt;</code></a></li>
-            <li><a 
href="#JDBCDriverManager"><code>&lt;DriverManager&gt;</code></a></li>
+            <li><a href="#JDBCDataSource"><code>&lt;DataSource&gt;</code></a>: 
Uses JNDI.</li>
+            <li><a 
href="#JDBCConnectionFactory"><code>&lt;ConnectionFactory&gt;</code></a>: 
Points to a class-method pair to provide JDBC connections.</li>
+            <li><a 
href="#JDBCDriverManager"><code>&lt;DriverManager&gt;</code></a>: A quick and 
dirty way to get off the ground, no connection pooling.</li>
+            <li><a 
href="#JDBCPoolingDriver"><code>&lt;PoolingDriver&gt;</code></a>: Uses Apache 
Commons DBCP to provide connection pooling.</li>
           </ul>
           <a name="JDBCDataSource"/>
           <table>
@@ -1149,6 +1150,27 @@ CREATE TABLE logs (
               <td>A list of properties. You cannot specify both properties and 
a user name or password.</td>
             </tr>
           </table>
+          <a name="JDBCPoolingDriver"/>
+          <table>
+            <caption align="top">PoolingDriver Parameters (Apache Commons 
DBCP)</caption>
+            <tr>
+              <th>Parameter Name</th>
+              <th>Type</th>
+              <th>Description</th>
+            </tr>
+            <tr>
+              <td>DriverManager parameters</td>
+              <td>DriverManager parameters</td>
+              <td>This connection source inherits all parameter from the 
DriverManager connection source.</td>
+            </tr>
+            <tr>
+              <td>poolName</td>
+              <td>String</td>
+              <td>The pool name used to pool JDBC Connections. Defaults to 
<code>example</code>. You can use the JDBC 
+              connection string prefix <code>jdbc:apache:commons:dbcp:</code> 
followed by the pool name if you want 
+              to use a pooled connection elsewhere. For example: 
<code>jdbc:apache:commons:dbcp:example</code>.</td>
+            </tr>
+          </table>
           <p>When configuring the JDBCAppender, use the nested 
<code>&lt;Column&gt;</code> elements to specify which
             columns in the table should be written to and how to write to 
them. The JDBCAppender uses this information
             to formulate a <code>PreparedStatement</code> to insert records 
without SQL injection vulnerability.</p>

Reply via email to