001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.appender.db.jdbc;
018
019import java.sql.DriverManager;
020
021import org.apache.logging.log4j.core.Core;
022import org.apache.logging.log4j.core.config.Property;
023import org.apache.logging.log4j.core.config.plugins.Plugin;
024import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
025
026/**
027 * A {@link ConnectionSource} that uses a JDBC connection string, a user name, and a password to call
028 * {@link DriverManager#getConnection(String, String, String)}.
029 * <p>
030 * This plugin does not provide any connection pooling unless it is available through the connection string and driver
031 * itself. This handy to get you off the ground without having to deal with JNDI.
032 * </p>
033 */
034@Plugin(name = "DriverManager", category = Core.CATEGORY_NAME, elementType = "connectionSource", printObject = true)
035public class DriverManagerConnectionSource extends AbstractDriverManagerConnectionSource {
036
037    /**
038     * Builds DriverManagerConnectionSource instances.
039     *
040     * @param <B>
041     *            This builder type or a subclass.
042     */
043    public static class Builder<B extends Builder<B>> extends AbstractDriverManagerConnectionSource.Builder<B>
044            implements org.apache.logging.log4j.core.util.Builder<DriverManagerConnectionSource> {
045
046        @Override
047        public DriverManagerConnectionSource build() {
048            return new DriverManagerConnectionSource(getDriverClassName(), getConnectionString(), getConnectionString(),
049                    getUserName(), getPassword(), getProperties());
050        }
051
052    }
053
054    @PluginBuilderFactory
055    public static <B extends Builder<B>> B newBuilder() {
056        return new Builder<B>().asBuilder();
057    }
058
059    public DriverManagerConnectionSource(final String driverClassName, final String connectionString,
060            final String actualConnectionString, final char[] userName, final char[] password, final Property[] properties) {
061        super(driverClassName, connectionString, actualConnectionString, userName, password, properties);
062    }
063
064}