Source Code Cross Referenced for BasicDataSource.java in  » Testing » Ejb3Unit » com » bm » utils » 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 » Testing » Ejb3Unit » com.bm.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bm.utils;
002:
003:        import java.io.PrintWriter;
004:        import java.sql.Connection;
005:        import java.sql.DriverManager;
006:        import java.sql.PreparedStatement;
007:        import java.sql.SQLException;
008:
009:        import javax.sql.DataSource;
010:
011:        import com.bm.cfg.Ejb3UnitCfg;
012:
013:        /**
014:         * <p>
015:         * Basic implementation of <code>javax.sql.DataSource</code> that is
016:         * configured via Ejb3Prop properties.
017:         * 
018:         * @author Daniel Wiese
019:         */
020:        public class BasicDataSource implements  DataSource {
021:
022:            private final Ejb3UnitCfg config;
023:
024:            private PrintWriter logger = null;
025:
026:            private int loginTimeout = 0;
027:
028:            /**
029:             * Constructor.
030:             * 
031:             * @param config -
032:             *            die konfiguration.
033:             */
034:            public BasicDataSource(Ejb3UnitCfg config) {
035:                this .config = config;
036:            }
037:
038:            /**
039:             * The connection.
040:             * @author Daniel Wiese
041:             * @since 08.11.2005
042:             * @return connection
043:             * @see javax.sql.DataSource#getConnection()
044:             */
045:            public synchronized Connection getConnection() throws SQLException {
046:                if (Ejb3UnitCfg.getConfiguration().isInMemory()) {
047:                    return this .getConnection("sa", "");
048:                } else {
049:                    final String user = config
050:                            .getValue(Ejb3UnitCfg.KEY_CONNECTION_USERNAME);
051:                    final String pw = config
052:                            .getValue(Ejb3UnitCfg.KEY_CONNECTION_PASSWORD);
053:                    return this .getConnection(user, pw);
054:                }
055:            }
056:
057:            /**
058:             * {@inheritDoc}
059:             */
060:            public synchronized Connection getConnection(String username,
061:                    String password) throws SQLException {
062:                try {
063:                    if (Ejb3UnitCfg.getConfiguration().isInMemory()) {
064:                        Class.forName("org.hsqldb.jdbcDriver");
065:                        final Connection cn = DriverManager.getConnection(
066:                                "jdbc:hsqldb:mem:ejb3unit", username, password);
067:                        return cn;
068:                    } else {
069:                        Class
070:                                .forName(config
071:                                        .getValue(Ejb3UnitCfg.KEY_CONNECTION_DRIVER_CLASS));
072:                        final Connection cn = DriverManager
073:                                .getConnection(
074:                                        config
075:                                                .getValue(Ejb3UnitCfg.KEY_CONNECTION_URL),
076:                                        username, password);
077:                        return cn;
078:                    }
079:                } catch (ClassNotFoundException e) {
080:                    throw new RuntimeException(e);
081:                } catch (SQLException e) {
082:                    throw new RuntimeException(e);
083:                }
084:            }
085:
086:            /**
087:             * {@inheritDoc}
088:             */
089:            public PrintWriter getLogWriter() throws SQLException {
090:                return this .logger;
091:            }
092:
093:            /**
094:             * {@inheritDoc}
095:             */
096:            public void setLogWriter(PrintWriter logger) throws SQLException {
097:                this .logger = logger;
098:
099:            }
100:
101:            /**
102:             * {@inheritDoc}
103:             */
104:            public void setLoginTimeout(int arg0) throws SQLException {
105:                this .loginTimeout = arg0;
106:
107:            }
108:
109:            /**
110:             * {@inheritDoc}
111:             */
112:            public int getLoginTimeout() throws SQLException {
113:                return this .loginTimeout;
114:            }
115:
116:            /**
117:             * If the datasource is in memory this will shutdown the database.
118:             */
119:            public void shutdownInMemoryDatabase() throws Exception {
120:                Connection con = null;
121:                PreparedStatement ps = null;
122:                try {
123:                    con = this .getConnection();
124:                    ps = con.prepareStatement("SHUTDOWN");
125:                    ps.execute();
126:                } finally {
127:                    SQLUtils.cleanup(con, ps);
128:                }
129:            }
130:
131:            /**
132:             * Does not wrap anything.
133:             * @param forInterface for which interface
134:             * @return always false
135:             */
136:            public boolean isWrapperFor(Class<?> forInterface)
137:                    throws SQLException {
138:                return false;
139:            }
140:
141:            /**
142:             * {@inheritDoc}
143:             */
144:            public <T> T unwrap(Class<T> arg0) throws SQLException {
145:                return null;
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.