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 *     https://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.commons.configuration2.builder;
018
019import javax.sql.DataSource;
020
021/**
022 * <p>
023 * A specialized parameters object for database configurations.
024 * </p>
025 * <p>
026 * This class has properties for defining the database structures the configuration operates on.
027 * </p>
028 * <p>
029 * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
030 * during configuration of a {@code ConfigurationBuilder}.
031 * </p>
032 *
033 * @since 2.0
034 */
035public class DatabaseBuilderParametersImpl extends BasicBuilderParameters implements DatabaseBuilderProperties<DatabaseBuilderParametersImpl> {
036    /** Constant for the data source property. */
037    private static final String PROP_DATA_SOURCE = "dataSource";
038
039    /** Constant for the table property. */
040    private static final String PROP_TABLE = "table";
041
042    /** Constant for the key column property. */
043    private static final String PROP_KEY_COLUMN = "keyColumn";
044
045    /** Constant for the value column property. */
046    private static final String PROP_VALUE_COLUMN = "valueColumn";
047
048    /** Constant for the configuration name column property. */
049    private static final String PROP_CONFIG_NAME_COLUMN = "configurationNameColumn";
050
051    /** Constant for the configuration name property. */
052    private static final String PROP_CONFIG_NAME = "configurationName";
053
054    /** Constant for the auto commit property. */
055    private static final String PROP_AUTO_COMMIT = "autoCommit";
056
057    /**
058     * Constructs a new instance.
059     */
060    public DatabaseBuilderParametersImpl() {
061        // empty
062    }
063
064    @Override
065    public DatabaseBuilderParametersImpl setAutoCommit(final boolean f) {
066        storeProperty(PROP_AUTO_COMMIT, Boolean.valueOf(f));
067        return this;
068    }
069
070    @Override
071    public DatabaseBuilderParametersImpl setConfigurationName(final String name) {
072        storeProperty(PROP_CONFIG_NAME, name);
073        return this;
074    }
075
076    @Override
077    public DatabaseBuilderParametersImpl setConfigurationNameColumn(final String name) {
078        storeProperty(PROP_CONFIG_NAME_COLUMN, name);
079        return this;
080    }
081
082    @Override
083    public DatabaseBuilderParametersImpl setDataSource(final DataSource src) {
084        storeProperty(PROP_DATA_SOURCE, src);
085        return this;
086    }
087
088    @Override
089    public DatabaseBuilderParametersImpl setKeyColumn(final String name) {
090        storeProperty(PROP_KEY_COLUMN, name);
091        return this;
092    }
093
094    @Override
095    public DatabaseBuilderParametersImpl setTable(final String tableName) {
096        storeProperty(PROP_TABLE, tableName);
097        return this;
098    }
099
100    @Override
101    public DatabaseBuilderParametersImpl setValueColumn(final String name) {
102        storeProperty(PROP_VALUE_COLUMN, name);
103        return this;
104    }
105}