本文整理汇总了Java中com.mongodb.BasicDBObjectBuilder类的典型用法代码示例。如果您正苦于以下问题:Java BasicDBObjectBuilder类的具体用法?Java BasicDBObjectBuilder怎么用?Java BasicDBObjectBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicDBObjectBuilder类属于com.mongodb包,在下文中一共展示了BasicDBObjectBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUsers
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
@ChangeSet(order = "01",
author = "developer",
id = "01-addUsers")
public void addUsers(final DB db) {
final DBCollection userCollection = db.getCollection(User.COLLECTION_NAME);
userCollection.insert(BasicDBObjectBuilder
.start()
.add(FIELD_NAME_ID, new ObjectId("590f86d92449343841cc2c3f"))
.add(User.FIELD_NAME_FIRST_NAME, "User")
.add(User.FIELD_NAME_LAST_NAME, "One")
.add(User.FIELD_NAME_EMAIL, "[email protected]")
.get());
userCollection.insert(BasicDBObjectBuilder
.start()
.add(FIELD_NAME_ID, new ObjectId("590f86d92449343841cc2c40"))
.add(User.FIELD_NAME_FIRST_NAME, "User")
.add(User.FIELD_NAME_LAST_NAME, "Two")
.add(User.FIELD_NAME_EMAIL, "[email protected]")
.get());
}
示例2: deleteUserSucceeds
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
@Test
@DirtiesContext // because we can't authenticate twice on same DB
public void deleteUserSucceeds() throws MongoServiceException {
service.createDatabase(DB_NAME);
DBObject createUserCmd = BasicDBObjectBuilder.start("createUser", "user").add("pwd", "password")
.add("roles", new BasicDBList()).get();
CommandResult result = client.getDB(DB_NAME).command(createUserCmd);
assertTrue("create should succeed", result.ok());
service.deleteUser(DB_NAME, "user");
assertFalse(client.getDB(DB_NAME).authenticate("user", "password".toCharArray()));
}
示例3: addSocialUserConnection
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
@ChangeSet(order = "03", author = "initiator", id = "03-addSocialUserConnection")
public void addSocialUserConnection(DB db) {
DBCollection socialUserConnectionCollection = db.getCollection("jhi_social_user_connection");
socialUserConnectionCollection.createIndex(BasicDBObjectBuilder
.start("user_id", 1)
.add("provider_id", 1)
.add("provider_user_id", 1)
.get(),
"user-prov-provusr-idx", true);
}
示例4: createBetweenFilter
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
private DBObject createBetweenFilter(Object value) {
JSONObject dateRange = parseDateRange(value);
org.joda.time.format.DateTimeFormatter parser = ISODateTimeFormat.dateTime();
BasicDBObjectBuilder start = BasicDBObjectBuilder.start();
if (dateRange.get("startDate") != null) {
DateTime startDate = parser.parseDateTime((String) dateRange.get("startDate"));
start.add(QueryOperators.GTE, startDate.toDate());
}
if (dateRange.get("endDate") != null) {
DateTime endDate = parser.parseDateTime((String) dateRange.get("endDate"));
start.add(QueryOperators.LTE, endDate.toDate());
}
return start.get();
}
示例5: toDBObject
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
/**
* Serializes {@link RyaDetails} to mongo {@link DBObject}.
* @param details - The details to be serialized.
* @return The mongo {@link DBObject}.
*/
public static BasicDBObject toDBObject(final RyaDetails details) {
Preconditions.checkNotNull(details);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start()
.add(INSTANCE_KEY, details.getRyaInstanceName())
.add(VERSION_KEY, details.getRyaVersion())
.add(ENTITY_DETAILS_KEY, details.getEntityCentricIndexDetails().isEnabled())
//RYA-215 .add(GEO_DETAILS_KEY, details.getGeoIndexDetails().isEnabled())
.add(PCJ_DETAILS_KEY, toDBObject(details.getPCJIndexDetails()))
.add(TEMPORAL_DETAILS_KEY, details.getTemporalIndexDetails().isEnabled())
.add(FREETEXT_DETAILS_KEY, details.getFreeTextIndexDetails().isEnabled());
if(details.getProspectorDetails().getLastUpdated().isPresent()) {
builder.add(PROSPECTOR_DETAILS_KEY, details.getProspectorDetails().getLastUpdated().get());
}
if(details.getJoinSelectivityDetails().getLastUpdated().isPresent()) {
builder.add(JOIN_SELECTIVITY_DETAILS_KEY, details.getJoinSelectivityDetails().getLastUpdated().get());
}
return (BasicDBObject) builder.get();
}
示例6: toDBObject
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
/**
* Serializes a {@link DocumentVisibility} to a MongoDB {@link DBObject}.
* @param documentVisibility the {@link DocumentVisibility} to be
* serialized.
* @return The MongoDB {@link DBObject}.
*/
public static BasicDBObject toDBObject(final DocumentVisibility documentVisibility) {
DocumentVisibility dv;
if (documentVisibility == null) {
dv = MongoDbRdfConstants.EMPTY_DV;
} else {
dv = documentVisibility;
}
Object[] dvArray = null;
try {
dvArray = DocumentVisibilityUtil.toMultidimensionalArray(dv);
} catch (final DocumentVisibilityConversionException e) {
log.error("Unable to convert document visibility");
}
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
builder.add(DOCUMENT_VISIBILITY_KEY, dvArray);
return (BasicDBObject) builder.get();
}
示例7: serialize
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
@Override
public DBObject serialize(final RyaStatement ryaStatement) {
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("_id", ryaStatement.getSubject().hashCode());
final URI obj = ryaStatement.getObject().getDataType();
if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) ||
obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) {
try {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser());
if (geo.getNumPoints() > 1) {
builder.add(GEO_KEY, geoStrategy.getCorrespondingPoints(geo));
} else {
builder.add(GEO_KEY, geoStrategy.getDBPoint(geo));
}
} catch (final ParseException e) {
LOG.error("Could not create geometry for statement " + ryaStatement, e);
return null;
}
} else {
builder.add(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData()));
}
return builder.get();
}
示例8: deserializeTest
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
@Test
public void deserializeTest() {
final DBObject dbo = BasicDBObjectBuilder.start()
.add(RYANAME_KEY, TEST_INSTANCE)
.add(TIMESTAMP_KEY, TEST_TIMESTAMP)
.add(FILTER_TIMESTAMP_KEY, TEST_FILTER_TIMESTAMP)
.add(PARENT_TIME_OFFSET_KEY, TEST_TIME_OFFSET)
.get();
final MergeParentMetadata expected = new MergeParentMetadata.Builder()
.setRyaInstanceName(TEST_INSTANCE)
.setTimestamp(TEST_TIMESTAMP)
.setFilterTimestmap(TEST_FILTER_TIMESTAMP)
.setParentTimeOffset(TEST_TIME_OFFSET)
.build();
final MergeParentMetadata actual = adapter.deserialize(dbo);
assertEquals(expected, actual);
}
示例9: serializeTest
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
@Test
public void serializeTest() {
final MergeParentMetadata merge = new MergeParentMetadata.Builder()
.setRyaInstanceName(TEST_INSTANCE)
.setTimestamp(TEST_TIMESTAMP)
.setFilterTimestmap(TEST_FILTER_TIMESTAMP)
.setParentTimeOffset(TEST_TIME_OFFSET)
.build();
final DBObject expected = BasicDBObjectBuilder.start()
.add(RYANAME_KEY, TEST_INSTANCE)
.add(TIMESTAMP_KEY, TEST_TIMESTAMP)
.add(FILTER_TIMESTAMP_KEY, TEST_FILTER_TIMESTAMP)
.add(PARENT_TIME_OFFSET_KEY, TEST_TIME_OFFSET)
.get();
final DBObject actual = adapter.serialize(merge);
assertEquals(expected, actual);
}
示例10: initialize
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void initialize() {
// Make sure the fields we want to query are indexed
DBCollection assets = db.getCollection(ASSETS_COLLECTION);
DBCollection attachments = db.getCollection(ATTACHMENTS_COLLECTION);
// Add text index
BasicDBObjectBuilder textIndex = BasicDBObjectBuilder.start();
for (String indexField : searchIndexFields) {
textIndex.add(indexField, "text");
}
assets.ensureIndex(textIndex.get());
// Add Attachment(assetId) index
attachments.ensureIndex(new BasicDBObject("assetId", 1));
}
示例11: mapReduce
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
public ObjectListPresentation mapReduce(String map, String reduce, Bindings options) {
BasicDBObjectBuilder command = new BasicDBObjectBuilder();
command.add("mapReduce", name);
command.add("map", map);
command.add("reduce", reduce);
putObject("query", options, command);
putObject("out", options, command);
putObject("scope", options, command);
putSimpleField("field", options, command);
putSimpleField("jsMode", options, command);
putSimpleField("finilize", options, command);
putSimpleField("verbose", options, command);
return singletonIter(mongoDatabase.getMongoDb().runCommand((Bson)command.get()));
}
示例12: getUserNames
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
public java.util.List<String> getUserNames() throws Exception {
List<String> result = new LinkedList<String>();
DBCollection users = getDB().getCollection(
configuration.getUserCollectionName());
DBObject userProjection = new BasicDBObjectBuilder().add("_id", 0)
.add("username", 1).get();
DBCursor uc = users.find(null, userProjection);
while (uc.hasNext()) {
DBObject group = uc.next();
result.add((String) group.get("username"));
}
uc.close();
return result;
}
示例13: GridFS
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
/**
* Creates a GridFS instance for the specified bucket
* in the given database. Set the preferred WriteConcern on the give DB with DB.setWriteConcern
*
* @see com.mongodb.WriteConcern
* @param db database to work with
* @param bucket bucket to use in the given database
* @throws MongoException
*/
public GridFS(DB db, String bucket) {
_db = db;
_bucketName = bucket;
_filesCollection = _db.getCollection( _bucketName + ".files" );
_chunkCollection = _db.getCollection( _bucketName + ".chunks" );
// ensure standard indexes as long as collections are small
try {
if (_filesCollection.count() < 1000) {
_filesCollection.ensureIndex( BasicDBObjectBuilder.start().add( "filename" , 1 ).add( "uploadDate" , 1 ).get() );
}
if (_chunkCollection.count() < 1000) {
_chunkCollection.ensureIndex( BasicDBObjectBuilder.start().add( "files_id" , 1 ).add( "n" , 1 ).get() ,
BasicDBObjectBuilder.start().add( "unique" , true ).get() );
}
} catch (MongoException e) {
LOGGER.info(String.format("Unable to ensure indices on GridFS collections in database %s", db.getName()));
}
_filesCollection.setObjectClass( GridFSDBFile.class );
}
示例14: validateLogin
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
public DBObject validateLogin(String username, String password) {
DBObject user = null;
// XXX look in the user collection for a user that has this username
// assign the result to the user variable.
user = usersCollection.findOne(new BasicDBObjectBuilder().add("_id", username).get());
if (user == null) {
System.out.println("User not in database");
return null;
}
String hashedAndSalted = user.get("password").toString();
String salt = hashedAndSalted.split(",")[1];
if (!hashedAndSalted.equals(makePasswordHash(password, salt))) {
System.out.println("Submitted password is not a match");
return null;
}
return user;
}
示例15: reduce
import com.mongodb.BasicDBObjectBuilder; //导入依赖的package包/类
@Override
public void reduce(final IntWritable key, final Iterable<DoubleWritable> values, final Context context)
throws IOException, InterruptedException {
DescriptiveStatistics stats = new DescriptiveStatistics();
for(DoubleWritable rating : values) {
stats.addValue(rating.get());
}
DBObject builder = new BasicDBObjectBuilder().start()
.add("movieid", key.get())
.add("mean", stats.getMean())
.add("median", stats.getPercentile(50))
.add("std", stats.getStandardDeviation())
.add("count", stats.getN())
.add("total", stats.getSum())
.get();
BSONWritable doc = new BSONWritable(builder);
context.write(NullWritable.get(), doc);
}