Source Code Cross Referenced for TestDerbyDialect.java in  » Database-JDBC-Connection-Pool » HA-JDBC » net » sf » hajdbc » dialect » 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 JDBC Connection Pool » HA JDBC » net.sf.hajdbc.dialect 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HA-JDBC: High-Availability JDBC
003:         * Copyright (c) 2004-2007 Paul Ferraro
004:         * 
005:         * This library is free software; you can redistribute it and/or modify it 
006:         * under the terms of the GNU Lesser General Public License as published by the 
007:         * Free Software Foundation; either version 2.1 of the License, or (at your 
008:         * option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful, but WITHOUT
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013:         * for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public License
016:         * along with this library; if not, write to the Free Software Foundation, 
017:         * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         * 
019:         * Contact: ferraro@users.sourceforge.net
020:         */
021:        package net.sf.hajdbc.dialect;
022:
023:        import java.sql.DatabaseMetaData;
024:        import java.sql.SQLException;
025:        import java.util.Collection;
026:
027:        import net.sf.hajdbc.ColumnProperties;
028:        import net.sf.hajdbc.Dialect;
029:        import net.sf.hajdbc.ForeignKeyConstraint;
030:        import net.sf.hajdbc.QualifiedName;
031:        import net.sf.hajdbc.SequenceProperties;
032:
033:        import org.easymock.EasyMock;
034:        import org.testng.annotations.DataProvider;
035:        import org.testng.annotations.Test;
036:
037:        /**
038:         * @author Paul Ferraro
039:         *
040:         */
041:        @SuppressWarnings("nls")
042:        public class TestDerbyDialect extends TestStandardDialect {
043:            @Override
044:            protected Dialect createDialect() {
045:                return new DerbyDialect();
046:            }
047:
048:            @Override
049:            @Test(dataProvider="foreign-key")
050:            public String getCreateForeignKeyConstraintSQL(
051:                    ForeignKeyConstraint constraint) throws SQLException {
052:                this .replay();
053:
054:                String sql = this .dialect
055:                        .getCreateForeignKeyConstraintSQL(constraint);
056:
057:                this .verify();
058:
059:                assert sql
060:                        .equals("ALTER TABLE table ADD CONSTRAINT name FOREIGN KEY (column1, column2) REFERENCES foreign_table (foreign_column1, foreign_column2) ON DELETE CASCADE ON UPDATE RESTRICT") : sql;
061:
062:                return sql;
063:            }
064:
065:            /*
066:             @Override
067:             @Test(dataProvider = "table")
068:             public String getLockTableSQL(TableProperties properties) throws SQLException
069:             {
070:             EasyMock.expect(properties.getName()).andReturn("table");
071:            
072:             this.replay();
073:            
074:             String sql = this.dialect.getLockTableSQL(properties);
075:            
076:             this.verify();
077:            
078:             assert sql.equals("LOCK TABLE table IN SHARE MODE") : sql;
079:            
080:             return sql;
081:             }
082:             */
083:            @Override
084:            @Test
085:            public String getSimpleSQL() throws SQLException {
086:                this .replay();
087:
088:                String sql = this .dialect.getSimpleSQL();
089:
090:                this .verify();
091:
092:                assert sql.equals("VALUES CURRENT_TIMESTAMP") : sql;
093:
094:                return sql;
095:            }
096:
097:            @Override
098:            @Test(dataProvider="sequence-sql")
099:            public String parseSequence(String sql) throws SQLException {
100:                this .replay();
101:
102:                String sequence = this .dialect.parseSequence(sql);
103:
104:                this .verify();
105:
106:                assert sequence == null : sequence;
107:
108:                return sequence;
109:            }
110:
111:            @Override
112:            @Test(dataProvider="meta-data")
113:            public Collection<QualifiedName> getSequences(
114:                    DatabaseMetaData metaData) throws SQLException {
115:                this .replay();
116:
117:                Collection<QualifiedName> sequences = this .dialect
118:                        .getSequences(metaData);
119:
120:                this .verify();
121:
122:                assert sequences.isEmpty() : sequences;
123:
124:                return sequences;
125:            }
126:
127:            @Override
128:            @Test(dataProvider="column")
129:            public boolean isIdentity(ColumnProperties properties)
130:                    throws SQLException {
131:                EasyMock.expect(properties.getRemarks()).andReturn(
132:                        "GENERATED ALWAYS AS IDENTITY");
133:
134:                this .replay();
135:
136:                boolean identity = this .dialect.isIdentity(properties);
137:
138:                this .verify();
139:
140:                assert identity;
141:
142:                this .reset();
143:
144:                EasyMock.expect(this .columnProperties.getRemarks()).andReturn(
145:                        null);
146:
147:                this .replay();
148:
149:                identity = this .dialect.isIdentity(properties);
150:
151:                this .verify();
152:
153:                assert !identity;
154:
155:                return identity;
156:            }
157:
158:            @Override
159:            @Test(dataProvider="sequence")
160:            public String getNextSequenceValueSQL(SequenceProperties sequence)
161:                    throws SQLException {
162:                EasyMock.expect(sequence.getName()).andReturn("sequence");
163:
164:                this .replay();
165:
166:                String sql = this .dialect.getNextSequenceValueSQL(sequence);
167:
168:                this .verify();
169:
170:                assert sql.equals("VALUES NEXT VALUE FOR sequence") : sql;
171:
172:                return sql;
173:            }
174:
175:            @Override
176:            @DataProvider(name="current-date")
177:            Object[][] currentDateProvider() {
178:                java.sql.Date date = new java.sql.Date(System
179:                        .currentTimeMillis());
180:
181:                return new Object[][] {
182:                        new Object[] { "SELECT CURRENT_DATE FROM success", date },
183:                        new Object[] { "SELECT CURRENT DATE FROM success", date },
184:                        new Object[] { "SELECT CCURRENT_DATE FROM failure",
185:                                date },
186:                        new Object[] { "SELECT CURRENT_DATES FROM failure",
187:                                date },
188:                        new Object[] { "SELECT 1 FROM failure", date }, };
189:            }
190:
191:            @Override
192:            @Test(dataProvider="current-date")
193:            public String evaluateCurrentDate(String sql, java.sql.Date date)
194:                    throws SQLException {
195:                String expected = sql.contains("success") ? "SELECT DATE('"
196:                        + date.toString() + "') FROM success" : sql;
197:
198:                String evaluated = this .dialect.evaluateCurrentDate(sql, date);
199:
200:                assert evaluated.equals(expected) : evaluated;
201:
202:                return evaluated;
203:            }
204:
205:            @Override
206:            @DataProvider(name="current-time")
207:            Object[][] currentTimeProvider() {
208:                java.sql.Time date = new java.sql.Time(System
209:                        .currentTimeMillis());
210:
211:                return new Object[][] {
212:                        new Object[] { "SELECT CURRENT_TIME FROM success", date },
213:                        new Object[] { "SELECT CURRENT TIME FROM success", date },
214:                        new Object[] { "SELECT CCURRENT_TIME FROM failure",
215:                                date },
216:                        new Object[] { "SELECT CURRENT_TIMESTAMP FROM failure",
217:                                date },
218:                        new Object[] { "SELECT 1 FROM failure", date }, };
219:            }
220:
221:            @Override
222:            @Test(dataProvider="current-time")
223:            public String evaluateCurrentTime(String sql, java.sql.Time date)
224:                    throws SQLException {
225:                String expected = sql.contains("success") ? "SELECT TIME('"
226:                        + date.toString() + "') FROM success" : sql;
227:
228:                String evaluated = this .dialect.evaluateCurrentTime(sql, date);
229:
230:                assert evaluated.equals(expected) : evaluated;
231:
232:                return evaluated;
233:            }
234:
235:            @Override
236:            @DataProvider(name="current-timestamp")
237:            Object[][] currentTimestampProvider() {
238:                java.sql.Timestamp date = new java.sql.Timestamp(System
239:                        .currentTimeMillis());
240:
241:                return new Object[][] {
242:                        new Object[] { "SELECT CURRENT_TIMESTAMP FROM success",
243:                                date },
244:                        new Object[] { "SELECT CURRENT TIMESTAMP FROM success",
245:                                date },
246:                        new Object[] {
247:                                "SELECT CCURRENT_TIMESTAMP FROM failure", date },
248:                        new Object[] {
249:                                "SELECT CURRENT_TIMESTAMPS FROM failure", date },
250:                        new Object[] { "SELECT 1 FROM failure", date }, };
251:            }
252:
253:            @Override
254:            @Test(dataProvider="current-timestamp")
255:            public String evaluateCurrentTimestamp(String sql,
256:                    java.sql.Timestamp date) throws SQLException {
257:                String expected = sql.contains("success") ? "SELECT TIMESTAMP('"
258:                        + date.toString() + "') FROM success"
259:                        : sql;
260:
261:                String evaluated = this.dialect.evaluateCurrentTimestamp(sql,
262:                        date);
263:
264:                assert evaluated.equals(expected) : evaluated;
265:
266:                return evaluated;
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.