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 @Override
041 public String getType() {
042 DB db = DBFactoryUtil.getDB();
043
044 return db.getType();
045 }
046
047 @Override
048 public void runSQLTemplate(String path)
049 throws IOException, NamingException, SQLException {
050
051 DB db = DBFactoryUtil.getDB();
052
053 db.runSQLTemplate(path);
054 }
055
056 @Override
057 public void runSQLTemplate(String path, boolean failOnError)
058 throws IOException, NamingException, SQLException {
059
060 DB db = DBFactoryUtil.getDB();
061
062 db.runSQLTemplate(path, failOnError);
063 }
064
065 };
066
067 return _database;
068 }
069
070 public static String getType() {
071 return getDatabase().getType();
072 }
073
074 public static void runSQLTemplate(String path)
075 throws IOException, NamingException, SQLException {
076
077 getDatabase().runSQLTemplate(path);
078 }
079
080 public static void runSQLTemplate(String path, boolean failOnError)
081 throws IOException, NamingException, SQLException {
082
083 getDatabase().runSQLTemplate(path, failOnError);
084 }
085
086 public void setDatabase(Database database) {
087 _database = database;
088 }
089
090 private static Database _database;
091
092 }