Search in sources :

Example 11 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class DataSourceInformationListFactoryTest method testCreateDataSourceInformationList.

/**
 * Test creating a list of DataSourceInformation objects from properties
 */
public void testCreateDataSourceInformationList() {
    Properties properties = new Properties();
    properties.put("synapse.datasources", "dataSource1,dataSource2,dataSource3");
    properties.put("synapse.datasources.dataSource1.driverClassName", "org.h2.Driver");
    properties.put("synapse.datasources.dataSource1.url", "jdbc:h2:repository/database/test_db1");
    properties.put("synapse.datasources.dataSource1.dsName", "dataSource1");
    properties.put("synapse.datasources.dataSource2.driverClassName", "org.h2.Driver");
    properties.put("synapse.datasources.dataSource2.url", "jdbc:h2:repository/database/test_db2");
    properties.put("synapse.datasources.dataSource2.dsName", "dataSource2");
    properties.put("synapse.datasources.dataSource3.driverClassName", "org.h2.Driver");
    properties.put("synapse.datasources.dataSource3.url", "jdbc:h2:repository/database/test_db3");
    properties.put("synapse.datasources.dataSource3.dsName", "dataSource3");
    List<DataSourceInformation> dataSourceInformations = DataSourceInformationListFactory.createDataSourceInformationList(properties);
    assertEquals("Invalid no of DataSourceInformation objects created", 3, dataSourceInformations.size());
}
Also used : DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation) Properties(java.util.Properties)

Example 12 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class DataSourceInformationListFactory method createDataSourceInformationList.

/**
 * Factory method for creating a  a DataSourceInformation Collection
 *
 * @param dsProperties Datasource configuration properties
 * @return A List of DataSourceInformation
 */
public static List<DataSourceInformation> createDataSourceInformationList(Properties dsProperties) {
    final List<DataSourceInformation> dataSourceInformations = new ArrayList<DataSourceInformation>();
    if (dsProperties == null) {
        if (log.isDebugEnabled()) {
            log.debug("DataSource properties cannot be found..");
        }
        return dataSourceInformations;
    }
    String dataSources = MiscellaneousUtil.getProperty(dsProperties, DataSourceConstants.PROP_SYNAPSE_PREFIX_DS, null);
    if (dataSources == null || "".equals(dataSources)) {
        if (log.isDebugEnabled()) {
            log.debug("No DataSources defined for initialization..");
        }
        return dataSourceInformations;
    }
    String[] dataSourcesNames = dataSources.split(",");
    if (dataSourcesNames == null || dataSourcesNames.length == 0) {
        if (log.isDebugEnabled()) {
            log.debug("No DataSource definitions found for initialization..");
        }
        return dataSourceInformations;
    }
    for (String dsName : dataSourcesNames) {
        if (dsName == null) {
            continue;
        }
        DataSourceInformation information = DataSourceInformationFactory.createDataSourceInformation(dsName, dsProperties);
        if (information == null) {
            continue;
        }
        dataSourceInformations.add(information);
    }
    return dataSourceInformations;
}
Also used : ArrayList(java.util.ArrayList) DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation)

Example 13 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class DataSourceInformationListSerializer method serialize.

/**
 * Serializes a list of DataSourceInformation into a properties
 *
 * @param dataSourceInformationList A list of DataSourceInformation
 * @return DataSource configuration properties
 */
public static Properties serialize(List<DataSourceInformation> dataSourceInformationList) {
    final Properties properties = new Properties();
    StringBuffer dataSources = new StringBuffer();
    for (DataSourceInformation information : dataSourceInformationList) {
        if (information != null) {
            String name = information.getAlias();
            dataSources.append(name);
            dataSources.append(DataSourceConstants.COMMA_STRING);
            properties.putAll(DataSourceInformationSerializer.serialize(information));
        }
    }
    properties.put(DataSourceConstants.PROP_SYNAPSE_PREFIX_DS, dataSources.toString());
    return properties;
}
Also used : DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation) Properties(java.util.Properties)

Aggregations

DataSourceInformation (org.apache.synapse.commons.datasource.DataSourceInformation)13 Properties (java.util.Properties)7 SecretInformation (org.wso2.securevault.secret.SecretInformation)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)1 DataSource (javax.sql.DataSource)1 OMElement (org.apache.axiom.om.OMElement)1 SynapseCommonsException (org.apache.synapse.commons.SynapseCommonsException)1