// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.documentapi.local; import com.yahoo.document.Document; import com.yahoo.document.DocumentId; import com.yahoo.document.DocumentPut; import com.yahoo.document.DocumentRemove; import com.yahoo.document.DocumentUpdate; import com.yahoo.documentapi.Response; import com.yahoo.documentapi.SyncSession; import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; /** * @author bratseth */ public class LocalSyncSession implements SyncSession { private LocalDocumentAccess access; public LocalSyncSession(LocalDocumentAccess access) { this.access = access; } @Override public void put(DocumentPut documentPut) { if (documentPut.getCondition().isPresent()) { throw new UnsupportedOperationException("test-and-set is not supported."); } access.documents.put(documentPut.getId(), documentPut.getDocument()); } @Override public void put(DocumentPut documentPut, DocumentProtocol.Priority priority) { access.documents.put(documentPut.getId(), documentPut.getDocument()); } @Override public Document get(DocumentId id) { return access.documents.get(id); } @Override public Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority pri) { // FIXME: More than half the get() methods are deprecated, but they all // call exactly the same method, including this one, throwing away most // of the parameters return access.documents.get(id); } @Override public boolean remove(DocumentRemove documentRemove) { if (documentRemove.getCondition().isPresent()) { throw new UnsupportedOperationException("test-and-set is not supported."); } access.documents.remove(documentRemove.getId()); return true; } @Override public boolean remove(DocumentRemove documentRemove, DocumentProtocol.Priority priority) { return remove(documentRemove); } @Override public boolean update(DocumentUpdate update) { Document document = access.documents.get(update.getId()); if (document == null) { return false; } update.applyTo(document); return true; } @Override public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) { Document document = access.documents.get(update.getId()); if (document == null) { return false; } update.applyTo(document); return true; } @Override public Response getNext() { throw new UnsupportedOperationException("Queue not supported."); } @Override public Response getNext(int timeout) { throw new UnsupportedOperationException("Queue not supported."); } @Override public void destroy() { access = null; } }