1
22
23 package com.liferay.portal.kernel.upgrade;
24
25 import com.liferay.portal.kernel.dao.db.DB;
26 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
27 import com.liferay.portal.kernel.log.Log;
28 import com.liferay.portal.kernel.log.LogFactoryUtil;
29 import com.liferay.portal.kernel.util.InstancePool;
30
31 import java.io.IOException;
32
33 import java.sql.SQLException;
34
35 import javax.naming.NamingException;
36
37
43 public abstract class UpgradeProcess {
44
45 public UpgradeProcess() {
46 }
47
48 public int getThreshold() {
49
50
54 return 0;
55 }
56
57 public boolean isSupportsAlterColumnName() {
58 DB db = DBFactoryUtil.getDB();
59
60 return db.isSupportsAlterColumnName();
61 }
62
63 public boolean isSupportsAlterColumnType() {
64 DB db = DBFactoryUtil.getDB();
65
66 return db.isSupportsAlterColumnType();
67 }
68
69 public boolean isSupportsStringCaseSensitiveQuery() {
70 DB db = DBFactoryUtil.getDB();
71
72 return db.isSupportsStringCaseSensitiveQuery();
73 }
74
75 public boolean isSupportsUpdateWithInnerJoin() {
76 DB db = DBFactoryUtil.getDB();
77
78 return db.isSupportsUpdateWithInnerJoin();
79 }
80
81 public void runSQL(String template) throws IOException, SQLException {
82 DB db = DBFactoryUtil.getDB();
83
84 db.runSQL(template);
85 }
86
87 public void runSQL(String[] templates) throws IOException, SQLException {
88 DB db = DBFactoryUtil.getDB();
89
90 db.runSQL(templates);
91 }
92
93 public void runSQLTemplate(String path)
94 throws IOException, NamingException, SQLException {
95
96 DB db = DBFactoryUtil.getDB();
97
98 db.runSQLTemplate(path);
99 }
100
101 public void runSQLTemplate(String path, boolean failOnError)
102 throws IOException, NamingException, SQLException {
103
104 DB db = DBFactoryUtil.getDB();
105
106 db.runSQLTemplate(path, failOnError);
107 }
108
109 public void upgrade() throws UpgradeException {
110 try {
111 if (_log.isInfoEnabled()) {
112 _log.info("Upgrading " + getClass().getName());
113 }
114
115 doUpgrade();
116 }
117 catch (Exception e) {
118 throw new UpgradeException(e);
119 }
120 }
121
122 public void upgrade(Class<?> upgradeProcessClass)
123 throws UpgradeException {
124
125 UpgradeProcess upgradeProcess = (UpgradeProcess)InstancePool.get(
126 upgradeProcessClass.getName());
127
128 upgradeProcess.upgrade();
129 }
130
131 public void upgrade(UpgradeProcess upgradeProcess)
132 throws UpgradeException {
133
134 upgradeProcess.upgrade();
135 }
136
137 protected void doUpgrade() throws Exception {
138 }
139
140 private static Log _log = LogFactoryUtil.getLog(UpgradeProcess.class);
141
142 }