Source Code Cross Referenced for SDataSource.java in  » Database-ORM » SimpleORM » simpleorm » core » 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 ORM » SimpleORM » simpleorm.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package simpleorm.core;
002:
003:        import java.sql.Connection;
004:        import java.util.*;
005:        import java.io.File;
006:        import java.io.FileInputStream;
007:        import java.io.PrintStream;
008:
009:        /**
010:         * Provides a source of JDBC connections.  It has been introduced 
011:         * because some key generation 
012:         * algorithms require the creation of separate connections to create the
013:         * actual key value.  So just passing a single jdbc connection object into 
014:         * SConnection.attach is not sufficient.<p>
015:         *
016:         * If no connection pooling is used then just do:-
017:         * <pre> 
018:         * Class.forName(dbDriver);
019:         * SDataSource ds = new SDataSource(dburl, dbUserName, dbPassword);
020:         * // ds.setSDriverName("..."); to use a non-default driver
021:         * SConnection.attach(ds, "TestCon");
022:         * </pre>
023:         * 
024:         * attach calls openDBConnection which simply calls
025:         * <code>java.sql.DriverManager.getConnection(url, jdbcProperties)</code><p>
026:         * 
027:         * It is intended that this class can be subclassed, especially to enable
028:         * connection pooling.  It does not directly implement javax.sql.DataSource 
029:         * to avoid dependencies on Java 1.4 and EJBs.<p> 
030:         * 
031:         * @see SDataSourceJavaX is normally used for connection pooling.
032:         * 
033:         */
034:        public class SDataSource {
035:
036:            String url;
037:            Properties jdbcProperties;
038:
039:            /**
040:             * Constructor used to provide connections expicitly.
041:             * Normally SConfiguration.Default is used instead.
042:             * secondary is only required for certain key generation algorithms.
043:             * driverName normally null, in which case a default will be inferred from the Connection.
044:             * Note that this means that a new configuration is needed each time ###.
045:             */
046:            public SDataSource(String url, Properties props) {
047:                this .url = url;
048:                jdbcProperties = props;
049:            }
050:
051:            public SDataSource(String url) {
052:                this .url = url;
053:            }
054:
055:            public SDataSource(String url, String username, String password) {
056:                this .url = url;
057:                setUsername(username);
058:                setPassword(password);
059:            }
060:
061:            public SDataSource() {
062:            }
063:
064:            public Properties getJdbcProperties() {
065:                return jdbcProperties;
066:            }
067:
068:            public void setJdbcProperties(Properties jdbcProperties) {
069:                this .jdbcProperties = jdbcProperties;
070:            }
071:
072:            public String getUrl() {
073:                return url;
074:            }
075:
076:            public void setUrl(String url) {
077:                this .url = url;
078:            }
079:
080:            /** Sets "user" property.  Creates new Properties if ncessary.*/
081:            public void setUsername(String username) {
082:                if (jdbcProperties == null)
083:                    jdbcProperties = new Properties();
084:                jdbcProperties.put("user", username);
085:            }
086:
087:            /** Sets "password" property. Creates new Properties if ncessary.*/
088:            public void setPassword(String password) {
089:                if (jdbcProperties == null)
090:                    jdbcProperties = new Properties();
091:                jdbcProperties.put("password", password);
092:            }
093:
094:            /**
095:             * The main connection used by SimpleORM.
096:             * (Some applications might just provide an explicit connection to SConnection.attach
097:             * in which case this is never called.)
098:             */
099:            protected Connection openPrimaryDBConnection() {
100:                return openDBConnection();
101:            }
102:
103:            /**
104:             * Secondary connection(s) are mainly used for generating primary keys
105:             * using some table based algorithms.  
106:             */
107:            protected Connection openSecondaryDBConnection() {
108:                return openDBConnection();
109:            }
110:
111:            /**
112:             * Called by obtainPrimary|SecondaryJDBCConnection
113:             */
114:            protected Connection openDBConnection() {
115:                Connection con;
116:                try {
117:                    con = java.sql.DriverManager.getConnection(url,
118:                            jdbcProperties);
119:                } catch (Exception ex) {
120:                    throw new SException.JDBC("Opening " + url, ex);
121:                }
122:                return con;
123:
124:            }
125:
126:            String sDriverName;
127:
128:            /**
129:             * An override for the name of the SDriver.  Normally this just
130:             * returns null and SDriver.getSDriver picks the 
131:             * SDriver based on the URL.
132:             */
133:            public String getSDriverName() {
134:                return sDriverName;
135:            }
136:
137:            public void setSDriverName(String driver) {
138:                sDriverName = driver;
139:            }
140:
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.