Package org.wso2.carbon.datasource.multitenancy

Source Code of org.wso2.carbon.datasource.multitenancy.DataSourceInitializer

/*
*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing,
*  software distributed under the License is distributed on an
*  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
*  KIND, either express or implied.  See the License for the
*  specific language governing permissions and limitations
*  under the License.
*
*/
package org.wso2.carbon.datasource.multitenancy;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.commons.datasource.DataSourceInformationRepository;
import org.wso2.carbon.core.multitenancy.SuperTenantCarbonContext;
import org.wso2.carbon.datasource.DataSourceInformationManager;
import org.wso2.carbon.datasource.internal.DataSourceServiceComponent;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;

import java.util.HashMap;
import java.util.Map;

public class DataSourceInitializer extends AbstractAxis2ConfigurationContextObserver {

    private static final Log log = LogFactory.getLog(DataSourceInitializer.class);

    public void createdConfigurationContext(ConfigurationContext configurationContext) {
        int tenatId = SuperTenantCarbonContext.getCurrentContext(
                configurationContext).getTenantId();
        DataSourceInformationManager dataSourceInformationManager =
                new DataSourceInformationManager();
        try {
            dataSourceInformationManager.setRepository(new DataSourceInformationRepository());
            dataSourceInformationManager.setRegistry(DataSourceServiceComponent.
                    getRegistryService().getConfigSystemRegistry(tenatId));
        } catch (RegistryException e) {
            log.error(e);
        }

        Map<Integer, DataSourceInformationRepository> repositoryMap = (
                Map<Integer, DataSourceInformationRepository>) configurationContext.getProperty(
                DataSourceServiceComponent.DATA_SOURCE_REPOSITORY_MAP);
        if (repositoryMap == null) {
            repositoryMap = new HashMap<Integer, DataSourceInformationRepository>();
            repositoryMap.put(tenatId, dataSourceInformationManager.getRepository());
        }

        configurationContext.setProperty(
                DataSourceServiceComponent.DATA_SOURCE_REPOSITORY_MAP, repositoryMap);
    }

}
TOP

Related Classes of org.wso2.carbon.datasource.multitenancy.DataSourceInitializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.