001    /**
002     * Copyright (c) 2000-present 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    @Deprecated
032    public class DatabaseUtil {
033    
034            public static Database getDatabase() {
035                    if (_database != null) {
036                            return _database;
037                    }
038    
039                    _database = new Database() {
040    
041                            @Override
042                            public String getType() {
043                                    DB db = DBFactoryUtil.getDB();
044    
045                                    return db.getType();
046                            }
047    
048                            @Override
049                            public void runSQLTemplate(String path)
050                                    throws IOException, NamingException, SQLException {
051    
052                                    DB db = DBFactoryUtil.getDB();
053    
054                                    db.runSQLTemplate(path);
055                            }
056    
057                            @Override
058                            public void runSQLTemplate(String path, boolean failOnError)
059                                    throws IOException, NamingException, SQLException {
060    
061                                    DB db = DBFactoryUtil.getDB();
062    
063                                    db.runSQLTemplate(path, failOnError);
064                            }
065    
066                    };
067    
068                    return _database;
069            }
070    
071            public static String getType() {
072                    return getDatabase().getType();
073            }
074    
075            public static void runSQLTemplate(String path)
076                    throws IOException, NamingException, SQLException {
077    
078                    getDatabase().runSQLTemplate(path);
079            }
080    
081            public static void runSQLTemplate(String path, boolean failOnError)
082                    throws IOException, NamingException, SQLException {
083    
084                    getDatabase().runSQLTemplate(path, failOnError);
085            }
086    
087            public void setDatabase(Database database) {
088                    _database = database;
089            }
090    
091            private static Database _database;
092    
093    }