001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.upgrade;
022:
023: import com.liferay.portal.kernel.util.InstancePool;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * <a href="SmartUpgradeSchema.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public abstract class SmartUpgradeSchema extends UpgradeProcess {
035:
036: public void upgrade() throws UpgradeException {
037: String smartUpgradeSchemaImplClassName = this .getClass()
038: .getName();
039:
040: if (_alreadyUpgraded) {
041: _log.info("Skipping " + smartUpgradeSchemaImplClassName
042: + " because it has already been executed");
043:
044: return;
045: }
046:
047: _alreadyUpgraded = true;
048:
049: try {
050: upgradeOnce();
051:
052: boolean doUpgrade = false;
053:
054: for (int i = 0; i < _UPGRADE_PROGRESS_CLASSES.length; i++) {
055: String curUpgradeSchemaClassName = _UPGRADE_PROGRESS_CLASSES[i]
056: .getName();
057:
058: if (doUpgrade) {
059: SmartUpgradeSchema upgradeSchema = (SmartUpgradeSchema) InstancePool
060: .get(curUpgradeSchemaClassName);
061:
062: if (!upgradeSchema.isAlreadyUpgraded()) {
063: _log.info("Automatically executing "
064: + curUpgradeSchemaClassName);
065:
066: upgradeSchema.setAlreadyUpgraded(true);
067:
068: upgradeSchema.upgradeOnce();
069: }
070: }
071:
072: if (smartUpgradeSchemaImplClassName
073: .equals(curUpgradeSchemaClassName)) {
074:
075: doUpgrade = true;
076: }
077: }
078: } catch (Exception e) {
079: throw new UpgradeException(e);
080: }
081: }
082:
083: protected boolean isAlreadyUpgraded() {
084: return _alreadyUpgraded;
085: }
086:
087: protected void setAlreadyUpgraded(boolean alreadyUpgraded) {
088: _alreadyUpgraded = alreadyUpgraded;
089: }
090:
091: protected abstract void upgradeOnce() throws Exception;
092:
093: private static final Class[] _UPGRADE_PROGRESS_CLASSES = new Class[] {
094: com.liferay.portal.upgrade.v4_3_0.UpgradeSchema.class,
095: com.liferay.portal.upgrade.v4_3_1.UpgradeSchema.class,
096: com.liferay.portal.upgrade.v4_3_2.UpgradeSchema.class,
097: com.liferay.portal.upgrade.v4_3_3.UpgradeSchema.class,
098: com.liferay.portal.upgrade.v4_3_4.UpgradeSchema.class,
099: com.liferay.portal.upgrade.v4_4_0.UpgradeSchema.class, };
100:
101: private static Log _log = LogFactory
102: .getLog(SmartUpgradeSchema.class);
103:
104: private boolean _alreadyUpgraded;
105:
106: }
|