View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.spi.config.ds;
17  
18  import de.smartics.util.lang.Arg;
19  
20  /**
21   * Helper to create database configurations with a data source.
22   */
23  public abstract class AbstractDataSourceDescriptor implements
24      PropertiesDataSourceDescriptor
25  {
26    // ********************************* Fields *********************************
27  
28    // --- constants ------------------------------------------------------------
29  
30    /**
31     * The class version identifier.
32     */
33    private static final long serialVersionUID = 1L;
34  
35    // --- members --------------------------------------------------------------
36  
37    /**
38     * The name of the configuration table.
39     */
40    private final String table;
41  
42    /**
43     * The name of the configuration key column.
44     */
45    private final String configColumn;
46  
47    /**
48     * The name of the property name column.
49     */
50    private final String nameColumn;
51  
52    /**
53     * The name of the property value column.
54     */
55    private final String valueColumn;
56  
57    // ****************************** Initializer *******************************
58  
59    // ****************************** Constructors ******************************
60  
61    /**
62     * Default constructor.
63     *
64     * @param builder the builder of descriptor instances.
65     */
66    protected AbstractDataSourceDescriptor(final Builder builder)
67    {
68      this.table = builder.table;
69      this.configColumn = builder.configColumn;
70      this.nameColumn = builder.nameColumn;
71      this.valueColumn = builder.valueColumn;
72    }
73  
74    // ****************************** Inner Classes *****************************
75  
76    /**
77     * The builder of descriptor instances.
78     */
79    public static class Builder
80    {
81      // ******************************** Fields ********************************
82  
83      // --- constants ----------------------------------------------------------
84  
85      // --- members ------------------------------------------------------------
86  
87      /**
88       * The name of the configuration table.
89       */
90      private String table = "config";
91  
92      /**
93       * The name of the configuration key column.
94       */
95      private String configColumn = "config";
96  
97      /**
98       * The name of the property name column.
99       */
100     private String nameColumn = "name";
101 
102     /**
103      * The name of the property value column.
104      */
105     private String valueColumn = "value";
106 
107     // ***************************** Initializer ******************************
108 
109     // ***************************** Constructors *****************************
110 
111     // ***************************** Inner Classes ****************************
112 
113     // ******************************** Methods *******************************
114 
115     // --- init ---------------------------------------------------------------
116 
117     // --- get&set ------------------------------------------------------------
118 
119     /**
120      * Sets the name of the configuration table.
121      *
122      * @param table the name of the configuration table.
123      * @throws NullPointerException if {@code table} is <code>null</code>.
124      * @throws IllegalArgumentException if {@code table} is blank.
125      */
126     public final void setTable(final String table) throws NullPointerException,
127       IllegalArgumentException
128     {
129       this.table = Arg.checkNotBlank("table", table);
130     }
131 
132     /**
133      * Sets the name of the optional configuration key column.
134      *
135      * @param configColumn the name of the optional configuration key column.
136      * @throws NullPointerException if {@code configColumn} is <code>null</code>
137      *           .
138      * @throws IllegalArgumentException if {@code configColumn} is blank.
139      */
140     public final void setConfigColumn(final String configColumn)
141       throws NullPointerException, IllegalArgumentException
142     {
143       this.configColumn = Arg.checkNotBlank("configColumn", configColumn);
144     }
145 
146     /**
147      * Sets the name of the property name column.
148      *
149      * @param nameColumn the name of the property name column.
150      * @throws NullPointerException if {@code nameColumn} is <code>null</code>.
151      * @throws IllegalArgumentException if {@code nameColumn} is blank.
152      */
153     public final void setNameColumn(final String nameColumn)
154       throws NullPointerException, IllegalArgumentException
155     {
156       this.nameColumn = Arg.checkNotBlank("nameColumn", nameColumn);
157     }
158 
159     /**
160      * Sets the name of the property value column.
161      *
162      * @param valueColumn the name of the property value column.
163      * @throws NullPointerException if {@code valueColumn} is <code>null</code>.
164      * @throws IllegalArgumentException if {@code valueColumn} is blank.
165      */
166     public final void setValueColumn(final String valueColumn)
167       throws NullPointerException, IllegalArgumentException
168     {
169       this.valueColumn = Arg.checkNotBlank("valueColumn", valueColumn);
170     }
171 
172     // --- business -----------------------------------------------------------
173 
174     // --- object basics ------------------------------------------------------
175 
176   }
177 
178   // ********************************* Methods ********************************
179 
180   // --- init -----------------------------------------------------------------
181 
182   // --- get&set --------------------------------------------------------------
183 
184   @Override
185   public final String getTable()
186   {
187     return table;
188   }
189 
190   @Override
191   public final String getConfigColumn()
192   {
193     return configColumn;
194   }
195 
196   @Override
197   public final String getNameColumn()
198   {
199     return nameColumn;
200   }
201 
202   @Override
203   public final String getValueColumn()
204   {
205     return valueColumn;
206   }
207 
208   // --- business -------------------------------------------------------------
209 
210   // --- object basics --------------------------------------------------------
211 
212 }