Search in sources :

Example 1 with UnitDbAdapter

use of org.apache.cayenne.unit.UnitDbAdapter in project cayenne by apache.

the class UnitDbAdapterProvider method get.

public UnitDbAdapter get() throws ConfigurationException {
    String testAdapterType = adapterTypesMap.get(dataSourceInfo.getAdapterClassName());
    if (testAdapterType == null) {
        throw new IllegalStateException("Unmapped adapter type: " + dataSourceInfo.getAdapterClassName());
    }
    Class<UnitDbAdapter> type;
    try {
        type = (Class<UnitDbAdapter>) Util.getJavaClass(testAdapterType);
    } catch (ClassNotFoundException e) {
        throw new CayenneRuntimeException("Invalid class %s of type AccessStackAdapter", e, testAdapterType);
    }
    if (!UnitDbAdapter.class.isAssignableFrom(type)) {
        throw new CayenneRuntimeException("Class %s is not assignable to AccessStackAdapter", testAdapterType);
    }
    try {
        Constructor<UnitDbAdapter> c = type.getConstructor(DbAdapter.class);
        UnitDbAdapter unitAdapter = c.newInstance(adapter);
        injector.injectMembers(unitAdapter);
        return unitAdapter;
    } catch (Exception e) {
        throw new ConfigurationException("Error instantiating " + testAdapterType, e);
    }
}
Also used : ConfigurationException(org.apache.cayenne.ConfigurationException) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) ConfigurationException(org.apache.cayenne.ConfigurationException)

Aggregations

CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 ConfigurationException (org.apache.cayenne.ConfigurationException)1 UnitDbAdapter (org.apache.cayenne.unit.UnitDbAdapter)1