Source Code Cross Referenced for PentahoConnectionFactory.java in  » Report » pentaho-report » org » pentaho » data » 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 » Report » pentaho report » org.pentaho.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * Created Aug 29, 2005 
014:         * @author wseyler
015:         */
016:
017:        package org.pentaho.data;
018:
019:        import java.lang.reflect.Constructor;
020:        import java.util.Properties;
021:
022:        import org.pentaho.commons.connection.IPentahoConnection;
023:        import org.pentaho.core.system.PentahoSystem;
024:        import org.pentaho.data.connection.mdx.MDXConnection;
025:        import org.pentaho.data.connection.sql.SQLConnection;
026:        import org.pentaho.data.connection.xquery.XQConnection;
027:        import org.pentaho.messages.Messages;
028:        import org.pentaho.util.logging.ILogger;
029:        import org.pentaho.util.logging.Logger;
030:
031:        /**
032:         * @author wseyler
033:         * 
034:         * TODO To change the template for this generated type comment go to Window -
035:         * Preferences - Java - Code Style - Code Templates
036:         */
037:        public class PentahoConnectionFactory {
038:
039:            /**
040:             * @param datasourceType
041:             *            valid type is defined as SQL_DATASOURCE or MDX_DATASOURCE
042:             * @param connectStr -
043:             *            In the case of SQL_DATASOURCE, the name of the JNDI connection
044:             *            to use. Or in the case of MDX_DATASOURCE a properly formatted
045:             *            connection String.
046:             * @return a connection object that can be queried against.
047:             */
048:            public static IPentahoConnection getConnection(int datasourceType,
049:                    String connectStr, ILogger logger) {
050:                /*
051:                 * TODO - This is where the "connection factory" action occurs. Based on
052:                 * if the datasourceType, location, username, or password have changed
053:                 * then we create a new one.
054:                 */
055:                switch (datasourceType) {
056:                case IPentahoConnection.SQL_DATASOURCE:
057:                    return new SQLConnection(connectStr, logger);
058:                case IPentahoConnection.MDX_DATASOURCE:
059:                    return new MDXConnection(connectStr, logger);
060:                default:
061:                    return null;
062:                }
063:            }
064:
065:            public static IPentahoConnection getConnection(String propName,
066:                    ILogger logger) {
067:                IPentahoConnection connection = null;
068:
069:                String baseNode = "objects/" + propName; //$NON-NLS-1$
070:                Properties props = getProperties(baseNode);
071:
072:                String className = props.getProperty(
073:                        IPentahoConnection.CLASSNAME_KEY, null);
074:                if (className == null) {
075:                    if (logger != null) {
076:                        logger
077:                                .error(Messages
078:                                        .getErrorString(
079:                                                "CONNECTFACTORY.ERROR_0001_NOT_DEFINED", propName)); //$NON-NLS-1$
080:                    } else {
081:                        Logger
082:                                .error(
083:                                        PentahoConnectionFactory.class
084:                                                .getName(),
085:                                        Messages
086:                                                .getErrorString(
087:                                                        "CONNECTFACTORY.ERROR_0001_NOT_DEFINED", propName)); //$NON-NLS-1$
088:                    }
089:                    return null;
090:                }
091:                try {
092:                    Class connectionClass = Class.forName(className);
093:                    Class[] argTypes = new Class[] { Properties.class,
094:                            ILogger.class };
095:                    Object[] args = new Object[] { props, logger };
096:                    Constructor constructor = connectionClass
097:                            .getConstructor(argTypes);
098:                    connection = (IPentahoConnection) constructor
099:                            .newInstance(args);
100:                } catch (Exception e) {
101:                    if (logger != null) {
102:                        logger.error(e.getLocalizedMessage(), e);
103:                    } else {
104:                        Logger.error(PentahoConnectionFactory.class.getName(),
105:                                e.getLocalizedMessage(), e);
106:                    }
107:                }
108:
109:                return connection;
110:            }
111:
112:            private static Properties getProperties(String baseNode) {
113:                Properties props = new Properties();
114:                for (int i = 0; i < IPentahoConnection.KEYS.length; i++) {
115:                    String key = baseNode + "/" + IPentahoConnection.KEYS[i]; //$NON-NLS-1$
116:                    Object value = PentahoSystem.getSystemSetting(key, null);
117:                    if (value != null) {
118:                        props.put(IPentahoConnection.KEYS[i], value);
119:                    }
120:                }
121:                return props;
122:            }
123:
124:            /**
125:             * @param datasourceType
126:             *            valid types are defined as SQL_DATASOURCE, MDX_DATASOURCE and
127:             *            XML_DATASOURCE
128:             * @param location -
129:             *            A string specfic to the location and type of datasource. For
130:             *            an SQL instance it would be the URL string required by the
131:             *            implementing driver.
132:             * @param userName
133:             * @param password
134:             * @return a connection object that can be queried against.
135:             */
136:            public static IPentahoConnection getConnection(int datasourceType,
137:                    String driver, String location, String userName,
138:                    String password, ILogger logger) {
139:                /*
140:                 * TODO - This is where the "connection factory" action occurs. Based on
141:                 * if the datasourceType, location, username, or password have changed
142:                 * then we create a new one.
143:                 */
144:                switch (datasourceType) {
145:                case IPentahoConnection.SQL_DATASOURCE: {
146:                    SQLConnection connection = new SQLConnection(driver,
147:                            location, userName, password, logger);
148:                    if (connection.initialized()) {
149:                        return connection;
150:                    } else {
151:                        return null;
152:                    }
153:                }
154:                case IPentahoConnection.MDX_DATASOURCE:
155:                    return new MDXConnection(driver, location, userName,
156:                            password);
157:                case IPentahoConnection.XML_DATASOURCE:
158:                    return new XQConnection(logger);
159:                default:
160:                    return null;
161:                }
162:            }
163:
164:            public static IPentahoConnection getConnection(int datasourceType,
165:                    ILogger logger) {
166:                switch (datasourceType) {
167:                case IPentahoConnection.XML_DATASOURCE:
168:                    return new XQConnection(logger);
169:                default:
170:                    return null;
171:                }
172:            }
173:
174:            public static IPentahoConnection getConnection(int datasourceType,
175:                    Properties mdxConnectionProps, ILogger logger) {
176:                switch (datasourceType) {
177:                case IPentahoConnection.MDX_DATASOURCE:
178:                    return new MDXConnection(mdxConnectionProps, logger);
179:                default:
180:                    return null;
181:                }
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.