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


Java FindIterable.first方法代码示例

本文整理汇总了Java中com.mongodb.client.FindIterable.first方法的典型用法代码示例。如果您正苦于以下问题:Java FindIterable.first方法的具体用法?Java FindIterable.first怎么用?Java FindIterable.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.client.FindIterable的用法示例。


在下文中一共展示了FindIterable.first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addUserComment

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public String addUserComment() {
    MongoCollection collection = null;
    Document query = null;
    try {
        // add a comment from user Melanie
        String who = "Melanie";
        Document comment = new Document("_id", who)
                .append("name", who)
                .append("address", new BasicDBObject("street", "123 Main Street")
                        .append("city", "Fastville")
                        .append("state", "MA")
                        .append("zip", 18180))
                .append("comment", "MongoDB Is Web Scale");
        // save the comment
        collection = database.getCollection("comments");
        collection.insertOne(comment);

        // look up the comment from Melanie
        query = new Document("_id", who);
        FindIterable cursor = collection.find(query);
        Object userComment = cursor.first();
        return userComment.toString();
    } finally {
        collection.drop();
    }
}
 
开发者ID:wildfly,项目名称:wildfly-nosql,代码行数:27,代码来源:StatefulTestBean.java

示例2: load

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * load the data by the query.
 *
 * @param <T>
 *            the subclass of Bean
 * @param collection
 *            the collection name
 * @param query
 *            the query
 * @param b
 *            the Bean
 * @return the Bean
 */
