Example usage for org.apache.commons.dbcp2 BasicDataSource getClass

List of usage examples for org.apache.commons.dbcp2 BasicDataSource getClass

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 BasicDataSource getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.everit.osgi.jdbc.commons.dbcp.internal.Util.java

private static final <T> void setPropertyIfNotNull(final BasicDataSource dataSource,
        final Map<String, Object> properties, String propKey, Class<T> paramType) {

    Object propValueObject = properties.get(propKey);
    propValueObject = convertConfigurationValueIfNecessary(paramType, propValueObject);
    if (propValueObject == null) {
        return;/*from  ww w  .  j a  v  a  2  s. com*/
    }

    Class<?> propType = convertToConfigValueType(paramType);
    if (!propType.isAssignableFrom(propValueObject.getClass())) {
        throw new RuntimeException("Expected type of property '" + propKey + "' is '" + propType
                + "' while the component property has the type '" + propValueObject.getClass() + "'");
    }

    String methodName = convertPropNameToMethodName(propKey);
    try {
        Method method = dataSource.getClass().getMethod(methodName, paramType);
        method.invoke(dataSource, propValueObject);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (SecurityException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    }
}

From source file:org.everit.persistence.jdbc.commons.dbcp.ecm.internal.Util.java

private static <T> void setPropertyIfNotNull(final BasicDataSource dataSource,
        final Map<String, Object> properties, final String propKey, final Class<T> paramType) {

    Object propValueObject = properties.get(propKey);
    propValueObject = Util.convertConfigurationValueIfNecessary(paramType, propValueObject);
    if (propValueObject == null) {
        return;//from w  w  w  .  j av a 2s  .  c  om
    }

    Class<?> propType = Util.convertToConfigValueType(paramType);
    if (!propType.isAssignableFrom(propValueObject.getClass())) {
        throw new RuntimeException("Expected type of property '" + propKey + "' is '" + propType
                + "' while the component property has the type '" + propValueObject.getClass() + "'");
    }

    String methodName = Util.convertPropNameToMethodName(propKey);
    try {
        Method method = dataSource.getClass().getMethod(methodName, paramType);
        method.invoke(dataSource, propValueObject);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (SecurityException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Error during setting property '" + propKey + "' of datasource", e);
    }
}