Source Code Cross Referenced for AbstractEsqlConnection.java in  » Web-Framework » cocoon » org » apache » cocoon » components » language » markup » xsp » 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 » Web Framework » cocoon » org.apache.cocoon.components.language.markup.xsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.components.language.markup.xsp;
018:
019:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
020:        import org.apache.commons.lang.BooleanUtils;
021:
022:        import java.sql.Connection;
023:        import java.util.Properties;
024:        import java.sql.SQLException;
025:        import java.sql.DatabaseMetaData;
026:
027:        /**
028:         * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
029:         * @version CVS $Id: AbstractEsqlConnection.java 433543 2006-08-22 06:22:54Z crossley $
030:         */
031:        public abstract class AbstractEsqlConnection extends AbstractLogEnabled {
032:
033:            private String url = null;
034:            private Properties properties = null;
035:            private boolean multipleResults = false;
036:
037:            protected AbstractEsqlConnection() {
038:            }
039:
040:            protected abstract Connection getConnection() throws SQLException;
041:
042:            /**
043:             * It appears that some commercial DBMSs like Oracle and Informix
044:             * are broken in that they don't follow the JDBC standard and
045:             * calls to getUpdateCount after getMoreResults result either in
046:             * an exception (Informix) or return the same value (i.e. not -1) (Oracle).
047:             * In addition, this feature is only useful with stored procedures.
048:             * Hence we disable it per default.
049:             **/
050:            public void setMultipleResults(String value) {
051:                this .multipleResults = BooleanUtils.toBoolean(value);
052:            }
053:
054:            public boolean getMultipleResults() {
055:                return (this .multipleResults);
056:            }
057:
058:            public Properties getProperties() {
059:                return (properties);
060:            }
061:
062:            public void setProperty(final String name, final Object value) {
063:                if (properties == null)
064:                    properties = new Properties();
065:                properties.put(name, value);
066:            }
067:
068:            public void setUser(String user) {
069:                setProperty("user", user);
070:            }
071:
072:            public void setPassword(String password) {
073:                setProperty("password", password);
074:            }
075:
076:            public void setAutoCommit(final boolean autocommit)
077:                    throws SQLException {
078:                getConnection().setAutoCommit(autocommit);
079:            }
080:
081:            public boolean getAutoCommit() throws SQLException {
082:                return (getConnection().getAutoCommit());
083:            }
084:
085:            public String getURL() throws SQLException {
086:                if (this .url == null) {
087:                    this .url = getConnection().getMetaData().getURL();
088:                }
089:                return (this .url);
090:            }
091:
092:            public void setURL(final String url) {
093:                this .url = url;
094:            }
095:
096:            public DatabaseMetaData getMetaData() throws SQLException {
097:                return (getConnection().getMetaData());
098:            }
099:
100:            public void commit() throws SQLException {
101:                getConnection().commit();
102:            }
103:
104:            public void rollback() throws SQLException {
105:                getConnection().rollback();
106:            }
107:
108:            public void close() throws SQLException {
109:                getConnection().close();
110:            }
111:
112:            /**
113:             * Factory method for creating an EsqlQuery object. If type is set to
114:             * "" or "auto" it will try to find type from the JDBC connection URL.
115:             * If this does not succeed the generic JDBC type will be assumed.
116:             * (This type does not work for some databases like mssql though)
117:             *
118:             * @param type {sybase|postgresql|mysql|oracle|jdbc}
119:             * @param queryString
120:             * @return implementation of the AbstractEsqlQuery
121:             * @throws SQLException
122:             */
123:            public AbstractEsqlQuery createQuery(final String type,
124:                    final String queryString) throws SQLException {
125:                AbstractEsqlQuery query;
126:
127:                Connection connection = getConnection();
128:
129:                if ("".equals(type) || "auto".equalsIgnoreCase(type)) {
130:                    String database = connection.getMetaData()
131:                            .getDatabaseProductName().toLowerCase();
132:
133:                    if (database.indexOf("postgresql") > -1) {
134:                        query = new PostgresEsqlQuery(connection, queryString);
135:                    } else if (database.indexOf("mysql") > -1) {
136:                        query = new MysqlEsqlQuery(connection, queryString);
137:                    } else if (database.indexOf("adaptive server anywhere") > -1
138:                            || database.indexOf("microsoft sql server") > -1) {
139:                        query = new SybaseEsqlQuery(connection, queryString);
140:                    } else if (database.indexOf("oracle") > -1) {
141:                        query = new OracleEsqlQuery(connection, queryString);
142:                    } else if (database.indexOf("pervasive") > -1) {
143:                        query = new PervasiveEsqlQuery(connection, queryString);
144:                    } else if (database.indexOf("hsql") > -1
145:                            || database.indexOf("interbase") > -1
146:                            || database.indexOf("access") > -1
147:                            || database.indexOf("ingres") > -1
148:                            || database.indexOf("sap db") > -1
149:                            || database.indexOf("firebird") > -1
150:                            || database.indexOf("informix-online") > -1
151:                            || database.indexOf("sybase sql server") > -1) {
152:                        query = new JdbcEsqlQuery(getConnection(), queryString);
153:                    } else {
154:                        getLogger()
155:                                .warn(
156:                                        "Your database ["
157:                                                + String.valueOf(database)
158:                                                + "] is not being recognized yet."
159:                                                + " Using the generic [jdbc] query as default. "
160:                                                + " Please report this to dev@cocoon.apache.org");
161:
162:                        query = new JdbcEsqlQuery(getConnection(), queryString);
163:                    }
164:                } else if ("sybase".equalsIgnoreCase(type)) {
165:                    query = new SybaseEsqlQuery(connection, queryString);
166:                } else if ("postgresql".equalsIgnoreCase(type)) {
167:                    query = new PostgresEsqlQuery(connection, queryString);
168:                } else if ("postgresql-old".equalsIgnoreCase(type)) {
169:                    query = new PostgresOldEsqlQuery(connection, queryString);
170:                } else if ("mysql".equalsIgnoreCase(type)) {
171:                    query = new MysqlEsqlQuery(connection, queryString);
172:                } else if ("oracle".equalsIgnoreCase(type)) {
173:                    query = new OracleEsqlQuery(connection, queryString);
174:                } else if ("pervasive".equalsIgnoreCase(type)) {
175:                    query = new PervasiveEsqlQuery(connection, queryString);
176:                } else if ("jdbc".equalsIgnoreCase(type)) {
177:                    query = new JdbcEsqlQuery(connection, queryString);
178:                } else {
179:                    getLogger().error(
180:                            "Unknown database type: " + String.valueOf(type));
181:                    throw new SQLException("Unknown database type: "
182:                            + String.valueOf(type));
183:                }
184:                setupLogger(query);
185:                return (query);
186:            }
187:        }
ww__w._j_a___v___a_2___s___._c__o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.