本文整理汇总了Java中org.bson.BsonObjectId类的典型用法代码示例。如果您正苦于以下问题:Java BsonObjectId类的具体用法?Java BsonObjectId怎么用?Java BsonObjectId使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BsonObjectId类属于org.bson包,在下文中一共展示了BsonObjectId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBsonDocument
import org.bson.BsonObjectId; //导入依赖的package包/类
public static BsonDocument getBsonDocument() {
BsonDocument bsonObj = new BsonDocument().append("testDouble", new BsonDouble(20.777));
List<BsonDocument> list = new ArrayList<BsonDocument>();
list.add(bsonObj);
list.add(bsonObj);
byte[] bytes = new byte[3];
bytes[0] = 3;
bytes[1] = 2;
bytes[2] = 1;
BsonDocument bsonDocument = new BsonDocument().append("testDouble", new BsonDouble(20.99))
.append("testString", new BsonString("testStringV"))
.append("testArray", new BsonArray(list));
return new BsonDocument().append("testDouble", new BsonDouble(20.99))
.append("testString", new BsonString("testStringV"))
.append("testArray", new BsonArray(list))
.append("bson_test", bsonDocument)
.append("testBinary", new BsonBinary(bytes))
.append("testBsonUndefined", new BsonUndefined())
.append("testObjectId", new BsonObjectId())
.append("testStringObjectId", new BsonObjectId())
.append("testBoolean", new BsonBoolean(true))
.append("testDate", new BsonDateTime(time))
.append("testNull", new BsonNull())
.append("testInt", new BsonInt32(233))
.append("testLong", new BsonInt64(233332));
}
示例2: fromGridRef
import org.bson.BsonObjectId; //导入依赖的package包/类
private BsonValue fromGridRef(SmofGridRef fileRef, PrimaryField fieldOpts) {
if(fileRef.isEmpty()) {
return new BsonNull();
}
if(fileRef.getId() == null) {
final SmofObject annotation = fieldOpts.getSmofAnnotationAs(SmofObject.class);
if(fileRef.getBucketName() == null) {
fileRef.setBucketName(annotation.bucketName());
}
//TODO test if upload file adds id to fileRef
if(!annotation.preInsert() && !fieldOpts.isForcePreInsert()) {
return new BsonLazyObjectId(fieldOpts.getName(), fileRef);
}
fieldOpts.setForcePreInsert(false);
dispatcher.insert(fileRef);
}
final BsonDocument bsonRef = new BsonDocument("id", new BsonObjectId(fileRef.getId()))
.append("bucket", new BsonString(fileRef.getBucketName()));
return bsonRef;
}
示例3: capture
import org.bson.BsonObjectId; //导入依赖的package包/类
public void capture(BsonObjectId dataID, Long eventTime, Set<String> epcList, BsonArray epcQuantities,
String readPoint, String bizLocation, BsonArray sourceList, BsonArray destinationList) {
ChronoGraph pg = Configuration.persistentGraph;
if (epcList != null && !epcList.isEmpty()) {
epcList.stream().forEach(object -> {
MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, object, readPoint, bizLocation, sourceList,
destinationList);
pg.addTimestampVertexProperty(object, eventTime, "data", dataID);
});
}
if (epcQuantities != null && !epcQuantities.isEmpty()) {
epcQuantities.stream().forEach(classElem -> {
MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, classElem, readPoint, bizLocation,
sourceList, destinationList);
pg.addTimestampVertexProperty(classElem.asDocument().getString("epcClass").getValue(), eventTime,
"data", dataID);
});
}
return;
}
示例4: capture
import org.bson.BsonObjectId; //导入依赖的package包/类
public void capture(BsonObjectId dataID, Long eventTime, Set<String> epcList, BsonArray epcQuantities,
String readPoint, String bizLocation, BsonArray sourceList, BsonArray destinationList) {
ChronoGraph pg = Configuration.persistentGraph;
if (epcList != null && !epcList.isEmpty()) {
epcList.stream().forEach(object -> {
MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, object, readPoint, bizLocation, sourceList,
destinationList);
pg.addTimestampVertexProperty(object, eventTime, "data", dataID);
});
}
if (epcQuantities != null && !epcQuantities.isEmpty()) {
epcQuantities.stream().forEach(classElem -> {
MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, classElem, readPoint, bizLocation,
sourceList, destinationList);
pg.addTimestampVertexProperty(classElem.asDocument().getString("epcClass").getValue(), eventTime,
"data", dataID);
});
}
}
示例5: _transform
import org.bson.BsonObjectId; //导入依赖的package包/类
private void _transform(BsonDocument data, Set<String> propertiesNames) {
data.keySet().stream().forEach(key -> {
BsonValue value = data.get(key);
if (shouldTransform(key, propertiesNames)) {
if (value.isString()
&& ObjectId.isValid(value
.asString()
.getValue())) {
data.put(key,
new BsonObjectId(
new ObjectId(value
.asString()
.getValue())));
}
}
if (value instanceof BsonDocument) {
_transform(value.asDocument(), propertiesNames);
}
});
}
示例6: getDocumentId
import org.bson.BsonObjectId; //导入依赖的package包/类
@Override
public BsonValue getDocumentId( T document )
{
Object value = _getId( document );
if ( value != null )
{
if ( ObjectId.class.isInstance( value ) )
{
return new BsonObjectId( (ObjectId) value );
}
else if ( String.class.isInstance( value ) )
{
return new BsonString( (String) value );
}
}
return null;
}
示例7: getObjectId
import org.bson.BsonObjectId; //导入依赖的package包/类
@Override
public ObjectId getObjectId(Object key) {
BsonObjectId objectId = innerBsonDocument.getObjectId(key);
if (objectId != null) {
return (ObjectId) BsonValueConverterRepertory.getValueConverterByBsonType(objectId.getBsonType()).decode(objectId);
} else {
return null;
}
}
示例8: toBson
import org.bson.BsonObjectId; //导入依赖的package包/类
@Override
public BsonValue toBson(Object value, SmofField fieldOpts) {
if(contextContains(value, fieldOpts, serializationContext)) {
return serializationContext.get(value, fieldOpts.getType());
}
final Class<?> type = value.getClass();
final BsonDocument serValue;
if(value instanceof ObjectId) {
return new BsonObjectId((ObjectId) value);
}
else if(isMaster(fieldOpts)) {
return fromMasterField((Element) value, fieldOpts, serializationContext);
}
else if(isSmofGridRef(type)) {
return fromGridRef((SmofGridRef) value, (PrimaryField) fieldOpts);
}
else if(isElement(type)) {
if(fieldOpts instanceof PrimaryField) {
return fromElement((Element) value, (PrimaryField) fieldOpts, serializationContext);
}
return fromElement((Element) value, serializationContext);
}
else if(isMap(type) && isPrimaryField(fieldOpts)) {
return fromMap((Map<?, ?>) value, (PrimaryField) fieldOpts, serializationContext);
}
else if(isEnum(type)) {
return fromEnum((Enum<?>) value, serializationContext);
}
serValue = fromObject(value);
serializationContext.put(value, SmofType.OBJECT, serValue);
return serValue;
}
示例9: fromElement
import org.bson.BsonObjectId; //导入依赖的package包/类
private BsonValue fromElement(Element value, SerializationContext serContext) {
final SmofOpOptions options = new SmofOpOptionsImpl();
options.bypassCache(true);
dispatcher.insert(value, options);
final BsonObjectId id = BsonUtils.toBsonObjectId(value);
serContext.put(value, SmofType.OBJECT, id);
return id;
}
示例10: testObjectIdType
import org.bson.BsonObjectId; //导入依赖的package包/类
@Test
public void testObjectIdType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonObjectId value = new BsonObjectId(new ObjectId());
bsonDoc.append("_idKey", value);
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
assertTrue(Arrays.equals(value.getValue().toByteArray(), readByteArray));
}
示例11: getDocumentId
import org.bson.BsonObjectId; //导入依赖的package包/类
@Override
public BsonValue getDocumentId(T document) {
Object id = idHandler.get(document);
if (id instanceof ObjectId) return new BsonObjectId((ObjectId) id);
if (id instanceof String) new BsonString((String) id);
throw Exceptions.error("unsupported id type, id={}", id);
}
示例12: checkReadEtag
import org.bson.BsonObjectId; //导入依赖的package包/类
/**
*
* @param exchange
* @param etag
* @return
*/
public static boolean checkReadEtag(HttpServerExchange exchange, BsonObjectId etag) {
if (etag == null) {
return false;
}
HeaderValues vs = exchange.getRequestHeaders().get(Headers.IF_NONE_MATCH);
return vs == null || vs.getFirst() == null
? false
: vs.getFirst().equals(etag.getValue().toString());
}
示例13: getIdAsObjectId
import org.bson.BsonObjectId; //导入依赖的package包/类
private static BsonObjectId getIdAsObjectId(String id)
throws IllegalArgumentException {
if (!ObjectId.isValid(id)) {
throw new IllegalArgumentException("The id is not a valid ObjectId " + id);
}
return new BsonObjectId(new ObjectId(id));
}
示例14: bulkUpsertDocumentsPost
import org.bson.BsonObjectId; //导入依赖的package包/类
/**
* @param dbName
* @param collName
* @param documents
* @param shardKeys
* @return
*/
@Override
@SuppressWarnings("unchecked")
public BulkOperationResult bulkUpsertDocumentsPost(
final String dbName,
final String collName,
final BsonArray documents,
final BsonDocument filter,
final BsonDocument shardKeys) {
Objects.requireNonNull(documents);
MongoDatabase mdb = client.getDatabase(dbName);
MongoCollection<BsonDocument> mcoll
= mdb.getCollection(collName, BsonDocument.class);
BsonObjectId newEtag = new BsonObjectId(new ObjectId());
documents
.stream()
.filter(d -> d != null && d.isDocument())
.forEachOrdered(document -> {
document.
asDocument()
.put("_etag", newEtag);
});
return DAOUtils.bulkUpsertDocuments(
mcoll,
documents,
filter,
shardKeys);
}
示例15: checkEtag
import org.bson.BsonObjectId; //导入依赖的package包/类
private boolean checkEtag(HttpServerExchange exchange, GridFSFile dbsfile) {
if (dbsfile != null) {
Object etag;
if (dbsfile.getMetadata() != null
&& dbsfile.getMetadata().containsKey("_etag")) {
etag = dbsfile.getMetadata().get("_etag");
} else {
etag = null;
}
if (etag != null && etag instanceof ObjectId) {
ObjectId _etag = (ObjectId) etag;
BsonObjectId __etag = new BsonObjectId(_etag);
// in case the request contains the IF_NONE_MATCH header with the current etag value,
// just return 304 NOT_MODIFIED code
if (RequestHelper.checkReadEtag(exchange, __etag)) {
exchange.setStatusCode(HttpStatus.SC_NOT_MODIFIED);
exchange.endExchange();
return true;
}
}
}
return false;
}