@@ -93,11 +93,7 @@ public void writeEntity(
93
93
boolean nameOrParentChanged ,
94
94
PolarisBaseEntity originalEntity ) {
95
95
try {
96
- datasourceOperations .runWithinTransaction (
97
- statement -> {
98
- persistEntity (callCtx , entity , originalEntity , statement );
99
- return true ;
100
- });
96
+ persistEntity (callCtx , entity , originalEntity , datasourceOperations ::executeUpdate );
101
97
} catch (SQLException e ) {
102
98
throw new RuntimeException ("Error persisting entity" , e );
103
99
}
@@ -115,7 +111,6 @@ public void writeEntities(
115
111
PolarisBaseEntity entity = entities .get (i );
116
112
PolarisBaseEntity originalEntity =
117
113
originalEntities != null ? originalEntities .get (i ) : null ;
118
-
119
114
// first, check if the entity has already been created, in which case we will simply
120
115
// return it.
121
116
PolarisBaseEntity entityFound =
@@ -127,7 +122,7 @@ public void writeEntities(
127
122
// already been updated after the creation.
128
123
continue ;
129
124
}
130
- persistEntity (callCtx , entity , originalEntity , statement );
125
+ persistEntity (callCtx , entity , originalEntity , statement :: executeUpdate );
131
126
}
132
127
return true ;
133
128
});
@@ -143,12 +138,12 @@ private void persistEntity(
143
138
@ Nonnull PolarisCallContext callCtx ,
144
139
@ Nonnull PolarisBaseEntity entity ,
145
140
PolarisBaseEntity originalEntity ,
146
- Statement statement )
141
+ QueryAction queryAction )
147
142
throws SQLException {
148
143
ModelEntity modelEntity = ModelEntity .fromEntity (entity );
149
144
if (originalEntity == null ) {
150
145
try {
151
- statement . executeUpdate (generateInsertQuery (modelEntity , realmId ));
146
+ queryAction . apply (generateInsertQuery (modelEntity , realmId ));
152
147
} catch (SQLException e ) {
153
148
if (datasourceOperations .isConstraintViolation (e )) {
154
149
PolarisBaseEntity existingEntity =
@@ -176,7 +171,7 @@ private void persistEntity(
176
171
"realm_id" ,
177
172
realmId );
178
173
try {
179
- int rowsUpdated = statement . executeUpdate (generateUpdateQuery (modelEntity , params ));
174
+ int rowsUpdated = queryAction . apply (generateUpdateQuery (modelEntity , params ));
180
175
if (rowsUpdated == 0 ) {
181
176
throw new RetryOnConcurrencyException (
182
177
"Entity '%s' id '%s' concurrently modified; expected version %s" ,
@@ -923,4 +918,9 @@ PolarisStorageIntegration<T> loadPolarisStorageIntegration(
923
918
BaseMetaStoreManager .extractStorageConfiguration (callContext , entity );
924
919
return storageIntegrationProvider .getStorageIntegrationForConfig (storageConfig );
925
920
}
921
+
922
+ @ FunctionalInterface
923
+ private interface QueryAction {
924
+ Integer apply (String query ) throws SQLException ;
925
+ }
926
926
}
0 commit comments