public RepositoryConnection getConnection() throws RepositorySourceException {
String errMsg = null;
// check name
if (getName() == null) {
errMsg = JdbcMetadataI18n.propertyIsRequired.text("name");
throw new RepositorySourceException(errMsg);
}
// create Jdbc connection using data source first
try {
if (dataSourceProvider != null) {
// create wrapper for Jdbc connection
return new JdbcConnection(getName(),
getDefaultCachePolicy(),
dataSourceProvider.getConnection(),
rootUuid);
}
} catch (Exception e) {
errMsg = JdbcMetadataI18n.unableToGetConnectionUsingDriver.text(getName(), getDriverClassName(), getDatabaseUrl());
throw new RepositorySourceException(errMsg, e);
}
// create Jdbc connection using driver and database URL
try {
if (driverProvider != null) {
// create wrapper for Jdbc connection
return new JdbcConnection(getName(),
getDefaultCachePolicy(),
driverProvider.getConnection(),
rootUuid);
}
} catch (Exception e) {
errMsg = JdbcMetadataI18n.unableToGetConnectionUsingDataSource.text(getName(), getDataSourceName());
throw new RepositorySourceException(errMsg, e);
}
// Either data source name or JDBC driver connection properties must be defined
errMsg = JdbcMetadataI18n.oneOfPropertiesIsRequired.text(getName());
throw new RepositorySourceException(errMsg);
}