001
014
015 package com.liferay.portal.kernel.util;
016
017 import com.liferay.portal.kernel.dao.db.DB;
018 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
019
020 import java.io.IOException;
021
022 import java.sql.SQLException;
023
024 import javax.naming.NamingException;
025
026
031 public class DatabaseUtil {
032
033 public static Database getDatabase() {
034 if (_database != null) {
035 return _database;
036 }
037
038 _database = new Database() {
039
040 public String getType() {
041 DB db = DBFactoryUtil.getDB();
042
043 return db.getType();
044 }
045
046 public void runSQLTemplate(String path)
047 throws IOException, NamingException, SQLException {
048
049 DB db = DBFactoryUtil.getDB();
050
051 db.runSQLTemplate(path);
052 }
053
054 public void runSQLTemplate(String path, boolean failOnError)
055 throws IOException, NamingException, SQLException {
056
057 DB db = DBFactoryUtil.getDB();
058
059 db.runSQLTemplate(path, failOnError);
060 }
061
062 };
063
064 return _database;
065 }
066
067 public static String getType() {
068 return getDatabase().getType();
069 }
070
071 public static void runSQLTemplate(String path)
072 throws IOException, NamingException, SQLException {
073
074 getDatabase().runSQLTemplate(path);
075 }
076
077 public static void runSQLTemplate(String path, boolean failOnError)
078 throws IOException, NamingException, SQLException {
079
080 getDatabase().runSQLTemplate(path, failOnError);
081 }
082
083 public void setDatabase(Database database) {
084 _database = database;
085 }
086
087 private static Database _database;
088
089 }