1
22
23 package com.liferay.portal.kernel.upgrade;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.db.DB;
27 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
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 long increment() throws SystemException {
58 DB db = DBFactoryUtil.getDB();
59
60 return db.increment();
61 }
62
63 public boolean isSupportsAlterColumnName() {
64 DB db = DBFactoryUtil.getDB();
65
66 return db.isSupportsAlterColumnName();
67 }
68
69 public boolean isSupportsAlterColumnType() {
70 DB db = DBFactoryUtil.getDB();
71
72 return db.isSupportsAlterColumnType();
73 }
74
75 public boolean isSupportsStringCaseSensitiveQuery() {
76 DB db = DBFactoryUtil.getDB();
77
78 return db.isSupportsStringCaseSensitiveQuery();
79 }
80
81 public boolean isSupportsUpdateWithInnerJoin() {
82 DB db = DBFactoryUtil.getDB();
83
84 return db.isSupportsUpdateWithInnerJoin();
85 }
86
87 public void runSQL(String template) throws IOException, SQLException {
88 DB db = DBFactoryUtil.getDB();
89
90 db.runSQL(template);
91 }
92
93 public void runSQL(String[] templates) throws IOException, SQLException {
94 DB db = DBFactoryUtil.getDB();
95
96 db.runSQL(templates);
97 }
98
99 public void runSQLTemplate(String path)
100 throws IOException, NamingException, SQLException {
101
102 DB db = DBFactoryUtil.getDB();
103
104 db.runSQLTemplate(path);
105 }
106
107 public void runSQLTemplate(String path, boolean failOnError)
108 throws IOException, NamingException, SQLException {
109
110 DB db = DBFactoryUtil.getDB();
111
112 db.runSQLTemplate(path, failOnError);
113 }
114
115 public void upgrade() throws UpgradeException {
116 try {
117 if (_log.isInfoEnabled()) {
118 _log.info("Upgrading " + getClass().getName());
119 }
120
121 doUpgrade();
122 }
123 catch (Exception e) {
124 throw new UpgradeException(e);
125 }
126 }
127
128 public void upgrade(Class<?> upgradeProcessClass)
129 throws UpgradeException {
130
131 UpgradeProcess upgradeProcess = null;
132
133 try {
134 upgradeProcess = (UpgradeProcess)upgradeProcessClass.newInstance();
135 }
136 catch (Exception e) {
137 throw new UpgradeException(e);
138 }
139
140 upgradeProcess.upgrade();
141 }
142
143 public void upgrade(UpgradeProcess upgradeProcess)
144 throws UpgradeException {
145
146 upgradeProcess.upgrade();
147 }
148
149 protected void doUpgrade() throws Exception {
150 }
151
152 private static Log _log = LogFactoryUtil.getLog(UpgradeProcess.class);
153
154 }