001
014
015 package com.liferay.portal.verify;
016
017 import com.liferay.portal.kernel.dao.db.DB;
018 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
019 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.model.ReleaseConstants;
023
024 import java.io.IOException;
025
026 import java.sql.Connection;
027 import java.sql.PreparedStatement;
028 import java.sql.ResultSet;
029 import java.sql.SQLException;
030
031 import javax.naming.NamingException;
032
033
042 public abstract class VerifyProcess {
043
044 public static final int ALWAYS = -1;
045
046 public static final int NEVER = 0;
047
048 public static final int ONCE = 1;
049
050 public void runSQL(String template) throws IOException, SQLException {
051 DB db = DBFactoryUtil.getDB();
052
053 db.runSQL(template);
054 }
055
056 public void runSQL(String[] templates) throws IOException, SQLException {
057 DB db = DBFactoryUtil.getDB();
058
059 db.runSQL(templates);
060 }
061
062 public void runSQLTemplate(String path)
063 throws IOException, NamingException, SQLException {
064
065 DB db = DBFactoryUtil.getDB();
066
067 db.runSQLTemplate(path);
068 }
069
070 public void runSQLTemplate(String path, boolean failOnError)
071 throws IOException, NamingException, SQLException {
072
073 DB db = DBFactoryUtil.getDB();
074
075 db.runSQLTemplate(path, failOnError);
076 }
077
078 public void verify() throws VerifyException {
079 try {
080 if (_log.isInfoEnabled()) {
081 _log.info("Verifying " + getClass().getName());
082 }
083
084 doVerify();
085 }
086 catch (Exception e) {
087 throw new VerifyException(e);
088 }
089 }
090
091 public void verify(VerifyProcess verifyProcess) throws VerifyException {
092 verifyProcess.verify();
093 }
094
095 protected void doVerify() throws Exception {
096 }
097
098
103 protected int getBuildNumber() throws Exception {
104 Connection con = null;
105 PreparedStatement ps = null;
106 ResultSet rs = null;
107
108 try {
109 con = DataAccess.getUpgradeOptimizedConnection();
110
111 ps = con.prepareStatement(
112 "select buildNumber from Release_ where servletContextName " +
113 "= ?");
114
115 ps.setString(1, ReleaseConstants.DEFAULT_SERVLET_CONTEXT_NAME);
116
117 rs = ps.executeQuery();
118
119 rs.next();
120
121 return rs.getInt(1);
122 }
123 finally {
124 DataAccess.cleanUp(con, ps, rs);
125 }
126 }
127
128 private static Log _log = LogFactoryUtil.getLog(VerifyProcess.class);
129
130 }