From db9c2796b34943d62df46074c85e8f6acf48f79e Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 24 Sep 2015 17:42:52 +0200 Subject: [PATCH] Query refactoring: last //norelease addressed Some methods had default implementation while queries were going to be refactored, now that they are all refactored all those methods can be made abstract. --- .../index/query/AbstractQueryBuilder.java | 36 +++---------------- .../index/query/QueryBuilder.java | 11 ------ .../index/query/WrapperQueryBuilderTests.java | 4 +-- .../query/plugin/DummyQueryParserPlugin.java | 22 ++++++++++++ 4 files changed, 28 insertions(+), 45 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java index 3d454e32ec3..560476a69d8 100644 --- a/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java @@ -156,10 +156,7 @@ public abstract class AbstractQueryBuilder exte return queryBuilder; } - //norelease make this abstract once all builders implement doReadFrom themselves - protected QB doReadFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException(); - } + protected abstract QB doReadFrom(StreamInput in) throws IOException; @Override public final void writeTo(StreamOutput out) throws IOException { @@ -168,10 +165,7 @@ public abstract class AbstractQueryBuilder exte out.writeOptionalString(queryName); } - //norelease make this abstract once all builders implement doWriteTo themselves - protected void doWriteTo(StreamOutput out) throws IOException { - throw new UnsupportedOperationException(); - } + protected abstract void doWriteTo(StreamOutput out) throws IOException; protected final QueryValidationException addValidationError(String validationError, QueryValidationException validationException) { return QueryValidationException.addValidationError(getName(), validationError, validationException); @@ -195,20 +189,14 @@ public abstract class AbstractQueryBuilder exte /** * Indicates whether some other {@link QueryBuilder} object of the same type is "equal to" this one. */ - //norelease to be made abstract once all queries are refactored - protected boolean doEquals(QB other) { - return super.equals(other); - } + protected abstract boolean doEquals(QB other); @Override public final int hashCode() { return Objects.hash(getClass(), queryName, boost, doHashCode()); } - //norelease to be made abstract once all queries are refactored - protected int doHashCode() { - return super.hashCode(); - } + protected abstract int doHashCode(); /** * This helper method checks if the object passed in is a string, if so it @@ -275,20 +263,4 @@ public abstract class AbstractQueryBuilder exte } return queries; } - - protected final void writeOptionalQuery(StreamOutput out, QueryBuilder query) throws IOException { - if (query == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeQuery(query); - } - } - - protected final QueryBuilder readOptionalQuery(StreamInput in) throws IOException { - if (in.readBoolean()) { - return in.readQuery(); - } - return null; - } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/QueryBuilder.java index 3bc9bcb65d6..2fde316a561 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryBuilder.java @@ -20,11 +20,8 @@ package org.elasticsearch.index.query; import org.apache.lucene.search.Query; -import org.elasticsearch.client.Requests; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; @@ -50,14 +47,6 @@ public interface QueryBuilder extends NamedWriteable)wrappedQuery).buildAsBytes().toBytes()); case 2: - return new WrapperQueryBuilder(wrappedQuery.buildAsBytes()); + return new WrapperQueryBuilder(((AbstractQueryBuilder)wrappedQuery).buildAsBytes()); default: throw new UnsupportedOperationException(); } diff --git a/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java b/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java index e007b0798c2..432c833aef2 100644 --- a/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java +++ b/core/src/test/java/org/elasticsearch/index/query/plugin/DummyQueryParserPlugin.java @@ -23,6 +23,8 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.Weight; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.*; @@ -60,6 +62,26 @@ public class DummyQueryParserPlugin extends Plugin { return new DummyQuery(context.isFilter()); } + @Override + protected DummyQueryBuilder doReadFrom(StreamInput in) throws IOException { + return null; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + + } + + @Override + protected boolean doEquals(DummyQueryBuilder other) { + return false; + } + + @Override + protected int doHashCode() { + return 0; + } + @Override public String getWriteableName() { return NAME;