Search in sources :

Example 1 with ClientConnectionFactoryWrapper

use of org.apache.geode.internal.datasource.ClientConnectionFactoryWrapper in project geode by apache.

the class JNDIInvoker method mapDatasource.

/**
   * Binds a single Datasource to the existing JNDI tree. The JNDI tree may be The Datasource
   * properties are contained in the map. The Datasource implementation class is populated based on
   * properties in the map.
   * 
   * @param map contains Datasource configuration properties.
   */
public static void mapDatasource(Map map, List props) {
    String value = (String) map.get("type");
    String jndiName = "";
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    Object ds = null;
    try {
        jndiName = (String) map.get("jndi-name");
        if (value.equals("PooledDataSource")) {
            ds = DataSourceFactory.getPooledDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds);
            dataSourceList.add(ds);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else if (value.equals("XAPooledDataSource")) {
            ds = DataSourceFactory.getTranxDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds);
            dataSourceList.add(ds);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else if (value.equals("SimpleDataSource")) {
            ds = DataSourceFactory.getSimpleDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else if (value.equals("ManagedDataSource")) {
            ClientConnectionFactoryWrapper ds1 = DataSourceFactory.getManagedDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds1.getClientConnFactory());
            dataSourceList.add(ds1);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else {
            String exception = "JNDIInvoker::mapDataSource::No correct type of DataSource";
            if (writer.fineEnabled())
                writer.fine(exception);
            throw new DataSourceCreateException(exception);
        }
        ds = null;
    } catch (NamingException ne) {
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKER_MAPDATASOURCE_0_WHILE_BINDING_1_TO_JNDI_CONTEXT, new Object[] { "NamingException", jndiName });
    } catch (DataSourceCreateException dsce) {
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKER_MAPDATASOURCE_0_WHILE_BINDING_1_TO_JNDI_CONTEXT, new Object[] { "DataSourceCreateException", jndiName });
    }
}
Also used : ClientConnectionFactoryWrapper(org.apache.geode.internal.datasource.ClientConnectionFactoryWrapper) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) DataSourceCreateException(org.apache.geode.internal.datasource.DataSourceCreateException)

Aggregations

LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)1 ClientConnectionFactoryWrapper (org.apache.geode.internal.datasource.ClientConnectionFactoryWrapper)1 DataSourceCreateException (org.apache.geode.internal.datasource.DataSourceCreateException)1