return (MConnector) doWithConnection(new DoWithConnection() {
@Override
public Object doIt(Connection conn) throws Exception {
String connectorUniqueName = mConnector.getUniqueName();
MConnector result = handler.findConnector(connectorUniqueName, conn);
if (result == null) {
handler.registerConnector(mConnector, conn);
return mConnector;
} else {
// Same connector, check if the version is the same.
// For now, use the "string" versions itself - later we should
// probably include a build number or something that is
// monotonically increasing.
if (result.getUniqueName().equals(mConnector.getUniqueName()) &&
mConnector.getVersion().compareTo(result.getVersion()) > 0) {
if (autoUpgrade) {
upgradeConnector(result, mConnector);
return mConnector;
} else {
throw new SqoopException(RepositoryError.JDBCREPO_0026,
"Connector: " + mConnector.getUniqueName());
}
}
if (!result.equals(mConnector)) {
throw new SqoopException(RepositoryError.JDBCREPO_0013,
"Connector: " + mConnector.getUniqueName()
+ " given: " + mConnector
+ " found: " + result);
}