Skip to content

Commit b3a06bb

Browse files
committed
Remove overloads of BasePersistence.listEntities
`BasePersistence.listEntities` and `TransactionalPersistence.listEntitiesInCurrentTxn` are afaict only overloaded to make the `entityFilter` and `transformer` parameters "optional" for some callers. the most central method still has to have support for both of them. using default methods in the interface would enable this more clearly but as it turns out, hardly any callers are utilizing those overloads and thus if we simply remove the overloads we have less code and things become clearer across the board. we also add a `EntityNameLookupRecord.fromEntity` factory method to replace the overloaded constructor.
1 parent af69d9f commit b3a06bb

File tree

11 files changed

+24
-241
lines changed

11 files changed

+24
-241
lines changed

persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.polaris.extension.persistence.impl.eclipselink;
2020

2121
import com.google.common.annotations.VisibleForTesting;
22-
import com.google.common.base.Predicates;
2322
import jakarta.annotation.Nonnull;
2423
import jakarta.annotation.Nullable;
2524
import jakarta.persistence.EntityManager;
@@ -424,44 +423,6 @@ public List<EntityNameLookupRecord> lookupEntityActiveBatchInCurrentTxn(
424423
.collect(Collectors.toList());
425424
}
426425

427-
/** {@inheritDoc} */
428-
@Override
429-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
430-
@Nonnull PolarisCallContext callCtx,
431-
long catalogId,
432-
long parentId,
433-
@Nonnull PolarisEntityType entityType,
434-
@Nonnull PageToken pageToken) {
435-
return this.listEntitiesInCurrentTxn(
436-
callCtx, catalogId, parentId, entityType, Predicates.alwaysTrue(), pageToken);
437-
}
438-
439-
@Override
440-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
441-
@Nonnull PolarisCallContext callCtx,
442-
long catalogId,
443-
long parentId,
444-
@Nonnull PolarisEntityType entityType,
445-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
446-
@Nonnull PageToken pageToken) {
447-
// full range scan under the parent for that type
448-
return this.listEntitiesInCurrentTxn(
449-
callCtx,
450-
catalogId,
451-
parentId,
452-
entityType,
453-
entityFilter,
454-
entity ->
455-
new EntityNameLookupRecord(
456-
entity.getCatalogId(),
457-
entity.getId(),
458-
entity.getParentId(),
459-
entity.getName(),
460-
entity.getTypeCode(),
461-
entity.getSubTypeCode()),
462-
pageToken);
463-
}
464-
465426
@Override
466427
public @Nonnull <T> Page<T> listEntitiesInCurrentTxn(
467428
@Nonnull PolarisCallContext callCtx,

persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ void writeToEntitiesActive(EntityManager session, PolarisBaseEntity entity) {
105105

106106
ModelEntityActive model = lookupEntityActive(session, new PolarisEntitiesActiveKey(entity));
107107
if (model == null) {
108-
session.persist(ModelEntityActive.fromEntityActive(new EntityNameLookupRecord(entity)));
108+
session.persist(
109+
ModelEntityActive.fromEntityActive(EntityNameLookupRecord.fromEntity(entity)));
109110
}
110111
}
111112

persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.util.function.Predicate;
3838
import java.util.stream.Collectors;
3939
import org.apache.polaris.core.PolarisCallContext;
40-
import org.apache.polaris.core.entity.EntityNameLookupRecord;
4140
import org.apache.polaris.core.entity.LocationBasedEntity;
4241
import org.apache.polaris.core.entity.PolarisBaseEntity;
4342
import org.apache.polaris.core.entity.PolarisChangeTrackingVersions;
@@ -420,50 +419,13 @@ public List<PolarisChangeTrackingVersions> lookupEntityVersions(
420419
.collect(Collectors.toList());
421420
}
422421

423-
@Nonnull
424-
@Override
425-
public Page<EntityNameLookupRecord> listEntities(
426-
@Nonnull PolarisCallContext callCtx,
427-
long catalogId,
428-
long parentId,
429-
@Nonnull PolarisEntityType entityType,
430-
@Nonnull PageToken pageToken) {
431-
return listEntities(
432-
callCtx,
433-
catalogId,
434-
parentId,
435-
entityType,
436-
entity -> true,
437-
EntityNameLookupRecord::new,
438-
pageToken);
439-
}
440-
441-
@Nonnull
442-
@Override
443-
public Page<EntityNameLookupRecord> listEntities(
444-
@Nonnull PolarisCallContext callCtx,
445-
long catalogId,
446-
long parentId,
447-
@Nonnull PolarisEntityType entityType,
448-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
449-
@Nonnull PageToken pageToken) {
450-
return listEntities(
451-
callCtx,
452-
catalogId,
453-
parentId,
454-
entityType,
455-
entityFilter,
456-
EntityNameLookupRecord::new,
457-
pageToken);
458-
}
459-
460422
@Nonnull
461423
@Override
462424
public <T> Page<T> listEntities(
463425
@Nonnull PolarisCallContext callCtx,
464426
long catalogId,
465427
long parentId,
466-
PolarisEntityType entityType,
428+
@Nonnull PolarisEntityType entityType,
467429
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
468430
@Nonnull Function<PolarisBaseEntity, T> transformer,
469431
@Nonnull PageToken pageToken) {

polaris-core/src/main/java/org/apache/polaris/core/entity/EntityNameLookupRecord.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public EntityNameLookupRecord(
8989
this.subTypeCode = subTypeCode;
9090
}
9191

92-
/** Constructor to create the object with provided entity */
93-
public EntityNameLookupRecord(PolarisBaseEntity entity) {
94-
this.catalogId = entity.getCatalogId();
95-
this.id = entity.getId();
96-
this.parentId = entity.getParentId();
97-
this.typeCode = entity.getTypeCode();
98-
this.name = entity.getName();
99-
this.subTypeCode = entity.getSubTypeCode();
92+
public static EntityNameLookupRecord fromEntity(PolarisBaseEntity entity) {
93+
return new EntityNameLookupRecord(
94+
entity.getCatalogId(),
95+
entity.getId(),
96+
entity.getParentId(),
97+
entity.getName(),
98+
entity.getTypeCode(),
99+
entity.getSubTypeCode());
100100
}
101101

102102
@Override
@@ -119,7 +119,7 @@ public int hashCode() {
119119

120120
@Override
121121
public String toString() {
122-
return "PolarisEntitiesActiveRecord{"
122+
return "EntityNameLookupRecord{"
123123
+ "catalogId="
124124
+ catalogId
125125
+ ", id="

polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,14 @@ private void revokeGrantRecord(
709709
: entity -> true;
710710

711711
Page<EntityNameLookupRecord> resultPage =
712-
ms.listEntities(callCtx, catalogId, parentId, entityType, filter, pageToken);
712+
ms.listEntities(
713+
callCtx,
714+
catalogId,
715+
parentId,
716+
entityType,
717+
filter,
718+
EntityNameLookupRecord::fromEntity,
719+
pageToken);
713720

714721
// TODO: Use post-validation to enforce consistent view against catalogPath. In the
715722
// meantime, happens-before ordering semantics aren't guaranteed during high-concurrency

polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ default EntityNameLookupRecord lookupEntityIdAndSubTypeByName(
241241
if (baseEntity == null) {
242242
return null;
243243
}
244-
return new EntityNameLookupRecord(baseEntity);
244+
return EntityNameLookupRecord.fromEntity(baseEntity);
245245
}
246246

247247
/**
@@ -268,45 +268,6 @@ List<PolarisBaseEntity> lookupEntities(
268268
List<PolarisChangeTrackingVersions> lookupEntityVersions(
269269
@Nonnull PolarisCallContext callCtx, List<PolarisEntityId> entityIds);
270270

271-
/**
272-
* List all entities of the specified type which are child entities of the specified parent
273-
*
274-
* @param callCtx call context
275-
* @param catalogId catalog id for that entity, NULL_ID if the entity is top-level
276-
* @param parentId id of the parent, can be the special 0 value representing the root entity
277-
* @param entityType type of entities to list
278-
* @param pageToken the token to start listing after
279-
* @return the list of entities for the specified list operation
280-
*/
281-
@Nonnull
282-
Page<EntityNameLookupRecord> listEntities(
283-
@Nonnull PolarisCallContext callCtx,
284-
long catalogId,
285-
long parentId,
286-
@Nonnull PolarisEntityType entityType,
287-
@Nonnull PageToken pageToken);
288-
289-
/**
290-
* List entities where some predicate returns true
291-
*
292-
* @param callCtx call context
293-
* @param catalogId catalog id for that entity, NULL_ID if the entity is top-level
294-
* @param parentId id of the parent, can be the special 0 value representing the root entity
295-
* @param entityType type of entities to list
296-
* @param entityFilter the filter to be applied to each entity. Only entities where the predicate
297-
* returns true are returned in the list
298-
* @param pageToken the token to start listing after
299-
* @return the list of entities for which the predicate returns true
300-
*/
301-
@Nonnull
302-
Page<EntityNameLookupRecord> listEntities(
303-
@Nonnull PolarisCallContext callCtx,
304-
long catalogId,
305-
long parentId,
306-
@Nonnull PolarisEntityType entityType,
307-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
308-
@Nonnull PageToken pageToken);
309-
310271
/**
311272
* List entities where some predicate returns true and transform the entities with a function
312273
*

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -351,37 +351,6 @@ public List<PolarisChangeTrackingVersions> lookupEntityVersions(
351351
callCtx, () -> this.lookupEntityVersionsInCurrentTxn(callCtx, entityIds));
352352
}
353353

354-
/** {@inheritDoc} */
355-
@Override
356-
@Nonnull
357-
public Page<EntityNameLookupRecord> listEntities(
358-
@Nonnull PolarisCallContext callCtx,
359-
long catalogId,
360-
long parentId,
361-
@Nonnull PolarisEntityType entityType,
362-
@Nonnull PageToken pageToken) {
363-
return runInReadTransaction(
364-
callCtx,
365-
() -> this.listEntitiesInCurrentTxn(callCtx, catalogId, parentId, entityType, pageToken));
366-
}
367-
368-
/** {@inheritDoc} */
369-
@Override
370-
@Nonnull
371-
public Page<EntityNameLookupRecord> listEntities(
372-
@Nonnull PolarisCallContext callCtx,
373-
long catalogId,
374-
long parentId,
375-
@Nonnull PolarisEntityType entityType,
376-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
377-
@Nonnull PageToken pageToken) {
378-
return runInReadTransaction(
379-
callCtx,
380-
() ->
381-
this.listEntitiesInCurrentTxn(
382-
callCtx, catalogId, parentId, entityType, entityFilter, pageToken));
383-
}
384-
385354
/** {@inheritDoc} */
386355
@Override
387356
@Nonnull

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ private void bootstrapPolarisService(
717717
resolver.getParentId(),
718718
entityType,
719719
filter,
720+
EntityNameLookupRecord::fromEntity,
720721
pageToken);
721722

722723
// done

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalPersistence.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,6 @@ List<PolarisBaseEntity> lookupEntitiesInCurrentTxn(
201201
List<PolarisChangeTrackingVersions> lookupEntityVersionsInCurrentTxn(
202202
@Nonnull PolarisCallContext callCtx, List<PolarisEntityId> entityIds);
203203

204-
/** See {@link org.apache.polaris.core.persistence.BasePersistence#listEntities} */
205-
@Nonnull
206-
Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
207-
@Nonnull PolarisCallContext callCtx,
208-
long catalogId,
209-
long parentId,
210-
@Nonnull PolarisEntityType entityType,
211-
@Nonnull PageToken pageToken);
212-
213-
/** See {@link org.apache.polaris.core.persistence.BasePersistence#listEntities} */
214-
@Nonnull
215-
Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
216-
@Nonnull PolarisCallContext callCtx,
217-
long catalogId,
218-
long parentId,
219-
@Nonnull PolarisEntityType entityType,
220-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
221-
@Nonnull PageToken pageToken);
222-
223204
/** See {@link org.apache.polaris.core.persistence.BasePersistence#listEntities} */
224205
@Nonnull
225206
<T> Page<T> listEntitiesInCurrentTxn(

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.polaris.core.persistence.transactional;
2020

21-
import com.google.common.base.Predicates;
2221
import jakarta.annotation.Nonnull;
2322
import jakarta.annotation.Nullable;
2423
import java.util.Comparator;
@@ -288,15 +287,7 @@ public EntityNameLookupRecord lookupEntityActiveInCurrentTxn(
288287
entityActiveKey.getName()));
289288

290289
// return record
291-
return (entity == null)
292-
? null
293-
: new EntityNameLookupRecord(
294-
entity.getCatalogId(),
295-
entity.getId(),
296-
entity.getParentId(),
297-
entity.getName(),
298-
entity.getTypeCode(),
299-
entity.getSubTypeCode());
290+
return (entity == null) ? null : EntityNameLookupRecord.fromEntity(entity);
300291
}
301292

302293
/** {@inheritDoc} */
@@ -311,44 +302,6 @@ public List<EntityNameLookupRecord> lookupEntityActiveBatchInCurrentTxn(
311302
.collect(Collectors.toList());
312303
}
313304

314-
/** {@inheritDoc} */
315-
@Override
316-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
317-
@Nonnull PolarisCallContext callCtx,
318-
long catalogId,
319-
long parentId,
320-
@Nonnull PolarisEntityType entityType,
321-
@Nonnull PageToken pageToken) {
322-
return this.listEntitiesInCurrentTxn(
323-
callCtx, catalogId, parentId, entityType, Predicates.alwaysTrue(), pageToken);
324-
}
325-
326-
@Override
327-
public @Nonnull Page<EntityNameLookupRecord> listEntitiesInCurrentTxn(
328-
@Nonnull PolarisCallContext callCtx,
329-
long catalogId,
330-
long parentId,
331-
@Nonnull PolarisEntityType entityType,
332-
@Nonnull Predicate<PolarisBaseEntity> entityFilter,
333-
@Nonnull PageToken pageToken) {
334-
// full range scan under the parent for that type
335-
return this.listEntitiesInCurrentTxn(
336-
callCtx,
337-
catalogId,
338-
parentId,
339-
entityType,
340-
entityFilter,
341-
entity ->
342-
new EntityNameLookupRecord(
343-
entity.getCatalogId(),
344-
entity.getId(),
345-
entity.getParentId(),
346-
entity.getName(),
347-
entity.getTypeCode(),
348-
entity.getSubTypeCode()),
349-
pageToken);
350-
}
351-
352305
@Override
353306
public @Nonnull <T> Page<T> listEntitiesInCurrentTxn(
354307
@Nonnull PolarisCallContext callCtx,

0 commit comments

Comments
 (0)