You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "HonahX (via GitHub)" <gi...@apache.org> on 2025/04/26 03:47:20 UTC

[PR] Make writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

HonahX opened a new pull request, #1469:
URL: https://github.com/apache/polaris/pull/1469

   <!--
       Possible security vulnerabilities: STOP here and contact security@apache.org instead!
   
       Please update the title of the PR with a meaningful message - do not leave it "empty" or "generated"
       Please update this summary field:
   
       The summary should cover these topics, if applicable:
       * the motivation for the change
       * a description of the status quo, for example the current behavior
       * the desired behavior
       * etc
   
       PR checklist:
       - Do a self-review of your code before opening a pull request
       - Make sure that there's good test coverage for the changes included in this PR
       - Run tests locally before pushing a PR (./gradlew check)
       - Code should have comments where applicable. Particularly hard-to-understand
         areas deserve good in-line documentation.
       - Include changes and enhancements to the documentation (in site/content/in-dev/unreleased)
       - For Work In Progress Pull Requests, please use the Draft PR feature.
   
       Make sure to add the information BELOW this comment.
       Everything in this comment will NOT be added to the PR description.
   -->
   `writeToPolicyMappingRecords` should update the existing record if there is one with the same primary key. This PR fix the implementation in EclipseLink Persistence to align with the expectation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard merged PR #1469:
