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    *     https://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.commons.configuration2.builder;
18  
19  import javax.sql.DataSource;
20  
21  /**
22   * <p>
23   * A specialized parameters object for database configurations.
24   * </p>
25   * <p>
26   * This class has properties for defining the database structures the configuration operates on.
27   * </p>
28   * <p>
29   * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
30   * during configuration of a {@code ConfigurationBuilder}.
31   * </p>
32   *
33   * @since 2.0
34   */
35  public class DatabaseBuilderParametersImpl extends BasicBuilderParameters implements DatabaseBuilderProperties<DatabaseBuilderParametersImpl> {
36  
37      /** Constant for the data source property. */
38      private static final String PROP_DATA_SOURCE = "dataSource";
39  
40      /** Constant for the table property. */
41      private static final String PROP_TABLE = "table";
42  
43      /** Constant for the key column property. */
44      private static final String PROP_KEY_COLUMN = "keyColumn";
45  
46      /** Constant for the value column property. */
47      private static final String PROP_VALUE_COLUMN = "valueColumn";
48  
49      /** Constant for the configuration name column property. */
50      private static final String PROP_CONFIG_NAME_COLUMN = "configurationNameColumn";
51  
52      /** Constant for the configuration name property. */
53      private static final String PROP_CONFIG_NAME = "configurationName";
54  
55      /** Constant for the auto commit property. */
56      private static final String PROP_AUTO_COMMIT = "autoCommit";
57  
58      /**
59       * Constructs a new instance.
60       */
61      public DatabaseBuilderParametersImpl() {
62          // empty
63      }
64  
65      @Override
66      public DatabaseBuilderParametersImpl setAutoCommit(final boolean f) {
67          storeProperty(PROP_AUTO_COMMIT, Boolean.valueOf(f));
68          return this;
69      }
70  
71      @Override
72      public DatabaseBuilderParametersImpl setConfigurationName(final String name) {
73          storeProperty(PROP_CONFIG_NAME, name);
74          return this;
75      }
76  
77      @Override
78      public DatabaseBuilderParametersImpl setConfigurationNameColumn(final String name) {
79          storeProperty(PROP_CONFIG_NAME_COLUMN, name);
80          return this;
81      }
82  
83      @Override
84      public DatabaseBuilderParametersImpl setDataSource(final DataSource src) {
85          storeProperty(PROP_DATA_SOURCE, src);
86          return this;
87      }
88  
89      @Override
90      public DatabaseBuilderParametersImpl setKeyColumn(final String name) {
91          storeProperty(PROP_KEY_COLUMN, name);
92          return this;
93      }
94  
95      @Override
96      public DatabaseBuilderParametersImpl setTable(final String tableName) {
97          storeProperty(PROP_TABLE, tableName);
98          return this;
99      }
100 
101     @Override
102     public DatabaseBuilderParametersImpl setValueColumn(final String name) {
103         storeProperty(PROP_VALUE_COLUMN, name);
104         return this;
105     }
106 }