Source Code Cross Referenced for DefinitionVersionManager.java in  » Report » pentaho-report » org » pentaho » repository » 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 » Report » pentaho report » org.pentaho.repository 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * The purpose of this class is to maintain a list of versions of each hibernated
014:         * class (the object definition, not the contents of any one object) for the purposes
015:         * of initiating an automatic schema update.
016:         *
017:         * Created Sep 28, 2005 
018:         * @author mbatchel
019:         */
020:        package org.pentaho.repository;
021:
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:
027:        import org.hibernate.LockMode;
028:        import org.hibernate.Session;
029:        import org.pentaho.core.repository.RepositoryException;
030:
031:        public class DefinitionVersionManager {
032:            private Map versionMap = new HashMap();
033:
034:            private int revision = -1; // Hibernate Revision
035:
036:            private String key;
037:
038:            private static final String VersionKey = "PENTAHO_HIBERNATE_VERSIONS"; //$NON-NLS-1$
039:
040:            protected static String getVersionKey() {
041:                return VersionKey;
042:            }
043:
044:            public static void performAutoUpdateIfRequired() {
045:                Session session = HibernateUtil.getSession();
046:                try {
047:                    DefinitionVersionManager mgr = null;
048:                    try {
049:                        mgr = (DefinitionVersionManager) session.get(
050:                                DefinitionVersionManager.class,
051:                                getVersionKey(), LockMode.READ); // Ignore Caches and just check the object
052:                    } catch (Exception handledForPG) {
053:                        // Gotta rollback or the connection gets messed up by PostgreSQL
054:                        try {
055:                            session.connection().rollback();
056:                        } catch (Exception ex) {
057:                            ex.printStackTrace();
058:                        }
059:                        HibernateUtil.closeSession();
060:                    }
061:                    if (mgr == null) {
062:                        // Never been stored before - Create one
063:                        mgr = new DefinitionVersionManager();
064:                        mgr.setKey(getVersionKey());
065:                    }
066:                    boolean needsUpdate = mgr.versionsUpdated();
067:                    if (needsUpdate) {
068:                        // Make sure that hibernate session is closed
069:                        HibernateUtil.closeSession();
070:                        // Update the schema using PentahoSchemaUpdate
071:                        HibernateUtil.updateSchema();
072:                        // Gets the session
073:                        session = HibernateUtil.getSession();
074:                        // Persist the DefinitionVersionManager class with the updated version numbers
075:                        session.saveOrUpdate(mgr);
076:                        // Write the changes to the DB
077:                        session.flush();
078:                        try {
079:                            // Commit the work
080:                            session.connection().commit();
081:                        } catch (Exception ex) {
082:                            try {
083:                                session.connection().rollback();
084:                            } catch (Exception e2) {
085:                                throw new RepositoryException(e2);
086:                            }
087:                            throw new RepositoryException(ex);
088:                        }
089:                    }
090:                } finally {
091:                    HibernateUtil.closeSession();
092:                }
093:            }
094:
095:            public boolean versionsUpdated() {
096:                Map verMap = this .getVersionMap();
097:                boolean needsUpdate = false;
098:                List objectHandlers = HibernateUtil
099:                        .getHibernatedObjectHandlerList();
100:                IHibernatedObjectExtensionList handler;
101:                Map objectVersionMap;
102:                Iterator it;
103:                Map.Entry ent;
104:                String clName;
105:                Integer clVersion;
106:                for (int i = 0; i < objectHandlers.size(); i++) {
107:                    handler = (IHibernatedObjectExtensionList) objectHandlers
108:                            .get(i);
109:                    objectVersionMap = handler.getHibernatedObjectVersionMap();
110:                    it = objectVersionMap.entrySet().iterator();
111:                    while (it.hasNext()) {
112:                        ent = (Map.Entry) it.next();
113:                        clName = (String) ent.getKey();
114:                        clVersion = (Integer) ent.getValue();
115:                        needsUpdate |= checkVersion(verMap, clVersion
116:                                .intValue(), clName);
117:                    }
118:                }
119:                /*
120:                 * needsUpdate = checkVersion(verMap, ContentItem.ClassVersionNumber,
121:                 * "ContentItem"); //$NON-NLS-1$ needsUpdate |= checkVersion(verMap,
122:                 * ContentItemFile.ClassVersionNumber, "ContentItemFile"); //$NON-NLS-1$
123:                 * needsUpdate |= checkVersion(verMap,
124:                 * ContentLocation.ClassVersionNumber, "ContentLocation"); //$NON-NLS-1$
125:                 * needsUpdate |= checkVersion(verMap,
126:                 * RuntimeElement.ClassVersionNumber, "RuntimeElement"); //$NON-NLS-1$
127:                 */
128:                return needsUpdate;
129:            }
130:
131:            private boolean checkVersion(Map verMap, int curVerNum,
132:                    String className) {
133:                Long currentVersionNumber = new Long(curVerNum);
134:                Long storedVerNum = (Long) verMap.get(className);
135:                if (storedVerNum == null) {
136:                    verMap.put(className, currentVersionNumber);
137:                    return true;
138:                } else if (!storedVerNum.equals(currentVersionNumber)) {
139:                    verMap.put(className, currentVersionNumber);
140:                    return true;
141:                }
142:                return false;
143:            }
144:
145:            public int getRevision() {
146:                return revision;
147:            }
148:
149:            public void setRevision(int revision) {
150:                this .revision = revision;
151:            }
152:
153:            protected Map getVersionMap() {
154:                return versionMap;
155:            }
156:
157:            protected void setVersionMap(Map versionMap) {
158:                this .versionMap = versionMap;
159:            }
160:
161:            public String getKey() {
162:                return key;
163:            }
164:
165:            public void setKey(String value) {
166:                this.key = value;
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.