Class QueryGenerator
java.lang.Object
org.apache.polaris.persistence.relational.jdbc.QueryGenerator
Utility class to generate parameterized SQL queries (SELECT, INSERT, UPDATE, DELETE). Ensures
consistent SQL generation and protects against injection by managing parameters separately.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA container for the SQL string and the ordered parameter values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic QueryGenerator.PreparedQueryBuilds a DELETE query with the given conditions.static QueryGenerator.PreparedQuerygenerateDeleteQueryForEntityGrantRecords(org.apache.polaris.core.entity.PolarisEntityCore entity, String realmId) Builds a DELETE query to remove grant records for a given entity.static QueryGenerator.PreparedQueryGenerates an INSERT query for a given table.static QueryGenerator.PreparedQuerygenerateOverlapQuery(String realmId, long catalogId, String baseLocation) Generate a SELECT query to find any entities that have a given realm invalid input: '&' parent and that may with a given location.static QueryGenerator.PreparedQueryGenerates a SELECT query with projection and filtering.static QueryGenerator.PreparedQuerygenerateSelectQueryWithEntityIds(String realmId, List<org.apache.polaris.core.entity.PolarisEntityId> entityIds) Builds a SELECT query using a list of entity ID pairs (catalog_id, id).static QueryGenerator.PreparedQuerygenerateUpdateQuery(List<String> allColumns, String tableName, List<Object> values, Map<String, Object> whereClause) Builds an UPDATE query.
-
Constructor Details
-
QueryGenerator
public QueryGenerator()
-
-
Method Details
-
generateSelectQuery
public static QueryGenerator.PreparedQuery generateSelectQuery(@Nonnull List<String> projections, @Nonnull String tableName, @Nonnull Map<String, Object> whereClause) Generates a SELECT query with projection and filtering.- Parameters:
projections- List of columns to retrieve.tableName- Target table name.whereClause- Column-value pairs used in WHERE filtering.- Returns:
- A parameterized SELECT query.
- Throws:
IllegalArgumentException- if any whereClause column isn't in projections.
-
generateDeleteQueryForEntityGrantRecords
public static QueryGenerator.PreparedQuery generateDeleteQueryForEntityGrantRecords(@Nonnull org.apache.polaris.core.entity.PolarisEntityCore entity, @Nonnull String realmId) Builds a DELETE query to remove grant records for a given entity.- Parameters:
entity- The target entity (either grantee or securable).realmId- The associated realm.- Returns:
- A DELETE query removing all grants for this entity.
-
generateSelectQueryWithEntityIds
public static QueryGenerator.PreparedQuery generateSelectQueryWithEntityIds(@Nonnull String realmId, @Nonnull List<org.apache.polaris.core.entity.PolarisEntityId> entityIds) Builds a SELECT query using a list of entity ID pairs (catalog_id, id).- Parameters:
realmId- Realm to filter by.entityIds- List of PolarisEntityId pairs.- Returns:
- SELECT query to retrieve matching entities.
- Throws:
IllegalArgumentException- if entityIds is empty.
-
generateInsertQuery
public static QueryGenerator.PreparedQuery generateInsertQuery(@Nonnull List<String> allColumns, @Nonnull String tableName, List<Object> values, String realmId) Generates an INSERT query for a given table.- Parameters:
allColumns- Columns to insert values into.tableName- Target table name.values- Values for each column (must match order of columns).realmId- Realm value to append.- Returns:
- INSERT query with value bindings.
-
generateUpdateQuery
public static QueryGenerator.PreparedQuery generateUpdateQuery(@Nonnull List<String> allColumns, @Nonnull String tableName, @Nonnull List<Object> values, @Nonnull Map<String, Object> whereClause) Builds an UPDATE query.- Parameters:
allColumns- Columns to update.tableName- Target table.values- New values (must match columns in order).whereClause- Conditions for filtering rows to update.- Returns:
- UPDATE query with parameter values.
-
generateDeleteQuery
public static QueryGenerator.PreparedQuery generateDeleteQuery(@Nonnull List<String> tableColumns, @Nonnull String tableName, @Nonnull Map<String, Object> whereClause) Builds a DELETE query with the given conditions.- Parameters:
tableColumns- List of valid table columns.tableName- Target table.whereClause- Column-value filters.- Returns:
- DELETE query with parameter bindings.
-
generateOverlapQuery
public static QueryGenerator.PreparedQuery generateOverlapQuery(String realmId, long catalogId, String baseLocation) Generate a SELECT query to find any entities that have a given realm invalid input: '&' parent and that may with a given location. The check is performed without consideration for the scheme, so a path on one storage type may give a false positive for overlapping with another storage type. This should be combined with a check using `StorageLocation`.- Parameters:
realmId- A realm to search withincatalogId- A catalog entity to search withinbaseLocation- The base location to look for overlap with, with or without a scheme- Returns:
- The list of possibly overlapping entities that meet the criteria
-