Add mixin interface for matchable predicates

Only change predicates need to have a match method, because for
historic reasons changes may be loaded from multiple sources.
Predicates for other indices do not need to implement a match method
because the data is always loaded from the index. An exception are
the predicates that check visibility for which a match method is
always required.

Change-Id: I3492bc83b6faf6708ab0102a49463aa0d4a3d10b
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-06-28 10:00:53 +02:00
parent 4492ab39e8
commit cc82b24695
76 changed files with 459 additions and 249 deletions

View File

@@ -633,7 +633,7 @@ defintion which creates a `MyPredicate`:
@Singleton @Singleton
public class SampleOperator public class SampleOperator
implements ChangeQueryBuilder.ChangeOperatorFactory { implements ChangeQueryBuilder.ChangeOperatorFactory {
public static class MyPredicate extends OperatorPredicate<ChangeData> { public static class MyPredicate extends OperatorChangePredicate<ChangeData> {
... ...
} }

View File

@@ -14,10 +14,8 @@
package com.google.gerrit.server.index; package com.google.gerrit.server.index;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.gerrit.server.query.DataSource; import com.google.gerrit.server.query.DataSource;
import com.google.gerrit.server.query.Paginated; import com.google.gerrit.server.query.Paginated;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
@@ -26,10 +24,7 @@ import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet; import com.google.gwtorm.server.ResultSet;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Wrapper combining an {@link IndexPredicate} together with a * Wrapper combining an {@link IndexPredicate} together with a
@@ -48,8 +43,7 @@ public class IndexedQuery<I, T> extends Predicate<T>
private QueryOptions opts; private QueryOptions opts;
private final Predicate<T> pred; private final Predicate<T> pred;
private DataSource<T> source; protected DataSource<T> source;
private final Map<T, DataSource<T>> fromSource;
public IndexedQuery(Index<I, T> index, Predicate<T> pred, public IndexedQuery(Index<I, T> index, Predicate<T> pred,
QueryOptions opts) throws QueryParseException { QueryOptions opts) throws QueryParseException {
@@ -57,7 +51,6 @@ public class IndexedQuery<I, T> extends Predicate<T>
this.opts = opts; this.opts = opts;
this.pred = pred; this.pred = pred;
this.source = index.getSource(pred, this.opts); this.source = index.getSource(pred, this.opts);
this.fromSource = new HashMap<>();
} }
@Override @Override
@@ -90,38 +83,7 @@ public class IndexedQuery<I, T> extends Predicate<T>
@Override @Override
public ResultSet<T> read() throws OrmException { public ResultSet<T> read() throws OrmException {
final DataSource<T> currSource = source; return source.read();
final ResultSet<T> rs = currSource.read();
return new ResultSet<T>() {
@Override
public Iterator<T> iterator() {
return Iterables.transform(
rs,
new Function<T, T>() {
@Override
public
T apply(T t) {
fromSource.put(t, currSource);
return t;
}
}).iterator();
}
@Override
public List<T> toList() {
List<T> r = rs.toList();
for (T t : r) {
fromSource.put(t, currSource);
}
return r;
}
@Override
public void close() {
rs.close();
}
};
} }
@Override @Override
@@ -145,19 +107,6 @@ public class IndexedQuery<I, T> extends Predicate<T>
return this; return this;
} }
@Override
public boolean match(T t) throws OrmException {
return (source != null && fromSource.get(t) == source) || pred.match(t);
}
@Override
public int getCost() {
// Index queries are assumed to be cheaper than any other type of query, so
// so try to make sure they get picked. Note that pred's cost may be higher
// because it doesn't know whether it's being used in an index query or not.
return 1;
}
@Override @Override
public int hashCode() { public int hashCode() {
return pred.hashCode(); return pred.hashCode();

View File

@@ -33,7 +33,6 @@ public abstract class IntegerRangePredicate<T> extends IndexPredicate<T> {
protected abstract int getValueInt(T object) throws OrmException; protected abstract int getValueInt(T object) throws OrmException;
@Override
public boolean match(T object) throws OrmException { public boolean match(T object) throws OrmException {
int valueInt = getValueInt(object); int valueInt = getValueInt(object);
return valueInt >= range.min && valueInt <= range.max; return valueInt >= range.min && valueInt <= range.max;
@@ -48,9 +47,4 @@ public abstract class IntegerRangePredicate<T> extends IndexPredicate<T> {
public int getMaximumValue() { public int getMaximumValue() {
return range.max; return range.max;
} }
@Override
public int getCost() {
return 1;
}
} }

View File

@@ -38,9 +38,4 @@ public abstract class TimestampRangePredicate<I> extends IndexPredicate<I> {
public abstract Date getMinTimestamp(); public abstract Date getMinTimestamp();
public abstract Date getMaxTimestamp(); public abstract Date getMaxTimestamp();
@Override
public int getCost() {
return 1;
}
} }

View File

@@ -14,22 +14,33 @@
package com.google.gerrit.server.index.change; package com.google.gerrit.server.index.change;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.index.change.ChangeField.CHANGE; import static com.google.gerrit.server.index.change.ChangeField.CHANGE;
import static com.google.gerrit.server.index.change.ChangeField.PROJECT; import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexConfig; import com.google.gerrit.server.index.IndexConfig;
import com.google.gerrit.server.index.IndexPredicate; import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.IndexedQuery; import com.google.gerrit.server.index.IndexedQuery;
import com.google.gerrit.server.index.QueryOptions; import com.google.gerrit.server.index.QueryOptions;
import com.google.gerrit.server.query.DataSource;
import com.google.gerrit.server.query.Matchable;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.ChangeDataSource; import com.google.gerrit.server.query.change.ChangeDataSource;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
@@ -41,7 +52,7 @@ import java.util.Set;
* {@link ChangeDataSource} to be chosen by the query processor. * {@link ChangeDataSource} to be chosen by the query processor.
*/ */
public class IndexedChangeQuery extends IndexedQuery<Change.Id, ChangeData> public class IndexedChangeQuery extends IndexedQuery<Change.Id, ChangeData>
implements ChangeDataSource { implements ChangeDataSource, Matchable<ChangeData> {
public static QueryOptions oneResult() { public static QueryOptions oneResult() {
return createOptions(IndexConfig.createDefault(), 0, 1, return createOptions(IndexConfig.createDefault(), 0, 1,
ImmutableSet.<String> of()); ImmutableSet.<String> of());
@@ -65,9 +76,68 @@ public class IndexedChangeQuery extends IndexedQuery<Change.Id, ChangeData>
opts.limit(), opts.fields()); opts.limit(), opts.fields());
} }
private final Map<ChangeData, DataSource<ChangeData>> fromSource;
public IndexedChangeQuery(ChangeIndex index, Predicate<ChangeData> pred, public IndexedChangeQuery(ChangeIndex index, Predicate<ChangeData> pred,
QueryOptions opts) throws QueryParseException { QueryOptions opts) throws QueryParseException {
super(index, pred, convertOptions(opts)); super(index, pred, convertOptions(opts));
this.fromSource = new HashMap<>();
}
@Override
public ResultSet<ChangeData> read() throws OrmException {
final DataSource<ChangeData> currSource = source;
final ResultSet<ChangeData> rs = currSource.read();
return new ResultSet<ChangeData>() {
@Override
public Iterator<ChangeData> iterator() {
return Iterables.transform(
rs,
new Function<ChangeData, ChangeData>() {
@Override
public ChangeData apply(ChangeData cd) {
fromSource.put(cd, currSource);
return cd;
}
}).iterator();
}
@Override
public List<ChangeData> toList() {
List<ChangeData> r = rs.toList();
for (ChangeData cd : r) {
fromSource.put(cd, currSource);
}
return r;
}
@Override
public void close() {
rs.close();
}
};
}
@Override
public boolean match(ChangeData cd) throws OrmException {
if (source != null && fromSource.get(cd) == source) {
return true;
}
Predicate<ChangeData> pred = getChild(0);
checkState(pred.isMatchable(),
"match invoked, but child predicate %s " + "doesn't implement %s", pred,
Matchable.class.getName());
return pred.asMatchable().match(cd);
}
@Override
public int getCost() {
// Index queries are assumed to be cheaper than any other type of query, so
// so try to make sure they get picked. Note that pred's cost may be higher
// because it doesn't know whether it's being used in an index query or not.
return 1;
} }
@Override @Override

View File

@@ -211,6 +211,6 @@ public class ProjectWatch {
p = Predicate.and(filterPredicate, p); p = Predicate.and(filterPredicate, p);
} }
} }
return p == null || p.match(changeData); return p == null || p.asMatchable().match(changeData);
} }
} }

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.query; package com.google.gerrit.server.query;
import static com.google.common.base.Preconditions.checkState;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -23,7 +25,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
/** Requires all predicates to be true. */ /** Requires all predicates to be true. */
public class AndPredicate<T> extends Predicate<T> { public class AndPredicate<T> extends Predicate<T> implements Matchable<T> {
private final List<Predicate<T>> children; private final List<Predicate<T>> children;
private final int cost; private final int cost;
@@ -39,11 +41,11 @@ public class AndPredicate<T> extends Predicate<T> {
if (getClass() == p.getClass()) { if (getClass() == p.getClass()) {
for (Predicate<T> gp : p.getChildren()) { for (Predicate<T> gp : p.getChildren()) {
t.add(gp); t.add(gp);
c += gp.getCost(); c += gp.estimateCost();
} }
} else { } else {
t.add(p); t.add(p);
c += p.getCost(); c += p.estimateCost();
} }
} }
children = t; children = t;
@@ -70,10 +72,22 @@ public class AndPredicate<T> extends Predicate<T> {
return new AndPredicate<>(children); return new AndPredicate<>(children);
} }
@Override
public boolean isMatchable() {
for (Predicate<T> c : children) {
if (!c.isMatchable()) {
return false;
}
}
return true;
}
@Override @Override
public boolean match(final T object) throws OrmException { public boolean match(final T object) throws OrmException {
for (final Predicate<T> c : children) { for (Predicate<T> c : children) {
if (!c.match(object)) { checkState(c.isMatchable(), "match invoked, but child predicate %s "
+ "doesn't implement %s", c, Matchable.class.getName());
if (!c.asMatchable().match(object)) {
return false; return false;
} }
} }

View File

@@ -36,17 +36,29 @@ public class AndSource<T> extends AndPredicate<T>
implements DataSource<T>, Comparator<Predicate<T>> { implements DataSource<T>, Comparator<Predicate<T>> {
protected final DataSource<T> source; protected final DataSource<T> source;
private final IsVisibleToPredicate<T> isVisibleToPredicate;
private final int start; private final int start;
private final int cardinality; private final int cardinality;
public AndSource(Collection<? extends Predicate<T>> that) { public AndSource(Collection<? extends Predicate<T>> that) {
this(that, 0); this(that, null, 0);
} }
public AndSource(Collection<? extends Predicate<T>> that, int start) { public AndSource(Predicate<T> that,
IsVisibleToPredicate<T> isVisibleToPredicate) {
this(that, isVisibleToPredicate, 0);
}
public AndSource(Predicate<T> that,
IsVisibleToPredicate<T> isVisibleToPredicate, int start) {
this(ImmutableList.of(that), isVisibleToPredicate, start);
}
public AndSource(Collection<? extends Predicate<T>> that,
IsVisibleToPredicate<T> isVisibleToPredicate, int start) {
super(that); super(that);
checkArgument(start >= 0, "negative start: %s", start); checkArgument(start >= 0, "negative start: %s", start);
this.isVisibleToPredicate = isVisibleToPredicate;
this.start = start; this.start = start;
int c = Integer.MAX_VALUE; int c = Integer.MAX_VALUE;
@@ -56,9 +68,10 @@ public class AndSource<T> extends AndPredicate<T>
if (p instanceof DataSource) { if (p instanceof DataSource) {
c = Math.min(c, ((DataSource<?>) p).getCardinality()); c = Math.min(c, ((DataSource<?>) p).getCardinality());
if (p.getCost() < minCost) { int cost = p.estimateCost();
if (cost < minCost) {
s = toDataSource(p); s = toDataSource(p);
minCost = p.getCost(); minCost = cost;
} }
} }
} }
@@ -85,7 +98,7 @@ public class AndSource<T> extends AndPredicate<T>
int nextStart = 0; int nextStart = 0;
boolean skipped = false; boolean skipped = false;
for (T data : buffer(source.read())) { for (T data : buffer(source.read())) {
if (match(data)) { if (!isMatchable() || match(data)) {
r.add(data); r.add(data);
} else { } else {
skipped = true; skipped = true;
@@ -124,6 +137,24 @@ public class AndSource<T> extends AndPredicate<T>
return new ListResultSet<>(r); return new ListResultSet<>(r);
} }
@Override
public boolean isMatchable() {
return isVisibleToPredicate != null || super.isMatchable();
}
@Override
public boolean match(T object) throws OrmException {
if (isVisibleToPredicate != null && !isVisibleToPredicate.match(object)) {
return false;
}
if (super.isMatchable() && !super.match(object)) {
return false;
}
return true;
}
private Iterable<T> buffer(ResultSet<T> scanner) { private Iterable<T> buffer(ResultSet<T> scanner) {
return FluentIterable.from(Iterables.partition(scanner, 50)) return FluentIterable.from(Iterables.partition(scanner, 50))
.transformAndConcat(new Function<List<T>, List<T>>() { .transformAndConcat(new Function<List<T>, List<T>>() {
@@ -156,7 +187,7 @@ public class AndSource<T> extends AndPredicate<T>
int cmp = ai - bi; int cmp = ai - bi;
if (cmp == 0) { if (cmp == 0) {
cmp = a.getCost() - b.getCost(); cmp = a.estimateCost() - b.estimateCost();
} }
if (cmp == 0 if (cmp == 0

View File

@@ -0,0 +1,22 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query;
public abstract class IsVisibleToPredicate<T> extends OperatorPredicate<T>
implements Matchable<T> {
public IsVisibleToPredicate(String name, String value) {
super(name, value);
}
}

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.server.query; package com.google.gerrit.server.query;
public class LimitPredicate<T> extends IntPredicate<T> { public class LimitPredicate<T> extends IntPredicate<T> implements Matchable<T> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Integer getLimit(String fieldName, Predicate<?> p) { public static Integer getLimit(String fieldName, Predicate<?> p) {
IntPredicate<?> ip = QueryBuilder.find(p, IntPredicate.class, fieldName); IntPredicate<?> ip = QueryBuilder.find(p, IntPredicate.class, fieldName);

View File

@@ -0,0 +1,29 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query;
import com.google.gwtorm.server.OrmException;
public interface Matchable<T> {
/**
* Does this predicate match this object?
*
* @throws OrmException
*/
boolean match(T object) throws OrmException;
/** @return a cost estimate to run this predicate, higher figures cost more. */
int getCost();
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.query; package com.google.gerrit.server.query;
import static com.google.common.base.Preconditions.checkState;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.Collection; import java.util.Collection;
@@ -21,7 +23,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
/** Negates the result of another predicate. */ /** Negates the result of another predicate. */
public class NotPredicate<T> extends Predicate<T> { public class NotPredicate<T> extends Predicate<T> implements Matchable<T> {
private final Predicate<T> that; private final Predicate<T> that;
protected NotPredicate(final Predicate<T> that) { protected NotPredicate(final Predicate<T> that) {
@@ -57,14 +59,21 @@ public class NotPredicate<T> extends Predicate<T> {
return new NotPredicate<>(children.iterator().next()); return new NotPredicate<>(children.iterator().next());
} }
@Override
public boolean isMatchable() {
return that.isMatchable();
}
@Override @Override
public boolean match(final T object) throws OrmException { public boolean match(final T object) throws OrmException {
return !that.match(object); checkState(that.isMatchable(), "match invoked, but child predicate %s "
+ "doesn't implement %s", that, Matchable.class.getName());
return !that.asMatchable().match(object);
} }
@Override @Override
public int getCost() { public int getCost() {
return that.getCost(); return that.estimateCost();
} }
@Override @Override

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.query; package com.google.gerrit.server.query;
import static com.google.common.base.Preconditions.checkState;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -23,7 +25,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
/** Requires one predicate to be true. */ /** Requires one predicate to be true. */
public class OrPredicate<T> extends Predicate<T> { public class OrPredicate<T> extends Predicate<T> implements Matchable<T> {
private final List<Predicate<T>> children; private final List<Predicate<T>> children;
private final int cost; private final int cost;
@@ -39,11 +41,11 @@ public class OrPredicate<T> extends Predicate<T> {
if (getClass() == p.getClass()) { if (getClass() == p.getClass()) {
for (Predicate<T> gp : p.getChildren()) { for (Predicate<T> gp : p.getChildren()) {
t.add(gp); t.add(gp);
c += gp.getCost(); c += gp.estimateCost();
} }
} else { } else {
t.add(p); t.add(p);
c += p.getCost(); c += p.estimateCost();
} }
} }
children = t; children = t;
@@ -70,10 +72,22 @@ public class OrPredicate<T> extends Predicate<T> {
return new OrPredicate<>(children); return new OrPredicate<>(children);
} }
@Override
public boolean isMatchable() {
for (Predicate<T> c : children) {
if (!c.isMatchable()) {
return false;
}
}
return true;
}
@Override @Override
public boolean match(final T object) throws OrmException { public boolean match(final T object) throws OrmException {
for (final Predicate<T> c : children) { for (final Predicate<T> c : children) {
if (c.match(object)) { checkState(c.isMatchable(), "match invoked, but child predicate %s "
+ "doesn't implement %s", c, Matchable.class.getName());
if (c.asMatchable().match(object)) {
return true; return true;
} }
} }

View File

@@ -14,8 +14,9 @@
package com.google.gerrit.server.query; package com.google.gerrit.server.query;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.gwtorm.server.OrmException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@@ -113,15 +114,23 @@ public abstract class Predicate<T> {
/** Create a copy of this predicate, with new children. */ /** Create a copy of this predicate, with new children. */
public abstract Predicate<T> copy(Collection<? extends Predicate<T>> children); public abstract Predicate<T> copy(Collection<? extends Predicate<T>> children);
/** public boolean isMatchable() {
* Does this predicate match this object? return this instanceof Matchable;
* }
* @throws OrmException
*/ @SuppressWarnings("unchecked")
public abstract boolean match(T object) throws OrmException; public Matchable<T> asMatchable() {
checkState(isMatchable(), "not matchable");
return (Matchable<T>) this;
}
/** @return a cost estimate to run this predicate, higher figures cost more. */ /** @return a cost estimate to run this predicate, higher figures cost more. */
public abstract int getCost(); public int estimateCost() {
if (!isMatchable()) {
return 1;
}
return asMatchable().getCost();
}
@Override @Override
public abstract int hashCode(); public abstract int hashCode();
@@ -129,7 +138,7 @@ public abstract class Predicate<T> {
@Override @Override
public abstract boolean equals(Object other); public abstract boolean equals(Object other);
private static class Any<T> extends Predicate<T> { private static class Any<T> extends Predicate<T> implements Matchable<T> {
private static final Any<Object> INSTANCE = new Any<>(); private static final Any<Object> INSTANCE = new Any<>();
private Any() { private Any() {

View File

@@ -18,25 +18,10 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.account.AccountState; import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.index.IndexPredicate; import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.account.AccountField; import com.google.gerrit.server.index.account.AccountField;
import com.google.gwtorm.server.OrmException;
public class AccountIdPredicate extends IndexPredicate<AccountState> { public class AccountIdPredicate extends IndexPredicate<AccountState> {
private final Account.Id accountId;
public AccountIdPredicate(Account.Id accountId) { public AccountIdPredicate(Account.Id accountId) {
super(AccountField.ID, AccountQueryBuilder.FIELD_ACCOUNT, super(AccountField.ID, AccountQueryBuilder.FIELD_ACCOUNT,
accountId.toString()); accountId.toString());
this.accountId = accountId;
} }
@Override
public boolean match(AccountState accountState) throws OrmException {
return accountId.equals(accountState.getAccount().getId());
}
@Override
public int getCost() {
return 1;
}
} }

View File

@@ -17,11 +17,12 @@ package com.google.gerrit.server.query.account;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.AccountControl; import com.google.gerrit.server.account.AccountControl;
import com.google.gerrit.server.account.AccountState; import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.query.OperatorPredicate; import com.google.gerrit.server.query.IsVisibleToPredicate;
import com.google.gerrit.server.query.change.SingleGroupUser; import com.google.gerrit.server.query.change.SingleGroupUser;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class IsVisibleToPredicate extends OperatorPredicate<AccountState> { public class AccountIsVisibleToPredicate
extends IsVisibleToPredicate<AccountState> {
private static String describe(CurrentUser user) { private static String describe(CurrentUser user) {
if (user.isIdentifiedUser()) { if (user.isIdentifiedUser()) {
return user.getAccountId().toString(); return user.getAccountId().toString();
@@ -35,7 +36,7 @@ public class IsVisibleToPredicate extends OperatorPredicate<AccountState> {
private final AccountControl accountControl; private final AccountControl accountControl;
IsVisibleToPredicate(AccountControl accountControl) { AccountIsVisibleToPredicate(AccountControl accountControl) {
super(AccountQueryBuilder.FIELD_VISIBLETO, super(AccountQueryBuilder.FIELD_VISIBLETO,
describe(accountControl.getUser())); describe(accountControl.getUser()));
this.accountControl = accountControl; this.accountControl = accountControl;

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.query.account;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.query.account.AccountQueryBuilder.FIELD_LIMIT; import static com.google.gerrit.server.query.account.AccountQueryBuilder.FIELD_LIMIT;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.AccountControl; import com.google.gerrit.server.account.AccountControl;
import com.google.gerrit.server.account.AccountState; import com.google.gerrit.server.account.AccountState;
@@ -38,7 +37,7 @@ public class AccountQueryProcessor extends QueryProcessor<AccountState> {
static { static {
// It is assumed that basic rewrites do not touch visibleto predicates. // It is assumed that basic rewrites do not touch visibleto predicates.
checkState( checkState(
!IsVisibleToPredicate.class.isAssignableFrom(IndexPredicate.class), !AccountIsVisibleToPredicate.class.isAssignableFrom(IndexPredicate.class),
"AccountQueryProcessor assumes visibleto is not used by the index rewriter."); "AccountQueryProcessor assumes visibleto is not used by the index rewriter.");
} }
@@ -57,7 +56,7 @@ public class AccountQueryProcessor extends QueryProcessor<AccountState> {
@Override @Override
protected Predicate<AccountState> enforceVisibility( protected Predicate<AccountState> enforceVisibility(
Predicate<AccountState> pred) { Predicate<AccountState> pred) {
return new AndSource<>(ImmutableList.of(pred, return new AndSource<>(pred,
new IsVisibleToPredicate(accountControlFactory.get()))); new AccountIsVisibleToPredicate(accountControlFactory.get()));
} }
} }

View File

@@ -14,12 +14,11 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.IntegerRangePredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class AddedPredicate extends IntegerRangePredicate<ChangeData> { public class AddedPredicate extends IntegerRangeChangePredicate {
AddedPredicate(String value) throws QueryParseException { AddedPredicate(String value) throws QueryParseException {
super(ChangeField.ADDED, value); super(ChangeField.ADDED, value);
} }

View File

@@ -14,14 +14,13 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.TimestampRangePredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.Date; import java.util.Date;
public class AfterPredicate extends TimestampRangePredicate<ChangeData> { public class AfterPredicate extends TimestampRangeChangePredicate {
private final Date cut; private final Date cut;
AfterPredicate(String value) throws QueryParseException { AfterPredicate(String value) throws QueryParseException {

View File

@@ -20,13 +20,12 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.gerrit.common.TimeUtil; import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.config.ConfigUtil; import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.index.TimestampRangePredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.sql.Timestamp; import java.sql.Timestamp;
public class AgePredicate extends TimestampRangePredicate<ChangeData> { public class AgePredicate extends TimestampRangeChangePredicate {
private final long cut; private final long cut;
AgePredicate(String value) { AgePredicate(String value) {

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.query.AndSource; import com.google.gerrit.server.query.AndSource;
import com.google.gerrit.server.query.IsVisibleToPredicate;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.OrmRuntimeException; import com.google.gwtorm.server.OrmRuntimeException;
@@ -25,13 +26,13 @@ import java.util.List;
public class AndChangeSource extends AndSource<ChangeData> public class AndChangeSource extends AndSource<ChangeData>
implements ChangeDataSource { implements ChangeDataSource {
public AndChangeSource(Collection<? extends Predicate<ChangeData>> that) { public AndChangeSource(Collection<Predicate<ChangeData>> that) {
super(that, 0); super(that);
} }
public AndChangeSource(Collection<? extends Predicate<ChangeData>> that, public AndChangeSource(Predicate<ChangeData> that,
int start) { IsVisibleToPredicate<ChangeData> isVisibleToPredicate, int start) {
super(that, start); super(that, isVisibleToPredicate, start);
} }
@Override @Override

View File

@@ -17,11 +17,10 @@ package com.google.gerrit.server.query.change;
import static com.google.gerrit.server.index.change.ChangeField.AUTHOR; import static com.google.gerrit.server.index.change.ChangeField.AUTHOR;
import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_AUTHOR; import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_AUTHOR;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class AuthorPredicate extends IndexPredicate<ChangeData> { public class AuthorPredicate extends ChangeIndexPredicate {
AuthorPredicate(String value) { AuthorPredicate(String value) {
super(AUTHOR, FIELD_AUTHOR, value.toLowerCase()); super(AUTHOR, FIELD_AUTHOR, value.toLowerCase());
} }

View File

@@ -14,14 +14,13 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.TimestampRangePredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.Date; import java.util.Date;
public class BeforePredicate extends TimestampRangePredicate<ChangeData> { public class BeforePredicate extends TimestampRangeChangePredicate {
private final Date cut; private final Date cut;
BeforePredicate(String value) throws QueryParseException { BeforePredicate(String value) throws QueryParseException {

View File

@@ -15,12 +15,11 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
/** Predicate over Change-Id strings (aka Change.Key). */ /** Predicate over Change-Id strings (aka Change.Key). */
class ChangeIdPredicate extends IndexPredicate<ChangeData> { class ChangeIdPredicate extends ChangeIndexPredicate {
ChangeIdPredicate(String id) { ChangeIdPredicate(String id) {
super(ChangeField.ID, ChangeQueryBuilder.FIELD_CHANGE, id); super(ChangeField.ID, ChangeQueryBuilder.FIELD_CHANGE, id);
} }

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.query.Matchable;
public abstract class ChangeIndexPredicate extends IndexPredicate<ChangeData>
implements Matchable<ChangeData> {
protected ChangeIndexPredicate(FieldDef<ChangeData, ?> def, String value) {
super(def, value);
}
protected ChangeIndexPredicate(FieldDef<ChangeData, ?> def, String name,
String value) {
super(def, name, value);
}
}

View File

@@ -20,11 +20,11 @@ import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.OperatorPredicate; import com.google.gerrit.server.query.IsVisibleToPredicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider; import com.google.inject.Provider;
class IsVisibleToPredicate extends OperatorPredicate<ChangeData> { class ChangeIsVisibleToPredicate extends IsVisibleToPredicate<ChangeData> {
private static String describe(CurrentUser user) { private static String describe(CurrentUser user) {
if (user.isIdentifiedUser()) { if (user.isIdentifiedUser()) {
return user.getAccountId().toString(); return user.getAccountId().toString();
@@ -41,7 +41,8 @@ class IsVisibleToPredicate extends OperatorPredicate<ChangeData> {
private final ChangeControl.GenericFactory changeControl; private final ChangeControl.GenericFactory changeControl;
private final CurrentUser user; private final CurrentUser user;
IsVisibleToPredicate(Provider<ReviewDb> db, ChangeNotes.Factory notesFactory, ChangeIsVisibleToPredicate(Provider<ReviewDb> db,
ChangeNotes.Factory notesFactory,
ChangeControl.GenericFactory changeControlFactory, CurrentUser user) { ChangeControl.GenericFactory changeControlFactory, CurrentUser user) {
super(ChangeQueryBuilder.FIELD_VISIBLETO, describe(user)); super(ChangeQueryBuilder.FIELD_VISIBLETO, describe(user));
this.db = db; this.db = db;

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.server.query.Matchable;
import com.google.gerrit.server.query.OperatorPredicate;
public abstract class ChangeOperatorPredicate extends
OperatorPredicate<ChangeData> implements Matchable<ChangeData> {
protected ChangeOperatorPredicate(String name, String value) {
super(name, value);
}
}

View File

@@ -768,7 +768,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
} }
public Predicate<ChangeData> visibleto(CurrentUser user) { public Predicate<ChangeData> visibleto(CurrentUser user) {
return new IsVisibleToPredicate(args.db, args.notesFactory, return new ChangeIsVisibleToPredicate(args.db, args.notesFactory,
args.changeControlGenericFactory, user); args.changeControlGenericFactory, user);
} }

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.query.change;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_LIMIT; import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_LIMIT;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.index.IndexConfig; import com.google.gerrit.server.index.IndexConfig;
@@ -44,7 +43,7 @@ public class ChangeQueryProcessor extends QueryProcessor<ChangeData> {
static { static {
// It is assumed that basic rewrites do not touch visibleto predicates. // It is assumed that basic rewrites do not touch visibleto predicates.
checkState( checkState(
!IsVisibleToPredicate.class.isAssignableFrom(IndexPredicate.class), !ChangeIsVisibleToPredicate.class.isAssignableFrom(IndexPredicate.class),
"ChangeQueryProcessor assumes visibleto is not used by the index rewriter."); "ChangeQueryProcessor assumes visibleto is not used by the index rewriter.");
} }
@@ -80,7 +79,7 @@ public class ChangeQueryProcessor extends QueryProcessor<ChangeData> {
@Override @Override
protected Predicate<ChangeData> enforceVisibility( protected Predicate<ChangeData> enforceVisibility(
Predicate<ChangeData> pred) { Predicate<ChangeData> pred) {
return new AndChangeSource(ImmutableList.of(pred, new IsVisibleToPredicate(db, return new AndChangeSource(pred, new ChangeIsVisibleToPredicate(db,
notesFactory, changeControlFactory, userProvider.get())), start); notesFactory, changeControlFactory, userProvider.get()), start);
} }
} }

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.RegexPredicate;
import com.google.gerrit.server.query.Matchable;
public abstract class ChangeRegexPredicate extends RegexPredicate<ChangeData>
implements Matchable<ChangeData> {
protected ChangeRegexPredicate(FieldDef<ChangeData, ?> def, String value) {
super(def, value);
}
protected ChangeRegexPredicate(FieldDef<ChangeData, ?> def, String name,
String value) {
super(def, name, value);
}
}

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status; import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -36,7 +35,7 @@ import java.util.TreeMap;
* <p> * <p>
* Status names are looked up by prefix case-insensitively. * Status names are looked up by prefix case-insensitively.
*/ */
public final class ChangeStatusPredicate extends IndexPredicate<ChangeData> { public final class ChangeStatusPredicate extends ChangeIndexPredicate {
private static final TreeMap<String, Predicate<ChangeData>> PREDICATES; private static final TreeMap<String, Predicate<ChangeData>> PREDICATES;
private static final Predicate<ChangeData> CLOSED; private static final Predicate<ChangeData> CLOSED;
private static final Predicate<ChangeData> OPEN; private static final Predicate<ChangeData> OPEN;

View File

@@ -17,13 +17,12 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.ChangeMessage; import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.Objects; import java.util.Objects;
class CommentByPredicate extends IndexPredicate<ChangeData> { class CommentByPredicate extends ChangeIndexPredicate {
private final Account.Id id; private final Account.Id id;
CommentByPredicate(Account.Id id) { CommentByPredicate(Account.Id id) {

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.index.change.ChangeIndex; import com.google.gerrit.server.index.change.ChangeIndex;
import com.google.gerrit.server.index.change.IndexedChangeQuery; import com.google.gerrit.server.index.change.IndexedChangeQuery;
@@ -22,7 +21,7 @@ import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class CommentPredicate extends IndexPredicate<ChangeData> { class CommentPredicate extends ChangeIndexPredicate {
private final ChangeIndex index; private final ChangeIndex index;
CommentPredicate(ChangeIndex index, String value) { CommentPredicate(ChangeIndex index, String value) {

View File

@@ -20,10 +20,9 @@ import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.index.FieldDef; import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class CommitPredicate extends IndexPredicate<ChangeData> { class CommitPredicate extends ChangeIndexPredicate {
static FieldDef<ChangeData, ?> commitField(String id) { static FieldDef<ChangeData, ?> commitField(String id) {
if (id.length() == OBJECT_ID_STRING_LENGTH) { if (id.length() == OBJECT_ID_STRING_LENGTH) {
return EXACT_COMMIT; return EXACT_COMMIT;

View File

@@ -17,11 +17,10 @@ package com.google.gerrit.server.query.change;
import static com.google.gerrit.server.index.change.ChangeField.COMMITTER; import static com.google.gerrit.server.index.change.ChangeField.COMMITTER;
import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_COMMITTER; import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_COMMITTER;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class CommitterPredicate extends IndexPredicate<ChangeData> { public class CommitterPredicate extends ChangeIndexPredicate {
CommitterPredicate(String value) { CommitterPredicate(String value) {
super(COMMITTER, FIELD_COMMITTER, value.toLowerCase()); super(COMMITTER, FIELD_COMMITTER, value.toLowerCase());
} }

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.server.git.strategy.SubmitDryRun;
import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.query.OperatorPredicate;
import com.google.gerrit.server.query.OrPredicate; import com.google.gerrit.server.query.OrPredicate;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments; import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments;
@@ -84,7 +83,7 @@ class ConflictsPredicate extends OrPredicate<ChangeData> {
predicatesForOneChange.add(or(or(filePredicates), predicatesForOneChange.add(or(or(filePredicates),
new IsMergePredicate(args, value))); new IsMergePredicate(args, value)));
predicatesForOneChange.add(new OperatorPredicate<ChangeData>( predicatesForOneChange.add(new ChangeOperatorPredicate(
ChangeQueryBuilder.FIELD_CONFLICTS, value) { ChangeQueryBuilder.FIELD_CONFLICTS, value) {
@Override @Override

View File

@@ -14,12 +14,11 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.IntegerRangePredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class DeletedPredicate extends IntegerRangePredicate<ChangeData> { public class DeletedPredicate extends IntegerRangeChangePredicate {
DeletedPredicate(String value) throws QueryParseException { DeletedPredicate(String value) throws QueryParseException {
super(ChangeField.DELETED, value); super(ChangeField.DELETED, value);
} }

View File

@@ -14,13 +14,12 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.IntegerRangePredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gerrit.server.query.change.ChangeData.ChangedLines; import com.google.gerrit.server.query.change.ChangeData.ChangedLines;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class DeltaPredicate extends IntegerRangePredicate<ChangeData> { public class DeltaPredicate extends IntegerRangeChangePredicate {
DeltaPredicate(String value) throws QueryParseException { DeltaPredicate(String value) throws QueryParseException {
super(ChangeField.DELTA, value); super(ChangeField.DELTA, value);
} }

View File

@@ -16,12 +16,11 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.query.OperatorPredicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.Set; import java.util.Set;
class DestinationPredicate extends OperatorPredicate<ChangeData> { class DestinationPredicate extends ChangeOperatorPredicate {
Set<Branch.NameKey> destinations; Set<Branch.NameKey> destinations;
DestinationPredicate(Set<Branch.NameKey> destinations, String value) { DestinationPredicate(Set<Branch.NameKey> destinations, String value) {

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class EditByPredicate extends IndexPredicate<ChangeData> { class EditByPredicate extends ChangeIndexPredicate {
private final Account.Id id; private final Account.Id id;
EditByPredicate(Account.Id id) { EditByPredicate(Account.Id id) {

View File

@@ -14,13 +14,12 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments; import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class EqualsFilePredicate extends IndexPredicate<ChangeData> { class EqualsFilePredicate extends ChangeIndexPredicate {
static Predicate<ChangeData> create(Arguments args, String value) { static Predicate<ChangeData> create(Arguments args, String value) {
Predicate<ChangeData> eqPath = Predicate<ChangeData> eqPath =
new EqualsPathPredicate(ChangeQueryBuilder.FIELD_FILE, value); new EqualsPathPredicate(ChangeQueryBuilder.FIELD_FILE, value);

View File

@@ -23,7 +23,6 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSetApproval; import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.NoSuchChangeException;
@@ -32,7 +31,7 @@ import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider; import com.google.inject.Provider;
class EqualsLabelPredicate extends IndexPredicate<ChangeData> { class EqualsLabelPredicate extends ChangeIndexPredicate {
private final ProjectCache projectCache; private final ProjectCache projectCache;
private final ChangeControl.GenericFactory ccFactory; private final ChangeControl.GenericFactory ccFactory;
private final IdentifiedUser.GenericFactory userFactory; private final IdentifiedUser.GenericFactory userFactory;

View File

@@ -14,14 +14,13 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
class EqualsPathPredicate extends IndexPredicate<ChangeData> { class EqualsPathPredicate extends ChangeIndexPredicate {
private final String value; private final String value;
EqualsPathPredicate(String fieldName, String value) { EqualsPathPredicate(String fieldName, String value) {

View File

@@ -17,10 +17,9 @@ package com.google.gerrit.server.query.change;
import static com.google.gerrit.server.index.change.ChangeField.EXACT_TOPIC; import static com.google.gerrit.server.index.change.ChangeField.EXACT_TOPIC;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class ExactTopicPredicate extends IndexPredicate<ChangeData> { class ExactTopicPredicate extends ChangeIndexPredicate {
ExactTopicPredicate(String topic) { ExactTopicPredicate(String topic) {
super(EXACT_TOPIC, topic); super(EXACT_TOPIC, topic);
} }

View File

@@ -18,14 +18,13 @@ import static com.google.gerrit.server.index.change.ChangeField.FUZZY_TOPIC;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeIndex; import com.google.gerrit.server.index.change.ChangeIndex;
import com.google.gerrit.server.index.change.IndexedChangeQuery; import com.google.gerrit.server.index.change.IndexedChangeQuery;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class FuzzyTopicPredicate extends IndexPredicate<ChangeData> { class FuzzyTopicPredicate extends ChangeIndexPredicate {
private final ChangeIndex index; private final ChangeIndex index;
FuzzyTopicPredicate(String topic, ChangeIndex index) { FuzzyTopicPredicate(String topic, ChangeIndex index) {

View File

@@ -15,13 +15,12 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.List; import java.util.List;
class GroupPredicate extends IndexPredicate<ChangeData> { class GroupPredicate extends ChangeIndexPredicate {
GroupPredicate(String group) { GroupPredicate(String group) {
super(ChangeField.GROUP, group); super(ChangeField.GROUP, group);
} }

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.server.query.OperatorPredicate;
import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments; import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments;
import com.google.gwtorm.server.ListResultSet; import com.google.gwtorm.server.ListResultSet;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -29,8 +28,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
@Deprecated @Deprecated
class HasDraftByLegacyPredicate extends OperatorPredicate<ChangeData> implements class HasDraftByLegacyPredicate extends ChangeOperatorPredicate
ChangeDataSource { implements ChangeDataSource {
private final Arguments args; private final Arguments args;
private final Account.Id accountId; private final Account.Id accountId;

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class HasDraftByPredicate extends IndexPredicate<ChangeData> { class HasDraftByPredicate extends ChangeIndexPredicate {
private final Account.Id accountId; private final Account.Id accountId;
HasDraftByPredicate(Account.Id accountId) { HasDraftByPredicate(Account.Id accountId) {

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class HasStarsPredicate extends IndexPredicate<ChangeData> { public class HasStarsPredicate extends ChangeIndexPredicate {
private final Account.Id accountId; private final Account.Id accountId;
HasStarsPredicate(Account.Id accountId) { HasStarsPredicate(Account.Id accountId) {

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.change.HashtagsUtil; import com.google.gerrit.server.change.HashtagsUtil;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class HashtagPredicate extends IndexPredicate<ChangeData> { class HashtagPredicate extends ChangeIndexPredicate {
HashtagPredicate(String hashtag) { HashtagPredicate(String hashtag) {
super(ChangeField.HASHTAG, HashtagsUtil.cleanupHashtag(hashtag)); super(ChangeField.HASHTAG, HashtagsUtil.cleanupHashtag(hashtag));
} }

View File

@@ -0,0 +1,34 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.IntegerRangePredicate;
import com.google.gerrit.server.query.Matchable;
import com.google.gerrit.server.query.QueryParseException;
public abstract class IntegerRangeChangePredicate
extends IntegerRangePredicate<ChangeData> implements Matchable<ChangeData> {
protected IntegerRangeChangePredicate(FieldDef<ChangeData, Integer> type,
String value) throws QueryParseException {
super(type, value);
}
@Override
public int getCost() {
return 1;
}
}

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.query.OperatorPredicate;
import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments; import com.google.gerrit.server.query.change.ChangeQueryBuilder.Arguments;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -26,7 +25,7 @@ import org.eclipse.jgit.revwalk.RevWalk;
import java.io.IOException; import java.io.IOException;
public class IsMergePredicate extends OperatorPredicate<ChangeData> { public class IsMergePredicate extends ChangeOperatorPredicate {
private final Arguments args; private final Arguments args;
public IsMergePredicate(Arguments args, String value) { public IsMergePredicate(Arguments args, String value) {

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.FieldDef.FillArgs; import com.google.gerrit.server.index.FieldDef.FillArgs;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class IsMergeablePredicate extends IndexPredicate<ChangeData> { class IsMergeablePredicate extends ChangeIndexPredicate {
private final FillArgs args; private final FillArgs args;
IsMergeablePredicate(FillArgs args) { IsMergeablePredicate(FillArgs args) {

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.query.change;
import static com.google.gerrit.server.index.change.ChangeField.REVIEWEDBY; import static com.google.gerrit.server.index.change.ChangeField.REVIEWEDBY;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -27,7 +26,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
class IsReviewedPredicate extends IndexPredicate<ChangeData> { class IsReviewedPredicate extends ChangeIndexPredicate {
private static final Account.Id NOT_REVIEWED = private static final Account.Id NOT_REVIEWED =
new Account.Id(ChangeField.NOT_REVIEWED); new Account.Id(ChangeField.NOT_REVIEWED);

View File

@@ -15,12 +15,11 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@Deprecated @Deprecated
class IsStarredByPredicate extends IndexPredicate<ChangeData> { class IsStarredByPredicate extends ChangeIndexPredicate {
private final Account.Id accountId; private final Account.Id accountId;
IsStarredByPredicate(Account.Id accountId) { IsStarredByPredicate(Account.Id accountId) {

View File

@@ -17,10 +17,9 @@ package com.google.gerrit.server.query.change;
import static com.google.gerrit.server.index.change.ChangeField.LEGACY_ID; import static com.google.gerrit.server.index.change.ChangeField.LEGACY_ID;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
/** Predicate over change number (aka legacy ID or Change.Id). */ /** Predicate over change number (aka legacy ID or Change.Id). */
public class LegacyChangeIdPredicate extends IndexPredicate<ChangeData> { public class LegacyChangeIdPredicate extends ChangeIndexPredicate {
private final Change.Id id; private final Change.Id id;
LegacyChangeIdPredicate(Change.Id id) { LegacyChangeIdPredicate(Change.Id id) {

View File

@@ -15,12 +15,11 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@Deprecated @Deprecated
class LegacyReviewerPredicate extends IndexPredicate<ChangeData> { class LegacyReviewerPredicate extends ChangeIndexPredicate {
private final Account.Id id; private final Account.Id id;
LegacyReviewerPredicate(Account.Id id) { LegacyReviewerPredicate(Account.Id id) {

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.index.change.ChangeIndex; import com.google.gerrit.server.index.change.ChangeIndex;
import com.google.gerrit.server.index.change.IndexedChangeQuery; import com.google.gerrit.server.index.change.IndexedChangeQuery;
@@ -26,7 +25,7 @@ import com.google.gwtorm.server.OrmException;
* Predicate to match changes that contains specified text in commit messages * Predicate to match changes that contains specified text in commit messages
* body. * body.
*/ */
class MessagePredicate extends IndexPredicate<ChangeData> { class MessagePredicate extends ChangeIndexPredicate {
private final ChangeIndex index; private final ChangeIndex index;
MessagePredicate(ChangeIndex index, String value) { MessagePredicate(ChangeIndex index, String value) {

View File

@@ -16,11 +16,10 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class OwnerPredicate extends IndexPredicate<ChangeData> { class OwnerPredicate extends ChangeIndexPredicate {
private final Account.Id id; private final Account.Id id;
OwnerPredicate(Account.Id id) { OwnerPredicate(Account.Id id) {

View File

@@ -17,10 +17,9 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.query.OperatorPredicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class OwnerinPredicate extends OperatorPredicate<ChangeData> { class OwnerinPredicate extends ChangeOperatorPredicate {
private final IdentifiedUser.GenericFactory userFactory; private final IdentifiedUser.GenericFactory userFactory;
private final AccountGroup.UUID uuid; private final AccountGroup.UUID uuid;

View File

@@ -16,11 +16,10 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class ProjectPredicate extends IndexPredicate<ChangeData> { class ProjectPredicate extends ChangeIndexPredicate {
ProjectPredicate(String id) { ProjectPredicate(String id) {
super(ChangeField.PROJECT, id); super(ChangeField.PROJECT, id);
} }

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class ProjectPrefixPredicate extends IndexPredicate<ChangeData> { class ProjectPrefixPredicate extends ChangeIndexPredicate {
ProjectPrefixPredicate(String prefix) { ProjectPrefixPredicate(String prefix) {
super(ChangeField.PROJECTS, prefix); super(ChangeField.PROJECTS, prefix);
} }

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class RefPredicate extends IndexPredicate<ChangeData> { class RefPredicate extends ChangeIndexPredicate {
RefPredicate(String ref) { RefPredicate(String ref) {
super(ChangeField.REF, ref); super(ChangeField.REF, ref);
} }

View File

@@ -14,14 +14,13 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.RegexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.util.RegexListSearcher; import com.google.gerrit.server.util.RegexListSearcher;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import java.util.List; import java.util.List;
class RegexPathPredicate extends RegexPredicate<ChangeData> { class RegexPathPredicate extends ChangeRegexPredicate {
RegexPathPredicate(String re) { RegexPathPredicate(String re) {
super(ChangeField.PATH, re); super(ChangeField.PATH, re);
} }

View File

@@ -16,14 +16,13 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.index.RegexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import dk.brics.automaton.RegExp; import dk.brics.automaton.RegExp;
import dk.brics.automaton.RunAutomaton; import dk.brics.automaton.RunAutomaton;
class RegexProjectPredicate extends RegexPredicate<ChangeData> { class RegexProjectPredicate extends ChangeRegexPredicate {
private final RunAutomaton pattern; private final RunAutomaton pattern;
RegexProjectPredicate(String re) { RegexProjectPredicate(String re) {

View File

@@ -15,14 +15,13 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.RegexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import dk.brics.automaton.RegExp; import dk.brics.automaton.RegExp;
import dk.brics.automaton.RunAutomaton; import dk.brics.automaton.RunAutomaton;
class RegexRefPredicate extends RegexPredicate<ChangeData> { class RegexRefPredicate extends ChangeRegexPredicate {
private final RunAutomaton pattern; private final RunAutomaton pattern;
RegexRefPredicate(String re) { RegexRefPredicate(String re) {

View File

@@ -17,13 +17,12 @@ package com.google.gerrit.server.query.change;
import static com.google.gerrit.server.index.change.ChangeField.FUZZY_TOPIC; import static com.google.gerrit.server.index.change.ChangeField.FUZZY_TOPIC;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.RegexPredicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import dk.brics.automaton.RegExp; import dk.brics.automaton.RegExp;
import dk.brics.automaton.RunAutomaton; import dk.brics.automaton.RunAutomaton;
class RegexTopicPredicate extends RegexPredicate<ChangeData> { class RegexTopicPredicate extends ChangeRegexPredicate {
private final RunAutomaton pattern; private final RunAutomaton pattern;
RegexTopicPredicate(String re) { RegexTopicPredicate(String re) {

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.notedb.ReviewerStateInternal; import com.google.gerrit.server.notedb.ReviewerStateInternal;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
@@ -26,7 +25,7 @@ import com.google.gwtorm.server.OrmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
class ReviewerPredicate extends IndexPredicate<ChangeData> { class ReviewerPredicate extends ChangeIndexPredicate {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
static Predicate<ChangeData> create(Arguments args, Account.Id id) { static Predicate<ChangeData> create(Arguments args, Account.Id id) {
List<Predicate<ChangeData>> and = new ArrayList<>(2); List<Predicate<ChangeData>> and = new ArrayList<>(2);

View File

@@ -17,10 +17,9 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.query.OperatorPredicate;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class ReviewerinPredicate extends OperatorPredicate<ChangeData> { class ReviewerinPredicate extends ChangeOperatorPredicate {
private final IdentifiedUser.GenericFactory userFactory; private final IdentifiedUser.GenericFactory userFactory;
private final AccountGroup.UUID uuid; private final AccountGroup.UUID uuid;

View File

@@ -16,11 +16,10 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.StarredChangesUtil; import com.google.gerrit.server.StarredChangesUtil;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
public class StarPredicate extends IndexPredicate<ChangeData> { public class StarPredicate extends ChangeIndexPredicate {
private final Account.Id accountId; private final Account.Id accountId;
private final String label; private final String label;

View File

@@ -15,11 +15,10 @@
package com.google.gerrit.server.query.change; package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
class SubmissionIdPredicate extends IndexPredicate<ChangeData> { class SubmissionIdPredicate extends ChangeIndexPredicate {
SubmissionIdPredicate(String changeSet) { SubmissionIdPredicate(String changeSet) {
super(ChangeField.SUBMISSIONID, changeSet); super(ChangeField.SUBMISSIONID, changeSet);

View File

@@ -0,0 +1,34 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.TimestampRangePredicate;
import com.google.gerrit.server.query.Matchable;
import java.sql.Timestamp;
public abstract class TimestampRangeChangePredicate extends
TimestampRangePredicate<ChangeData> implements Matchable<ChangeData> {
protected TimestampRangeChangePredicate(FieldDef<ChangeData, Timestamp> def,
String name, String value) {
super(def, name, value);
}
@Override
public int getCost() {
return 1;
}
}

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.config.TrackingFooters; import com.google.gerrit.server.config.TrackingFooters;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -27,7 +26,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
class TrackingIdPredicate extends IndexPredicate<ChangeData> { class TrackingIdPredicate extends ChangeIndexPredicate {
private static final Logger log = LoggerFactory.getLogger(TrackingIdPredicate.class); private static final Logger log = LoggerFactory.getLogger(TrackingIdPredicate.class);
private final TrackingFooters trackingFooters; private final TrackingFooters trackingFooters;

View File

@@ -18,7 +18,6 @@ import com.google.gerrit.server.query.OperatorPredicate;
import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.ChangeQueryBuilder; import com.google.gerrit.server.query.change.ChangeQueryBuilder;
import com.google.gwtorm.server.OrmException;
import org.junit.Ignore; import org.junit.Ignore;
@@ -44,16 +43,6 @@ public class FakeQueryBuilder extends ChangeQueryBuilder {
} }
private Predicate<ChangeData> predicate(String name, String value) { private Predicate<ChangeData> predicate(String name, String value) {
return new OperatorPredicate<ChangeData>(name, value) { return new OperatorPredicate<ChangeData>(name, value) {};
@Override
public boolean match(ChangeData object) throws OrmException {
return false;
}
@Override
public int getCost() {
return 0;
}
};
} }
} }

View File

@@ -24,16 +24,6 @@ public abstract class PredicateTest extends GerritBaseTests {
protected TestPredicate(String name, String value) { protected TestPredicate(String name, String value) {
super(name, value); super(name, value);
} }
@Override
public boolean match(String object) {
return false;
}
@Override
public int getCost() {
return 0;
}
} }
protected static TestPredicate f(String name, String value) { protected static TestPredicate f(String name, String value) {