Example usage for com.mongodb.client MongoCollection find

List of usage examples for com.mongodb.client MongoCollection find

Introduction

In this page you can find the example usage for com.mongodb.client MongoCollection find.

Prototype

FindIterable<TDocument> find(ClientSession clientSession);

Source Link

Document

Finds all documents in the collection.

Usage

From source file:com.sitewhere.asset.persistence.mongodb.MongoAssetManagement.java

License:Open Source License

@Override
public IAsset getAssetByToken(String token) throws SiteWhereException {
    try {/*from  ww w  .  j  a va  2s .  c om*/
        MongoCollection<Document> assets = getMongoClient().getAssetsCollection();
        Document query = new Document(MongoAsset.PROP_TOKEN, token);
        Document dbAsset = assets.find(query).first();
        if (dbAsset != null) {
            return MongoAsset.fromDocument(dbAsset);
        }
        return null;
    } catch (MongoClientException e) {
        throw MongoPersistence.handleClientException(e);
    }
}

From source file:com.sitewhere.asset.persistence.mongodb.MongoAssetManagement.java

License:Open Source License

/**
 * Return the {@link Document} for the given asset type. Returns null if not
 * found./* www .jav a  2s  .  co m*/
 * 
 * @param assetTypeId
 * @return
 * @throws SiteWhereException
 */
protected Document getAssetTypeDocument(UUID assetTypeId) throws SiteWhereException {
    try {
        MongoCollection<Document> types = getMongoClient().getAssetTypesCollection();
        Document query = new Document(MongoAssetType.PROP_ID, assetTypeId);
        return types.find(query).first();
    } catch (MongoClientException e) {
        throw MongoPersistence.handleClientException(e);
    }
}

From source file:com.sitewhere.asset.persistence.mongodb.MongoAssetManagement.java

License:Open Source License

/**
 * Return the {@link Document} for the given asset. Returns null if not found.
 * // w  w w . j ava  2  s .  c o m
 * @param assetId
 * @return
 * @throws SiteWhereException
 */
protected Document getAssetDocument(UUID assetId) throws SiteWhereException {
    try {
        MongoCollection<Document> assets = getMongoClient().getAssetsCollection();
        Document query = new Document(MongoAsset.PROP_ID, assetId);
        return assets.find(query).first();
    } catch (MongoClientException e) {
        throw MongoPersistence.handleClientException(e);
    }
}

From source file:com.sitewhere.batch.persistence.mongodb.MongoBatchManagement.java

License:Open Source License

/**
 * Returns the {@link Document} for the batch operation with the given token.
 * Returns null if not found.// w  ww .j  a  v  a2s. co m
 * 
 * @param token
 * @return
 * @throws SiteWhereException
 */
protected Document getBatchOperationDocumentByToken(String token) throws SiteWhereException {
    try {
        MongoCollection<Document> ops = getMongoClient().getBatchOperationsCollection();
        Document query = new Document(MongoBatchOperation.PROP_TOKEN, token);
        return ops.find(query).first();
    } catch (MongoClientException e) {
        throw MongoPersistence.handleClientException(e);
    }
}

From source file:com.sitewhere.batch.persistence.mongodb.MongoBatchManagement.java

License:Open Source License

/**
 * Returns the {@link Document} for the batch operation with the given unique
 * id. Returns null if not found.//from   w  ww. jav  a2s.co m
 * 
 * @param token
 * @return
 * @throws SiteWhereException
 */
protected Document getBatchOperationDocument(UUID id) throws SiteWhereException {
    try {
        MongoCollection<Document> ops = getMongoClient().getBatchOperationsCollection();
        Document query = new Document(MongoBatchOperation.PROP_ID, id);
        return ops.find(query).first();
    } catch (MongoClientException e) {
        throw MongoPersistence.handleClientException(e);
    }
}

From source file:com.sitewhere.batch.persistence.mongodb.MongoBatchManagement.java

License:Open Source License

/**
 * Returns the {@link Document} for the batch operation element with the given
 * unique id. Returns null if not found.
 * //from   w  w w  .j  a  va 2 s  .co m
 * @param token
 * @return
 * @throws SiteWhereException
 */
protected Document getBatchOperationElementDocument(UUID id) throws SiteWhereException {
    try {
        MongoCollection<Document> elements = getMongoClient().getBatchOperationElementsCollection();
        Document query = new Document(MongoBatchElement.PROP_ID, id);
        return elements.find(query).first();
    } catch (MongoClientException e) {
        throw MongoPersistence.handleClientException(e);
    }
}

From source file:com.sitewhere.device.persistence.mongodb.MongoDeviceManagement.java

License:Open Source License

/**
 * Return the {@link Document} for the device type with the given token.
 * /*from w  w w. j a v  a2  s. com*/
 * @param token
 * @return
 * @throws SiteWhereException
 */
protected Document getDeviceTypeDocumentByToken(String token) throws SiteWhereException {
    MongoCollection<Document> types = getMongoClient().getDeviceTypesCollection();
    Document query = new Document(MongoDeviceType.PROP_TOKEN, token);
    return types.find(query).first();
}

From source file:com.sitewhere.device.persistence.mongodb.MongoDeviceManagement.java

License:Open Source License

/**
 * Return the {@link Document} for the device type with the given id.
 * /*ww w .  j av  a2 s .  c o m*/
 * @param id
 * @return
 * @throws SiteWhereException
 */
protected Document getDeviceTypeDocumentById(UUID id) throws SiteWhereException {
    MongoCollection<Document> types = getMongoClient().getDeviceTypesCollection();
    Document query = new Document(MongoDeviceType.PROP_ID, id);
    return types.find(query).first();
}

From source file:com.sitewhere.device.persistence.mongodb.MongoDeviceManagement.java

License:Open Source License

/**
 * Return the {@link Document} for the device command with the given token.
 * /*from w ww  .j  av a 2  s  . co  m*/
 * @param token
 * @return
 * @throws SiteWhereException
 */
protected Document getDeviceCommandDocumentByToken(String token) throws SiteWhereException {
    MongoCollection<Document> commands = getMongoClient().getDeviceCommandsCollection();
    Document query = new Document(MongoDeviceCommand.PROP_TOKEN, token);
    return commands.find(query).first();
}

From source file:com.sitewhere.device.persistence.mongodb.MongoDeviceManagement.java

License:Open Source License

/**
 * Return the {@link Document} for the device command with the given id.
 * //from w  w  w . ja v  a 2  s .  co  m
 * @param id
 * @return
 * @throws SiteWhereException
 */
protected Document getDeviceCommandDocumentById(UUID id) throws SiteWhereException {
    MongoCollection<Document> commands = getMongoClient().getDeviceCommandsCollection();
    Document query = new Document(MongoDeviceCommand.PROP_ID, id);
    return commands.find(query).first();
}