Example usage for com.mongodb DBObject put

List of usage examples for com.mongodb DBObject put

Introduction

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

Prototype

Object put(String key, Object v);

Source Link

Document

Sets a name/value pair in this object.

Usage

From source file:com.eywa.impl.app.mongo.services.ProductTransactionService.java

License:Open Source License

public static List<DBObject> getByProduct(final String productId) {
    try {//from w  w  w .  ja v  a2  s .c  o  m
        final ProductTransactionService srvc = new ProductTransactionService();
        final DBObject query = new BasicDBObject();
        query.put(ProductTransaction.PRODUCT_ID, productId);
        return srvc.find(query);
    } catch (Throwable ignored) {
    }
    return null;
}

From source file:com.eywa.impl.app.mongo.services.ScheduledJobService.java

License:Open Source License

public List<DBObject> removeExpired() throws Exception {
    final DBObject query = MongoUtils.queryLowerThan(ScheduledJob.EXPIRATION_DATE, DateUtils.now().getTime(),
            true);//  ww w  .j  a  v a  2 s  .  com
    query.put(ScheduledJob.RUNNING, true);

    final List<DBObject> expired = super.find(query);
    if (!expired.isEmpty()) {
        super.remove(query);
    }
    return expired;
}

From source file:com.eywa.impl.app.mongo.services.ScheduledJobService.java

License:Open Source License

/**
 * Returns all jobs that are not still running and should.
 *
 * @return List of jobs/*w  w  w  . j  a  va2 s .  com*/
 * @throws Exception
 */
public List<DBObject> getRunnable() throws Exception {
    final List<DBObject> result = new LinkedList<>();
    final DBObject query = MongoUtils.queryLowerThan(ScheduledJob.RUN_NEXT_DATE, DateUtils.now().getTime(),
            true);
    query.put(ScheduledJob.RUNNING, false);

    final List<DBObject> jobs = super.find(query);
    // check max count
    for (final DBObject job : jobs) {
        final int max = ScheduledJob.getMaxRunCount(job); // 0=infinite
        final int count = ScheduledJob.getRunCount(job);
        // running=true, so next task will not find the job until stopped
        ScheduledJob.setRunning(job, true); // inc count
        if (max == 0 || max > count) {
            result.add(job);
        } else {
            // mark job as expired, so will be removed
            ScheduledJob.setExpirationDate(job, DateUtils.now().getTime());
        }
        super.upsert(job);
    }

    return result;
}

From source file:com.eywa.impl.app.mongo.services.ScheduledJobService.java

License:Open Source License

public static List<DBObject> getByType(final String userId, final String type) {
    try {//w w w . ja va2 s  .c o m
        final ScheduledJobService srvc = new ScheduledJobService();
        final DBObject query = new BasicDBObject();
        query.put(ScheduledJob.USER_ID, userId);
        query.put(ScheduledJob.TYPE, type);
        query.put(ScheduledJob.EXPIRED, false);
        return srvc.find(query);
    } catch (Throwable ignored) {
    }
    return new ArrayList<DBObject>();
}

From source file:com.eywa.impl.app.mongo.services.ScheduledJobService.java

License:Open Source License

public static List<DBObject> getByUid(final String userId, final String uid) {
    try {/* w ww . java  2 s . c  o m*/
        final ScheduledJobService srvc = new ScheduledJobService();
        final DBObject query = new BasicDBObject();
        query.put(ScheduledJob.USER_ID, userId);
        query.put(ScheduledJob.UID, uid);
        query.put(ScheduledJob.EXPIRED, false);
        return srvc.find(query);
    } catch (Throwable ignored) {
    }
    return new ArrayList<DBObject>();
}

From source file:com.eywa.impl.app.mongo.services.SessionService.java

License:Open Source License

