1
19
20 package com.liferay.portal.upgrade;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24 import com.liferay.portal.kernel.util.InstancePool;
25
26
32 public abstract class SmartUpgradeSchema extends UpgradeProcess {
33
34 public void upgrade() throws UpgradeException {
35 String smartUpgradeSchemaImplClassName = this.getClass().getName();
36
37 if (_alreadyUpgraded) {
38 _log.info(
39 "Skipping " + smartUpgradeSchemaImplClassName +
40 " because it has already been executed");
41
42 return;
43 }
44
45 _alreadyUpgraded = true;
46
47 try {
48 upgradeOnce();
49
50 boolean doUpgrade = false;
51
52 for (int i = 0; i < _UPGRADE_PROGRESS_CLASSES.length; i++) {
53 String curUpgradeSchemaClassName =
54 _UPGRADE_PROGRESS_CLASSES[i].getName();
55
56 if (doUpgrade) {
57 SmartUpgradeSchema upgradeSchema =
58 (SmartUpgradeSchema)InstancePool.get(
59 curUpgradeSchemaClassName);
60
61 if (!upgradeSchema.isAlreadyUpgraded()) {
62 _log.info(
63 "Automatically executing " +
64 curUpgradeSchemaClassName);
65
66 upgradeSchema.setAlreadyUpgraded(true);
67
68 upgradeSchema.upgradeOnce();
69 }
70 }
71
72 if (smartUpgradeSchemaImplClassName.equals(
73 curUpgradeSchemaClassName)) {
74
75 doUpgrade = true;
76 }
77 }
78 }
79 catch (Exception e) {
80 throw new UpgradeException(e);
81 }
82 }
83
84 protected boolean isAlreadyUpgraded() {
85 return _alreadyUpgraded;
86 }
87
88 protected void setAlreadyUpgraded(boolean alreadyUpgraded) {
89 _alreadyUpgraded = alreadyUpgraded;
90 }
91
92 protected abstract void upgradeOnce() throws Exception;
93
94 private static final Class<?>[] _UPGRADE_PROGRESS_CLASSES = new Class[] {
95 com.liferay.portal.upgrade.v4_3_0.UpgradeSchema.class,
96 com.liferay.portal.upgrade.v4_3_1.UpgradeSchema.class,
97 com.liferay.portal.upgrade.v4_3_2.UpgradeSchema.class,
98 com.liferay.portal.upgrade.v4_3_3.UpgradeSchema.class,
99 com.liferay.portal.upgrade.v4_3_4.UpgradeSchema.class,
100 com.liferay.portal.upgrade.v4_4_0.UpgradeSchema.class,
101 com.liferay.portal.upgrade.v5_0_0.UpgradeSchema.class,
102 com.liferay.portal.upgrade.v5_1_0.UpgradeSchema.class,
103 com.liferay.portal.upgrade.v5_1_2.UpgradeSchema.class,
104 com.liferay.portal.upgrade.v5_2_0.UpgradeSchema.class,
105 com.liferay.portal.upgrade.v5_2_1.UpgradeSchema.class,
106 com.liferay.portal.upgrade.v5_2_3.UpgradeSchema.class
107 };
108
109 private static Log _log = LogFactoryUtil.getLog(SmartUpgradeSchema.class);
110
111 private boolean _alreadyUpgraded;
112
113 }