001    /**
002     * Copyright (c) 2000-2013 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.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 {@link #initDataSource(String, String, String, String,
050             *             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    }