singhpk234 commented on code in PR #3334:
URL: https://github.com/apache/polaris/pull/3334#discussion_r2651527711


##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java:
##########
@@ -431,15 +448,34 @@ public PolarisBaseEntity lookupEntityByName(
             name,
             "realm_id",
             realmId);
-    return getPolarisBaseEntity(
+    QueryGenerator.PreparedQuery query =
         QueryGenerator.generateSelectQuery(
-            ModelEntity.getAllColumnNames(schemaVersion), 
ModelEntity.TABLE_NAME, params));
+            ModelEntity.getAllColumnNames(schemaVersion), 
ModelEntity.TABLE_NAME, params);
+    return getPolarisBaseEntity(query, connection);
   }
 
   @Nullable
   private PolarisBaseEntity getPolarisBaseEntity(QueryGenerator.PreparedQuery 
query) {
+    return getPolarisBaseEntity(query, null);
+  }
+
+  /**
+   * Execute entity lookup, optionally using an existing connection to 
maintain transaction
+   * consistency.
+   *
+   * @param query the prepared query to execute
+   * @param connection optional connection to reuse; if null, a new connection 
will be obtained
+   * @return the entity if found, null otherwise
+   */
+  @Nullable
+  private PolarisBaseEntity getPolarisBaseEntity(
+      QueryGenerator.PreparedQuery query, @Nullable Connection connection) {
     try {
-      var results = datasourceOperations.executeSelect(query, new 
ModelEntity(schemaVersion));
+      List<PolarisBaseEntity> results =
+          connection != null

Review Comment:
   writeEntity is an atomicOperation, its not wrapped within transaction, so if 
write failed due to constrain violation, it would have been because of an 
entity thats actually persisted, hence it would fine to do a lookup in new 
connection, unlike writeEntities which would conflict with the entities not 
committed yet. 
   Let me know WDYT considering above, happy to wrap the writeEntity in a 
transaction too for connection reuse for consistency ?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to