1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.verify;
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  
22  import java.io.IOException;
23  
24  import java.sql.SQLException;
25  
26  import javax.naming.NamingException;
27  
28  /**
29   * <a href="VerifyProcess.java.html"><b><i>View Source</i></b></a>
30   *
31   * This abstract class should be extended for startup processes that verify the
32   * integrity of the database. They can be added as part of
33   * <code>com.liferay.portal.verify.VerifyProcessSuite</code> or be executed
34   * independently by being set in the portal.properties file. Each of these
35   * processes should not cause any problems if run multiple times. <a
36   * href="VerifyProcess.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Alexander Chow
39   */
40  public abstract class VerifyProcess {
41  
42      public static final int ALWAYS = -1;
43  
44      public static final int NEVER = 0;
45  
46      public static final int ONCE = 1;
47  
48      public void runSQL(String template) throws IOException, SQLException {
49          DB db = DBFactoryUtil.getDB();
50  
51          db.runSQL(template);
52      }
53  
54      public void runSQL(String[] templates) throws IOException, SQLException {
55          DB db = DBFactoryUtil.getDB();
56  
57          db.runSQL(templates);
58      }
59  
60      public void runSQLTemplate(String path)
61          throws IOException, NamingException, SQLException {
62  
63          DB db = DBFactoryUtil.getDB();
64  
65          db.runSQLTemplate(path);
66      }
67  
68      public void runSQLTemplate(String path, boolean failOnError)
69          throws IOException, NamingException, SQLException {
70  
71          DB db = DBFactoryUtil.getDB();
72  
73          db.runSQLTemplate(path, failOnError);
74      }
75  
76      public void verify() throws VerifyException {
77          try {
78              if (_log.isInfoEnabled()) {
79                  _log.info("Verifying " + getClass().getName());
80              }
81  
82              doVerify();
83          }
84          catch (Exception e) {
85              throw new VerifyException(e);
86          }
87      }
88  
89      public void verify(VerifyProcess verifyProcess)
90          throws VerifyException {
91  
92          verifyProcess.verify();
93      }
94  
95      protected void doVerify() throws Exception {
96      }
97  
98      private static Log _log = LogFactoryUtil.getLog(VerifyProcess.class);
99  
100 }