1
22
23 package com.liferay.portal.verify;
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.dao.jdbc.DataAccess;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30 import com.liferay.portal.util.PropsValues;
31
32 import java.sql.Connection;
33 import java.sql.PreparedStatement;
34 import java.sql.ResultSet;
35
36
41 public class VerifyMySQL extends VerifyProcess {
42
43 protected void alterTableEngine(String tableName) throws Exception {
44 if (_log.isInfoEnabled()) {
45 _log.info(
46 "Updating table " + tableName + " to use engine " +
47 PropsValues.DATABASE_MYSQL_ENGINE);
48 }
49
50 Connection con = null;
51 PreparedStatement ps = null;
52
53 try {
54 con = DataAccess.getConnection();
55
56 ps = con.prepareStatement(
57 "alter table " + tableName + " engine " +
58 PropsValues.DATABASE_MYSQL_ENGINE);
59
60 ps.executeUpdate();
61 }
62 finally {
63 DataAccess.cleanUp(con, ps);
64 }
65 }
66
67 protected void doVerify() throws Exception {
68 DB db = DBFactoryUtil.getDB();
69
70 if (!db.getType().equals(DB.TYPE_MYSQL)) {
71 return;
72 }
73
74 Connection con = null;
75 PreparedStatement ps = null;
76 ResultSet rs = null;
77
78 try {
79 con = DataAccess.getConnection();
80
81 ps = con.prepareStatement("show table status");
82
83 rs = ps.executeQuery();
84
85 while (rs.next()) {
86 String tableName = rs.getString("Name");
87 String engine = rs.getString("Engine");
88
89 if (!engine.equalsIgnoreCase(
90 PropsValues.DATABASE_MYSQL_ENGINE)) {
91
92 alterTableEngine(tableName);
93 }
94 }
95 }
96 finally {
97 DataAccess.cleanUp(con, ps, rs);
98 }
99 }
100
101 private static Log _log = LogFactoryUtil.getLog(VerifyMySQL.class);
102
103 }