View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib;
20  
21  import java.io.Serializable;
22  import java.time.Duration;
23  import org.apache.commons.lang3.StringUtils;
24  
25  public abstract class AbstractJDBCConf implements Serializable {
26  
27      private static final long serialVersionUID = 2675132530878660196L;
28  
29      /**
30       * SQL query to execute. Example: {@code SELECT * FROM table WHERE name=?}.
31       */
32      private String sql;
33  
34      /**
35       * The database dialect is a configuration setting for platform independent software (JPA, Hibernate, etc)
36       * which allows such software to translate its generic SQL statements into vendor specific DDL, DML.
37       */
38      private String dialect = "org.hibernate.dialect.H2Dialect";
39  
40      /**
41       * The JDBC driver used to connect to the database.
42       */
43      private String driverClass = "org.h2.Driver";
44  
45      /**
46       * The database connection URL.
47       */
48      private String url = "jdbc:h2:tcp://localhost:9092/mem:authdb;DB_CLOSE_DELAY=-1";
49  
50      /**
51       * The database user.
52       * <p>
53       * The database user must have sufficient permissions to be able to handle
54       * schema changes and updates, when needed.
55       */
56      private String user = "sa";
57  
58      /**
59       * The database connection password.
60       */
61      private String password = "sa";
62  
63      /**
64       * Qualifies unqualified table names with the given catalog in generated SQL.
65       */
66      private String defaultCatalog;
67  
68      /**
69       * Qualify unqualified table names with the given schema/tablespace in generated SQL.
70       */
71      private String defaultSchema;
72  
73      /**
74       * The SQL query to be executed to test the validity of connections.
75       * This is for "legacy" databases that do not support the JDBC4 {@code Connection.isValid()} API.
76       */
77      private String healthQuery = StringUtils.EMPTY;
78  
79      /**
80       * Controls the maximum amount of time that a connection is allowed to sit idle in the pool.
81       */
82      private Duration idleTimeout = Duration.parse("PT10M");
83  
84      /**
85       * Attempts to do a JNDI data source look up for the data source name specified.
86       * Will attempt to locate the data source object as is.
87       */
88      private String dataSourceName;
89  
90      /**
91       * Controls the minimum size that the pool is allowed
92       * to reach, including both idle and in-use connections.
93       */
94      private int minPoolSize = 6;
95  
96      /**
97       * Controls the maximum number of connections to keep
98       * in the pool, including both idle and in-use connections.
99       */
100     private int maxPoolSize = 18;
101 
102     /**
103      * Sets the maximum time in seconds that this data source will wait
104      * while attempting to connect to a database.
105      * A value of zero specifies that the timeout is the default system timeout
106      * if there is one; otherwise, it specifies that there is no timeout.
107      */
108     private Duration maxPoolWait = Duration.parse("PT2S");
109 
110     /**
111      * Whether or not pool suspension is allowed.
112      * There is a performance impact when pool suspension is enabled.
113      * Unless you need it (for a redundancy system for example) do not enable it.
114      */
115     private boolean poolSuspension;
116 
117     /**
118      * The maximum number of milliseconds that the
119      * pool will wait for a connection to be validated as alive.
120      */
121     private long poolTimeoutMillis = 1_000;
122 
123     /**
124      * Controls the amount of time that a connection can be out of the pool before a message
125      * is logged indicating a possible connection leak.
126      */
127     private int poolLeakThreshold = 3_000;
128 
129     public String getSql() {
130         return sql;
131     }
132 
133     public void setSql(final String sql) {
134         this.sql = sql;
135     }
136 
137     public String getDialect() {
138         return dialect;
139     }
140 
141     public void setDialect(final String dialect) {
142         this.dialect = dialect;
143     }
144 
145     public String getDriverClass() {
146         return driverClass;
147     }
148 
149     public void setDriverClass(final String driverClass) {
150         this.driverClass = driverClass;
151     }
152 
153     public String getUrl() {
154         return url;
155     }
156 
157     public void setUrl(final String url) {
158         this.url = url;
159     }
160 
161     public String getUser() {
162         return user;
163     }
164 
165     public void setUser(final String user) {
166         this.user = user;
167     }
168 
169     public String getPassword() {
170         return password;
171     }
172 
173     public void setPassword(final String password) {
174         this.password = password;
175     }
176 
177     public String getDefaultCatalog() {
178         return defaultCatalog;
179     }
180 
181     public void setDefaultCatalog(final String defaultCatalog) {
182         this.defaultCatalog = defaultCatalog;
183     }
184 
185     public String getDefaultSchema() {
186         return defaultSchema;
187     }
188 
189     public void setDefaultSchema(final String defaultSchema) {
190         this.defaultSchema = defaultSchema;
191     }
192 
193     public String getHealthQuery() {
194         return healthQuery;
195     }
196 
197     public void setHealthQuery(final String healthQuery) {
198         this.healthQuery = healthQuery;
199     }
200 
201     public Duration getIdleTimeout() {
202         return idleTimeout;
203     }
204 
205     public void setIdleTimeout(final Duration idleTimeout) {
206         this.idleTimeout = idleTimeout;
207     }
208 
209     public String getDataSourceName() {
210         return dataSourceName;
211     }
212 
213     public void setDataSourceName(final String dataSourceName) {
214         this.dataSourceName = dataSourceName;
215     }
216 
217     public int getMinPoolSize() {
218         return minPoolSize;
219     }
220 
221     public void setMinPoolSize(final int minPoolSize) {
222         this.minPoolSize = minPoolSize;
223     }
224 
225     public int getMaxPoolSize() {
226         return maxPoolSize;
227     }
228 
229     public void setMaxPoolSize(final int maxPoolSize) {
230         this.maxPoolSize = maxPoolSize;
231     }
232 
233     public Duration getMaxPoolWait() {
234         return maxPoolWait;
235     }
236 
237     public void setMaxPoolWait(final Duration maxPoolWait) {
238         this.maxPoolWait = maxPoolWait;
239     }
240 
241     public boolean isPoolSuspension() {
242         return poolSuspension;
243     }
244 
245     public void setPoolSuspension(final boolean poolSuspension) {
246         this.poolSuspension = poolSuspension;
247     }
248 
249     public long getPoolTimeoutMillis() {
250         return poolTimeoutMillis;
251     }
252 
253     public void setPoolTimeoutMillis(final long poolTimeoutMillis) {
254         this.poolTimeoutMillis = poolTimeoutMillis;
255     }
256 
257     public int getPoolLeakThreshold() {
258         return poolLeakThreshold;
259     }
260 
261     public void setPoolLeakThreshold(final int poolLeakThreshold) {
262         this.poolLeakThreshold = poolLeakThreshold;
263     }
264 }