dimas-b commented on code in PR #3334:
URL: https://github.com/apache/polaris/pull/3334#discussion_r2651976971
##########
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:
I mean that `writeEntity` invokes this select as part of its execution, but
the select will run in a new JDBC transaction (because `connection` is `null`).
Basically, the change `persistEntity` (called by ` writeEntity`) will make and
the select it may do on exception will run in different connections in runtime.
The code of `persistEntity` declares a connection parameter, which makes the
impression that _all_ the logic in that method runs over the same connection
:thinking:
I agree that there is no bug ATM, but the logic is very obscure now that
connection may or may not be `null` (new).
Would it be possible to refactor the code such that `connection` parameters
a non-null when present?
--
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]