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