URL: https://github.com/apache/polaris/pull/1469


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "HonahX (via GitHub)" <gi...@apache.org>.
HonahX commented on code in PR #1469:
URL: https://github.com/apache/polaris/pull/1469#discussion_r2064415260


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java:
##########
@@ -420,7 +420,21 @@ void writeToPolicyMappingRecords(
     diagnosticServices.check(session != null, "session_is_null");
     checkInitialized();
 
-    session.persist(ModelPolicyMappingRecord.fromPolicyMappingRecord(mappingRecord));
+    ModelPolicyMappingRecord model =
+        lookupPolicyMappingRecord(
+            session,
+            mappingRecord.getTargetCatalogId(),
+            mappingRecord.getTargetId(),
+            mappingRecord.getPolicyTypeCode(),
+            mappingRecord.getPolicyCatalogId(),
+            mappingRecord.getPolicyId());
+    if (model != null) {
+      model.update(mappingRecord);

Review Comment:
   Added a TODO. Yeah, I did several attempts to use the existence checking annotation and `merge` but it did not work out-of-box. We probably still need to query the database to get the "version" for existing row for optimistic locking. Will try this approach or other approach later when I got some time : )



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "HonahX (via GitHub)" <gi...@apache.org>.
HonahX commented on code in PR #1469:
URL: https://github.com/apache/polaris/pull/1469#discussion_r2064415260


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java:
##########
@@ -420,7 +420,21 @@ void writeToPolicyMappingRecords(
     diagnosticServices.check(session != null, "session_is_null");
     checkInitialized();
 
-    session.persist(ModelPolicyMappingRecord.fromPolicyMappingRecord(mappingRecord));
+    ModelPolicyMappingRecord model =
+        lookupPolicyMappingRecord(
+            session,
+            mappingRecord.getTargetCatalogId(),
+            mappingRecord.getTargetId(),
+            mappingRecord.getPolicyTypeCode(),
+            mappingRecord.getPolicyCatalogId(),
+            mappingRecord.getPolicyId());
+    if (model != null) {
+      model.update(mappingRecord);

Review Comment:
   Added a TODO. Yeah, I did several attempts to use the existence checking annotation and `merge` but it did not work out-of-box. Will try this approach or other approach later when I got some time : )



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #1469:
URL: https://github.com/apache/polaris/pull/1469#discussion_r2064383501


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java:
##########
@@ -420,7 +420,21 @@ void writeToPolicyMappingRecords(
     diagnosticServices.check(session != null, "session_is_null");
     checkInitialized();
 
-    session.persist(ModelPolicyMappingRecord.fromPolicyMappingRecord(mappingRecord));
+    ModelPolicyMappingRecord model =
+        lookupPolicyMappingRecord(
+            session,
+            mappingRecord.getTargetCatalogId(),
+            mappingRecord.getTargetId(),
+            mappingRecord.getPolicyTypeCode(),
+            mappingRecord.getPolicyCatalogId(),
+            mappingRecord.getPolicyId());
+    if (model != null) {
+      model.update(mappingRecord);

Review Comment:
   For EclipseLink, see:
   https://eclipse.dev/eclipselink/documentation/2.4/jpa/extensions/a_existencechecking.htm



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #1469:
URL: https://github.com/apache/polaris/pull/1469#discussion_r2064191804


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java:
##########
@@ -420,7 +420,21 @@ void writeToPolicyMappingRecords(
     diagnosticServices.check(session != null, "session_is_null");
     checkInitialized();
 
-    session.persist(ModelPolicyMappingRecord.fromPolicyMappingRecord(mappingRecord));
+    ModelPolicyMappingRecord model =
+        lookupPolicyMappingRecord(
+            session,
+            mappingRecord.getTargetCatalogId(),
+            mappingRecord.getTargetId(),
+            mappingRecord.getPolicyTypeCode(),
+            mappingRecord.getPolicyCatalogId(),
+            mappingRecord.getPolicyId());
+    if (model != null) {
+      model.update(mappingRecord);

Review Comment:
   Is this adding another roundtrip to the metastore? Can that be avoided?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #1469:
URL: https://github.com/apache/polaris/pull/1469#discussion_r2064455721


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java:
##########
@@ -420,7 +420,21 @@ void writeToPolicyMappingRecords(
     diagnosticServices.check(session != null, "session_is_null");
     checkInitialized();
 
-    session.persist(ModelPolicyMappingRecord.fromPolicyMappingRecord(mappingRecord));
+    ModelPolicyMappingRecord model =
+        lookupPolicyMappingRecord(
+            session,
+            mappingRecord.getTargetCatalogId(),
+            mappingRecord.getTargetId(),
+            mappingRecord.getPolicyTypeCode(),
+            mappingRecord.getPolicyCatalogId(),
+            mappingRecord.getPolicyId());
+    if (model != null) {
+      model.update(mappingRecord);

Review Comment:
   yes, i tried merge too when i thinking of re:using the eclipselink for AtomicMetaStoreManager, but i think the issue is that when we run hand crafted queries (i.e not model.update() / .merge()) the entity manager goes out of sync and hence the two queries are un-avoidable here even though this is a atomic operation :/ , atleast to the best of my understanding. It would be really awesome if we can work around this or get this into one query !



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "HonahX (via GitHub)" <gi...@apache.org>.
HonahX commented on code in PR #1469:
URL: https://github.com/apache/polaris/pull/1469#discussion_r2064360108


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java:
##########
@@ -420,7 +420,21 @@ void writeToPolicyMappingRecords(
     diagnosticServices.check(session != null, "session_is_null");
     checkInitialized();
 
-    session.persist(ModelPolicyMappingRecord.fromPolicyMappingRecord(mappingRecord));
+    ModelPolicyMappingRecord model =
+        lookupPolicyMappingRecord(
+            session,
+            mappingRecord.getTargetCatalogId(),
+            mappingRecord.getTargetId(),
+            mappingRecord.getPolicyTypeCode(),
+            mappingRecord.getPolicyCatalogId(),
+            mappingRecord.getPolicyId());
+    if (model != null) {
+      model.update(mappingRecord);

Review Comment:
   I did not find useful things in EclipseLink to do existence check + upsert in one command. So I followed the existing pattern in `writeEntities` https://github.com/apache/polaris/blob/a84b5c4a512edbd5535fb509332e911f87db38d6/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java#L87-L97 to do this. 
   
   Shall we add a "TODO" here to note that we are looking for ways to improve this to one execution?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #1469:
URL: https://github.com/apache/polaris/pull/1469#discussion_r2064383047


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java:
##########
@@ -420,7 +420,21 @@ void writeToPolicyMappingRecords(
     diagnosticServices.check(session != null, "session_is_null");
     checkInitialized();
 
-    session.persist(ModelPolicyMappingRecord.fromPolicyMappingRecord(mappingRecord));
+    ModelPolicyMappingRecord model =
+        lookupPolicyMappingRecord(
+            session,
+            mappingRecord.getTargetCatalogId(),
+            mappingRecord.getTargetId(),
+            mappingRecord.getPolicyTypeCode(),
+            mappingRecord.getPolicyCatalogId(),
+            mappingRecord.getPolicyId());
+    if (model != null) {
+      model.update(mappingRecord);

Review Comment:
   Yeah with a TODO, this LGTM



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl [polaris]

Posted by "HonahX (via GitHub)" <gi...@apache.org>.
HonahX closed pull request #1469: Ensure writeToPolicyMappingRecord update existing record if primary key equals in EclipseLink Persistence Impl
URL: https://github.com/apache/polaris/pull/1469


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org