當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。