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.dao.jdbc;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    import com.liferay.portal.kernel.util.StringPool;
019    
020    import java.util.Properties;
021    
022    import javax.sql.DataSource;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class DataSourceFactoryUtil {
028    
029            public static void destroyDataSource(DataSource dataSource)
030                    throws Exception {
031    
032                    getDataSourceFactory().destroyDataSource(dataSource);
033            }
034    
035            public static DataSourceFactory getDataSourceFactory() {
036                    PortalRuntimePermission.checkGetBeanProperty(
037                            DataSourceFactoryUtil.class);
038    
039                    return _dataSourceFactory;
040            }
041    
042            public static DataSource initDataSource(Properties properties)
043                    throws Exception {
044    
045                    return getDataSourceFactory().initDataSource(properties);
046            }
047    
048            /**
049             * @deprecated As of 6.2.0, replaced by {@link #initDataSource(String,
050             *             String, String, String, String)}
051             */
052            public static DataSource initDataSource(
053                            String driverClassName, String url, String userName,
054                            String password)
055                    throws Exception {
056    
057                    return initDataSource(
058                            driverClassName, url, userName, password, StringPool.BLANK);
059            }
060    
061            public static DataSource initDataSource(
062                            String driverClassName, String url, String userName,
063                            String password, String jndiName)
064                    throws Exception {
065    
066                    return getDataSourceFactory().initDataSource(
067                            driverClassName, url, userName, password, jndiName);
068            }
069    
070            public static void setDataSourceFactory(
071                    DataSourceFactory dataSourceFactory) {
072    
073                    PortalRuntimePermission.checkSetBeanProperty(
074                            DataSourceFactoryUtil.class);
075    
076                    _dataSourceFactory = dataSourceFactory;
077            }
078    
079            private static DataSourceFactory _dataSourceFactory;
080    
081    }