public static DBObject getByType(final String type, final String uid) {
    try {//from  w  ww  . ja  va2 s.  c  o  m
        final SessionService srvc = new SessionService();
        final DBObject query = new BasicDBObject();
        query.put(Session.TYPE, type);
        query.put(Session.UID, uid);
        return srvc.findOne(query);
    } catch (Throwable ignored) {
    }
    return null;
}

From source file:com.eywa.impl.app.mongo.services.ShopService.java

License:Open Source License

public MongoPage pagedByUserId(final String userId, final String searchText, final int skip, final int limit) {
    final DBObject user = UserService.getEnabled(userId);
    if (null != user) {
        final DBObject query;

        // user collaborations
        final String[] collaborations = User.getCollaborationsAsArray(user);
        if (!CollectionUtils.isEmpty(collaborations)) {
            // user filter
            final DBObject query_user = this.queryByUserId(userId);

            // collaboration filter
            final DBObject query_collaborations = MongoUtils.queryIn(Shop.ID, collaborations);

            final BasicDBList or_conditions = new BasicDBList();
            or_conditions.add(query_user);
            or_conditions.add(query_collaborations);

            query = StringUtils.hasText(searchText) ? queryLookup(searchText) : new BasicDBObject();
            query.put(IMongoConstants.OP_OR, or_conditions);
        } else {/*from   w w w . j ava  2s .  co  m*/
            if (StringUtils.hasText(searchText)) {
                // user filter
                final BasicDBList and_conditions = new BasicDBList();
                final DBObject query_user = this.queryByUserId(userId);
                final DBObject query_search = queryLookup(searchText);
                and_conditions.add(query_user);
                and_conditions.add(query_search);

                query = new BasicDBObject();
                query.put(IMongoConstants.OP_AND, and_conditions);
            } else {
                query = this.queryByUserId(userId);
            }
        }
        final MongoPage result = super.paged(query, null, skip, limit, new String[] { Shop.NAME }, null);
        return result;
    }
    return new MongoPage();
}

From source file:com.eywa.impl.app.mongo.services.ShopTemplateService.java

License:Open Source License

public List<DBObject> lookup(final String parentId, final String type) {
    try {/*from w ww .java2 s .  c  o  m*/
        final DBObject query = new BasicDBObject();

        if (StringUtils.hasText(parentId)) {
            query.put(ShopTemplate.PARENT_ID, parentId);
        }
        if (StringUtils.hasText(type)) {
            query.put(ShopTemplate.TYPE, type);
        }

        return super.find(query);
    } catch (Throwable ignored) {
    }
    return new ArrayList<>();
}

From source file:com.eywa.impl.app.mongo.services.ShopTemplateService.java

License:Open Source License

public static List<DBObject> getTemplateElements(final String templateId) {
    try {/* w w  w  .  j ava 2  s  .  co m*/
        if (StringUtils.hasText(templateId)) {
            final String id = StringUtils.isNULL(templateId) ? User.DEFAULT_SHOP_TEMPLATE_ID : templateId;
            final DBObject query = new BasicDBObject();
            query.put(ShopTemplate.ROOT_ID, id);
            final ShopTemplateService srvc = new ShopTemplateService();
            return srvc.find(query, null, new String[] { ShopTemplate.UID }, null);
        }
    } catch (Throwable ignored) {
    }
    return new ArrayList<>();
}

From source file:com.eywa.impl.app.mongo.services.UserService.java

License:Open Source License

public DBObject signin(final String id_user, final String password) {
    DBObject user = super.signin(id_user, password);
    if (null == user) {
        final DBObject query = new BasicDBObject();
        query.put(User.EMAILS, id_user);
        query.put(User.PASSWORD, password);
        final List<DBObject> list = super.find(query);
        if (!list.isEmpty()) {
            if (list.size() == 1) {
                user = list.get(0);/*from  ww w  .  j  a va  2  s .  c om*/
            } else {
                final String msg = "FOUND MULTIPLE USERS WITH SAME IDENTITY: " + list.toString();
                // send email to administrator
                CentralControl.onError(msg, null);
            }
        }
    }
    return user;
}