Skip to content

Commit

Permalink
final supposed structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgio Trettenero committed Dec 4, 2024
1 parent eb95f84 commit 231aa96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.model.DatabaseInfo;
import com.netflix.metacat.connector.polaris.common.PolarisUtils;
Expand All @@ -20,6 +21,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,17 +89,17 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na
try {
this.polarisStoreService.deleteDatabase(name.getDatabaseName());
} catch (DataIntegrityViolationException exception) {
// if (exception.getMessage().contains("violates foreign key constraint")
// || (exception.getCause() instanceof SQLException
// && "23503".equals(((SQLException) exception.getCause()).getSQLState()))) {
//
// final 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, exception.getMessage()
// );
// throw new DatabasePreconditionFailedException(name, errorMessage, exception);
// }
if (exception.getMessage().contains("violates foreign key constraint")
|| (exception.getCause() instanceof SQLException
&& "23503".equals(((SQLException) exception.getCause()).getSQLState()))) {

final 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, exception.getMessage()
);
throw new DatabasePreconditionFailedException(name, errorMessage, exception);
}
throw new InvalidMetaException(name, exception);
} catch (Exception exception) {
throw new ConnectorException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ public class PolarisConnectorDatabaseServiceTest {
*/
@BeforeEach
public void init() {
final String location = "file://temp2";
polarisStoreService.createDatabase(DB1_NAME, location, "metacat_user");
connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris",
new DefaultConfigImpl(
new MetacatProperties(null)
Expand Down Expand Up @@ -206,6 +204,8 @@ public void testDeleteDb() {

@Test
public void testDeleteDbNoCascades() {
final DatabaseInfo info = DatabaseInfo.builder().name(DB1_QUALIFIED_NAME).build();
polarisDBService.create(requestContext, info);
Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME));

final QualifiedName qualifiedName = QualifiedName.ofTable(
Expand Down

0 comments on commit 231aa96

Please sign in to comment.