001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
027     * @author     Ganesh Ram
028     * @author     Brian Wing Shun Chan
029     * @deprecated As of 6.1.0, replaced by {@link DBFactoryUtil}
030     */
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    }