Merge "provide ready-use maven setting for easy build"
[sdnc/core.git] / dblib / common / src / main / java / org / apache / tomcat / jdbc / pool / DataSourceFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openecomp
4  * ================================================================================
5  * Copyright (C) 2016 - 2017 AT&T
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 /*
22  * Licensed to the Apache Software Foundation (ASF) under one or more
23  * contributor license agreements.  See the NOTICE file distributed with
24  * this work for additional information regarding copyright ownership.
25  * The ASF licenses this file to You under the Apache License, Version 2.0
26  * (the "License"); you may not use this file except in compliance with
27  * the License.  You may obtain a copy of the License at
28  *
29  *      http://www.apache.org/licenses/LICENSE-2.0
30  *
31  * Unless required by applicable law or agreed to in writing, software
32  * distributed under the License is distributed on an "AS IS" BASIS,
33  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34  * See the License for the specific language governing permissions and
35  * limitations under the License.
36  */
37 package org.apache.tomcat.jdbc.pool;
38
39
40 import java.sql.Connection;
41 import java.util.Hashtable;
42 import java.util.Properties;
43
44 import javax.management.ObjectName;
45 import javax.naming.Context;
46 import javax.naming.InitialContext;
47 import javax.naming.Name;
48 import javax.naming.NamingException;
49 import javax.naming.RefAddr;
50 import javax.naming.Reference;
51 import javax.naming.spi.ObjectFactory;
52 import javax.sql.DataSource;
53
54 import org.apache.juli.logging.Log;
55 import org.apache.juli.logging.LogFactory;
56
57 /**
58  * <p>JNDI object factory that creates an instance of
59  * <code>BasicDataSource</code> that has been configured based on the
60  * <code>RefAddr</code> values of the specified <code>Reference</code>,
61  * which must match the names and data types of the
62  * <code>BasicDataSource</code> bean properties.</p>
63  * <br>
64  * Properties available for configuration:<br>
65  * <a href="http://commons.apache.org/dbcp/configuration.html">Commons DBCP properties</a><br>
66  *<ol>
67  *  <li>initSQL - A query that gets executed once, right after the connection is established.</li>
68  *  <li>testOnConnect - run validationQuery after connection has been established.</li>
69  *  <li>validationInterval - avoid excess validation, only run validation at most at this frequency - time in milliseconds.</li>
70  *  <li>jdbcInterceptors - a semicolon separated list of classnames extending {@link JdbcInterceptor} class.</li>
71  *  <li>jmxEnabled - true of false, whether to register the pool with JMX.</li>
72  *  <li>fairQueue - true of false, whether the pool should sacrifice a little bit of performance for true fairness.</li>
73  *</ol>
74  * @author Craig R. McClanahan
75  * @author Dirk Verbeeck
76  */
77 public class DataSourceFactory implements ObjectFactory {
78     private static final Log log = LogFactory.getLog(DataSourceFactory.class);
79
80     protected static final String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
81     protected static final String PROP_DEFAULTREADONLY = "defaultReadOnly";
82     protected static final String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
83     protected static final String PROP_DEFAULTCATALOG = "defaultCatalog";
84
85     protected static final String PROP_DRIVERCLASSNAME = "driverClassName";
86     protected static final String PROP_PASSWORD = "password";
87     protected static final String PROP_URL = "url";
88     protected static final String PROP_USERNAME = "username";
89
90     protected static final String PROP_MAXACTIVE = "maxActive";
91     protected static final String PROP_MAXIDLE = "maxIdle";
92     protected static final String PROP_MINIDLE = "minIdle";
93     protected static final String PROP_INITIALSIZE = "initialSize";
94     protected static final String PROP_MAXWAIT = "maxWait";
95     protected static final String PROP_MAXAGE = "maxAge";
96
97     protected static final String PROP_TESTONBORROW = "testOnBorrow";
98     protected static final String PROP_TESTONRETURN = "testOnReturn";
99     protected static final String PROP_TESTWHILEIDLE = "testWhileIdle";
100     protected static final String PROP_TESTONCONNECT = "testOnConnect";
101     protected static final String PROP_VALIDATIONQUERY = "validationQuery";
102     protected static final String PROP_VALIDATIONQUERY_TIMEOUT = "validationQueryTimeout";
103     protected static final String PROP_VALIDATOR_CLASS_NAME = "validatorClassName";
104
105     protected static final String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
106     protected static final String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
107     protected static final String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
108
109     protected static final String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED = "accessToUnderlyingConnectionAllowed";
110
111     protected static final String PROP_REMOVEABANDONED = "removeAbandoned";
112     protected static final String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout";
113     protected static final String PROP_LOGABANDONED = "logAbandoned";
114     protected static final String PROP_ABANDONWHENPERCENTAGEFULL = "abandonWhenPercentageFull";
115
116     protected static final String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements";
117     protected static final String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements";
118     protected static final String PROP_CONNECTIONPROPERTIES = "connectionProperties";
119
120     protected static final String PROP_INITSQL = "initSQL";
121     protected static final String PROP_INTERCEPTORS = "jdbcInterceptors";
122     protected static final String PROP_VALIDATIONINTERVAL = "validationInterval";
123     protected static final String PROP_JMX_ENABLED = "jmxEnabled";
124     protected static final String PROP_FAIR_QUEUE = "fairQueue";
125
126     protected static final String PROP_USE_EQUALS = "useEquals";
127     protected static final String PROP_USE_CON_LOCK = "useLock";
128
129     protected static final String PROP_DATASOURCE= "dataSource";
130     protected static final String PROP_DATASOURCE_JNDI = "dataSourceJNDI";
131
132     protected static final String PROP_SUSPECT_TIMEOUT = "suspectTimeout";
133
134     protected static final String PROP_ALTERNATE_USERNAME_ALLOWED = "alternateUsernameAllowed";
135
136     protected static final String PROP_COMMITONRETURN = "commitOnReturn";
137     protected static final String PROP_ROLLBACKONRETURN = "rollbackOnReturn";
138
139     protected static final String PROP_USEDISPOSABLECONNECTIONFACADE = "useDisposableConnectionFacade";
140
141     protected static final String PROP_LOGVALIDATIONERRORS = "logValidationErrors";
142
143     protected static final String PROP_PROPAGATEINTERRUPTSTATE = "propagateInterruptState";
144
145     protected static final String PROP_IGNOREEXCEPTIONONPRELOAD = "ignoreExceptionOnPreLoad";
146
147     public static final int UNKNOWN_TRANSACTIONISOLATION = -1;
148
149     public static final String OBJECT_NAME = "object_name";
150
151
152     protected static final String[] ALL_PROPERTIES = {
153         PROP_DEFAULTAUTOCOMMIT,
154         PROP_DEFAULTREADONLY,
155         PROP_DEFAULTTRANSACTIONISOLATION,
156         PROP_DEFAULTCATALOG,
157         PROP_DRIVERCLASSNAME,
158         PROP_MAXACTIVE,
159         PROP_MAXIDLE,
160         PROP_MINIDLE,
161         PROP_INITIALSIZE,
162         PROP_MAXWAIT,
163         PROP_TESTONBORROW,
164         PROP_TESTONRETURN,
165         PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
166         PROP_NUMTESTSPEREVICTIONRUN,
167         PROP_MINEVICTABLEIDLETIMEMILLIS,
168         PROP_TESTWHILEIDLE,
169         PROP_TESTONCONNECT,
170         PROP_PASSWORD,
171         PROP_URL,
172         PROP_USERNAME,
173         PROP_VALIDATIONQUERY,
174         PROP_VALIDATIONQUERY_TIMEOUT,
175         PROP_VALIDATOR_CLASS_NAME,
176         PROP_VALIDATIONINTERVAL,
177         PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
178         PROP_REMOVEABANDONED,
179         PROP_REMOVEABANDONEDTIMEOUT,
180         PROP_LOGABANDONED,
181         PROP_POOLPREPAREDSTATEMENTS,
182         PROP_MAXOPENPREPAREDSTATEMENTS,
183         PROP_CONNECTIONPROPERTIES,
184         PROP_INITSQL,
185         PROP_INTERCEPTORS,
186         PROP_JMX_ENABLED,
187         PROP_FAIR_QUEUE,
188         PROP_USE_EQUALS,
189         OBJECT_NAME,
190         PROP_ABANDONWHENPERCENTAGEFULL,
191         PROP_MAXAGE,
192         PROP_USE_CON_LOCK,
193         PROP_DATASOURCE,
194         PROP_DATASOURCE_JNDI,
195         PROP_SUSPECT_TIMEOUT,
196         PROP_ALTERNATE_USERNAME_ALLOWED,
197         PROP_COMMITONRETURN,
198         PROP_ROLLBACKONRETURN,
199         PROP_USEDISPOSABLECONNECTIONFACADE,
200         PROP_LOGVALIDATIONERRORS,
201         PROP_PROPAGATEINTERRUPTSTATE,
202         PROP_IGNOREEXCEPTIONONPRELOAD
203     };
204
205     // -------------------------------------------------- ObjectFactory Methods
206
207     /**
208      * <p>Create and return a new <code>BasicDataSource</code> instance.  If no
209      * instance can be created, return <code>null</code> instead.</p>
210      *
211      * @param obj The possibly null object containing location or
212      *  reference information that can be used in creating an object
213      * @param name The name of this object relative to <code>nameCtx</code>
214      * @param nameCtx The context relative to which the <code>name</code>
215      *  parameter is specified, or <code>null</code> if <code>name</code>
216      *  is relative to the default initial context
217      * @param environment The possibly null environment that is used in
218      *  creating this object
219      *
220      * @exception Exception if an exception occurs creating the instance
221      */
222     @Override
223     public Object getObjectInstance(Object obj, Name name, Context nameCtx,
224                                     Hashtable<?,?> environment) throws Exception {
225
226         // We only know how to deal with <code>javax.naming.Reference</code>s
227         // that specify a class name of "javax.sql.DataSource"
228         if ((obj == null) || !(obj instanceof Reference)) {
229             return null;
230         }
231         Reference ref = (Reference) obj;
232         boolean XA = false;
233         boolean ok = false;
234         if ("javax.sql.DataSource".equals(ref.getClassName())) {
235             ok = true;
236         }
237         if ("javax.sql.XADataSource".equals(ref.getClassName())) {
238             ok = true;
239             XA = true;
240         }
241         if (org.apache.tomcat.jdbc.pool.DataSource.class.getName().equals(ref.getClassName())) {
242             ok = true;
243         }
244
245         if (!ok) {
246             log.warn(ref.getClassName()+" is not a valid class name/type for this JNDI factory.");
247             return null;
248         }
249
250
251         Properties properties = new Properties();
252         for (int i = 0; i < ALL_PROPERTIES.length; i++) {
253             String propertyName = ALL_PROPERTIES[i];
254             RefAddr ra = ref.get(propertyName);
255             if (ra != null) {
256                 String propertyValue = ra.getContent().toString();
257                 properties.setProperty(propertyName, propertyValue);
258             }
259         }
260
261         return createDataSource(properties,nameCtx,XA);
262     }
263
264     public static PoolConfiguration parsePoolProperties(Properties properties) {
265         PoolConfiguration poolProperties = new PoolProperties();
266         String value = null;
267
268         value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT);
269         if (value != null) {
270             poolProperties.setDefaultAutoCommit(Boolean.valueOf(value));
271         }
272
273         value = properties.getProperty(PROP_DEFAULTREADONLY);
274         if (value != null) {
275             poolProperties.setDefaultReadOnly(Boolean.valueOf(value));
276         }
277
278         value = properties.getProperty(PROP_DEFAULTTRANSACTIONISOLATION);
279         if (value != null) {
280             int level = UNKNOWN_TRANSACTIONISOLATION;
281             if ("NONE".equalsIgnoreCase(value)) {
282                 level = Connection.TRANSACTION_NONE;
283             } else if ("READ_COMMITTED".equalsIgnoreCase(value)) {
284                 level = Connection.TRANSACTION_READ_COMMITTED;
285             } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) {
286                 level = Connection.TRANSACTION_READ_UNCOMMITTED;
287             } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) {
288                 level = Connection.TRANSACTION_REPEATABLE_READ;
289             } else if ("SERIALIZABLE".equalsIgnoreCase(value)) {
290                 level = Connection.TRANSACTION_SERIALIZABLE;
291             } else {
292                 try {
293                     level = Integer.parseInt(value);
294                 } catch (NumberFormatException e) {
295                     System.err.println("Could not parse defaultTransactionIsolation: " + value);
296                     System.err.println("WARNING: defaultTransactionIsolation not set");
297                     System.err.println("using default value of database driver");
298                     level = UNKNOWN_TRANSACTIONISOLATION;
299                 }
300             }
301             poolProperties.setDefaultTransactionIsolation(level);
302         }
303
304         value = properties.getProperty(PROP_DEFAULTCATALOG);
305         if (value != null) {
306             poolProperties.setDefaultCatalog(value);
307         }
308
309         value = properties.getProperty(PROP_DRIVERCLASSNAME);
310         if (value != null) {
311             poolProperties.setDriverClassName(value);
312         }
313
314         value = properties.getProperty(PROP_MAXACTIVE);
315         if (value != null) {
316             poolProperties.setMaxActive(Integer.parseInt(value));
317         }
318
319         value = properties.getProperty(PROP_MAXIDLE);
320         if (value != null) {
321             poolProperties.setMaxIdle(Integer.parseInt(value));
322         }
323
324         value = properties.getProperty(PROP_MINIDLE);
325         if (value != null) {
326             poolProperties.setMinIdle(Integer.parseInt(value));
327         }
328
329         value = properties.getProperty(PROP_INITIALSIZE);
330         if (value != null) {
331             poolProperties.setInitialSize(Integer.parseInt(value));
332         }
333
334         value = properties.getProperty(PROP_MAXWAIT);
335         if (value != null) {
336             poolProperties.setMaxWait(Integer.parseInt(value));
337         }
338
339         value = properties.getProperty(PROP_TESTONBORROW);
340         if (value != null) {
341             poolProperties.setTestOnBorrow(Boolean.parseBoolean(value));
342         }
343
344         value = properties.getProperty(PROP_TESTONRETURN);
345         if (value != null) {
346             poolProperties.setTestOnReturn(Boolean.parseBoolean(value));
347         }
348
349         value = properties.getProperty(PROP_TESTONCONNECT);
350         if (value != null) {
351             poolProperties.setTestOnConnect(Boolean.parseBoolean(value));
352         }
353
354         value = properties.getProperty(PROP_TIMEBETWEENEVICTIONRUNSMILLIS);
355         if (value != null) {
356             poolProperties.setTimeBetweenEvictionRunsMillis(Integer.parseInt(value));
357         }
358
359         value = properties.getProperty(PROP_NUMTESTSPEREVICTIONRUN);
360         if (value != null) {
361             poolProperties.setNumTestsPerEvictionRun(Integer.parseInt(value));
362         }
363
364         value = properties.getProperty(PROP_MINEVICTABLEIDLETIMEMILLIS);
365         if (value != null) {
366             poolProperties.setMinEvictableIdleTimeMillis(Integer.parseInt(value));
367         }
368
369         value = properties.getProperty(PROP_TESTWHILEIDLE);
370         if (value != null) {
371             poolProperties.setTestWhileIdle(Boolean.parseBoolean(value));
372         }
373
374         value = properties.getProperty(PROP_PASSWORD);
375         if (value != null) {
376             poolProperties.setPassword(value);
377         }
378
379         value = properties.getProperty(PROP_URL);
380         if (value != null) {
381             poolProperties.setUrl(value);
382         }
383
384         value = properties.getProperty(PROP_USERNAME);
385         if (value != null) {
386             poolProperties.setUsername(value);
387         }
388
389         value = properties.getProperty(PROP_VALIDATIONQUERY);
390         if (value != null) {
391             poolProperties.setValidationQuery(value);
392         }
393
394         value = properties.getProperty(PROP_VALIDATIONQUERY_TIMEOUT);
395         if (value != null) {
396             poolProperties.setValidationQueryTimeout(Integer.parseInt(value));
397         }
398
399         value = properties.getProperty(PROP_VALIDATOR_CLASS_NAME);
400         if (value != null) {
401             poolProperties.setValidatorClassName(value);
402         }
403
404         value = properties.getProperty(PROP_VALIDATIONINTERVAL);
405         if (value != null) {
406             poolProperties.setValidationInterval(Long.parseLong(value));
407         }
408
409         value = properties.getProperty(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED);
410         if (value != null) {
411             poolProperties.setAccessToUnderlyingConnectionAllowed(Boolean.parseBoolean(value));
412         }
413
414         value = properties.getProperty(PROP_REMOVEABANDONED);
415         if (value != null) {
416             poolProperties.setRemoveAbandoned(Boolean.parseBoolean(value));
417         }
418
419         value = properties.getProperty(PROP_REMOVEABANDONEDTIMEOUT);
420         if (value != null) {
421             poolProperties.setRemoveAbandonedTimeout(Integer.parseInt(value));
422         }
423
424         value = properties.getProperty(PROP_LOGABANDONED);
425         if (value != null) {
426             poolProperties.setLogAbandoned(Boolean.parseBoolean(value));
427         }
428
429         value = properties.getProperty(PROP_POOLPREPAREDSTATEMENTS);
430         if (value != null) {
431             log.warn(PROP_POOLPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
432         }
433
434         value = properties.getProperty(PROP_MAXOPENPREPAREDSTATEMENTS);
435         if (value != null) {
436             log.warn(PROP_MAXOPENPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
437         }
438
439         value = properties.getProperty(PROP_CONNECTIONPROPERTIES);
440         if (value != null) {
441             Properties p = getProperties(value);
442             poolProperties.setDbProperties(p);
443         } else {
444             poolProperties.setDbProperties(new Properties());
445         }
446
447         if (poolProperties.getUsername()!=null) {
448             poolProperties.getDbProperties().setProperty("user",poolProperties.getUsername());
449         }
450         if (poolProperties.getPassword()!=null) {
451             poolProperties.getDbProperties().setProperty("password",poolProperties.getPassword());
452         }
453
454         value = properties.getProperty(PROP_INITSQL);
455         if (value != null) {
456             poolProperties.setInitSQL(value);
457         }
458
459         value = properties.getProperty(PROP_INTERCEPTORS);
460         if (value != null) {
461             poolProperties.setJdbcInterceptors(value);
462         }
463
464         value = properties.getProperty(PROP_JMX_ENABLED);
465         if (value != null) {
466             poolProperties.setJmxEnabled(Boolean.parseBoolean(value));
467         }
468
469         value = properties.getProperty(PROP_FAIR_QUEUE);
470         if (value != null) {
471             poolProperties.setFairQueue(Boolean.parseBoolean(value));
472         }
473
474         value = properties.getProperty(PROP_USE_EQUALS);
475         if (value != null) {
476             poolProperties.setUseEquals(Boolean.parseBoolean(value));
477         }
478
479         value = properties.getProperty(OBJECT_NAME);
480         if (value != null) {
481             poolProperties.setName(ObjectName.quote(value));
482         }
483
484         value = properties.getProperty(PROP_ABANDONWHENPERCENTAGEFULL);
485         if (value != null) {
486             poolProperties.setAbandonWhenPercentageFull(Integer.parseInt(value));
487         }
488
489         value = properties.getProperty(PROP_MAXAGE);
490         if (value != null) {
491             poolProperties.setMaxAge(Long.parseLong(value));
492         }
493
494         value = properties.getProperty(PROP_USE_CON_LOCK);
495         if (value != null) {
496             poolProperties.setUseLock(Boolean.parseBoolean(value));
497         }
498
499         value = properties.getProperty(PROP_DATASOURCE);
500         if (value != null) {
501             //this should never happen
502             throw new IllegalArgumentException("Can't set dataSource property as a string, this must be a javax.sql.DataSource object.");
503
504         }
505
506         value = properties.getProperty(PROP_DATASOURCE_JNDI);
507         if (value != null) {
508             poolProperties.setDataSourceJNDI(value);
509         }
510
511         value = properties.getProperty(PROP_SUSPECT_TIMEOUT);
512         if (value != null) {
513             poolProperties.setSuspectTimeout(Integer.parseInt(value));
514         }
515
516         value = properties.getProperty(PROP_ALTERNATE_USERNAME_ALLOWED);
517         if (value != null) {
518             poolProperties.setAlternateUsernameAllowed(Boolean.parseBoolean(value));
519         }
520
521         value = properties.getProperty(PROP_COMMITONRETURN);
522         if (value != null) {
523             poolProperties.setCommitOnReturn(Boolean.parseBoolean(value));
524         }
525
526         value = properties.getProperty(PROP_ROLLBACKONRETURN);
527         if (value != null) {
528             poolProperties.setRollbackOnReturn(Boolean.parseBoolean(value));
529         }
530
531         value = properties.getProperty(PROP_USEDISPOSABLECONNECTIONFACADE);
532         if (value != null) {
533             poolProperties.setUseDisposableConnectionFacade(Boolean.parseBoolean(value));
534         }
535
536         value = properties.getProperty(PROP_LOGVALIDATIONERRORS);
537         if (value != null) {
538             poolProperties.setLogValidationErrors(Boolean.parseBoolean(value));
539         }
540
541         value = properties.getProperty(PROP_PROPAGATEINTERRUPTSTATE);
542         if (value != null) {
543             poolProperties.setPropagateInterruptState(Boolean.parseBoolean(value));
544         }
545
546         value = properties.getProperty(PROP_IGNOREEXCEPTIONONPRELOAD);
547         if (value != null) {
548             poolProperties.setIgnoreExceptionOnPreLoad(Boolean.parseBoolean(value));
549         }
550
551         return poolProperties;
552     }
553
554     /**
555      * Creates and configures a {@link DataSource} instance based on the
556      * given properties.
557      *
558      * @param properties the datasource configuration properties
559      * @return the datasource
560      * @throws Exception if an error occurs creating the data source
561      */
562     public DataSource createDataSource(Properties properties) throws Exception {
563         return createDataSource(properties,null,false);
564     }
565     public DataSource createDataSource(Properties properties,Context context, boolean XA) throws Exception {
566         PoolConfiguration poolProperties = DataSourceFactory.parsePoolProperties(properties);
567         if (poolProperties.getDataSourceJNDI()!=null && poolProperties.getDataSource()==null) {
568             performJNDILookup(context, poolProperties);
569         }
570         org.apache.tomcat.jdbc.pool.DataSource dataSource = XA?
571                 new org.apache.tomcat.jdbc.pool.XADataSource(poolProperties) :
572                 new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
573         //initialise the pool itself
574         dataSource.createPool();
575         // Return the configured DataSource instance
576         return dataSource;
577     }
578
579     public void performJNDILookup(Context context, PoolConfiguration poolProperties) {
580         Object jndiDS = null;
581         try {
582             if (context!=null) {
583                 jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
584             } else {
585                 log.warn("dataSourceJNDI property is configured, but local JNDI context is null.");
586             }
587         } catch (NamingException e) {
588             log.debug("The name \""+poolProperties.getDataSourceJNDI()+"\" cannot be found in the local context.");
589         }
590         if (jndiDS==null) {
591             try {
592                 context = new InitialContext();
593                 jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
594             } catch (NamingException e) {
595                 log.warn("The name \""+poolProperties.getDataSourceJNDI()+"\" cannot be found in the InitialContext.");
596             }
597         }
598         if (jndiDS!=null) {
599             poolProperties.setDataSource(jndiDS);
600         }
601     }
602
603     /**
604      * Parse properties from the string. Format of the string must be [propertyName=property;]*.
605      * @param propText The properties string
606      * @return the properties
607      */
608     protected static Properties getProperties(String propText) {
609         return PoolProperties.getProperties(propText,null);
610     }
611
612 }