/** * Create a document with the given document type and identifier. * @param docType DocumentType to use for creation * @param id The id for this document */ public Document(DocumentType docType, String id) { this(docType, new DocumentId(id)); }
public FeedErrorMessage(String operationId) { try { DocumentId id = new DocumentId(operationId); sequenceId = Arrays.hashCode(id.getGlobalId()); } catch (Exception e) { sequenceId = 0; } }
private void internalSetId(DocumentId id, DocumentType docType) { if (id != null && id.hasDocType() && docType != null && !id.getDocType().equals(docType.getName())) { throw new IllegalArgumentException("Trying to set a document id (type " + id.getDocType() + ") that doesn't match the document type (" + getDataType().getName() + ")."); } docId = id; }
final String attributeName = reader.getAttributeName(i).toString(); if ("documentid".equals(attributeName) || "id".equals(attributeName)) { document.setId(new DocumentId(reader.getAttributeValue(i))); } else if ("documenttype".equals(attributeName) || "type".equals(attributeName)) { typeName = reader.getAttributeValue(i); field = new FieldBase(document.getId().toString());
return id.toString(); } else if (field.equalsIgnoreCase("scheme")) { return id.getScheme().getType().toString(); } else if (field.equalsIgnoreCase("namespace")) { return id.getScheme().getNamespace(); } else if (field.equalsIgnoreCase("specific")) { return id.getScheme().getNamespaceSpecific(); } else if (field.equalsIgnoreCase("group")) { if (id.getScheme().hasGroup()) { return id.getScheme().getGroup(); if (id.getScheme().hasNumber()) { return id.getScheme().getNumber(); if (id.getScheme().hasDocType()) { return id.getScheme().getDocType(); if (id.getScheme() instanceof OrderDocIdString) { OrderDocIdString ods = (OrderDocIdString)id.getScheme(); if (ods.getWidthBits() == widthBits && ods.getDivisionBits() == divisionBits) { return ods.getOrdering();
docId = new DocumentId(id); } catch (IllegalArgumentException iae) { log.log(logLevel, "Bad result for " + query + ": " + iae.getMessage()); long userId; if (docId.getScheme().hasNumber()) { userId = docId.getScheme().getNumber(); } else { log.log(logLevel, "Got result with wrong scheme (expected " + IdString.Scheme.userdoc + String groupName; if (docId.getScheme().hasGroup()) { groupName = docId.getScheme().getGroup(); } else { log.log(logLevel, "Got result with wrong scheme (expected " + IdString.Scheme.groupdoc +
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof DocumentRemove)) return false; DocumentRemove that = (DocumentRemove) o; if (!docId.equals(that.docId)) return false; return true; }
/** * Get the bucket id for a given document. * * @param doc The doc. * @return The bucket id. */ public BucketId getBucketId(DocumentId doc) { long location = doc.getScheme().getLocation(); byte[] gid = doc.getGlobalId(); long gidContribution = getGidContribution(gid); IdString.GidModifier gm = doc.getScheme().getGidModifier(); if (gm != null && gm.usedBits != 0) { gidContribution &= (0xFFFFFFFFFFFFFFFFl << (gm.usedBits + getLocationBitCount())); gidContribution |= (gm.value << getLocationBitCount()); } return new BucketId(64 - BucketId.COUNT_BITS, initialCount | (gidMask & gidContribution) | (locationMask & location)); }
/** * Reads a single operation. The operation is not expected to be part of an array. * @param operationType the type of operation (update or put) * @param docIdString document ID. * @return the document */ public DocumentOperation readSingleDocument(DocumentParser.SupportedOperation operationType, String docIdString) { DocumentId docId = new DocumentId(docIdString); final DocumentParseInfo documentParseInfo; try { DocumentParser documentParser = new DocumentParser(parser); documentParseInfo = documentParser.parse(Optional.of(docId)).get(); } catch (IOException e) { state = END_OF_FEED; throw new RuntimeException(e); } documentParseInfo.operationType = operationType; VespaJsonDocumentReader vespaJsonDocumentReader = new VespaJsonDocumentReader(); DocumentOperation operation = vespaJsonDocumentReader.createDocumentOperation( getDocumentTypeFromString(documentParseInfo.documentId.getDocType(), typeManager), documentParseInfo); operation.setCondition(TestAndSetCondition.fromConditionString(documentParseInfo.condition)); return operation; }
public DocumentState(DocumentId docId, long timestamp, boolean removeEntry) { this.docId = docId; this.gid = new GlobalId(docId.getGlobalId()); this.timestamp = timestamp; this.removeEntry = removeEntry; }
@Override protected boolean doEncode(DocumentMessage obj, DocumentSerializer buf) { RemoveDocumentMessage msg = (RemoveDocumentMessage)obj; msg.getDocumentId().serialize(buf); encodeTasCondition(buf, (TestAndSetMessage) obj); return true; } }
@Override public int hashCode() { return docId.hashCode(); } }
public void onDeserialize(Deserializer data) throws DeserializationException { if (data instanceof DocumentReader) { id = ((DocumentReader)data).readDocumentId().getScheme(); } else { id = IdString.createFromSerialized(data.getString(null)); } }
if (removeMsg.getDocumentId().hasDocType()) { return selector.accepts(removeMsg.getDocumentRemove()) != Result.FALSE; } else { if (getMsg.getDocumentId().hasDocType()) { DocumentGet getOp = new DocumentGet(getMsg.getDocumentId()); return selector.accepts(getOp) != Result.FALSE;
void testIterationRequiringDocumentIdOnlyMatching(PersistenceProvider spi) throws Exception { Bucket b = new Bucket((short)0, new BucketId(8, 0x1)); spi.createBucket(b); feedDocs(spi, b, 100, 100, 100); DocumentId removedId = new DocumentId("userdoc:blarg:1:unknowndoc"); // Document does not already exist, remove should create a // remove entry for it regardless. assertFalse(spi.remove(b, 2000, removedId).wasFound()); spi.flush(b); CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("id == '" + removedId.toString() + "'", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE); List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0); List<String> removes = new ArrayList<String>(); List<DocEntry> docs = new ArrayList<DocEntry>(); removes.add(removedId.toString()); verifyDocs(docs, chunks, removes); spi.destroyIterator(iter.getIteratorId()); }
@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 long getSequenceId() { return Arrays.hashCode(remove.getId().getGlobalId()); }
@Override protected boolean doEncode(DocumentMessage obj, DocumentSerializer buf) { GetDocumentMessage msg = (GetDocumentMessage)obj; msg.getDocumentId().serialize(buf); encodeString(msg.getFieldSet(), buf); return true; } }
@Override public int hashCode() { return docId.hashCode(); }