1
14
15 package com.liferay.portal.upgrade.util;
16
17 import com.liferay.portal.kernel.dao.db.DB;
18 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
19 import com.liferay.portal.kernel.log.Log;
20 import com.liferay.portal.kernel.log.LogFactoryUtil;
21 import com.liferay.portal.kernel.upgrade.UpgradeException;
22 import com.liferay.portal.kernel.util.FileUtil;
23 import com.liferay.portal.kernel.util.Validator;
24
25
31 public abstract class BaseUpgradeTableImpl extends Table {
32
33 public BaseUpgradeTableImpl(String tableName) {
34 super(tableName);
35 }
36
37 public BaseUpgradeTableImpl(String tableName, Object[][] columns) {
38 super(tableName, columns);
39 }
40
41 public void setCreateSQL(String createSQL) throws Exception {
42 if (_calledUpdateTable) {
43 throw new UpgradeException(
44 "setCreateSQL is called after updateTable");
45 }
46
47 super.setCreateSQL(createSQL);
48 }
49
50 public void updateTable() throws Exception {
51 _calledUpdateTable = true;
52
53 String tempFileName = generateTempFile();
54
55 try {
56 DB db = DBFactoryUtil.getDB();
57
58 String createSQL = getCreateSQL();
59
60 if (Validator.isNotNull(createSQL)) {
61 db.runSQL("drop table " + getTableName());
62
63 db.runSQL(createSQL);
64 }
65
66 if (Validator.isNotNull(tempFileName)) {
67 String deleteSQL = getDeleteSQL();
68
69 db.runSQL(deleteSQL);
70
71 populateTable(tempFileName);
72 }
73 }
74 finally {
75 if (Validator.isNotNull(tempFileName)) {
76 FileUtil.delete(tempFileName);
77 }
78 }
79 }
80
81 static Log _log = LogFactoryUtil.getLog(BaseUpgradeTableImpl.class);
82
83 private boolean _calledUpdateTable;
84
85 }