diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2018-11-01 15:56:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-01 15:56:07 +0100 |
commit | d5401c846ff4d70eb95fa76e4fd3aeb3d3f754cf (patch) | |
tree | 89799202cedb091f5aa511cf2ae13936498c5b18 /document | |
parent | c3982d42b9d5ca9aea7600f5bc5fc6cceb78505a (diff) | |
parent | c71081ffc288bc0287e79275199ac04dd5b16ff7 (diff) |
Merge pull request #7538 from vespa-engine/toregge/narrow-down-routing-of-document-api-get-document-messages
Narrow down routing of Document API GetDocument messages.
Diffstat (limited to 'document')
5 files changed, 65 insertions, 1 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentGet.java b/document/src/main/java/com/yahoo/document/DocumentGet.java new file mode 100644 index 00000000000..0cf67f54b65 --- /dev/null +++ b/document/src/main/java/com/yahoo/document/DocumentGet.java @@ -0,0 +1,42 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.document; + +/** + * Transient class. Only for internal use in document and documentapi. + * + * @author baldersheim + * @author toregge + */ +public class DocumentGet extends DocumentOperation { + + private final DocumentId docId; + + public DocumentGet(DocumentId docId) { this.docId = docId; } + + @Override + public DocumentId getId() { return docId; } + + @Override + public void setCondition(TestAndSetCondition condition) { + throw new UnsupportedOperationException("conditional DocumentGet is not supported"); + } + + @Override + public String toString() { + return "DocumentGet '" + docId + "'"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DocumentGet)) return false; + DocumentGet that = (DocumentGet) o; + if (!docId.equals(that.docId)) return false; + return true; + } + + @Override + public int hashCode() { + return docId.hashCode(); + } +} diff --git a/document/src/main/java/com/yahoo/document/DocumentOperation.java b/document/src/main/java/com/yahoo/document/DocumentOperation.java index 22ee0fd93eb..8209322c472 100644 --- a/document/src/main/java/com/yahoo/document/DocumentOperation.java +++ b/document/src/main/java/com/yahoo/document/DocumentOperation.java @@ -3,7 +3,8 @@ package com.yahoo.document; /** * Base class for "document operations". - * These include "put" (DocumentPut), "update" (DocumentUpdate), and "remove" (DocumentRemove). + * These include "put" (DocumentPut), "update" (DocumentUpdate), "remove" (DocumentRemove) + * and "get" (DocumentGet). The latter only for internal use. * Historically, put operations were represented by the Document class alone, * but since it doesn't make much sense to put a *test and set* condition in Document, * a more uniform interface for document operations was needed. diff --git a/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java b/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java index 17f95087be1..b6d75acd0ea 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java @@ -135,6 +135,8 @@ public class AttributeNode implements ExpressionNode { return Result.INVALID; } else if (value instanceof DocumentRemove) { return Result.INVALID; + } else if (value instanceof DocumentGet) { + return Result.INVALID; } return Result.FALSE; } diff --git a/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java b/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java index 3fe3d5d7169..c0907693dab 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java @@ -46,6 +46,9 @@ public class DocumentNode implements ExpressionNode { } else if (op instanceof DocumentRemove) { DocumentRemove removeOp = (DocumentRemove)op; return (removeOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); + } else if (op instanceof DocumentGet) { + DocumentGet getOp = (DocumentGet)op; + return (getOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); } else { throw new IllegalStateException("Document class '" + op.getClass().getName() + "' is not supported."); } diff --git a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java index 1764079e897..10808f9b630 100644 --- a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java @@ -278,6 +278,22 @@ public class DocumentSelectorTestCase { } @Test + public void testDocumentGet() throws ParseException { + assertEquals(Result.TRUE, evaluate("test", createGet("id:ns:test::1"))); + assertEquals(Result.FALSE, evaluate("test", createGet("id:ns:null::1"))); + assertEquals(Result.FALSE, evaluate("test", createGet("userdoc:test:1234:1"))); + assertEquals(Result.INVALID, evaluate("test.hint", createGet("id:ns:test::1"))); + assertEquals(Result.FALSE, evaluate("test.hint", createGet("id:ns:null::1"))); + assertEquals(Result.INVALID, evaluate("test.hint == 0", createGet("id:ns:test::1"))); + assertEquals(Result.INVALID, evaluate("test.anything", createGet("id:ns:test::1"))); + assertEquals(Result.INVALID, evaluate("test and test.hint == 0", createGet("id:ns:test::1"))); + } + + private DocumentGet createGet(String docId) { + return new DocumentGet(new DocumentId(docId)); + } + + @Test public void testInvalidLogic() throws ParseException { DocumentPut put = new DocumentPut(manager.getDocumentType("test"), new DocumentId("doc:scheme:")); DocumentUpdate upd = new DocumentUpdate(manager.getDocumentType("test"), new DocumentId("doc:scheme:")); |