@@ -110,10 +110,15 @@ public void setSchemaConfig(EbeanLocalDAO.SchemaConfig schemaConfig) {
110110 @ Nonnull
111111 public <SNAPSHOT extends RecordTemplate > List <SNAPSHOT > findEntities (@ Nonnull Class <SNAPSHOT > snapshotClass ,
112112 @ Nonnull LocalRelationshipFilter filter , int offset , int count ) throws OperationNotSupportedException {
113+ return findEntitiesCore (snapshotClass , filter , offset , count , false );
114+ }
115+
116+ private <SNAPSHOT extends RecordTemplate > List <SNAPSHOT > findEntitiesCore (@ Nonnull Class <SNAPSHOT > snapshotClass ,
117+ @ Nonnull LocalRelationshipFilter filter , int offset , int count , boolean logicalExpressionFilterEnabled ) throws OperationNotSupportedException {
113118 if (_schemaConfig == EbeanLocalDAO .SchemaConfig .OLD_SCHEMA_ONLY ) {
114119 throw new OperationNotSupportedException ("findEntities is not supported in OLD_SCHEMA_MODE" );
115120 }
116- validateEntityFilter (filter , snapshotClass );
121+ validateEntityFilter (filter , snapshotClass , logicalExpressionFilterEnabled );
117122
118123 final String tableName = SQLSchemaUtils .getTableName (ModelUtils .getUrnTypeFromSnapshot (snapshotClass ));
119124 final StringBuilder sqlBuilder = new StringBuilder ();
@@ -129,6 +134,25 @@ public <SNAPSHOT extends RecordTemplate> List<SNAPSHOT> findEntities(@Nonnull Cl
129134 .collect (Collectors .toList ());
130135 }
131136
137+ /**
138+ * Finds a list of entities of a specific type based on the given filter on the entity.
139+ * Similar to {@link #findEntities(Class, LocalRelationshipFilter, int, int)},
140+ * but this method uses the LogicalExpressionLocalRelationshipCriterion in LocalRelationshipFilter.
141+ * The SNAPSHOT class must be defined within com.linkedin.metadata.snapshot package in metadata-models.
142+ * This method is not supported in OLD_SCHEMA_ONLY mode.
143+ * @param snapshotClass the snapshot class to query.
144+ * @param filter the filter to apply when querying. Uses `logicalExpressionCriteria` instead of `criteria`.
145+ * @param offset the offset the query should start at. Ignored if set to a negative value.
146+ * @param count the maximum number of entities to return. Ignored if set to a non-positive value.
147+ * @return A list of entity records of class SNAPSHOT.
148+ * @throws OperationNotSupportedException when called in OLD_SCHEMA_ONLY mode. This exception must be explicitly handled by the caller.
149+ */
150+ @ Nonnull
151+ public <SNAPSHOT extends RecordTemplate > List <SNAPSHOT > findEntitiesV2 (@ Nonnull Class <SNAPSHOT > snapshotClass ,
152+ @ Nonnull LocalRelationshipFilter filter , int offset , int count ) throws OperationNotSupportedException {
153+ return findEntitiesCore (snapshotClass , filter , offset , count , true );
154+ }
155+
132156 /**
133157 * Finds a list of entities of a specific type based on the given source, destination, and relationship filters.
134158 * Every SNAPSHOT class must be defined within com.linkedin.metadata.snapshot package in metadata-models.
@@ -449,18 +473,15 @@ private String getMgEntityTableName(@Nullable String entityType) {
449473 return SQLSchemaUtils .getTableName (entityType );
450474 }
451475
452- /**
453- * Validate:
454- * 1. The entity filter only contains supported conditions.
455- * 2. if the entity class is null, then the filter should be empty.
456- * If any of above is violated, throw an IllegalArgumentException.
457- */
458476 private <ENTITY extends RecordTemplate > void validateEntityFilter (@ Nonnull LocalRelationshipFilter filter , @ Nullable Class <ENTITY > entityClass ) {
459- if (entityClass == null && filter .hasCriteria () && filter .getCriteria ().size () > 0 ) {
460- throw new IllegalArgumentException ("Entity class is null but filter is not empty." );
461- }
477+ validateEntityFilter (filter , entityClass , false );
478+ }
462479
463- validateFilterCriteria (filter , false );
480+ private <ENTITY extends RecordTemplate > void validateEntityFilter (@ Nonnull LocalRelationshipFilter filter , @ Nullable Class <ENTITY > entityClass ,
481+ boolean logicalExpressionFilterEnabled ) {
482+ validateEntityTypeAndFilter (filter ,
483+ entityClass != null ? ModelUtils .getUrnTypeFromSnapshot (entityClass ) : null ,
484+ logicalExpressionFilterEnabled );
464485 }
465486
466487 /**
@@ -498,10 +519,10 @@ private static void validateLogicalExpressionFilter(@Nonnull LocalRelationshipFi
498519
499520 if (logicalExpressionFilterEnabled && filter .hasCriteria ()) {
500521 throw new IllegalArgumentException (
501- "Please do not use the 'criteria' field and use the 'logicalExpressionCriteria' field instead for findRelationshipsV4 API." );
522+ "Please do not use the 'criteria' field and use the 'logicalExpressionCriteria' field instead for this API." );
502523 } else if (!logicalExpressionFilterEnabled && filter .hasLogicalExpressionCriteria ()) {
503524 throw new IllegalArgumentException (
504- "Please do not use the 'logicalExpressionCriteria' field and use the 'criteria' field instead for findRelationshipsV2/V3 API." );
525+ "Please do not use the 'logicalExpressionCriteria' field and use the 'criteria' field instead for this API." );
505526 }
506527 }
507528
0 commit comments