001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 {@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                            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    }