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.kernel.util;
16  
17  import com.liferay.portal.kernel.dao.db.DB;
18  import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
19  
20  import java.io.IOException;
21  
22  import java.sql.SQLException;
23  
24  import javax.naming.NamingException;
25  
26  /**
27   * <a href="DatabaseUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author     Ganesh Ram
30   * @author     Brian Wing Shun Chan
31   * @deprecated {@link DBFactoryUtil}
32   */
33  public class DatabaseUtil {
34  
35      public static Database getDatabase() {
36          if (_database != null) {
37              return _database;
38          }
39  
40          _database = new Database() {
41  
42              public String getType() {
43                  DB db = DBFactoryUtil.getDB();
44  
45                  return db.getType();
46              }
47  
48              public void runSQLTemplate(String path)
49                  throws IOException, NamingException, SQLException {
50  
51                  DB db = DBFactoryUtil.getDB();
52  
53                  db.runSQLTemplate(path);
54              }
55  
56              public void runSQLTemplate(String path, boolean failOnError)
57                  throws IOException, NamingException, SQLException {
58  
59                  DB db = DBFactoryUtil.getDB();
60  
61                  db.runSQLTemplate(path, failOnError);
62              }
63  
64          };
65  
66          return _database;
67      }
68  
69      public static String getType() {
70          return getDatabase().getType();
71      }
72  
73      public static void runSQLTemplate(String path)
74          throws IOException, NamingException, SQLException {
75  
76          getDatabase().runSQLTemplate(path);
77      }
78  
79      public static void runSQLTemplate(String path, boolean failOnError)
80          throws IOException, NamingException, SQLException {
81  
82          getDatabase().runSQLTemplate(path, failOnError);
83      }
84  
85      public void setDatabase(Database database) {
86          _database = database;
87      }
88  
89      private static Database _database;
90  
91  }