当前位置: 首页>>代码示例>>Java>>正文


Java BasicDBObjectBuilder类代码示例

本文整理汇总了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());
}
 
开发者ID:karlkyck,项目名称:spring-boot-completablefuture,代码行数:23,代码来源:InitialSetupMigration.java

示例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()));
}
 
开发者ID:cf-platform-eng,项目名称:mongodb-broker,代码行数:12,代码来源:MongoAdminServiceIntegrationTest.java

示例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);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:11,代码来源:InitialSetupMigration.java

示例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();
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:20,代码来源:AbstractMongoDao.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:MongoDetailsAdapter.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:25,代码来源:DocumentVisibilityAdapter.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:26,代码来源:GeoTemporalMongoDBStorageStrategy.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:19,代码来源:ParentMetadataRepositoryAdapterTest.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:19,代码来源:ParentMetadataRepositoryAdapterTest.java

示例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));
}
 
开发者ID:WASdev,项目名称:tool.lars,代码行数:18,代码来源:PersistenceBean.java

示例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()));
}
 
开发者ID:daa84,项目名称:mongofx,代码行数:17,代码来源:Collection.java

示例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;
	}
 
开发者ID:bertramn,项目名称:karaf-jaas-mongo-module,代码行数:20,代码来源:DefaultUserDetailService.java

示例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 );
}
 
开发者ID:MaOrKsSi,项目名称:HZS.Durian,代码行数:31,代码来源:GridFS.java

示例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;
}
 
开发者ID:drei01,项目名称:M101J,代码行数:24,代码来源:UserDAO.java

示例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);
}
 
开发者ID:crcsmnky,项目名称:mongodb-hadoop-workshop,代码行数:22,代码来源:MapReduceExercise.java


注:本文中的com.mongodb.BasicDBObjectBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。