Source Code Cross Referenced for JdbcMigrationTaskSupport.java in  » Project-Management » XPlanner-0.7b7 » com » technoetic » xplanner » upgrade » 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 » Project Management » XPlanner 0.7b7 » com.technoetic.xplanner.upgrade 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created by IntelliJ IDEA.
003:         * User: sg426575
004:         * Date: May 13, 2006
005:         * Time: 1:51:27 PM
006:         */
007:        package com.technoetic.xplanner.upgrade;
008:
009:        import java.sql.Connection;
010:        import java.sql.SQLException;
011:
012:        import net.sf.hibernate.HibernateException;
013:        import net.sf.hibernate.Session;
014:        import org.springframework.jdbc.core.JdbcTemplate;
015:        import org.springframework.jdbc.datasource.SingleConnectionDataSource;
016:        import com.tacitknowledge.util.migration.MigrationContext;
017:        import com.tacitknowledge.util.migration.MigrationException;
018:        import com.tacitknowledge.util.migration.MigrationTaskSupport;
019:        import com.tacitknowledge.util.migration.jdbc.DataSourceMigrationContext;
020:        import com.tacitknowledge.util.migration.jdbc.JdbcMigrationContext;
021:
022:        import com.technoetic.xplanner.db.hibernate.GlobalSessionFactory;
023:        import com.technoetic.xplanner.db.hibernate.HibernateHelper;
024:        import com.technoetic.xplanner.upgrade.schema.DBSchemaMigrater;
025:
026:        public abstract class JdbcMigrationTaskSupport extends
027:                MigrationTaskSupport {
028:            protected DBSchemaMigrater migrater;
029:            protected JdbcTemplate template;
030:
031:            protected JdbcMigrationTaskSupport(String name, int level) {
032:                setName(name);
033:                setLevel(new Integer(level));
034:            }
035:
036:            private Connection getConnection(MigrationContext context)
037:                    throws MigrationException {
038:                try {
039:                    return ((JdbcMigrationContext) context).getConnection();
040:                } catch (SQLException e) {
041:                    throw new MigrationException("Could not open connection", e);
042:                }
043:            }
044:
045:            final public void migrate(MigrationContext context)
046:                    throws MigrationException {
047:                init(context);
048:
049:                boolean inException = false;
050:                try {
051:                    setUp();
052:                    migrate();
053:                } catch (MigrationException e) {
054:                    throw e;
055:                } catch (Exception e) {
056:                    inException = true;
057:                    throw new MigrationException("exception during migration",
058:                            e);
059:                } finally {
060:                    try {
061:                        tearDown();
062:                    } catch (Exception e) {
063:                        if (!inException) {
064:                            throw new MigrationException(
065:                                    "exception in tearDown", e);
066:                        }
067:                    }
068:                }
069:            }
070:
071:            protected void init(MigrationContext context)
072:                    throws MigrationException {
073:                Connection connection = getConnection(context);
074:                migrater = new DBSchemaMigrater(connection);
075:                template = new JdbcTemplate(new SingleConnectionDataSource(
076:                        connection, true));
077:            }
078:
079:            protected void setUp() throws Exception {
080:            }
081:
082:            protected void tearDown() throws Exception {
083:            }
084:
085:            abstract protected void migrate() throws Exception;
086:
087:            /**
088:             * Support for running a migration task in isolation (for manual testing for example)
089:             * Warning: This should be used with caution since it does not update the patch table and therefore will not take care
090:             * of preventing this task to run the next time
091:             */
092:            public void run() throws Exception {
093:                Session session = newSession();
094:                final Connection conn = session.connection();
095:                try {
096:                    migrate(new DataSourceMigrationContext() {
097:                        public Connection getConnection() throws SQLException {
098:                            return conn;
099:                        }
100:                    });
101:                } finally {
102:                    conn.commit();
103:                    session.close();
104:                }
105:            }
106:
107:            private Session newSession() throws HibernateException {
108:                HibernateHelper.initializeHibernate();
109:                Session session = GlobalSessionFactory.get().openSession();
110:                return session;
111:            }
112:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.