[SDNC-5] Rebase sdnc-core
[sdnc/core.git] / dblib / common / src / main / java / org / apache / tomcat / jdbc / pool / PoolProperties.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 import java.io.ByteArrayInputStream;
40 import java.io.IOException;
41 import java.io.Serializable;
42 import java.lang.reflect.Method;
43 import java.util.HashMap;
44 import java.util.Locale;
45 import java.util.Map;
46 import java.util.Properties;
47 import java.util.concurrent.atomic.AtomicInteger;
48
49
50 import org.apache.juli.logging.Log;
51 import org.apache.juli.logging.LogFactory;
52
53 public class PoolProperties implements PoolConfiguration, Cloneable, Serializable {
54
55     private static final long serialVersionUID = -8519283440854213745L;
56     private static final Log log = LogFactory.getLog(PoolProperties.class);
57
58     public static final int DEFAULT_MAX_ACTIVE = 100;
59
60     protected static final AtomicInteger poolCounter = new AtomicInteger(0);
61     private volatile Properties dbProperties = new Properties();
62     private volatile String url = null;
63     private volatile String driverClassName = null;
64     private volatile Boolean defaultAutoCommit = null;
65     private volatile Boolean defaultReadOnly = null;
66     private volatile int defaultTransactionIsolation = DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION;
67     private volatile String defaultCatalog = null;
68     private volatile String connectionProperties;
69     private volatile int initialSize = 10;
70     private volatile int maxActive = DEFAULT_MAX_ACTIVE;
71     private volatile int maxIdle = maxActive;
72     private volatile int minIdle = initialSize;
73     private volatile int maxWait = 30000;
74     private volatile String validationQuery;
75     private volatile int validationQueryTimeout = -1;
76     private volatile String validatorClassName;
77     private volatile Validator validator;
78     private volatile boolean testOnBorrow = false;
79     private volatile boolean testOnReturn = false;
80     private volatile boolean testWhileIdle = false;
81     private volatile int timeBetweenEvictionRunsMillis = 5000;
82     private volatile int numTestsPerEvictionRun;
83     private volatile int minEvictableIdleTimeMillis = 60000;
84     private volatile boolean accessToUnderlyingConnectionAllowed = true;
85     private volatile boolean removeAbandoned = false;
86     private volatile int removeAbandonedTimeout = 60;
87     private volatile boolean logAbandoned = false;
88     private volatile String name = "Tomcat Connection Pool["+(poolCounter.addAndGet(1))+"-"+System.identityHashCode(PoolProperties.class)+"]";
89     private volatile String password;
90     private volatile String username;
91     private volatile long validationInterval = 3000;
92     private volatile boolean jmxEnabled = true;
93     private volatile String initSQL;
94     private volatile boolean testOnConnect =false;
95     private volatile String jdbcInterceptors=null;
96     private volatile boolean fairQueue = true;
97     private volatile boolean useEquals = true;
98     private volatile int abandonWhenPercentageFull = 0;
99     private volatile long maxAge = 0;
100     private volatile boolean useLock = false;
101     private volatile InterceptorDefinition[] interceptors = null;
102     private volatile int suspectTimeout = 0;
103     private volatile Object dataSource = null;
104     private volatile String dataSourceJNDI = null;
105     private volatile boolean alternateUsernameAllowed = false;
106     private volatile boolean commitOnReturn = false;
107     private volatile boolean rollbackOnReturn = false;
108     private volatile boolean useDisposableConnectionFacade = true;
109     private volatile boolean logValidationErrors = false;
110     private volatile boolean propagateInterruptState = false;
111     private volatile boolean ignoreExceptionOnPreLoad = false;
112
113     /**
114      * {@inheritDoc}
115      */
116     @Override
117     public void setAbandonWhenPercentageFull(int percentage) {
118         if (percentage<0) abandonWhenPercentageFull = 0;
119         else if (percentage>100) abandonWhenPercentageFull = 100;
120         else abandonWhenPercentageFull = percentage;
121     }
122
123     /**
124      * {@inheritDoc}
125      */
126     @Override
127     public int getAbandonWhenPercentageFull() {
128         return abandonWhenPercentageFull;
129     }
130
131     /**
132      * {@inheritDoc}
133      */
134     @Override
135     public boolean isFairQueue() {
136         return fairQueue;
137     }
138
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     public void setFairQueue(boolean fairQueue) {
144         this.fairQueue = fairQueue;
145     }
146
147     /**
148      * {@inheritDoc}
149      */
150     @Override
151     public boolean isAccessToUnderlyingConnectionAllowed() {
152         return accessToUnderlyingConnectionAllowed;
153     }
154
155     /**
156      * {@inheritDoc}
157      */
158
159     @Override
160     public String getConnectionProperties() {
161         return connectionProperties;
162     }
163
164     /**
165      * {@inheritDoc}
166      */
167
168     @Override
169     public Properties getDbProperties() {
170         return dbProperties;
171     }
172
173     /**
174      * {@inheritDoc}
175      */
176
177     @Override
178     public Boolean isDefaultAutoCommit() {
179         return defaultAutoCommit;
180     }
181
182     /**
183      * {@inheritDoc}
184      */
185
186     @Override
187     public String getDefaultCatalog() {
188         return defaultCatalog;
189     }
190
191     /**
192      * {@inheritDoc}
193      */
194
195     @Override
196     public Boolean isDefaultReadOnly() {
197         return defaultReadOnly;
198     }
199
200     /**
201      * {@inheritDoc}
202      */
203
204     @Override
205     public int getDefaultTransactionIsolation() {
206         return defaultTransactionIsolation;
207     }
208
209     /**
210      * {@inheritDoc}
211      */
212
213     @Override
214     public String getDriverClassName() {
215         return driverClassName;
216     }
217
218     /**
219      * {@inheritDoc}
220      */
221
222     @Override
223     public int getInitialSize() {
224         return initialSize;
225     }
226
227     /**
228      * {@inheritDoc}
229      */
230
231     @Override
232     public boolean isLogAbandoned() {
233         return logAbandoned;
234     }
235
236     /**
237      * {@inheritDoc}
238      */
239
240     @Override
241     public int getMaxActive() {
242         return maxActive;
243     }
244
245     /**
246      * {@inheritDoc}
247      */
248
249     @Override
250     public int getMaxIdle() {
251         return maxIdle;
252     }
253
254     /**
255      * {@inheritDoc}
256      */
257
258     @Override
259     public int getMaxWait() {
260         return maxWait;
261     }
262
263     /**
264      * {@inheritDoc}
265      */
266
267     @Override
268     public int getMinEvictableIdleTimeMillis() {
269         return minEvictableIdleTimeMillis;
270     }
271
272     /**
273      * {@inheritDoc}
274      */
275
276     @Override
277     public int getMinIdle() {
278         return minIdle;
279     }
280
281     /**
282      * {@inheritDoc}
283      */
284
285     @Override
286     public String getName() {
287         return name;
288     }
289
290     /**
291      * {@inheritDoc}
292      */
293
294     @Override
295     public int getNumTestsPerEvictionRun() {
296         return numTestsPerEvictionRun;
297     }
298
299     /**
300      * {@inheritDoc}
301      */
302
303     @Override
304     public String getPassword() {
305         return password;
306     }
307
308     /**
309      * {@inheritDoc}
310      */
311
312     @Override
313     public String getPoolName() {
314         return getName();
315     }
316
317     /**
318      * {@inheritDoc}
319      */
320
321     @Override
322     public boolean isRemoveAbandoned() {
323         return removeAbandoned;
324     }
325
326     /**
327      * {@inheritDoc}
328      */
329
330     @Override
331     public int getRemoveAbandonedTimeout() {
332         return removeAbandonedTimeout;
333     }
334
335     /**
336      * {@inheritDoc}
337      */
338
339     @Override
340     public boolean isTestOnBorrow() {
341         return testOnBorrow;
342     }
343
344     /**
345      * {@inheritDoc}
346      */
347
348     @Override
349     public boolean isTestOnReturn() {
350         return testOnReturn;
351     }
352
353     /**
354      * {@inheritDoc}
355      */
356
357     @Override
358     public boolean isTestWhileIdle() {
359         return testWhileIdle;
360     }
361
362     /**
363      * {@inheritDoc}
364      */
365
366     @Override
367     public int getTimeBetweenEvictionRunsMillis() {
368         return timeBetweenEvictionRunsMillis;
369     }
370
371     /**
372      * {@inheritDoc}
373      */
374
375     @Override
376     public String getUrl() {
377         return url;
378     }
379
380     /**
381      * {@inheritDoc}
382      */
383
384     @Override
385     public String getUsername() {
386         return username;
387     }
388
389     /**
390      * {@inheritDoc}
391      */
392
393     @Override
394     public String getValidationQuery() {
395         return validationQuery;
396     }
397
398     /**
399      * {@inheritDoc}
400      */
401     @Override
402     public int getValidationQueryTimeout() {
403         return validationQueryTimeout;
404     }
405
406     /**
407      * {@inheritDoc}
408      */
409     @Override
410     public void setValidationQueryTimeout(int validationQueryTimeout) {
411         this.validationQueryTimeout = validationQueryTimeout;
412     }
413
414     /**
415      * {@inheritDoc}
416      */
417
418     @Override
419     public String getValidatorClassName() {
420         return validatorClassName;
421     }
422
423     /**
424      * {@inheritDoc}
425      */
426
427     @Override
428     public Validator getValidator() {
429         return validator;
430     }
431
432     /**
433      * {@inheritDoc}
434      */
435     @Override
436     public void setValidator(Validator validator) {
437         this.validator = validator;
438         if (validator!=null) {
439             this.validatorClassName = validator.getClass().getName();
440         } else {
441             this.validatorClassName = null;
442         }
443     }
444
445
446     /**
447      * {@inheritDoc}
448      */
449
450     @Override
451     public long getValidationInterval() {
452         return validationInterval;
453     }
454
455     /**
456      * {@inheritDoc}
457      */
458
459     @Override
460     public String getInitSQL() {
461         return initSQL;
462     }
463
464     /**
465      * {@inheritDoc}
466      */
467
468     @Override
469     public boolean isTestOnConnect() {
470         return testOnConnect;
471     }
472
473     /**
474      * {@inheritDoc}
475      */
476
477     @Override
478     public String getJdbcInterceptors() {
479         return jdbcInterceptors;
480     }
481
482     /**
483      * {@inheritDoc}
484      */
485
486     @Override
487     public InterceptorDefinition[] getJdbcInterceptorsAsArray() {
488         if (interceptors == null) {
489             if (jdbcInterceptors==null) {
490                 interceptors = new InterceptorDefinition[0];
491             } else {
492                 String[] interceptorValues = jdbcInterceptors.split(";");
493                 InterceptorDefinition[] definitions = new InterceptorDefinition[interceptorValues.length+1];
494                 //always add the trap interceptor to the mix
495                 definitions[0] = new InterceptorDefinition(TrapException.class);
496                 for (int i=0; i<interceptorValues.length; i++) {
497                     int propIndex = interceptorValues[i].indexOf('(');
498                     int endIndex = interceptorValues[i].indexOf(')');
499                     if (propIndex<0 || endIndex<0 || endIndex <= propIndex) {
500                         definitions[i+1] = new InterceptorDefinition(interceptorValues[i].trim());
501                     } else {
502                         String name = interceptorValues[i].substring(0,propIndex).trim();
503                         definitions[i+1] = new InterceptorDefinition(name);
504                         String propsAsString = interceptorValues[i].substring(propIndex+1, endIndex);
505                         String[] props = propsAsString.split(",");
506                         for (int j=0; j<props.length; j++) {
507                             int pidx = props[j].indexOf('=');
508                             String propName = props[j].substring(0,pidx).trim();
509                             String propValue = props[j].substring(pidx+1).trim();
510                             definitions[i+1].addProperty(new InterceptorProperty(propName,propValue));
511                         }
512                     }
513                 }
514                 interceptors = definitions;
515             }
516         }
517         return interceptors;
518     }
519
520     /**
521      * {@inheritDoc}
522      */
523
524     @Override
525     public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) {
526         // NOOP
527     }
528
529     /**
530      * {@inheritDoc}
531      */
532
533     @Override
534     public void setConnectionProperties(String connectionProperties) {
535         this.connectionProperties = connectionProperties;
536         getProperties(connectionProperties, getDbProperties());
537     }
538
539     /**
540      * {@inheritDoc}
541      */
542
543     @Override
544     public void setDbProperties(Properties dbProperties) {
545         this.dbProperties = dbProperties;
546     }
547
548     /**
549      * {@inheritDoc}
550      */
551
552     @Override
553     public void setDefaultAutoCommit(Boolean defaultAutoCommit) {
554         this.defaultAutoCommit = defaultAutoCommit;
555     }
556
557     /**
558      * {@inheritDoc}
559      */
560
561     @Override
562     public void setDefaultCatalog(String defaultCatalog) {
563         this.defaultCatalog = defaultCatalog;
564     }
565
566     /**
567      * {@inheritDoc}
568      */
569
570     @Override
571     public void setDefaultReadOnly(Boolean defaultReadOnly) {
572         this.defaultReadOnly = defaultReadOnly;
573     }
574
575     /**
576      * {@inheritDoc}
577      */
578
579     @Override
580     public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
581         this.defaultTransactionIsolation = defaultTransactionIsolation;
582     }
583
584     /**
585      * {@inheritDoc}
586      */
587
588     @Override
589     public void setDriverClassName(String driverClassName) {
590         this.driverClassName = driverClassName;
591     }
592
593     /**
594      * {@inheritDoc}
595      */
596
597     @Override
598     public void setInitialSize(int initialSize) {
599         this.initialSize = initialSize;
600     }
601
602     /**
603      * {@inheritDoc}
604      */
605
606     @Override
607     public void setLogAbandoned(boolean logAbandoned) {
608         this.logAbandoned = logAbandoned;
609     }
610
611     /**
612      * {@inheritDoc}
613      */
614
615     @Override
616     public void setMaxActive(int maxActive) {
617         this.maxActive = maxActive;
618     }
619
620     /**
621      * {@inheritDoc}
622      */
623
624     @Override
625     public void setMaxIdle(int maxIdle) {
626         this.maxIdle = maxIdle;
627     }
628
629     /**
630      * {@inheritDoc}
631      */
632
633     @Override
634     public void setMaxWait(int maxWait) {
635         this.maxWait = maxWait;
636     }
637
638     /**
639      * {@inheritDoc}
640      */
641
642     @Override
643     public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
644         this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
645     }
646
647     /**
648      * {@inheritDoc}
649      */
650
651     @Override
652     public void setMinIdle(int minIdle) {
653         this.minIdle = minIdle;
654     }
655
656     /**
657      * {@inheritDoc}
658      */
659
660     @Override
661     public void setName(String name) {
662         this.name = name;
663     }
664
665     /**
666      * {@inheritDoc}
667      */
668
669     @Override
670     public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
671         this.numTestsPerEvictionRun = numTestsPerEvictionRun;
672     }
673
674     /**
675      * {@inheritDoc}
676      */
677
678     @Override
679     public void setPassword(String password) {
680         this.password = password;
681     }
682
683     /**
684      * {@inheritDoc}
685      */
686
687     @Override
688     public void setRemoveAbandoned(boolean removeAbandoned) {
689         this.removeAbandoned = removeAbandoned;
690     }
691
692     /**
693      * {@inheritDoc}
694      */
695
696     @Override
697     public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
698         this.removeAbandonedTimeout = removeAbandonedTimeout;
699     }
700
701     /**
702      * {@inheritDoc}
703      */
704
705     @Override
706     public void setTestOnBorrow(boolean testOnBorrow) {
707         this.testOnBorrow = testOnBorrow;
708     }
709
710     /**
711      * {@inheritDoc}
712      */
713
714     @Override
715     public void setTestWhileIdle(boolean testWhileIdle) {
716         this.testWhileIdle = testWhileIdle;
717     }
718
719     /**
720      * {@inheritDoc}
721      */
722
723     @Override
724     public void setTestOnReturn(boolean testOnReturn) {
725         this.testOnReturn = testOnReturn;
726     }
727
728     /**
729      * {@inheritDoc}
730      */
731
732     @Override
733     public void setTimeBetweenEvictionRunsMillis(int
734                                                  timeBetweenEvictionRunsMillis) {
735         this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
736     }
737
738     /**
739      * {@inheritDoc}
740      */
741
742     @Override
743     public void setUrl(String url) {
744         this.url = url;
745     }
746
747     /**
748      * {@inheritDoc}
749      */
750
751     @Override
752     public void setUsername(String username) {
753         this.username = username;
754     }
755
756     /**
757      * {@inheritDoc}
758      */
759
760     @Override
761     public void setValidationInterval(long validationInterval) {
762         this.validationInterval = validationInterval;
763     }
764
765     /**
766      * {@inheritDoc}
767      */
768
769     @Override
770     public void setValidationQuery(String validationQuery) {
771         this.validationQuery = validationQuery;
772     }
773
774     /**
775      * {@inheritDoc}
776      */
777
778     @Override
779     public void setValidatorClassName(String className) {
780         this.validatorClassName = className;
781
782         validator = null;
783
784         if (className == null) {
785             return;
786         }
787
788         try {
789             @SuppressWarnings("unchecked")
790             Class<Validator> validatorClass = (Class<Validator>)ClassLoaderUtil.loadClass(
791                 className,
792                 PoolProperties.class.getClassLoader(),
793                 Thread.currentThread().getContextClassLoader()
794             );
795             validator = validatorClass.newInstance();
796         } catch (ClassNotFoundException e) {
797             log.warn("The class "+className+" cannot be found.", e);
798         } catch (ClassCastException e) {
799             log.warn("The class "+className+" does not implement the Validator interface.", e);
800         } catch (InstantiationException e) {
801             log.warn("An object of class "+className+" cannot be instantiated. Make sure that "+
802                      "it includes an implicit or explicit no-arg constructor.", e);
803         } catch (IllegalAccessException e) {
804             log.warn("The class "+className+" or its no-arg constructor are inaccessible.", e);
805         }
806     }
807
808     /**
809      * {@inheritDoc}
810      */
811
812     @Override
813     public void setInitSQL(String initSQL) {
814         this.initSQL = initSQL!=null && initSQL.trim().length()>0 ? initSQL : null;
815     }
816
817     /**
818      * {@inheritDoc}
819      */
820
821     @Override
822     public void setTestOnConnect(boolean testOnConnect) {
823         this.testOnConnect = testOnConnect;
824     }
825
826     /**
827      * {@inheritDoc}
828      */
829
830     @Override
831     public void setJdbcInterceptors(String jdbcInterceptors) {
832         this.jdbcInterceptors = jdbcInterceptors;
833         this.interceptors = null;
834     }
835
836
837     @Override
838     public String toString() {
839         StringBuilder buf = new StringBuilder("ConnectionPool[");
840         try {
841             String[] fields = DataSourceFactory.ALL_PROPERTIES;
842             for (String field: fields) {
843                 final String[] prefix = new String[] {"get","is"};
844                 for (int j=0; j<prefix.length; j++) {
845
846                     String name = prefix[j]
847                             + field.substring(0, 1).toUpperCase(Locale.ENGLISH)
848                             + field.substring(1);
849                     Method m = null;
850                     try {
851                         m = getClass().getMethod(name);
852                     }catch (NoSuchMethodException nm) {
853                         continue;
854                     }
855                     buf.append(field);
856                     buf.append("=");
857                     if (DataSourceFactory.PROP_PASSWORD.equals(field)) {
858                         buf.append("********");
859                     } else {
860                         buf.append(m.invoke(this, new Object[0]));
861                     }
862                     buf.append("; ");
863                     break;
864                 }
865             }
866         }catch (Exception x) {
867             //shouldn't happen
868             log.debug("toString() call failed", x);
869         }
870         return buf.toString();
871     }
872
873     public static int getPoolCounter() {
874         return poolCounter.get();
875     }
876
877     /**
878      * {@inheritDoc}
879      */
880
881     @Override
882     public boolean isJmxEnabled() {
883         return jmxEnabled;
884     }
885
886     /**
887      * {@inheritDoc}
888      */
889
890     @Override
891     public void setJmxEnabled(boolean jmxEnabled) {
892         this.jmxEnabled = jmxEnabled;
893     }
894
895     /**
896      * {@inheritDoc}
897      */
898
899     @Override
900     public Boolean getDefaultAutoCommit() {
901         return defaultAutoCommit;
902     }
903
904     /**
905      * {@inheritDoc}
906      */
907
908     @Override
909     public Boolean getDefaultReadOnly() {
910         return defaultReadOnly;
911     }
912
913
914     /**
915      * {@inheritDoc}
916      */
917
918     @Override
919     public int getSuspectTimeout() {
920         return this.suspectTimeout;
921     }
922
923     /**
924      * {@inheritDoc}
925      */
926
927     @Override
928     public void setSuspectTimeout(int seconds) {
929         this.suspectTimeout = seconds;
930     }
931
932     /**
933      * {@inheritDoc}
934      */
935
936     @Override
937     public boolean isPoolSweeperEnabled() {
938         boolean timer = getTimeBetweenEvictionRunsMillis()>0;
939         boolean result = timer && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0);
940         result = result || (timer && getSuspectTimeout()>0);
941         result = result || (timer && isTestWhileIdle() && getValidationQuery()!=null);
942         result = result || (timer && getMinEvictableIdleTimeMillis()>0);
943         return result;
944     }
945
946
947     public static class InterceptorDefinition implements Serializable {
948         private static final long serialVersionUID = 1L;
949         protected String className;
950         protected Map<String,InterceptorProperty> properties = new HashMap<>();
951         protected volatile Class<?> clazz = null;
952         public InterceptorDefinition(String className) {
953             this.className = className;
954         }
955
956         public InterceptorDefinition(Class<?> cl) {
957             this(cl.getName());
958             clazz = cl;
959         }
960
961         public String getClassName() {
962             return className;
963         }
964         public void addProperty(String name, String value) {
965             InterceptorProperty p = new InterceptorProperty(name,value);
966             addProperty(p);
967         }
968
969         public void addProperty(InterceptorProperty p) {
970             properties.put(p.getName(), p);
971         }
972
973         public Map<String,InterceptorProperty> getProperties() {
974             return properties;
975         }
976
977         @SuppressWarnings("unchecked")
978         public Class<? extends JdbcInterceptor> getInterceptorClass() throws ClassNotFoundException {
979             if (clazz==null) {
980                 if (getClassName().indexOf('.')<0) {
981                     if (log.isDebugEnabled()) {
982                         log.debug("Loading interceptor class:"+PoolConfiguration.PKG_PREFIX+getClassName());
983                     }
984                     clazz = ClassLoaderUtil.loadClass(
985                         PoolConfiguration.PKG_PREFIX+getClassName(),
986                         PoolProperties.class.getClassLoader(),
987                         Thread.currentThread().getContextClassLoader()
988                     );
989                 } else {
990                     if (log.isDebugEnabled()) {
991                         log.debug("Loading interceptor class:"+getClassName());
992                     }
993                     clazz = ClassLoaderUtil.loadClass(
994                         getClassName(),
995                         PoolProperties.class.getClassLoader(),
996                         Thread.currentThread().getContextClassLoader()
997                     );
998                 }
999             }
1000             return (Class<? extends JdbcInterceptor>)clazz;
1001         }
1002     }
1003
1004     public static class InterceptorProperty implements Serializable {
1005         private static final long serialVersionUID = 1L;
1006         String name;
1007         String value;
1008         public InterceptorProperty(String name, String value) {
1009             assert(name!=null);
1010             this.name = name;
1011             this.value = value;
1012         }
1013         public String getName() {
1014             return name;
1015         }
1016         public String getValue() {
1017             return value;
1018         }
1019
1020         public boolean getValueAsBoolean(boolean def) {
1021             if (value==null) return def;
1022             if ("true".equals(value)) return true;
1023             if ("false".equals(value)) return false;
1024             return def;
1025         }
1026
1027         public int getValueAsInt(int def) {
1028             if (value==null) return def;
1029             try {
1030                 int v = Integer.parseInt(value);
1031                 return v;
1032             }catch (NumberFormatException nfe) {
1033                 return def;
1034             }
1035         }
1036
1037         public long getValueAsLong(long def) {
1038             if (value==null) return def;
1039             try {
1040                 return Long.parseLong(value);
1041             }catch (NumberFormatException nfe) {
1042                 return def;
1043             }
1044         }
1045
1046         public byte getValueAsByte(byte def) {
1047             if (value==null) return def;
1048             try {
1049                 return Byte.parseByte(value);
1050             }catch (NumberFormatException nfe) {
1051                 return def;
1052             }
1053         }
1054
1055         public short getValueAsShort(short def) {
1056             if (value==null) return def;
1057             try {
1058                 return Short.parseShort(value);
1059             }catch (NumberFormatException nfe) {
1060                 return def;
1061             }
1062         }
1063
1064         public float getValueAsFloat(float def) {
1065             if (value==null) return def;
1066             try {
1067                 return Float.parseFloat(value);
1068             }catch (NumberFormatException nfe) {
1069                 return def;
1070             }
1071         }
1072
1073         public double getValueAsDouble(double def) {
1074             if (value==null) return def;
1075             try {
1076                 return Double.parseDouble(value);
1077             }catch (NumberFormatException nfe) {
1078                 return def;
1079             }
1080         }
1081
1082         public char getValueAschar(char def) {
1083             if (value==null) return def;
1084             try {
1085                 return value.charAt(0);
1086             }catch (StringIndexOutOfBoundsException nfe) {
1087                 return def;
1088             }
1089         }
1090
1091         @Override
1092         public int hashCode() {
1093             return name.hashCode();
1094         }
1095
1096         @Override
1097         public boolean equals(Object o) {
1098             if (o==this) return true;
1099             if (o instanceof InterceptorProperty) {
1100                 InterceptorProperty other = (InterceptorProperty)o;
1101                 return other.name.equals(this.name);
1102             }
1103             return false;
1104         }
1105     }
1106
1107     /**
1108      * {@inheritDoc}
1109      */
1110
1111     @Override
1112     public boolean isUseEquals() {
1113         return useEquals;
1114     }
1115
1116     /**
1117      * {@inheritDoc}
1118      */
1119
1120     @Override
1121     public void setUseEquals(boolean useEquals) {
1122         this.useEquals = useEquals;
1123     }
1124
1125     /**
1126      * {@inheritDoc}
1127      */
1128
1129     @Override
1130     public long getMaxAge() {
1131         return maxAge;
1132     }
1133
1134     /**
1135      * {@inheritDoc}
1136      */
1137
1138     @Override
1139     public void setMaxAge(long maxAge) {
1140         this.maxAge = maxAge;
1141     }
1142
1143     /**
1144      * {@inheritDoc}
1145      */
1146
1147     @Override
1148     public boolean getUseLock() {
1149         return useLock;
1150     }
1151
1152     /**
1153      * {@inheritDoc}
1154      */
1155
1156     @Override
1157     public void setUseLock(boolean useLock) {
1158         this.useLock = useLock;
1159     }
1160
1161
1162     /**
1163      * {@inheritDoc}
1164      */
1165     @Override
1166     public void setDataSource(Object ds) {
1167         if (ds instanceof DataSourceProxy) {
1168             throw new IllegalArgumentException("Layered pools are not allowed.");
1169         }
1170         this.dataSource = ds;
1171     }
1172
1173     /**
1174      * {@inheritDoc}
1175      */
1176     @Override
1177     public Object getDataSource() {
1178         return dataSource;
1179     }
1180
1181
1182     /**
1183      * {@inheritDoc}
1184      */
1185     @Override
1186     public void setDataSourceJNDI(String jndiDS) {
1187         this.dataSourceJNDI = jndiDS;
1188     }
1189
1190     /**
1191      * {@inheritDoc}
1192      */
1193     @Override
1194     public String getDataSourceJNDI() {
1195         return this.dataSourceJNDI;
1196     }
1197
1198
1199     public static Properties getProperties(String propText, Properties props) {
1200         if (props==null) props = new Properties();
1201         if (propText != null) {
1202             try {
1203                 props.load(new ByteArrayInputStream(propText.replace(';', '\n').getBytes()));
1204             }catch (IOException x) {
1205                 throw new RuntimeException(x);
1206             }
1207         }
1208         return props;
1209     }
1210
1211     /**
1212      * {@inheritDoc}
1213      */
1214     @Override
1215     public boolean isAlternateUsernameAllowed() {
1216         return alternateUsernameAllowed;
1217     }
1218
1219     /**
1220      * {@inheritDoc}
1221      */
1222     @Override
1223     public void setAlternateUsernameAllowed(boolean alternateUsernameAllowed) {
1224         this.alternateUsernameAllowed = alternateUsernameAllowed;
1225     }
1226
1227
1228     /**
1229      * {@inheritDoc}
1230      */
1231     @Override
1232     public void setCommitOnReturn(boolean commitOnReturn) {
1233         this.commitOnReturn = commitOnReturn;
1234     }
1235
1236     /**
1237      * {@inheritDoc}
1238      */
1239     @Override
1240     public boolean getCommitOnReturn() {
1241         return this.commitOnReturn;
1242     }
1243
1244     /**
1245      * {@inheritDoc}
1246      */
1247     @Override
1248     public void setRollbackOnReturn(boolean rollbackOnReturn) {
1249         this.rollbackOnReturn = rollbackOnReturn;
1250     }
1251
1252     /**
1253      * {@inheritDoc}
1254      */
1255     @Override
1256     public boolean getRollbackOnReturn() {
1257         return this.rollbackOnReturn;
1258     }
1259
1260     /**
1261      * {@inheritDoc}
1262      */
1263     @Override
1264     public void setUseDisposableConnectionFacade(boolean useDisposableConnectionFacade) {
1265         this.useDisposableConnectionFacade = useDisposableConnectionFacade;
1266     }
1267
1268     /**
1269      * {@inheritDoc}
1270      */
1271     @Override
1272     public boolean getUseDisposableConnectionFacade() {
1273         return useDisposableConnectionFacade;
1274     }
1275
1276     /**
1277      * {@inheritDoc}
1278      */
1279     @Override
1280     public void setLogValidationErrors(boolean logValidationErrors) {
1281         this.logValidationErrors = logValidationErrors;
1282     }
1283
1284     /**
1285      * {@inheritDoc}
1286      */
1287     @Override
1288     public boolean getLogValidationErrors() {
1289         return this.logValidationErrors;
1290     }
1291
1292     /**
1293      * {@inheritDoc}
1294      */
1295     @Override
1296     public boolean getPropagateInterruptState() {
1297         return propagateInterruptState;
1298     }
1299
1300     /**
1301      * {@inheritDoc}
1302      */
1303     @Override
1304     public void setPropagateInterruptState(boolean propagateInterruptState) {
1305         this.propagateInterruptState = propagateInterruptState;
1306     }
1307
1308     /**
1309      * {@inheritDoc}
1310      */
1311     @Override
1312     public boolean isIgnoreExceptionOnPreLoad() {
1313         return ignoreExceptionOnPreLoad;
1314     }
1315
1316     /**
1317      * {@inheritDoc}
1318      */
1319     @Override
1320     public void setIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad) {
1321         this.ignoreExceptionOnPreLoad = ignoreExceptionOnPreLoad;
1322     }
1323
1324     @Override
1325     protected Object clone() throws CloneNotSupportedException {
1326         // TODO Auto-generated method stub
1327         return super.clone();
1328     }
1329
1330
1331
1332 }