-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[jpa] Support state filter when querying #19581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,10 +142,10 @@ private static void addStateFilter(QueryEnhancedRequest.Builder queryBuilder, | |||||||||||
| return null; | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
| if (filter.getOperator() != null && filter.getState() != null) { | ||||||||||||
| if (filter.getState() != null) { | ||||||||||||
|
||||||||||||
| if (filter.getState() != null) { | |
| if (filter.getState() != null) { | |
| if (filter.getOperator() == null) { | |
| throw new IllegalArgumentException("Operator must not be null when state is provided in filter."); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOperator() is @NonNull, so the check is unnecessary
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,9 +73,9 @@ public String createQuery(FilterCriteria criteria, String retentionPolicy, @Null | |
| } | ||
|
|
||
| State filterState = criteria.getState(); | ||
| if (filterState != null && criteria.getOperator() != null) { | ||
| if (filterState != null) { | ||
| where.and(new SimpleClause(COLUMN_VALUE_NAME_V1, | ||
| getOperationSymbol(criteria.getOperator(), InfluxDBVersion.V1), stateToObject(filterState))); | ||
| getOperationSymbol(criteria.getOperator()), stateToObject(filterState))); | ||
| } | ||
|
|
||
| if (criteria.getOrdering() == FilterCriteria.Ordering.DESCENDING) { | ||
|
|
@@ -120,4 +120,11 @@ private String fullQualifiedTableName(String retentionPolicy, String tableName, | |
| } | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| private String getOperationSymbol(FilterCriteria.Operator operator) { | ||
| if (operator == NEQ) { | ||
| return "<>"; | ||
| } | ||
| return operator.getSymbol(); | ||
| } | ||
|
Comment on lines
123
to
128
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |||||
| import org.openhab.core.persistence.PersistenceService; | ||||||
| import org.openhab.core.persistence.QueryablePersistenceService; | ||||||
| import org.openhab.core.persistence.strategy.PersistenceStrategy; | ||||||
| import org.openhab.core.types.State; | ||||||
| import org.openhab.core.types.UnDefType; | ||||||
| import org.openhab.persistence.jpa.internal.model.JpaPersistentItem; | ||||||
| import org.osgi.framework.BundleContext; | ||||||
|
|
@@ -219,6 +220,7 @@ public Iterable<HistoricItem> query(FilterCriteria filter, @Nullable String alia | |||||
|
|
||||||
| boolean hasBeginDate = false; | ||||||
| boolean hasEndDate = false; | ||||||
| State state = null; | ||||||
| String queryString = "SELECT n FROM " + JpaPersistentItem.class.getSimpleName() | ||||||
| + " n WHERE n.realName = :itemName"; | ||||||
| if (filter.getBeginDate() != null) { | ||||||
|
|
@@ -229,6 +231,9 @@ public Iterable<HistoricItem> query(FilterCriteria filter, @Nullable String alia | |||||
| queryString += " AND n.timestamp <= :endDate"; | ||||||
| hasEndDate = true; | ||||||
| } | ||||||
| if ((state = filter.getState()) != null) { | ||||||
|
||||||
| if ((state = filter.getState()) != null) { | |
| if ((state = filter.getState()) != null && filter.getOperator() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
filterDescriptionis assigned but never used after line 360. It should either be removed or used in the logging statement instead of callingfilter.toString()implicitly.