Example usage for com.mongodb QueryBuilder QueryBuilder

List of usage examples for com.mongodb QueryBuilder QueryBuilder

Introduction

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

Prototype

public QueryBuilder() 

Source Link

Document

Creates a builder with an empty query

Usage

From source file:org.keycloak.storage.mongo.MongoUserFederatedStorageProvider.java

License:Apache License

@Override
public void preRemove(RealmModel realm, ComponentModel model) {
    if (!model.getProviderType().equals(UserStorageProvider.class.getName()))
        return;//w w w .j av  a2  s.  c  om
    DBObject query = new QueryBuilder().and("storageId").is(model.getId()).get();
    getMongoStore().removeEntities(FederatedUser.class, query, true, invocationContext);

}

From source file:org.keycloak.storage.mongo.MongoUserFederatedStorageProvider.java

License:Apache License

@Override
public List<String> getUsersByUserAttribute(RealmModel realm, String name, String value) {
    QueryBuilder queryBuilder = new QueryBuilder().and("realmId").is(realm.getId());
    queryBuilder.and("attributes." + name).is(value);

    List<FederatedUser> users = getMongoStore().loadEntities(FederatedUser.class, queryBuilder.get(),
            invocationContext);/*from  w  w  w .  j  a  va 2 s  .  co m*/
    List<String> ids = new LinkedList<>();
    for (FederatedUser user : users)
        ids.add(user.getId());
    return ids;
}

From source file:org.keycloak.storage.mongo.MongoUserFederatedStorageProvider.java

License:Apache License

@Override
public String getUserByFederatedIdentity(FederatedIdentityModel socialLink, RealmModel realm) {
    DBObject query = new QueryBuilder().and("federatedIdentities.identityProvider")
            .is(socialLink.getIdentityProvider()).and("federatedIdentities.userId").is(socialLink.getUserId())
            .and("realmId").is(realm.getId()).get();
    FederatedUser userEntity = getMongoStore().loadSingleEntity(FederatedUser.class, query, invocationContext);
    return userEntity != null ? userEntity.getId() : null;
}

From source file:org.keycloak.storage.mongo.MongoUserFederatedStorageProvider.java

License:Apache License

@Override
public List<String> getMembership(RealmModel realm, GroupModel group, int firstResult, int max) {
    QueryBuilder queryBuilder = new QueryBuilder().and("realmId").is(realm.getId());
    queryBuilder.and("groupIds").is(group.getId());

    List<FederatedUser> users = getMongoStore().loadEntities(FederatedUser.class, queryBuilder.get(), null,
            firstResult, max, invocationContext);
    List<String> ids = new LinkedList<>();
    for (FederatedUser user : users)
        ids.add(user.getId());/*from   w ww  .j  av  a  2 s .  c  o m*/
    return ids;
}

From source file:org.keycloak.storage.mongo.MongoUserFederatedStorageProvider.java

License:Apache License

@Override
public int getStoredUsersCount(RealmModel realm) {
    DBObject query = new QueryBuilder().and("realmId").is(realm.getId()).get();
    return getMongoStore().countEntities(FederatedUser.class, query, invocationContext);
}

From source file:org.mongeez.dao.impl.MongeezDaoImpl.java

License:Apache License

private void addTypeToUntypedRecords() {
    DBObject q = new QueryBuilder().put("type").exists(false).get();
    BasicDBObject o = new BasicDBObject("$set",
            new BasicDBObject("type", RecordType.changeSetExecution.name()));
    getMongeezCollection().update(q, o, false, true);
}

From source file:org.mongeez.dao.impl.MongeezDaoImpl.java

License:Apache License

private void loadConfigurationRecord() {
    DBObject q = new QueryBuilder().put("type").is(RecordType.configuration.name()).get();
    DBObject configRecord = getMongeezCollection().findOne(q);
    if (configRecord == null) {
        if (getMongeezCollection().count() > 0L) {
            // We have pre-existing records, so don't assume that they support the latest features
            configRecord = new BasicDBObject().append("type", RecordType.configuration.name())
                    .append("supportResourcePath", false);
        } else {//from w  w w.j a  va  2 s . com
            configRecord = new BasicDBObject().append("type", RecordType.configuration.name())
                    .append("supportResourcePath", true);
        }
        getMongeezCollection().insert(configRecord);
    }
    Object supportResourcePath = configRecord.get("supportResourcePath");

    changeSetAttributes = new ArrayList<ChangeSetAttribute>();
    changeSetAttributes.add(ChangeSetAttribute.file);
    changeSetAttributes.add(ChangeSetAttribute.changeId);
    changeSetAttributes.add(ChangeSetAttribute.author);
    if (Boolean.TRUE.equals(supportResourcePath)) {
        changeSetAttributes.add(ChangeSetAttribute.resourcePath);
    }
}

From source file:org.mongeez.dao.MongeezDao.java

License:Apache License

private void addTypeToUntypedRecords() {
    DBObject q = new QueryBuilder().put("type").exists(false).get();
    BasicDBObject o = new BasicDBObject("$set",
            new BasicDBObject("type", RecordType.changeSetExecution.name()));
    getMongeezCollection().update(q, o, false, true, WriteConcern.SAFE);
}

From source file:org.mongeez.dao.MongeezDao.java

License:Apache License

private void loadConfigurationRecord() {
    DBObject q = new QueryBuilder().put("type").is(RecordType.configuration.name()).get();
    DBObject configRecord = getMongeezCollection().findOne(q);
    if (configRecord == null) {
        if (getMongeezCollection().count() > 0L) {
            // We have pre-existing records, so don't assume that they support the latest features
            configRecord = new BasicDBObject().append("type", RecordType.configuration.name())
                    .append("supportResourcePath", false);
        } else {//from  ww w.  ja v  a  2  s .  c o  m
            configRecord = new BasicDBObject().append("type", RecordType.configuration.name())
                    .append("supportResourcePath", true);
        }
        getMongeezCollection().insert(configRecord, WriteConcern.SAFE);
    }
    Object supportResourcePath = configRecord.get("supportResourcePath");

    changeSetAttributes = new ArrayList<ChangeSetAttribute>();
    changeSetAttributes.add(ChangeSetAttribute.file);
    changeSetAttributes.add(ChangeSetAttribute.changeId);
    changeSetAttributes.add(ChangeSetAttribute.author);
    if (Boolean.TRUE.equals(supportResourcePath)) {
        changeSetAttributes.add(ChangeSetAttribute.resourcePath);
    }
}

From source file:org.mongoj.samples.service.persistence.CarPersistenceImpl.java

License:Open Source License

public Car fetchByPrimaryKey(Serializable primaryKey) throws SystemException {
    DBCollection collection = getDB().getCollection(CarImpl.COLLECTION_NAME);

    DBObject criteria = new QueryBuilder().put("_id").is(new ObjectId(primaryKey.toString())).get();

    DBObject dbObject = collection.findOne(criteria);

    return getDocument(dbObject);
}