Source Code Cross Referenced for ProxoolDataSource.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » proxool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » proxool » org.logicalcobwebs.proxool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is released under a licence similar to the Apache Software Licence.
003:         * See org.logicalcobwebs.proxool.package.html for details.
004:         * The latest version is available at http://proxool.sourceforge.net
005:         */
006:        package org.logicalcobwebs.proxool;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:
011:        import javax.naming.spi.ObjectFactory;
012:        import javax.naming.Name;
013:        import javax.naming.Context;
014:        import javax.naming.Reference;
015:        import javax.naming.RefAddr;
016:        import javax.naming.StringRefAddr;
017:        import javax.sql.DataSource;
018:        import java.sql.Connection;
019:        import java.sql.SQLException;
020:        import java.util.Hashtable;
021:        import java.util.Enumeration;
022:        import java.util.Properties;
023:        import java.util.StringTokenizer;
024:        import java.io.PrintWriter;
025:
026:        /**
027:         * The Proxool DataSource implementation. Supports three modes of configuration:
028:         * <ul>
029:         *   <li>pre-configured</li>
030:         *   <li>bean-configured</li>
031:         *   <li>factory-configured</li>
032:         * </ul>
033:         *
034:         * TODO - expand
035:         * @version $Revision: 1.7 $, $Date: 2006/05/23 21:17:55 $
036:         * @author bill
037:         * @author $Author: billhorsman $ (current maintainer)
038:         * @since Proxool 0.9
039:         */
040:        public class ProxoolDataSource implements  DataSource, ObjectFactory {
041:            private static final Log LOG = LogFactory
042:                    .getLog(ProxoolDataSource.class);
043:
044:            private int loginTimeout;
045:            private PrintWriter logWriter;
046:
047:            private String alias;
048:            private String driver;
049:            private String fatalSqlExceptionWrapperClass;
050:            private int houseKeepingSleepTime;
051:            private String houseKeepingTestSql;
052:            private int maximumActiveTime;
053:            private int maximumConnectionCount;
054:            private int maximumConnectionLifetime;;
055:            private int minimumConnectionCount;
056:            private int overloadWithoutRefusalLifetime;
057:            private String password;
058:            private int prototypeCount;
059:            private int recentlyStartedThreshold;
060:            private int simultaneousBuildThrottle;
061:            private String statistics;
062:            private String statisticsLogLevel;
063:            private boolean trace;
064:            private String driverUrl;
065:            private String user;
066:            private boolean verbose;
067:            private boolean jmx;
068:            private String jmxAgentId;
069:            private boolean testBeforeUse;
070:            private boolean testAfterUse;
071:            private Properties delegateProperties = new Properties();
072:
073:            /**
074:             * A String of all the fatalSqlExceptions delimited by
075:             * {@link ConnectionPoolDefinitionIF#FATAL_SQL_EXCEPTIONS_DELIMITER}
076:             */
077:            private String fatalSqlExceptionsAsString;
078:
079:            public ProxoolDataSource() {
080:                reset();
081:            }
082:
083:            public ProxoolDataSource(String alias) {
084:                this .alias = alias;
085:            }
086:
087:            /**
088:             * @see javax.sql.DataSource#getConnection()
089:             */
090:            public Connection getConnection() throws SQLException {
091:
092:                ConnectionPool cp = null;
093:                try {
094:                    if (!ConnectionPoolManager.getInstance()
095:                            .isPoolExists(alias)) {
096:                        registerPool();
097:                    }
098:                    cp = ConnectionPoolManager.getInstance().getConnectionPool(
099:                            alias);
100:                    return cp.getConnection();
101:                } catch (ProxoolException e) {
102:                    LOG.error("Problem getting connection", e);
103:                    throw new SQLException(e.toString());
104:                }
105:            }
106:
107:            /**
108:             * Register a pool using the properties of this data source. (Check that it
109:             * exists first)
110:             * @throws ProxoolException if the pool couldn't be registered
111:             */
112:            private synchronized void registerPool() throws ProxoolException {
113:                if (!ConnectionPoolManager.getInstance().isPoolExists(alias)) {
114:                    ConnectionPoolDefinition cpd = new ConnectionPoolDefinition();
115:                    cpd.setAlias(getAlias());
116:                    cpd.setDriver(getDriver());
117:                    cpd
118:                            .setFatalSqlExceptionsAsString(getFatalSqlExceptionsAsString());
119:                    cpd
120:                            .setFatalSqlExceptionWrapper(getFatalSqlExceptionWrapperClass());
121:                    cpd.setHouseKeepingSleepTime(getHouseKeepingSleepTime());
122:                    cpd.setHouseKeepingTestSql(getHouseKeepingTestSql());
123:                    cpd.setMaximumActiveTime(getMaximumActiveTime());
124:                    cpd.setMaximumConnectionCount(getMaximumConnectionCount());
125:                    cpd
126:                            .setMaximumConnectionLifetime(getMaximumConnectionLifetime());
127:                    cpd.setMinimumConnectionCount(getMinimumConnectionCount());
128:                    cpd
129:                            .setOverloadWithoutRefusalLifetime(getOverloadWithoutRefusalLifetime());
130:                    cpd.setPassword(getPassword());
131:                    cpd.setPrototypeCount(getPrototypeCount());
132:                    cpd
133:                            .setRecentlyStartedThreshold(getRecentlyStartedThreshold());
134:                    cpd
135:                            .setSimultaneousBuildThrottle(getSimultaneousBuildThrottle());
136:                    cpd.setStatistics(getStatistics());
137:                    cpd.setStatisticsLogLevel(getStatisticsLogLevel());
138:                    cpd.setTrace(isTrace());
139:                    cpd.setUrl(getDriverUrl());
140:                    cpd.setUser(getUser());
141:                    cpd.setVerbose(isVerbose());
142:                    cpd.setJmx(isJmx());
143:                    cpd.setJmxAgentId(getJmxAgentId());
144:                    cpd.setTestAfterUse(isTestAfterUse());
145:                    cpd.setTestBeforeUse(isTestBeforeUse());
146:                    cpd.setDelegateProperties(delegateProperties);
147:                    ProxoolFacade.registerConnectionPool(cpd);
148:                }
149:            }
150:
151:            public Object getObjectInstance(Object refObject, Name name,
152:                    Context context, Hashtable hashtable) throws Exception {
153:                // we only handle references
154:                if (!(refObject instanceof  Reference)) {
155:                    return null;
156:                }
157:                Reference reference = (Reference) refObject;
158:                /* Removed because JNDI implementations can not be trusted to implement reference.getFactoryClassName() correctly.
159:                 // check if this is relevant for us
160:                 if (!ProxoolDataSource.class.getName().equals(reference.getFactoryClassName())) {
161:                 return null;
162:                 }
163:                 */
164:                // check if we've allready parsed the properties.
165:                if (!ConnectionPoolManager.getInstance().isPoolExists(
166:                        reference.get(ProxoolConstants.ALIAS_PROPERTY)
167:                                .toString())) {
168:                    populatePropertiesFromReference(reference);
169:                }
170:                return this ;
171:            }
172:
173:            /**
174:             * @see ConnectionPoolDefinitionIF#getAlias
175:             */
176:            public String getAlias() {
177:                return alias;
178:            }
179:
180:            /**
181:             * @see ConnectionPoolDefinitionIF#getAlias
182:             */
183:            public void setAlias(String alias) {
184:                this .alias = alias;
185:            }
186:
187:            /**
188:             * @see ConnectionPoolDefinitionIF#getUrl
189:             */
190:            public String getDriverUrl() {
191:                return driverUrl;
192:            }
193:
194:            /**
195:             * @see ConnectionPoolDefinitionIF#getUrl
196:             */
197:            public void setDriverUrl(String url) {
198:                this .driverUrl = url;
199:            }
200:
201:            /**
202:             * @see ConnectionPoolDefinitionIF#getDriver
203:             */
204:            public String getDriver() {
205:                return driver;
206:            }
207:
208:            /**
209:             * @see ConnectionPoolDefinitionIF#getDriver
210:             */
211:            public void setDriver(String driver) {
212:                this .driver = driver;
213:            }
214:
215:            /**
216:             * @see ConnectionPoolDefinitionIF#getMaximumConnectionLifetime
217:             */
218:            public int getMaximumConnectionLifetime() {
219:                return maximumConnectionLifetime;
220:            }
221:
222:            /**
223:             * @see ConnectionPoolDefinitionIF#getMaximumConnectionLifetime
224:             */
225:            public void setMaximumConnectionLifetime(
226:                    int maximumConnectionLifetime) {
227:                this .maximumConnectionLifetime = maximumConnectionLifetime;
228:            }
229:
230:            /**
231:             * @see ConnectionPoolDefinitionIF#getPrototypeCount
232:             */
233:            public int getPrototypeCount() {
234:                return prototypeCount;
235:            }
236:
237:            /**
238:             * @see ConnectionPoolDefinitionIF#getPrototypeCount
239:             */
240:            public void setPrototypeCount(int prototypeCount) {
241:                this .prototypeCount = prototypeCount;
242:            }
243:
244:            /**
245:             * @see ConnectionPoolDefinitionIF#getMinimumConnectionCount
246:             */
247:            public int getMinimumConnectionCount() {
248:                return minimumConnectionCount;
249:            }
250:
251:            /**
252:             * @see ConnectionPoolDefinitionIF#getMinimumConnectionCount
253:             */
254:            public void setMinimumConnectionCount(int minimumConnectionCount) {
255:                this .minimumConnectionCount = minimumConnectionCount;
256:            }
257:
258:            /**
259:             * @see ConnectionPoolDefinitionIF#getMaximumConnectionCount
260:             */
261:            public int getMaximumConnectionCount() {
262:                return maximumConnectionCount;
263:            }
264:
265:            /**
266:             * @see ConnectionPoolDefinitionIF#getMaximumConnectionCount
267:             */
268:            public void setMaximumConnectionCount(int maximumConnectionCount) {
269:                this .maximumConnectionCount = maximumConnectionCount;
270:            }
271:
272:            /**
273:             * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime
274:             */
275:            public int getHouseKeepingSleepTime() {
276:                return houseKeepingSleepTime;
277:            }
278:
279:            /**
280:             * @see ConnectionPoolDefinitionIF#getHouseKeepingSleepTime
281:             */
282:            public void setHouseKeepingSleepTime(int houseKeepingSleepTime) {
283:                this .houseKeepingSleepTime = houseKeepingSleepTime;
284:            }
285:
286:            /**
287:             * @see ConnectionPoolDefinitionIF#getSimultaneousBuildThrottle
288:             */
289:            public int getSimultaneousBuildThrottle() {
290:                return simultaneousBuildThrottle;
291:            }
292:
293:            /**
294:             * @see ConnectionPoolDefinitionIF#getSimultaneousBuildThrottle
295:             */
296:            public void setSimultaneousBuildThrottle(
297:                    int simultaneousBuildThrottle) {
298:                this .simultaneousBuildThrottle = simultaneousBuildThrottle;
299:            }
300:
301:            /**
302:             * @see ConnectionPoolDefinitionIF#getRecentlyStartedThreshold
303:             */
304:            public int getRecentlyStartedThreshold() {
305:                return recentlyStartedThreshold;
306:            }
307:
308:            /**
309:             * @see ConnectionPoolDefinitionIF#getRecentlyStartedThreshold
310:             */
311:            public void setRecentlyStartedThreshold(int recentlyStartedThreshold) {
312:                this .recentlyStartedThreshold = recentlyStartedThreshold;
313:            }
314:
315:            /**
316:             * @see ConnectionPoolDefinitionIF#getOverloadWithoutRefusalLifetime
317:             */
318:            public int getOverloadWithoutRefusalLifetime() {
319:                return overloadWithoutRefusalLifetime;
320:            }
321:
322:            /**
323:             * @see ConnectionPoolDefinitionIF#getOverloadWithoutRefusalLifetime
324:             */
325:            public void setOverloadWithoutRefusalLifetime(
326:                    int overloadWithoutRefusalLifetime) {
327:                this .overloadWithoutRefusalLifetime = overloadWithoutRefusalLifetime;
328:            }
329:
330:            /**
331:             * @see ConnectionPoolDefinitionIF#getMaximumActiveTime
332:             */
333:            public int getMaximumActiveTime() {
334:                return maximumActiveTime;
335:            }
336:
337:            /**
338:             * @see ConnectionPoolDefinitionIF#getMaximumActiveTime
339:             */
340:            public void setMaximumActiveTime(int maximumActiveTime) {
341:                this .maximumActiveTime = maximumActiveTime;
342:            }
343:
344:            /**
345:             * @see ConnectionPoolDefinitionIF#isVerbose
346:             */
347:            public boolean isVerbose() {
348:                return verbose;
349:            }
350:
351:            /**
352:             * @see ConnectionPoolDefinitionIF#isVerbose
353:             */
354:            public void setVerbose(boolean verbose) {
355:                this .verbose = verbose;
356:            }
357:
358:            /**
359:             * @see ConnectionPoolDefinitionIF#isTrace
360:             */
361:            public boolean isTrace() {
362:                return trace;
363:            }
364:
365:            /**
366:             * @see ConnectionPoolDefinitionIF#isTrace
367:             */
368:            public void setTrace(boolean trace) {
369:                this .trace = trace;
370:            }
371:
372:            /**
373:             * @see ConnectionPoolDefinitionIF#getStatistics
374:             */
375:            public String getStatistics() {
376:                return statistics;
377:            }
378:
379:            /**
380:             * @see ConnectionPoolDefinitionIF#getStatistics
381:             */
382:            public void setStatistics(String statistics) {
383:                this .statistics = statistics;
384:            }
385:
386:            /**
387:             * @see ConnectionPoolDefinitionIF#getStatisticsLogLevel
388:             */
389:            public String getStatisticsLogLevel() {
390:                return statisticsLogLevel;
391:            }
392:
393:            /**
394:             * @see ConnectionPoolDefinitionIF#getStatisticsLogLevel
395:             */
396:            public void setStatisticsLogLevel(String statisticsLogLevel) {
397:                this .statisticsLogLevel = statisticsLogLevel;
398:            }
399:
400:            /**
401:             * @see ConnectionPoolDefinitionIF#getFatalSqlExceptions
402:             */
403:            public String getFatalSqlExceptionsAsString() {
404:                return fatalSqlExceptionsAsString;
405:            }
406:
407:            /**
408:             * @see ConnectionPoolDefinitionIF#getFatalSqlExceptions
409:             */
410:            public void setFatalSqlExceptionsAsString(
411:                    String fatalSqlExceptionsAsString) {
412:                this .fatalSqlExceptionsAsString = fatalSqlExceptionsAsString;
413:            }
414:
415:            /**
416:             * @see ConnectionPoolDefinitionIF#getFatalSqlExceptionWrapper()
417:             */
418:            public String getFatalSqlExceptionWrapperClass() {
419:                return fatalSqlExceptionWrapperClass;
420:            }
421:
422:            /**
423:             * @see ConnectionPoolDefinitionIF#getFatalSqlExceptionWrapper()
424:             */
425:            public void setFatalSqlExceptionWrapperClass(
426:                    String fatalSqlExceptionWrapperClass) {
427:                this .fatalSqlExceptionWrapperClass = fatalSqlExceptionWrapperClass;
428:            }
429:
430:            /**
431:             * @see ConnectionPoolDefinitionIF#getHouseKeepingTestSql
432:             */
433:            public String getHouseKeepingTestSql() {
434:                return houseKeepingTestSql;
435:            }
436:
437:            /**
438:             * @see ConnectionPoolDefinitionIF#getHouseKeepingTestSql
439:             */
440:            public void setHouseKeepingTestSql(String houseKeepingTestSql) {
441:                this .houseKeepingTestSql = houseKeepingTestSql;
442:            }
443:
444:            /**
445:             * @see ConnectionPoolDefinitionIF#getUser
446:             */
447:            public String getUser() {
448:                return user;
449:            }
450:
451:            /**
452:             * @see ConnectionPoolDefinitionIF#getUser
453:             */
454:            public void setUser(String user) {
455:                this .user = user;
456:            }
457:
458:            /**
459:             * @see ConnectionPoolDefinitionIF#getPassword
460:             */
461:            public String getPassword() {
462:                return password;
463:            }
464:
465:            /**
466:             * @see ConnectionPoolDefinitionIF#getPassword
467:             */
468:            public void setPassword(String password) {
469:                this .password = password;
470:            }
471:
472:            /**
473:             * @see ConnectionPoolDefinitionIF#isJmx()
474:             */
475:            public boolean isJmx() {
476:                return jmx;
477:            }
478:
479:            /**
480:             * @see ConnectionPoolDefinitionIF#isJmx()
481:             */
482:            public void setJmx(boolean jmx) {
483:                this .jmx = jmx;
484:            }
485:
486:            /**
487:             * @see ConnectionPoolDefinitionIF#getJmxAgentId()
488:             */
489:            public String getJmxAgentId() {
490:                return jmxAgentId;
491:            }
492:
493:            /**
494:             * @see ConnectionPoolDefinitionIF#getJmxAgentId()
495:             */
496:            public void setJmxAgentId(String jmxAgentId) {
497:                this .jmxAgentId = jmxAgentId;
498:            }
499:
500:            /**
501:             * @see ConnectionPoolDefinitionIF#isTestBeforeUse
502:             */
503:            public boolean isTestBeforeUse() {
504:                return testBeforeUse;
505:            }
506:
507:            /**
508:             * @see ConnectionPoolDefinitionIF#isTestBeforeUse
509:             */
510:            public void setTestBeforeUse(boolean testBeforeUse) {
511:                this .testBeforeUse = testBeforeUse;
512:            }
513:
514:            /**
515:             * @see ConnectionPoolDefinitionIF#isTestAfterUse
516:             */
517:            public boolean isTestAfterUse() {
518:                return testAfterUse;
519:            }
520:
521:            /**
522:             * @see ConnectionPoolDefinitionIF#isTestAfterUse
523:             */
524:            public void setTestAfterUse(boolean testAfterUse) {
525:                this .testAfterUse = testAfterUse;
526:            }
527:
528:            /**
529:             * Set any property that should be handed to the delegate driver.
530:             * E.g. <code>foo=1,bar=true</code>
531:             * @param properties a comma delimited list of name=value pairs
532:             * @see ConnectionPoolDefinitionIF#getDelegateProperties()
533:             */
534:            public void setDelegateProperties(String properties) {
535:                StringTokenizer stOuter = new StringTokenizer(properties, ",");
536:                while (stOuter.hasMoreTokens()) {
537:                    StringTokenizer stInner = new StringTokenizer(stOuter
538:                            .nextToken(), "=");
539:                    if (stInner.countTokens() != 2) {
540:                        throw new IllegalArgumentException(
541:                                "Unexpected delegateProperties value: '"
542:                                        + properties
543:                                        + "'. Expected 'name=value'");
544:                    }
545:                    delegateProperties.put(stInner.nextToken().trim(), stInner
546:                            .nextToken().trim());
547:                }
548:            }
549:
550:            private void populatePropertiesFromReference(Reference reference) {
551:                RefAddr property = reference
552:                        .get(ProxoolConstants.ALIAS_PROPERTY);
553:                if (property != null) {
554:                    setAlias(property.getContent().toString());
555:                }
556:                property = reference
557:                        .get(ProxoolConstants.DRIVER_CLASS_PROPERTY);
558:                if (property != null) {
559:                    setDriver(property.getContent().toString());
560:                }
561:                property = reference
562:                        .get(ProxoolConstants.FATAL_SQL_EXCEPTION_WRAPPER_CLASS_PROPERTY);
563:                if (property != null) {
564:                    setFatalSqlExceptionWrapperClass(property.getContent()
565:                            .toString());
566:                }
567:                property = reference
568:                        .get(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY);
569:                if (property != null) {
570:                    setHouseKeepingSleepTime(Integer.valueOf(
571:                            property.getContent().toString()).intValue());
572:                }
573:                property = reference
574:                        .get(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY);
575:                if (property != null) {
576:                    setHouseKeepingTestSql(property.getContent().toString());
577:                }
578:                property = reference
579:                        .get(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY);
580:                if (property != null) {
581:                    setMaximumConnectionCount(Integer.valueOf(
582:                            property.getContent().toString()).intValue());
583:                }
584:                property = reference
585:                        .get(ProxoolConstants.MAXIMUM_CONNECTION_LIFETIME_PROPERTY);
586:                if (property != null) {
587:                    setMaximumConnectionLifetime(Integer.valueOf(
588:                            property.getContent().toString()).intValue());
589:                }
590:                property = reference
591:                        .get(ProxoolConstants.MAXIMUM_ACTIVE_TIME_PROPERTY);
592:                if (property != null) {
593:                    setMaximumActiveTime(Integer.valueOf(
594:                            property.getContent().toString()).intValue());
595:                }
596:                property = reference
597:                        .get(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY);
598:                if (property != null) {
599:                    setMinimumConnectionCount(Integer.valueOf(
600:                            property.getContent().toString()).intValue());
601:                }
602:                property = reference
603:                        .get(ProxoolConstants.OVERLOAD_WITHOUT_REFUSAL_LIFETIME_PROPERTY);
604:                if (property != null) {
605:                    setOverloadWithoutRefusalLifetime(Integer.valueOf(
606:                            property.getContent().toString()).intValue());
607:                }
608:                property = reference.get(ProxoolConstants.PASSWORD_PROPERTY);
609:                if (property != null) {
610:                    setPassword(property.getContent().toString());
611:                }
612:                property = reference
613:                        .get(ProxoolConstants.PROTOTYPE_COUNT_PROPERTY);
614:                if (property != null) {
615:                    setPrototypeCount(Integer.valueOf(
616:                            property.getContent().toString()).intValue());
617:                }
618:                property = reference
619:                        .get(ProxoolConstants.RECENTLY_STARTED_THRESHOLD_PROPERTY);
620:                if (property != null) {
621:                    setRecentlyStartedThreshold(Integer.valueOf(
622:                            property.getContent().toString()).intValue());
623:                }
624:                property = reference
625:                        .get(ProxoolConstants.SIMULTANEOUS_BUILD_THROTTLE_PROPERTY);
626:                if (property != null) {
627:                    setSimultaneousBuildThrottle(Integer.valueOf(
628:                            property.getContent().toString()).intValue());
629:                }
630:                property = reference.get(ProxoolConstants.STATISTICS_PROPERTY);
631:                if (property != null) {
632:                    setStatistics(property.getContent().toString());
633:                }
634:                property = reference
635:                        .get(ProxoolConstants.STATISTICS_LOG_LEVEL_PROPERTY);
636:                if (property != null) {
637:                    setStatisticsLogLevel(property.getContent().toString());
638:                }
639:                property = reference.get(ProxoolConstants.TRACE_PROPERTY);
640:                if (property != null) {
641:                    setTrace("true".equalsIgnoreCase(property.getContent()
642:                            .toString()));
643:                }
644:                property = reference.get(ProxoolConstants.DRIVER_URL_PROPERTY);
645:                if (property != null) {
646:                    setDriverUrl(property.getContent().toString());
647:                }
648:                property = reference.get(ProxoolConstants.USER_PROPERTY);
649:                if (property != null) {
650:                    setUser(property.getContent().toString());
651:                }
652:                property = reference.get(ProxoolConstants.VERBOSE_PROPERTY);
653:                if (property != null) {
654:                    setVerbose("true".equalsIgnoreCase(property.getContent()
655:                            .toString()));
656:                }
657:                property = reference.get(ProxoolConstants.JMX_PROPERTY);
658:                if (property != null) {
659:                    setJmx("true".equalsIgnoreCase(property.getContent()
660:                            .toString()));
661:                }
662:                property = reference.get(ProxoolConstants.JMX_AGENT_PROPERTY);
663:                if (property != null) {
664:                    setJmxAgentId(property.getContent().toString());
665:                }
666:                property = reference
667:                        .get(ProxoolConstants.TEST_BEFORE_USE_PROPERTY);
668:                if (property != null) {
669:                    setTestBeforeUse("true".equalsIgnoreCase(property
670:                            .getContent().toString()));
671:                }
672:                property = reference
673:                        .get(ProxoolConstants.TEST_AFTER_USE_PROPERTY);
674:                if (property != null) {
675:                    setTestAfterUse("true".equalsIgnoreCase(property
676:                            .getContent().toString()));
677:                }
678:                // Pick up any properties that we don't recognise
679:                Enumeration e = reference.getAll();
680:                while (e.hasMoreElements()) {
681:                    StringRefAddr stringRefAddr = (StringRefAddr) e
682:                            .nextElement();
683:                    String name = stringRefAddr.getType();
684:                    String content = stringRefAddr.getContent().toString();
685:                    if (name.indexOf(ProxoolConstants.PROPERTY_PREFIX) != 0) {
686:                        delegateProperties.put(name, content);
687:                    }
688:                }
689:            }
690:
691:            /**
692:             * Reset all properties to their default values
693:             */
694:            private void reset() {
695:                driverUrl = null;
696:                driver = null;
697:                maximumConnectionLifetime = ConnectionPoolDefinitionIF.DEFAULT_MAXIMUM_CONNECTION_LIFETIME;
698:                prototypeCount = ConnectionPoolDefinitionIF.DEFAULT_PROTOTYPE_COUNT;
699:                minimumConnectionCount = ConnectionPoolDefinitionIF.DEFAULT_MINIMUM_CONNECTION_COUNT;
700:                maximumConnectionCount = ConnectionPoolDefinitionIF.DEFAULT_MAXIMUM_CONNECTION_COUNT;
701:                houseKeepingSleepTime = ConnectionPoolDefinitionIF.DEFAULT_HOUSE_KEEPING_SLEEP_TIME;
702:                houseKeepingTestSql = null;
703:                simultaneousBuildThrottle = ConnectionPoolDefinitionIF.DEFAULT_SIMULTANEOUS_BUILD_THROTTLE;
704:                recentlyStartedThreshold = ConnectionPoolDefinitionIF.DEFAULT_RECENTLY_STARTED_THRESHOLD;
705:                overloadWithoutRefusalLifetime = ConnectionPoolDefinitionIF.DEFAULT_OVERLOAD_WITHOUT_REFUSAL_THRESHOLD;
706:                maximumActiveTime = ConnectionPoolDefinitionIF.DEFAULT_MAXIMUM_ACTIVE_TIME;
707:                verbose = false;
708:                trace = false;
709:                statistics = null;
710:                statisticsLogLevel = null;
711:                delegateProperties.clear();
712:            }
713:
714:            public PrintWriter getLogWriter() throws SQLException {
715:                return this .logWriter;
716:            }
717:
718:            public int getLoginTimeout() throws SQLException {
719:                return this .loginTimeout;
720:            }
721:
722:            public void setLogWriter(PrintWriter logWriter) throws SQLException {
723:                this .logWriter = logWriter;
724:            }
725:
726:            public void setLoginTimeout(int loginTimeout) throws SQLException {
727:                this .loginTimeout = loginTimeout;
728:            }
729:
730:            public Connection getConnection(String s, String s1)
731:                    throws SQLException {
732:                throw new UnsupportedOperationException(
733:                        "You should configure the username and password "
734:                                + "within the proxool configuration and just call getConnection() instead.");
735:            }
736:        }
737:
738:        /*
739:         Revision history:
740:         $Log: ProxoolDataSource.java,v $
741:         Revision 1.7  2006/05/23 21:17:55  billhorsman
742:         Add in maximum-active-time. Credit to Paolo Di Tommaso.
743:
744:         Revision 1.6  2006/03/23 11:51:23  billhorsman
745:         Allow for delegate properties
746:
747:         Revision 1.5  2006/01/18 14:40:01  billhorsman
748:         Unbundled Jakarta's Commons Logging.
749:
750:         Revision 1.4  2004/08/19 12:28:28  chr32
751:         Removed factory type test.
752:
753:         Revision 1.3  2004/03/18 17:16:58  chr32
754:         Added a timy bit of doc.
755:
756:         Revision 1.2  2004/03/18 17:07:25  chr32
757:         Now supports all three modes: pre-configured, bean-configured and factory-configured.
758:
759:         Revision 1.1  2004/03/15 23:54:25  chr32
760:         Initail Proxool J2EE-managed DataSource. Not quite complete yet.
761:
762:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.