From e82a4a13be30cb38eccc0dc9e58153fdfb4d187e Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Fri, 6 Sep 2024 00:42:54 -0700 Subject: [PATCH] use entityexistsexception --- .../PolarisEclipseLinkMetaStoreSessionImpl.java | 3 ++- .../polaris/service/admin/PolarisServiceImpl.java | 14 +++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java index 4570d4018..ef631f171 100644 --- a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java +++ b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java @@ -22,6 +22,7 @@ import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_URL; import com.google.common.base.Predicates; +import jakarta.persistence.EntityExistsException; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityTransaction; @@ -261,7 +262,7 @@ public T runInTransaction( } } catch (PersistenceException e) { if (e.toString().toLowerCase(Locale.ROOT).contains("duplicate key")) { - throw new IllegalStateException("Duplicate key error when persisting entity", e); + throw new EntityExistsException("Duplicate key error when persisting entity", e); } else { throw e; } diff --git a/polaris-service/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java b/polaris-service/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java index 8c1c72f3f..4fa7a223c 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java @@ -360,11 +360,7 @@ public Response assignPrincipalRole( request.getPrincipalRole().getName(), principalName); PolarisAdminService adminService = newAdminService(securityContext); - try { - adminService.assignPrincipalRole(principalName, request.getPrincipalRole().getName()); - } catch (IllegalStateException e) { - throw new AlreadyExistsException("Grant already exists or resolution failed"); - } + adminService.assignPrincipalRole(principalName, request.getPrincipalRole().getName()); return Response.status(Response.Status.CREATED).build(); } @@ -406,12 +402,8 @@ public Response assignCatalogRoleToPrincipalRole( catalogName, principalRoleName); PolarisAdminService adminService = newAdminService(securityContext); - try { - adminService.assignCatalogRoleToPrincipalRole( - principalRoleName, catalogName, request.getCatalogRole().getName()); - } catch (IllegalStateException e) { - throw new AlreadyExistsException("Grant already exists or resolution failed"); - } + adminService.assignCatalogRoleToPrincipalRole( + principalRoleName, catalogName, request.getCatalogRole().getName()); return Response.status(Response.Status.CREATED).build(); }