private Document getDocumentDefinition(String key, Map<String, ByteIterator> values) { Document document = new Document(); document.set("id", key); if (!this.useHashQueryForScan) { // This field is only needed for range scans. // Even if this field is present in the document you // should still partition on id for simplicity of config. document.set("myid", key); } for (Entry<String, ByteIterator> entry : values.entrySet()) { document.set(entry.getKey(), entry.getValue().toString()); } return document; } }
public void writeInternal(final Object entity, final Document targetDocument, final DocumentDbPersistentEntity<?> entityInformation) { if (entity == null) { return; } if (entityInformation == null) { throw new MappingException("no mapping metadata for entity type: " + entity.getClass().getName()); } final ConvertingPropertyAccessor accessor = getPropertyAccessor(entity); final DocumentDbPersistentProperty idProperty = entityInformation.getIdProperty(); if (idProperty != null) { targetDocument.setId((String) accessor.getProperty(idProperty)); } for (final Field field : entity.getClass().getDeclaredFields()) { if (null != idProperty && field.getName().equals(idProperty.getName())) { continue; } targetDocument.set(field.getName(), accessor.getProperty(entityInformation.getPersistentProperty(field.getName()))); } }
public void writeInternal(final Object entity, final Document targetDocument, final DocumentDbPersistentEntity<?> entityInformation) { if (entity == null) { return; } if (entityInformation == null) { throw new MappingException("no mapping metadata for entity type: " + entity.getClass().getName()); } final ConvertingPropertyAccessor accessor = getPropertyAccessor(entity); final DocumentDbPersistentProperty idProperty = entityInformation.getIdProperty(); if (idProperty != null) { targetDocument.setId((String) accessor.getProperty(idProperty)); } for (final Field field : entity.getClass().getDeclaredFields()) { if (null != idProperty && field.getName().equals(idProperty.getName())) { continue; } final PersistentProperty property = entityInformation.getPersistentProperty(field.getName()); Assert.notNull(property, "Property is null."); targetDocument.set(field.getName(), mapToDocumentDBValue(accessor.getProperty(property))); } }
@Override public Status insert(String table, String key, Map<String, ByteIterator> values) { Document record = new Document(); record.set("id", key); for (Entry<String, ByteIterator> val : values.entrySet()) { record.set(val.getKey(), val.getValue().toString()); } try { documentClient.createDocument(collection.getSelfLink(), record, null, false); } catch (DocumentClientException e) { e.printStackTrace(System.err); return Status.ERROR; } return Status.OK; }
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { Document record = getDocumentById(table, key); if (record == null) { return Status.ERROR; } // Update each field. for (Entry<String, ByteIterator> val : values.entrySet()) { record.set(val.getKey(), val.getValue().toString()); } // Replace the document. try { documentClient.replaceDocument(record, null); } catch (DocumentClientException e) { e.printStackTrace(System.err); return Status.ERROR; } return Status.OK; }