Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgio Trettenero committed Dec 4, 2024
1 parent 5efabf5 commit 9a9e372
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DatabasePreconditionFailedException extends ConnectorException {
public DatabasePreconditionFailedException(final QualifiedName name,
@Nullable final String message,
@Nullable final Throwable error) {
super(String.format("Precondition failed to update table %s. %s", name, message), error);
super(String.format("Precondition failed to update database %s. %s", name, message), error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import com.netflix.metacat.common.server.connectors.exception.ConnectorException;
import com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException;
import com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException;
import com.netflix.metacat.common.server.connectors.exception.DatabasePreconditionFailedException;
import com.netflix.metacat.common.server.connectors.exception.InvalidMetaException;
import com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException;
import com.netflix.metacat.common.server.connectors.model.DatabaseInfo;
import com.netflix.metacat.connector.polaris.common.PolarisUtils;
import com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper;
Expand All @@ -20,6 +22,7 @@
import org.springframework.dao.DataIntegrityViolationException;

import javax.annotation.Nullable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -87,19 +90,23 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na
try {
this.polarisStoreService.deleteDatabase(name.getDatabaseName());
} catch (DataIntegrityViolationException exception) {
// if (exception.getCause() instanceof ConstraintViolationException) {
// throw new DatabasePreconditionFailedException(
// name,
// String.format("Cannot delete database %s because it is not empty.", name.getDatabaseName()),
// exception
// );
// }
String message = exception.getMessage();
if (message.contains("violates foreign key constraint") ||
(exception.getCause() instanceof SQLException &&
"23503".equals(((SQLException) exception.getCause()).getSQLState()))) {
// Log the specific constraint violation details
String errorMessage = String.format(
"Failed to delete database %s due to foreign key constraint violation. " +
"Ensure all dependent tables are removed first. Error: %s",
name, message
);
throw new DatabasePreconditionFailedException(name, errorMessage, exception);
}
throw new InvalidMetaException(name, exception);
} catch (Exception exception) {
throw new ConnectorException(
String.format("Failed deleting polaris database %s", name), exception);
}
System.out.println("DID NOT CATCH THE DB DELETE ERROR");
}

/**
Expand Down

0 comments on commit 9a9e372

Please sign in to comment.