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);
}
}
Aggregations