Source Code Cross Referenced for CmsUpdateDBDropOldIndexes.java in  » Content-Management-System » opencms » org » opencms » setup » update6to7 » oracle » 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 » Content Management System » opencms » org.opencms.setup.update6to7.oracle 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/update6to7/oracle/CmsUpdateDBDropOldIndexes.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:48 $
004:         * Version: $Revision: 1.2 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.setup.update6to7.oracle;
033:
034:        import org.opencms.setup.CmsSetupDBWrapper;
035:        import org.opencms.setup.CmsSetupDb;
036:
037:        import java.io.IOException;
038:        import java.sql.SQLException;
039:        import java.util.ArrayList;
040:        import java.util.Arrays;
041:        import java.util.Collections;
042:        import java.util.HashMap;
043:        import java.util.Iterator;
044:        import java.util.List;
045:
046:        /**
047:         * Oracle implementation to drop the old indexes from the database.<p> 
048:         * 
049:         * @author Roland Metzler
050:         * @author Peter Bonrad
051:         *
052:         * @version $Revision: 1.2 $
053:         * 
054:         * @since 7.0.0
055:         */
056:        public class CmsUpdateDBDropOldIndexes extends
057:                org.opencms.setup.update6to7.generic.CmsUpdateDBDropOldIndexes {
058:
059:            /** Constant for the field of the constraint name.<p> */
060:            private static final String FIELD_CONSTRAINT_ORACLE = "CONSTRAINT_NAME";
061:
062:            /** Constant for the field of the index name.<p> */
063:            private static final String FIELD_INDEX_ORACLE = "INDEX_NAME";
064:
065:            /** Constant for the sql query to drop a unique index key. */
066:            private static final String QUERY_DROP_CONSTRAINT = "Q_DROP_CONSTRAINT";
067:
068:            /** Constant for the SQL query properties.<p> */
069:            private static final String QUERY_PROPERTY_FILE_ORACLE = "oracle/cms_drop_all_indexes_queries.properties";
070:
071:            /** Constant for the sql query to list contraints for a table. */
072:            private static final String QUERY_SHOW_CONSTRAINTS = "Q_SHOW_CONSTRAINTS";
073:
074:            /** Constant for the replacement of the index name. */
075:            private static final String REPLACEMENT_INDEX_ORACLE = "${indexname}";
076:
077:            /** Constant array of the temporary indexes. */
078:            private static final String[] TEMP_INDEXES = {
079:                    "CMS_BACKUP_CONTENTS_INDEX_1",
080:                    "CMS_BACKUP_CONTENTS_INDEX_2",
081:                    "CMS_BACKUP_PROJECTRESOURCES_INDEX_1",
082:                    "CMS_BACKUP_PROJECTS_INDEX_1",
083:                    "CMS_BACKUP_PROJECTS_INDEX_2",
084:                    "CMS_BACKUP_PROJECTS_INDEX_3",
085:                    "CMS_BACKUP_PROJECTS_INDEX_4",
086:                    "CMS_BACKUP_PROJECTS_INDEX_5",
087:                    "CMS_BACKUP_PROJECTS_INDEX_6",
088:                    "CMS_BACKUP_PROPERTIES_INDEX_1",
089:                    "CMS_BACKUP_PROPERTIES_INDEX_2",
090:                    "CMS_BACKUP_PROPERTIES_INDEX_3",
091:                    "CMS_BACKUP_PROPERTYDEF_INDEX_1",
092:                    "CMS_BACKUP_RESOURCES_INDEX_1",
093:                    "CMS_BACKUP_RESOURCES_INDEX_2",
094:                    "CMS_BACKUP_RESOURCES_INDEX_3",
095:                    "CMS_BACKUP_RESOURCES_INDEX_4",
096:                    "CMS_BACKUP_RESOURCES_INDEX_5",
097:                    "CMS_BACKUP_STRUCTURE_INDEX_1",
098:                    "CMS_BACKUP_STRUCTURE_INDEX_2",
099:                    "CMS_BACKUP_STRUCTURE_INDEX_3",
100:                    "CMS_BACKUP_STRUCTURE_INDEX_4", "CMS_GROUPS_INDEX_1",
101:                    "CMS_OFFLINE_CONTENTS_INDEX_1",
102:                    "CMS_OFFLINE_RESOURCES_INDEX_1",
103:                    "CMS_OFFLINE_RESOURCES_INDEX_2",
104:                    "CMS_OFFLINE_RESOURCES_INDEX_3",
105:                    "CMS_OFFLINE_RESOURCES_INDEX_4",
106:                    "CMS_OFFLINE_STRUCTURE_INDEX_1",
107:                    "CMS_OFFLINE_STRUCTURE_INDEX_2",
108:                    "CMS_OFFLINE_STRUCTURE_INDEX_3",
109:                    "CMS_ONLINE_CONTENTS_INDEX_1",
110:                    "CMS_ONLINE_RESOURCES_INDEX_1",
111:                    "CMS_ONLINE_RESOURCES_INDEX_2",
112:                    "CMS_ONLINE_RESOURCES_INDEX_3",
113:                    "CMS_ONLINE_RESOURCES_INDEX_4",
114:                    "CMS_ONLINE_STRUCTURE_INDEX_1",
115:                    "CMS_ONLINE_STRUCTURE_INDEX_2",
116:                    "CMS_ONLINE_STRUCTURE_INDEX_3",
117:                    "CMS_PROJECTRESOURCES_INDEX_1", "CMS_PROJECTS_INDEX_1",
118:                    "CMS_PROJECTS_INDEX_2", "CMS_PROJECTS_INDEX_3",
119:                    "CMS_PROJECTS_INDEX_4", "CMS_PUBLISH_HISTORY_INDEX_1",
120:                    "CMS_PUBLISH_HISTORY_INDEX_2" };
121:
122:            /** Constant Array List of the temporary indexes. */
123:            private static final List TEMP_INDEXES_LIST = Collections
124:                    .unmodifiableList(Arrays.asList(TEMP_INDEXES));
125:
126:            /**
127:             * Constructor.<p>
128:             * 
129:             * @throws IOException if the sql queries properties file could not be read
130:             */
131:            public CmsUpdateDBDropOldIndexes() throws IOException {
132:
133:                super ();
134:                loadQueryProperties(QUERY_PROPERTIES_PREFIX
135:                        + QUERY_PROPERTY_FILE_ORACLE);
136:            }
137:
138:            // No implementation yet
139:
140:            /**
141:             * @see org.opencms.setup.update6to7.A_CmsUpdateDBPart#internalExecute(org.opencms.setup.CmsSetupDb)
142:             */
143:            protected void internalExecute(CmsSetupDb dbCon) {
144:
145:                List tablenames = CMS_TABLES_LIST;
146:
147:                // Iterate over all the tables.
148:                for (Iterator tableIterator = tablenames.iterator(); tableIterator
149:                        .hasNext();) {
150:                    String tablename = (String) tableIterator.next();
151:                    System.out.println("dropping indexes for table "
152:                            + tablename);
153:                    // Check if the table is existing
154:                    if (dbCon.hasTableOrColumn(tablename, null)) {
155:                        try {
156:
157:                            // First drop constraints
158:                            List constraints = getConstraints(dbCon, tablename);
159:                            Iterator iter = constraints.iterator();
160:                            while (iter.hasNext()) {
161:                                String constraint = (String) iter.next();
162:
163:                                String dropConstraint = readQuery(QUERY_DROP_CONSTRAINT);
164:                                HashMap replacer = new HashMap();
165:                                replacer.put(REPLACEMENT_TABLENAME, tablename);
166:                                replacer.put(REPLACEMENT_INDEX_ORACLE,
167:                                        constraint);
168:                                dbCon.updateSqlStatement(dropConstraint,
169:                                        replacer, null);
170:                            }
171:
172:                            // Drop the indexes from the table.
173:                            List indexes = getIndexes(dbCon, tablename);
174:                            iter = indexes.iterator();
175:                            while (iter.hasNext()) {
176:                                String index = (String) iter.next();
177:
178:                                // Drop the index
179:                                String dropIndex = readQuery(QUERY_DROP_INDEX);
180:                                HashMap replacerIndex = new HashMap();
181:                                replacerIndex.put(REPLACEMENT_INDEX_ORACLE,
182:                                        index);
183:                                dbCon.updateSqlStatement(dropIndex,
184:                                        replacerIndex, null);
185:                            }
186:                        } catch (SQLException e) {
187:                            e.printStackTrace();
188:                        }
189:                    }
190:                }
191:
192:                // Create the temporary indexes
193:                // Each index must be created in its own query
194:                for (Iterator tempIndexes = TEMP_INDEXES_LIST.iterator(); tempIndexes
195:                        .hasNext();) {
196:                    try {
197:                        String createIndex = (String) tempIndexes.next();
198:                        String creationQuery = readQuery(createIndex);
199:                        dbCon.updateSqlStatement(creationQuery, null, null);
200:                    } catch (SQLException e) {
201:                        e.printStackTrace();
202:                    }
203:                }
204:            }
205:
206:            /**
207:             * Gets the constraints for a table.<p>
208:             * 
209:             * @param dbCon the db connection interface
210:             * @param tablename the table to get the indexes from
211:             * 
212:             * @return a list of constraints
213:             * 
214:             * @throws SQLException if something goes wrong 
215:             */
216:            private List getConstraints(CmsSetupDb dbCon, String tablename)
217:                    throws SQLException {
218:
219:                ArrayList constraints = new ArrayList();
220:                String tableConstraints = readQuery(QUERY_SHOW_CONSTRAINTS);
221:                HashMap replacer = new HashMap();
222:                replacer.put(REPLACEMENT_TABLENAME, tablename);
223:                CmsSetupDBWrapper db = null;
224:                try {
225:                    db = dbCon.executeSqlStatement(tableConstraints, replacer);
226:                    while (db.getResultSet().next()) {
227:                        String constraint = db.getResultSet().getString(
228:                                FIELD_CONSTRAINT_ORACLE);
229:                        if (!constraints.contains(constraint)) {
230:                            constraints.add(constraint);
231:                        }
232:
233:                    }
234:                } finally {
235:                    if (db != null) {
236:                        db.close();
237:                    }
238:                }
239:
240:                return constraints;
241:            }
242:
243:            /**
244:             * Gets the indexes for a table.<p>
245:             * 
246:             * @param dbCon the db connection interface
247:             * @param tablename the table to get the indexes from
248:             * 
249:             * @return a list of indexes
250:             * 
251:             * @throws SQLException if something goes wrong 
252:             */
253:            private List getIndexes(CmsSetupDb dbCon, String tablename)
254:                    throws SQLException {
255:
256:                ArrayList indexes = new ArrayList();
257:                String tableIndex = readQuery(QUERY_SHOW_INDEX);
258:                HashMap replacer = new HashMap();
259:                replacer.put(REPLACEMENT_TABLENAME, tablename);
260:                CmsSetupDBWrapper db = null;
261:                try {
262:                    db = dbCon.executeSqlStatement(tableIndex, replacer);
263:                    while (db.getResultSet().next()) {
264:                        String index = db.getResultSet().getString(
265:                                FIELD_INDEX_ORACLE);
266:                        if (!indexes.contains(index)) {
267:                            indexes.add(index);
268:                        }
269:
270:                    }
271:                } finally {
272:                    if (db != null) {
273:                        db.close();
274:                    }
275:                }
276:                return indexes;
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.