| VerifyMySQL.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
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 /**
37 * <a href="VerifyMySQL.java.html"><b><i>View Source</i></b></a>
38 *
39 * @author Brian Wing Shun Chan
40 */
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 }