public <T extends Bean> T load(String collection, Bson query, T b) {
	try {
		MongoCollection<Document> db = getCollection(collection);
		if (db != null) {
			FindIterable<Document> d = db.find(query);
			if (d != null) {
				Document d1 = d.first();
				if (d1 != null) {
					b.load(d1, null);
					return b;
				}
			}
		}
	} catch (Exception e) {
		if (log.isErrorEnabled())
			log.error(e.getMessage(), e);
	}

	return null;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:34,代码来源:MongoHelper.java

示例3: addSalesComment

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public String addSalesComment() {
    MongoCollection collection = null;
    Document query = null;
    try {
        // add a comment from Sales department
        String who = "InsideSalesTeam";
        Document comment = new Document("_id", who)
                .append("name", who)
                .append("address", new BasicDBObject("street", "inside sales")
                        .append("city", "internal")
                        .append("state", "internal")
                        .append("zip", 99999))
                .append("comment", "Need to sell sell sell");
        // save the comment
        collection = database.getCollection("comments");
        collection.insertOne(comment);

        query = new Document("_id", who);
        FindIterable cursor = collection.find(query);
        Object userComment = cursor.first();
        return userComment.toString();
    } finally {
        collection.drop();
    }
}
 
开发者ID:wildfly,项目名称:wildfly-nosql,代码行数:26,代码来源:StatefulTestBean.java

示例4: addProduct

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public String addProduct() {
    MongoCollection collection = null;
    Document query = null;
    try {
        collection = injectedDatabase.getCollection("company");
        String companyName = "Acme products";
        JsonObject object = Json.createObjectBuilder()
                .add("companyName", companyName)
                .add("street", "999 Flow Lane")
                .add("city", "Indiville")
                .add("_id", companyName)
                .build();
        Document document = Document.parse(object.toString());
        collection.insertOne(document);
        query = new Document("_id", companyName);
        FindIterable cursor = collection.find(query);
        Object dbObject = cursor.first();
        return dbObject.toString();
    } finally {
        if (query != null) {
            collection.drop();
        }
    }
}
 
开发者ID:wildfly,项目名称:wildfly-nosql,代码行数:25,代码来源:StatefulTestBean.java

示例5: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public <T> T find(Class<T> typeClass, Object primary) {
    T t = null;
    MongoCollection<Document> collection = database.getCollection(typeClass.getSimpleName());
    BasicDBObject query = new BasicDBObject(MongoModel.OID, primary);
    FindIterable<Document> documents = collection.find(query);
    Document document = documents.first();
    try {
        t = typeClass.newInstance();
        if (MongoModel.class.isAssignableFrom(typeClass)) {
            MongoModel mongoModel = (MongoModel) t;
            mongoModel.fromDocument(document);
        } else {
            Log.error("class is not an instance of MongoModel, will not be able to set document to T object, class: " + typeClass);
        }
    } catch (InstantiationException | IllegalAccessException e) {
        Log.error("could not create mongo model of class: " + typeClass + " got exception: " + e, e);
    }
    return t;
}
 
开发者ID:canmogol,项目名称:FatJar,代码行数:21,代码来源:MongoDB.java

示例6: getLockForName

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public LockHandle getLockForName(String lockName) {
    // a lock is the document with the smallest id number whose lease hasn't
    // expired.
    FindIterable<Document> results = getLockCollection(lockName).find(new Document("lease", new Document("$gt", System.currentTimeMillis())))
            .sort(new Document("_id", 1)).limit(1);

    Document lock = results.first();
    if (lock != null) {
        LockHandle lockHandle = new LockHandle();
        lockHandle.setLockName((String) lock.get("lockName"));
        lockHandle.setHandle((String) lock.get("_id"));
        lockHandle.setLockHolder((String) lock.get("lockHolder"));
        return lockHandle;
    } else {
        return null;
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:18,代码来源:MongoLockHandler2.java

示例7: addProduct

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public String addProduct() {
    MongoCollection collection = null;
    Document query = null;
    try {
        collection = database.getCollection("company");
        String companyName = "Acme products";
        JsonObject object = Json.createObjectBuilder()
                .add("companyName", companyName)
                .add("street", "999 Flow Lane")
                .add("city", "Indiville")
                .add("_id", companyName)
                .build();
        Document document = Document.parse(object.toString());
        collection.insertOne(document);
        query = new Document("_id", companyName);
        FindIterable cursor = collection.find(query);
        Object dbObject = cursor.first();
        return dbObject.toString();
    } finally {
        if (query != null) {
            collection.drop();
        }
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:25,代码来源:StatefulTestBean.java

示例8: getArtifactMD5

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public String getArtifactMD5(DBKey dbKey, String objectID) {
  final String dbName = MongoDBClient.getDbName(dbKey.getCompany(), dbKey.getProject());

  FindIterable findIterable =
      client.getDatabase(dbName)
          .getCollection(ARTIFACTS_COLLECTION_NAME + FILES_COLLECTION_SUFFIX)
          .find(new Document(ID_FIELD_NAME, new ObjectId(objectID)));
  Document fileMetadata = (Document) findIterable.first();

  if (fileMetadata == null) {
    LOGGER.error("Unable to find file artifact with ObjectID: {}", objectID);
  }

  return fileMetadata != null ? fileMetadata.get(MD5_FIELD_NAME).toString() : null;
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:17,代码来源:ArtifactsDAOMongoDBImpl.java

示例9: getArtifactUploadDate

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public Date getArtifactUploadDate(DBKey dbKey, String objectID) {
  final String dbName = MongoDBClient.getDbName(dbKey.getCompany(), dbKey.getProject());

  FindIterable findIterable =
      client.getDatabase(dbName)
          .getCollection(ARTIFACTS_COLLECTION_NAME + FILES_COLLECTION_SUFFIX)
          .find(new Document(ID_FIELD_NAME, new ObjectId(objectID)));
  Document fileMetadata = (Document) findIterable.first();

  if (fileMetadata == null) {
    LOGGER.error("Unable to find file artifact with ObjectID: {}", objectID);
  }

  return fileMetadata != null ? (Date) fileMetadata.get(UPLOAD_DATE_FIELD_NAME) : null;
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:17,代码来源:ArtifactsDAOMongoDBImpl.java

示例10: loadResourceSecurity

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private ArrayList loadResourceSecurity() {
	MongoDBHelper ds = new MongoDBHelper();
	MongoDatabase db = ds.getConnection();
	
	try {
		MongoCollection<Document> c = db.getCollection(org.opengrid.constants.DB.META_COLLECTION_NAME);

		//we only have one doc in our meta collection
		FindIterable<Document> docs = c.find();
		Document doc = docs.first();
		ArrayList a = (ArrayList) doc.get("resourceSecurity");
		if (a == null) {
			throw ExceptionUtil.getException(Exceptions.ERR_SERVICE, "Cannot find resourceSecurity map.");
		}
		return a;			
	} finally {
		if (ds !=null) {
			ds.closeConnection();
		}
	}
}
 
开发者ID:smartchicago,项目名称:opengrid-svc-plenario,代码行数:22,代码来源:JwtRoleAccessValidator.java

示例11: getDescriptor

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public String getDescriptor() throws ServiceException {
	MongoDBHelper ds = new MongoDBHelper();
	MongoDatabase db = ds.getConnection();
			
	MongoCollection<Document> c = db.getCollection(org.opengrid.constants.DB.META_COLLECTION_NAME);

	//we only have one doc in our meta collection
	FindIterable<Document> docs = c.find();
	Document doc = docs.first();
	ArrayList a = (ArrayList) doc.get("datasets");
	
	//loop through the dataset descriptors
	for (Object o: a) {
		if ( ((Document) o).get("id").toString().equalsIgnoreCase(this.getId()) ) {
			
			//this is our descriptor, return
			return ((Document)o).toJson();
		}
	}
	//wrap and bubble up
	throw ExceptionUtil.getException(Exceptions.ERR_SERVICE, "Cannot find dataset descriptor from meta store for dataset '" + this.getId() + "'.");
}
 
开发者ID:smartchicago,项目名称:opengrid-svc-plenario,代码行数:24,代码来源:TwitterMongoDataProvider.java

示例12: get

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@GET
@Produces({"text/plain"})
public String get() {

    MongoCollection collection = null;
    Document query = null;
    try {
        collection = database.getCollection("company");
        String companyName = "Acme products";
        JsonObject object = Json.createObjectBuilder()
                .add("companyName", companyName)
                .add("street", "999 Flow Lane")
                .add("city", "Indiville")
                .add("_id", companyName)
                .build();
        Document document = Document.parse(object.toString());
        collection.insertOne(document);
        query = new Document("_id", companyName);
        FindIterable cursor = collection.find(query);
        Object dbObject = cursor.first();
        return dbObject.toString();
    } finally {
        if (query != null) {
            collection.drop();
        }
    }
}
 
开发者ID:wildfly,项目名称:wildfly-nosql,代码行数:28,代码来源:ClientResource.java

示例13: getUserInDatabase

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private JSONObject getUserInDatabase(JSONObject userData){
    JSONObject returnValue = null;

    BasicDBObject dbObject = (BasicDBObject) JSON.parse(userData.toString());

    FindIterable<Document> request = db.getCollection("userTable").find(dbObject);

    Document result = request.first();
    if(result != null)
        returnValue = new JSONObject(result.toJson());
    return returnValue;
}
 
开发者ID:kahre,项目名称:Cotton,代码行数:13,代码来源:MongoDBConnector.java

示例14: addUserComment

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public String addUserComment() {
    MongoCollection collection = null;
    Document query = null;
    try {
        // add a comment from user Melanie
        String who = "Melanie";
        Document comment = new Document("_id", who)
                .append("name", who)
                .append("address", new BasicDBObject("street", "123 Main Street")
                        .append("city", "Fastville")
                        .append("state", "MA")
                        .append("zip", 18180))
                .append("comment", "I really love your new website but I have a lot of questions about using NoSQL versus a traditional RDBMS.  " +
                        "I would like to sign up for your 'MongoDB Is Web Scale' training session.");
        // save the comment
        collection = database.getCollection("comments");
        collection.insertOne(comment);

        // look up the comment from Melanie
        query = new Document("_id", who);
        FindIterable cursor = collection.find(query);
        Object userComment = cursor.first();
        return userComment.toString();
    } finally {
        collection.drop();
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:28,代码来源:StatefulTestBean.java

示例15: getSuite

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public Suite getSuite(DBKey dbKey, String correlationId) throws StorageException {
  MongoCollection<Document> metadata = getMetadataCollection(dbKey);

  LOGGER.debug("Fetching suite with correlationId: {} ", correlationId);

  final FindIterable<Document> found = metadata
      .find(Filters.eq(CORRELATION_ID_PARAM_NAME, correlationId))
      .sort(Sorts.descending(SUITE_VERSION_PARAM_NAME))
      .limit(1);
  final Document result = found.first();
  return new DocumentConverter(result).toSuite();
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:14,代码来源:MetadataDAOMongoDBImpl.java


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