本文整理汇总了Java中org.bson.BsonString类的典型用法代码示例。如果您正苦于以下问题:Java BsonString类的具体用法?Java BsonString怎么用?Java BsonString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BsonString类属于org.bson包,在下文中一共展示了BsonString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCustomizedBsonConverter
import org.bson.BsonString; //导入依赖的package包/类
@Test
public void testCustomizedBsonConverter() throws Exception {
BsonValueConverterRepertory.registerCustomizedBsonConverter(String.class, new AbstractBsonConverter<String, BsonString>() {
@Override
public String decode(BsonReader bsonReader) {
return "replace string";
}
@Override
public void encode(BsonWriter bsonWriter, String value) {
}
@Override
public String decode(BsonValue bsonValue) {
return "replace string";
}
@Override
public BsonString encode(String object) {
return new BsonString("replace string");
}
});
readFrom();
}
示例2: getBsonDocument
import org.bson.BsonString; //导入依赖的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));
}
示例3: testBsonDocumentDeSerialize
import org.bson.BsonString; //导入依赖的package包/类
@Test
public void testBsonDocumentDeSerialize() {
BsonDocument document = new BsonDocument().append("a", new BsonString("MongoDB"))
.append("b", new BsonArray(Arrays.asList(new BsonInt32(1), new BsonInt32(2))))
.append("c", new BsonBoolean(true))
.append("d", new BsonDateTime(0));
String json = oson.useAttribute(false).setValueOnly(true).serialize(document);
String expected = "{\"a\":\"MongoDB\",\"b\":[1,2],\"c\":true,\"d\":0}";
assertEquals(expected, json);
BsonDocument document2 = oson.deserialize(json, BsonDocument.class);
assertEquals(expected, oson.serialize(document2));
}
示例4: fromGridRef
import org.bson.BsonString; //导入依赖的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;
}
示例5: get
import org.bson.BsonString; //导入依赖的package包/类
@Override
public Optional<Event> get(final RyaURI subject) throws EventStorageException {
requireNonNull(subject);
try {
final Document document = mongo.getDatabase(ryaInstanceName)
.getCollection(COLLECTION_NAME)
.find( new BsonDocument(EventDocumentConverter.SUBJECT, new BsonString(subject.getData())) )
.first();
return document == null ?
Optional.empty() :
Optional.of( EVENT_CONVERTER.fromDocument(document) );
} catch(final MongoException | DocumentConverterException e) {
throw new EventStorageException("Could not get the Event with Subject '" + subject.getData() + "'.", e);
}
}
示例6: setUp
import org.bson.BsonString; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Before
public void setUp() throws Exception {
interceptor = new MongoDBMethodInterceptor();
Config.Plugin.MongoDB.TRACE_PARAM = true;
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017");
BsonDocument document = new BsonDocument();
document.append("name", new BsonString("by"));
MongoNamespace mongoNamespace = new MongoNamespace("test.user");
Decoder decoder = PowerMockito.mock(Decoder.class);
FindOperation findOperation = new FindOperation(mongoNamespace, decoder);
findOperation.filter(document);
arguments = new Object[] {findOperation};
argumentTypes = new Class[] {findOperation.getClass()};
}
示例7: setTimestampProperties
import org.bson.BsonString; //导入依赖的package包/类
/**
* set timestamp properties (replace) for the given timestamp
*
* @param timestamp
* @param timestampProperties
*/
public void setTimestampProperties(final Long timestamp, BsonDocument timestampProperties) {
if (timestampProperties == null)
timestampProperties = new BsonDocument();
if (this instanceof ChronoVertex) {
graph.getVertexEvents().findOneAndReplace(
new BsonDocument(Tokens.VERTEX, new BsonString(this.id)).append(Tokens.TIMESTAMP,
new BsonDateTime(timestamp)),
Converter.makeTimestampVertexEventDocumentWithoutID(timestampProperties, this.id, timestamp),
new FindOneAndReplaceOptions().upsert(true));
} else {
ChronoEdge e = (ChronoEdge) this;
graph.getEdgeEvents().findOneAndReplace(
new BsonDocument(Tokens.OUT_VERTEX, new BsonString(e.getOutVertex().toString()))
.append(Tokens.LABEL, new BsonString(e.getLabel()))
.append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))
.append(Tokens.IN_VERTEX, new BsonString(e.getInVertex().toString())),
Converter.makeTimestampEdgeEventDocumentWithoutID(timestampProperties, this.id, timestamp),
new FindOneAndReplaceOptions().upsert(true));
}
}
示例8: testGetUriWithFilterManyIdsWithSpaces
import org.bson.BsonString; //导入依赖的package包/类
@Test
public void testGetUriWithFilterManyIdsWithSpaces() {
BsonValue[] ids = new BsonValue[]{
new BsonString("Three Imaginary Boys"),
new BsonString("Seventeen Seconds")
};
RequestContext context = prepareRequestContext();
String expResult = "/dbName/collName?filter={'_id':{'$in':[\'Three Imaginary Boys\','Seventeen Seconds\']}}";
String result;
try {
result = URLUtils.getUriWithFilterMany(context, "dbName", "collName", ids);
assertEquals(expResult, result);
} catch (UnsupportedDocumentIdException ex) {
fail(ex.getMessage());
}
}
示例9: convertToExtensionDocument
import org.bson.BsonString; //导入依赖的package包/类
private BsonDocument convertToExtensionDocument(Map<String, String> namespaces, BsonDocument extension) {
BsonDocument ext = new BsonDocument();
for (String key : extension.keySet()) {
String[] namespaceAndKey = key.split("#");
if (namespaceAndKey.length != 2)
continue;
String namespace = namespaceAndKey[0];
if (!namespaces.containsKey(namespace))
continue;
ext.put("@" + encodeMongoObjectKey(namespace), new BsonString(namespaces.get(namespace)));
BsonValue extValue = extension.get(key);
if (extValue instanceof BsonDocument) {
ext.put(encodeMongoObjectKey(key), convertToExtensionDocument(namespaces, extValue.asDocument()));
} else {
ext.put(encodeMongoObjectKey(key), extValue);
}
}
return ext;
}
示例10: addSpecialProperties
import org.bson.BsonString; //导入依赖的package包/类
public static void addSpecialProperties(final Representation rep, RequestContext.TYPE type, BsonDocument data) {
rep.addProperty("_type", new BsonString(type.name()));
Object etag = data.get("_etag");
if (etag != null && etag instanceof ObjectId) {
if (data.get("_lastupdated_on") == null) {
// add the _lastupdated_on in case the _etag field is present and its value is an ObjectId
rep.addProperty("_lastupdated_on",
new BsonString(Instant.ofEpochSecond(((ObjectId) etag).getTimestamp()).toString()));
}
}
Object id = data.get("_id");
// generate the _created_on timestamp from the _id if this is an instance of ObjectId
if (data.get("_created_on") == null && id != null && id instanceof ObjectId) {
rep.addProperty("_created_on",
new BsonString(Instant.ofEpochSecond(((ObjectId) id).getTimestamp()).toString()));
}
}
示例11: getSubscriptionIDs
import org.bson.BsonString; //导入依赖的package包/类
public List<String> getSubscriptionIDs(String queryName) {
List<String> retList = new ArrayList<String>();
MongoCollection<BsonDocument> collection = Configuration.mongoDatabase.getCollection("Subscription",
BsonDocument.class);
Iterator<BsonDocument> subIterator = collection
.find(new BsonDocument("pollParameters.queryName", new BsonString(queryName)), BsonDocument.class)
.iterator();
while (subIterator.hasNext()) {
BsonDocument subscription = subIterator.next();
retList.add(subscription.getString("subscriptionID").asString().getValue());
}
return retList;
}
示例12: putOutputQuantityList
import org.bson.BsonString; //导入依赖的package包/类
public BsonDocument putOutputQuantityList(BsonDocument base, List<QuantityElement> outputQuantityList) {
BsonArray quantityArray = new BsonArray();
for (QuantityElement quantityElement : outputQuantityList) {
BsonDocument bsonQuantityElement = new BsonDocument("epcClass",
new BsonString(quantityElement.getEpcClass()));
if (quantityElement.getQuantity() != null) {
bsonQuantityElement.put("quantity", new BsonDouble(quantityElement.getQuantity()));
}
if (quantityElement.getUom() != null) {
bsonQuantityElement.put("uom", new BsonString(quantityElement.getUom()));
}
quantityArray.add(bsonQuantityElement);
}
base.put("outputQuantityList", quantityArray);
return base;
}
示例13: getINFamilyQueryObject
import org.bson.BsonString; //导入依赖的package包/类
static BsonDocument getINFamilyQueryObject(String type, String field, String csv) {
String[] paramValueArr = csv.split(",");
BsonArray subObjectList = new BsonArray();
for (int i = 0; i < paramValueArr.length; i++) {
String val = paramValueArr[i].trim();
BsonDocument dbo = new BsonDocument();
dbo.put(type, new BsonString(val));
subObjectList.add(dbo);
}
if (subObjectList.isEmpty() == false) {
BsonDocument query = new BsonDocument();
query.put(field, new BsonDocument("$in", subObjectList));
return query;
}
return null;
}
示例14: unsubscribe
import org.bson.BsonString; //导入依赖的package包/类
public void unsubscribe(String subscriptionID) {
MongoCollection<BsonDocument> collection = Configuration.mongoDatabase.getCollection("Subscription",
BsonDocument.class);
// Its size should be 0 or 1
BsonDocument s = collection
.findOneAndDelete(new BsonDocument("subscriptionID", new BsonString(subscriptionID)));
if (s != null) {
SubscriptionType subscription = new SubscriptionType(s);
if (subscription.isScheduledSubscription() == true) {
// Remove from current Quartz
removeScheduleFromQuartz(subscription);
}else{
TriggerEngine.removeTriggerSubscription(subscription.getSubscriptionID());
}
}
}
示例15: getBsonGeoPoint
import org.bson.BsonString; //导入依赖的package包/类
public static BsonDocument getBsonGeoPoint(String pointString) {
try {
BsonDocument pointDoc = new BsonDocument();
pointDoc.put("type", new BsonString("Point"));
String[] pointArr = pointString.split(",");
if (pointArr.length != 2)
return null;
BsonArray arr = new BsonArray();
arr.add(new BsonDouble(Double.parseDouble(pointArr[0])));
arr.add(new BsonDouble(Double.parseDouble(pointArr[1])));
pointDoc.put("coordinates", arr);
return pointDoc;
} catch (NumberFormatException e) {
e.printStackTrace();
return null;
}
}