View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.core.appender.db.jdbc;
18  
19  import java.sql.DriverManager;
20  
21  import org.apache.logging.log4j.core.Core;
22  import org.apache.logging.log4j.core.config.Property;
23  import org.apache.logging.log4j.core.config.plugins.Plugin;
24  import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
25  
26  /**
27   * A {@link ConnectionSource} that uses a JDBC connection string, a user name, and a password to call
28   * {@link DriverManager#getConnection(String, String, String)}.
29   * <p>
30   * This plugin does not provide any connection pooling unless it is available through the connection string and driver
31   * itself. This handy to get you off the ground without having to deal with JNDI.
32   * </p>
33   */
34  @Plugin(name = "DriverManager", category = Core.CATEGORY_NAME, elementType = "connectionSource", printObject = true)
35  public class DriverManagerConnectionSource extends AbstractDriverManagerConnectionSource {
36  
37      /**
38       * Builds DriverManagerConnectionSource instances.
39       *
40       * @param <B>
41       *            This builder type or a subclass.
42       */
43      public static class Builder<B extends Builder<B>> extends AbstractDriverManagerConnectionSource.Builder<B>
44              implements org.apache.logging.log4j.core.util.Builder<DriverManagerConnectionSource> {
45  
46          @Override
47          public DriverManagerConnectionSource build() {
48              return new DriverManagerConnectionSource(getDriverClassName(), getConnectionString(), getConnectionString(),
49                      getUserName(), getPassword(), getProperties());
50          }
51  
52      }
53  
54      @PluginBuilderFactory
55      public static <B extends Builder<B>> B newBuilder() {
56          return new Builder<B>().asBuilder();
57      }
58  
59      public DriverManagerConnectionSource(final String driverClassName, final String connectionString,
60              final String actualConnectionString, final char[] userName, final char[] password, final Property[] properties) {
61          super(driverClassName, connectionString, actualConnectionString, userName, password, properties);
62      }
63  
64  }