Source Code Cross Referenced for DBMM.java in  » Database-ORM » Torque » org » apache » torque » adapter » 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 » Torque » org.apache.torque.adapter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.torque.adapter;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.sql.Connection;
023:        import java.sql.SQLException;
024:        import java.sql.Statement;
025:        import java.util.Date;
026:        import java.text.SimpleDateFormat;
027:
028:        import org.apache.torque.util.Query;
029:
030:        /**
031:         * This is used in order to connect to a MySQL database using the MM
032:         * drivers.  Simply comment the above and uncomment this code below and
033:         * fill in the appropriate values for DB_NAME, DB_HOST, DB_USER,
034:         * DB_PASS.
035:         *
036:         * <P><a href="http://www.mysql.com/">http://www.mysql.com/</a>
037:         * <p>"jdbc:mysql://" + DB_HOST + "/" + DB_NAME + "?user=" +
038:         * DB_USER + "&password=" + DB_PASS;
039:         *
040:         * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
041:         * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
042:         * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
043:         * @version $Id: DBMM.java 522044 2007-03-24 16:00:57Z tfischer $
044:         */
045:        public class DBMM extends AbstractDBAdapter {
046:            /**
047:             * Serial version
048:             */
049:            private static final long serialVersionUID = 7547291410802807010L;
050:
051:            /** A specialized date format for MySQL. */
052:            private static final String DATE_FORMAT = "yyyyMMddHHmmss";
053:
054:            /**
055:             * Empty protected constructor.
056:             */
057:            protected DBMM() {
058:            }
059:
060:            /**
061:             * This method is used to ignore case.
062:             *
063:             * @param in The string to transform to upper case.
064:             * @return The upper case string.
065:             */
066:            public String toUpperCase(String in) {
067:                return in;
068:            }
069:
070:            /**
071:             * This method is used to ignore case.
072:             *
073:             * @param in The string whose case to ignore.
074:             * @return The string in a case that can be ignored.
075:             */
076:            public String ignoreCase(String in) {
077:                return in;
078:            }
079:
080:            /**
081:             * @see org.apache.torque.adapter.DB#getIDMethodType()
082:             */
083:            public String getIDMethodType() {
084:                return AUTO_INCREMENT;
085:            }
086:
087:            /**
088:             * Returns the SQL to get the database key of the last row
089:             * inserted, which in this case is <code>SELECT
090:             * LAST_INSERT_ID()</code>.
091:             *
092:             * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
093:             */
094:            public String getIDMethodSQL(Object obj) {
095:                return "SELECT LAST_INSERT_ID()";
096:            }
097:
098:            /**
099:             * Locks the specified table.
100:             *
101:             * @param con The JDBC connection to use.
102:             * @param table The name of the table to lock.
103:             * @exception SQLException No Statement could be created or
104:             * executed.
105:             */
106:            public void lockTable(Connection con, String table)
107:                    throws SQLException {
108:                Statement statement = con.createStatement();
109:                StringBuffer stmt = new StringBuffer();
110:                stmt.append("LOCK TABLE ").append(table).append(" WRITE");
111:                statement.executeUpdate(stmt.toString());
112:            }
113:
114:            /**
115:             * Unlocks the specified table.
116:             *
117:             * @param con The JDBC connection to use.
118:             * @param table The name of the table to unlock.
119:             * @exception SQLException No Statement could be created or
120:             * executed.
121:             */
122:            public void unlockTable(Connection con, String table)
123:                    throws SQLException {
124:                Statement statement = con.createStatement();
125:                statement.executeUpdate("UNLOCK TABLES");
126:            }
127:
128:            /**
129:             * Generate a LIMIT offset, limit clause if offset &gt; 0
130:             * or an LIMIT limit clause if limit is &gt; 0 and offset
131:             * is 0.
132:             *
133:             * @param query The query to modify
134:             * @param offset the offset Value
135:             * @param limit the limit Value
136:             */
137:            public void generateLimits(Query query, int offset, int limit) {
138:                if (offset > 0) {
139:                    if (limit >= 0) {
140:                        query.setLimit(Integer.toString(limit));
141:                    } else {
142:                        // Limit must always be set in mysql if offset is set
143:                        query.setLimit("18446744073709551615");
144:                    }
145:                    query.setOffset(Integer.toString(offset));
146:                } else {
147:                    if (limit >= 0) {
148:                        query.setLimit(Integer.toString(limit));
149:                    }
150:                }
151:
152:                query.setPreLimit(null);
153:                query.setPostLimit(null);
154:            }
155:
156:            /**
157:             * This method is used to chek whether the database supports
158:             * limiting the size of the resultset.
159:             *
160:             * @return LIMIT_STYLE_MYSQL.
161:             * @deprecated This should not be exposed to the outside
162:             */
163:            public int getLimitStyle() {
164:                return DB.LIMIT_STYLE_MYSQL;
165:            }
166:
167:            /**
168:             * Return true for MySQL
169:             * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit()
170:             */
171:            public boolean supportsNativeLimit() {
172:                return true;
173:            }
174:
175:            /**
176:             * Return true for MySQL
177:             * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeOffset()
178:             */
179:            public boolean supportsNativeOffset() {
180:                return true;
181:            }
182:
183:            /**
184:             * This method overrides the JDBC escapes used to format dates
185:             * using a <code>DateFormat</code>.  As of version 2.0.11, the MM
186:             * JDBC driver does not implement JDBC 3.0 escapes.
187:             *
188:             * @param date the date to format
189:             * @return The properly formatted date String.
190:             */
191:            public String getDateString(Date date) {
192:                char delim = getStringDelimiter();
193:                return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim);
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.