Source Code Cross Referenced for AbstractSqlStatementTest.java in  » Database-Client » LiquiBase » liquibase » database » sql » 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 Client » LiquiBase » liquibase.database.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package liquibase.database.sql;
002:
003:        import liquibase.database.Database;
004:        import liquibase.database.PostgresDatabase;
005:        import liquibase.database.template.JdbcTemplate;
006:        import liquibase.exception.JDBCException;
007:        import liquibase.test.DatabaseTest;
008:        import liquibase.test.DatabaseTestTemplate;
009:        import liquibase.test.TestContext;
010:        import static org.junit.Assert.*;
011:        import org.junit.Before;
012:        import org.junit.Test;
013:
014:        import java.sql.SQLException;
015:
016:        public abstract class AbstractSqlStatementTest {
017:
018:            @Before
019:            public void setupAvailableDatabases() throws Exception {
020:                for (Database database : TestContext.getInstance()
021:                        .getAvailableDatabases()) {
022:                    if (generateTestStatement().supportsDatabase(database)) {
023:                        setupDatabase(database);
024:                    }
025:                }
026:            }
027:
028:            protected abstract void setupDatabase(Database database)
029:                    throws Exception;
030:
031:            protected void dropAndCreateTable(CreateTableStatement statement,
032:                    Database database) throws SQLException, JDBCException {
033:                if (statement.getSchemaName() != null
034:                        && !database.supportsSchemas()) {
035:                    return;
036:                }
037:
038:                dropTableIfExists(statement.getSchemaName(), statement
039:                        .getTableName(), database);
040:
041:                new JdbcTemplate(database).execute(statement);
042:
043:                if (!database.getAutoCommitMode()) {
044:                    database.getConnection().commit();
045:                }
046:
047:            }
048:
049:            protected void dropTableIfExists(String schemaName,
050:                    String tableName, Database database) throws SQLException {
051:                if (schemaName != null && !database.supportsSchemas()) {
052:                    return;
053:                }
054:
055:                if (!database.getAutoCommitMode()) {
056:                    database.getConnection().commit();
057:                }
058:
059:                try {
060:                    boolean cascade = false;
061:                    if (database instanceof  PostgresDatabase) {
062:                        cascade = true;
063:                    }
064:                    new JdbcTemplate(database).execute(new DropTableStatement(
065:                            schemaName, tableName, cascade));
066:
067:                    if (!database.getAutoCommitMode()) {
068:                        database.getConnection().commit();
069:                    }
070:
071:                } catch (JDBCException e) {
072:                    //            System.out.println("Error dropping table "+database.escapeTableName(schemaName, tableName)+" on "+database);
073:                    //            e.printStackTrace();
074:                    if (!database.getConnection().getAutoCommit()) {
075:                        database.getConnection().rollback();
076:                    }
077:                }
078:            }
079:
080:            protected void dropAndCreateSequence(
081:                    CreateSequenceStatement statement, Database database)
082:                    throws SQLException, JDBCException {
083:                if (statement.getSchemaName() != null
084:                        && !database.supportsSchemas()) {
085:                    return;
086:                }
087:
088:                dropSequenceIfExists(statement.getSchemaName(), statement
089:                        .getSequenceName(), database);
090:
091:                new JdbcTemplate(database).execute(statement);
092:
093:                if (!database.getAutoCommitMode()) {
094:                    database.getConnection().commit();
095:                }
096:
097:            }
098:
099:            protected void dropSequenceIfExists(String schemaName,
100:                    String sequenceName, Database database) throws SQLException {
101:                if (schemaName != null && !database.supportsSchemas()) {
102:                    return;
103:                }
104:
105:                if (!database.getAutoCommitMode()) {
106:                    database.getConnection().commit();
107:                }
108:
109:                try {
110:                    new JdbcTemplate(database)
111:                            .execute(new DropSequenceStatement(schemaName,
112:                                    sequenceName));
113:
114:                    if (!database.getAutoCommitMode()) {
115:                        database.getConnection().commit();
116:                    }
117:
118:                } catch (JDBCException e) {
119:                    //            System.out.println("Error dropping sequence "+database.escapeSequenceName(schemaName, sequenceName));
120:                    //            e.printStackTrace();
121:                    if (!database.getConnection().getAutoCommit()) {
122:                        database.getConnection().rollback();
123:                    }
124:                }
125:                if (!database.getAutoCommitMode()) {
126:                    database.getConnection().commit();
127:                }
128:
129:            }
130:
131:            protected void dropAndCreateView(CreateViewStatement statement,
132:                    Database database) throws SQLException, JDBCException {
133:                if (statement.getSchemaName() != null
134:                        && !database.supportsSchemas()) {
135:                    return;
136:                }
137:
138:                dropViewIfExists(statement.getSchemaName(), statement
139:                        .getViewName(), database);
140:
141:                new JdbcTemplate(database).execute(statement);
142:
143:                if (!database.getAutoCommitMode()) {
144:                    database.getConnection().commit();
145:                }
146:
147:            }
148:
149:            protected void dropViewIfExists(String schemaName, String viewName,
150:                    Database database) throws SQLException {
151:                if (schemaName != null && !database.supportsSchemas()) {
152:                    return;
153:                }
154:
155:                if (!database.getAutoCommitMode()) {
156:                    database.getConnection().commit();
157:                }
158:
159:                String schema = "";
160:                if (schemaName != null) {
161:                    schema = schemaName + ".";
162:                }
163:
164:                try {
165:                    new JdbcTemplate(database).execute(new RawSqlStatement(
166:                            "drop view " + schema + viewName));
167:
168:                    if (!database.getAutoCommitMode()) {
169:                        database.getConnection().commit();
170:                    }
171:
172:                } catch (JDBCException e) {
173:                    //            System.out.println("Cannot drop view "+database.escapeViewName(schemaName, viewName)+" on "+database);
174:                    //            e.printStackTrace();
175:                    if (!database.getConnection().getAutoCommit()) {
176:                        database.getConnection().rollback();
177:                    }
178:                }
179:
180:                if (!database.getAutoCommitMode()) {
181:                    database.getConnection().commit();
182:                }
183:
184:            }
185:
186:            protected abstract SqlStatement generateTestStatement();
187:
188:            @Test
189:            public void supportsDatabase() throws Exception {
190:                new DatabaseTestTemplate()
191:                        .testOnAllDatabases(new DatabaseTest() {
192:                            public void performTest(Database database)
193:                                    throws Exception {
194:                                assertTrue(generateTestStatement()
195:                                        .supportsDatabase(database));
196:                            }
197:                        });
198:            }
199:
200:            @Test
201:            public void getEndDelimiter() throws Exception {
202:                new DatabaseTestTemplate()
203:                        .testOnAllDatabases(new DatabaseTest() {
204:                            public void performTest(Database database)
205:                                    throws Exception {
206:                                assertEquals(";", generateTestStatement()
207:                                        .getEndDelimiter(database));
208:                            }
209:                        });
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.