Source Code Cross Referenced for DBSybase.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.text.SimpleDateFormat;
026:        import java.util.Date;
027:
028:        import org.apache.torque.TorqueException;
029:        import org.apache.torque.util.Criteria;
030:        import org.apache.torque.util.Query;
031:        import org.apache.torque.util.SqlExpression;
032:
033:        /**
034:         * This is used to connect to a Sybase database using Sybase's
035:         * JConnect JDBC driver.
036:         *
037:         * <B>NOTE:</B><I>Currently JConnect does not implement the required
038:         * methods for ResultSetMetaData, and therefore the village API's may
039:         * not function.  For connection pooling, everything works.</I>
040:         *
041:         * @author <a href="mailto:ekkerbj@netscape.net">Jeff Brekke</a>
042:         * @version $Id: DBSybase.java 586553 2007-10-19 17:33:53Z gmonroe $
043:         */
044:        public class DBSybase extends AbstractDBAdapter {
045:            /**
046:             * Serial version
047:             */
048:            private static final long serialVersionUID = 4782996646843056810L;
049:
050:            /** date format */
051:            private static final String DATE_FORMAT = "yyyyMMdd HH:mm:ss";
052:
053:            /**
054:             * Empty constructor.
055:             */
056:            protected DBSybase() {
057:            }
058:
059:            /**
060:             * This method is used to ignore case.
061:             *
062:             * @param in The string to transform to upper case.
063:             * @return The upper case string.
064:             */
065:            public String toUpperCase(String in) {
066:                return new StringBuffer("UPPER(").append(in).append(")")
067:                        .toString();
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 new StringBuffer("UPPER(").append(in).append(")")
078:                        .toString();
079:            }
080:
081:            /**
082:             * @see org.apache.torque.adapter.DB#getIDMethodType()
083:             */
084:            public String getIDMethodType() {
085:                return AUTO_INCREMENT;
086:            }
087:
088:            /**
089:             * Returns the last value from an identity column (available on a
090:             * per-session basis from the global variable
091:             * <code>@@identity</code>).
092:             *
093:             * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
094:             */
095:            public String getIDMethodSQL(Object unused) {
096:                return "select @@identity";
097:            }
098:
099:            /**
100:             * Locks the specified table.
101:             *
102:             * @param con The JDBC connection to use.
103:             * @param table The name of the table to lock.
104:             * @throws SQLException No Statement could be created or executed.
105:             */
106:            public void lockTable(Connection con, String table)
107:                    throws SQLException {
108:                Statement statement = con.createStatement();
109:
110:                StringBuffer stmt = new StringBuffer();
111:                stmt.append("SELECT next_id FROM ").append(table).append(
112:                        " FOR UPDATE");
113:
114:                statement.executeQuery(stmt.toString());
115:            }
116:
117:            /**
118:             * Unlocks the specified table.
119:             *
120:             * @param con The JDBC connection to use.
121:             * @param table The name of the table to unlock.
122:             * @throws SQLException No Statement could be created or executed.
123:             */
124:            public void unlockTable(Connection con, String table)
125:                    throws SQLException {
126:                // Tables in Sybase are unlocked when a commit is issued.  The
127:                // user may have issued a commit but do it here to be sure.
128:                con.commit();
129:            }
130:
131:            /**
132:             * This method is used to chek whether the database supports
133:             * limiting the size of the resultset.
134:             *
135:             * @return LIMIT_STYLE_SYBASE.
136:             * @deprecated This should not be exposed to the outside
137:             */
138:            public int getLimitStyle() {
139:                return DB.LIMIT_STYLE_SYBASE;
140:            }
141:
142:            /**
143:             * Return true for Sybase
144:             * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit()
145:             */
146:            public boolean supportsNativeLimit() {
147:                return true;
148:            }
149:
150:            /**
151:             * Modify a query to add limit and offset values for Sybase.
152:             *
153:             * @param query The query to modify
154:             * @param offset the offset Value
155:             * @param limit the limit Value
156:             *
157:             * @throws TorqueException if any error occurs when building the query
158:             */
159:            public void generateLimits(Query query, int offset, int limit)
160:                    throws TorqueException {
161:                if (limit < 0 && offset >= 0) // Offset only test
162:                {
163:                    return;
164:                }
165:                if (limit + offset > 0) {
166:                    query.setRowcount(String.valueOf(limit + offset));
167:                } else if (limit + offset == 0) {
168:                    // This is necessary to create the empty result set that Torque expects
169:                    query.getWhereClause().add(
170:                            SqlExpression.build("1", new Integer(0),
171:                                    Criteria.EQUAL));
172:                }
173:            }
174:
175:            /**
176:             * This method overrides the JDBC escapes used to format dates
177:             * using a <code>DateFormat</code>.  As of version 11, the Sybase
178:             * JDBC driver does not implement JDBC 3.0 escapes.
179:             *
180:             * @param date the date to format
181:             * @return The properly formatted date String.
182:             */
183:            public String getDateString(Date date) {
184:                char delim = getStringDelimiter();
185:                return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim);
186:            }
187:
188:            /**
189:             * Determines whether backslashes (\) should be escaped in explicit SQL
190:             * strings. If true is returned, a BACKSLASH will be changed to "\\".
191:             * If false is returned, a BACKSLASH will be left as "\".
192:             *
193:             * Sybase (and MSSQL) doesn't define a default escape character,
194:             * so false is returned.
195:             *
196:             * @return false
197:             * @see org.apache.torque.adapter.DB#escapeText()
198:             */
199:            public boolean escapeText() {
200:                return false;
201:            }
202:
203:            /**
204:             * Whether an escape clause in like should be used.
205:             * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
206:             *
207:             * Sybase needs this, so this implementation always returns
208:             * <code>true</code>.
209:             *
210:             * @return whether the escape clause should be appended or not.
211:             */
212:            public boolean useEscapeClauseForLike() {
213:                return true;
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.