Add initial GroupQueryBuilder and define key predicate for group index

Change-Id: I4e367d6b9417343524d9dcd91a55728b72d5d5b1
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-01-02 11:26:21 +01:00
parent bb24a5d208
commit 9750e9224d
3 changed files with 88 additions and 0 deletions

View File

@@ -17,9 +17,16 @@ package com.google.gerrit.server.index.group;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.index.Index;
import com.google.gerrit.server.index.IndexDefinition;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.group.GroupPredicates;
public interface GroupIndex extends Index<AccountGroup.UUID, AccountGroup> {
public interface Factory extends
IndexDefinition.IndexFactory<AccountGroup.UUID, AccountGroup, GroupIndex> {
}
@Override
default Predicate<AccountGroup> keyPredicate(AccountGroup.UUID uuid) {
return GroupPredicates.uuid(uuid);
}
}

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2017 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.group;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.group.GroupField;
import com.google.gerrit.server.query.Predicate;
public class GroupPredicates {
public static Predicate<AccountGroup> uuid(AccountGroup.UUID uuid) {
return new GroupPredicate(GroupField.UUID,
GroupQueryBuilder.FIELD_UUID, uuid.get());
}
static class GroupPredicate extends IndexPredicate<AccountGroup> {
GroupPredicate(FieldDef<AccountGroup, ?> def, String value) {
super(def, value);
}
GroupPredicate(FieldDef<AccountGroup, ?> def, String name, String value) {
super(def, name, value);
}
}
private GroupPredicates() {
}
}

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2017 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.group;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryBuilder;
import com.google.inject.Inject;
/**
* Parses a query string meant to be applied to group objects.
*/
public class GroupQueryBuilder extends QueryBuilder<AccountGroup> {
public static final String FIELD_UUID = "uuid";
private static final QueryBuilder.Definition<AccountGroup, GroupQueryBuilder> mydef =
new QueryBuilder.Definition<>(GroupQueryBuilder.class);
@Inject
GroupQueryBuilder() {
super(mydef);
}
@Operator
public Predicate<AccountGroup> uuid(String uuid) {
return GroupPredicates.uuid(new AccountGroup.UUID(uuid));
}
}