List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:com.entrib.mongoslate.visitor.expr.translator.ExpressionTranslatorVisitor.java
License:Apache License
public Object visit(ValueListExpression expression) { BasicDBList list = new BasicDBList(); List<Value> values = expression.getValues(); for (Value value : values) { list.add(value.getValueAsObject()); }/*w w w .jav a 2 s.co m*/ return list; }
From source file:com.entrib.mongoslate.visitor.stmt.translator.select.SelectStatementTranslator.java
License:Apache License
/** * Distinct keyword if used gets ignored. * * For the select_clause find all the column names where aggr function is used * /*from w w w. ja va 2 s . c o m*/ * if alias clause is used * * @param selectStatement * @return */ private Aggregation buildMongoAggregation(SelectStatement selectStatement) { Aggregation aggregation = new Aggregation(); BasicDBObject aggregate = new BasicDBObject(); aggregate.append(AGGREGATE, selectStatement.getCollection().getValueAsString()); BasicDBList pipeline = new BasicDBList(); aggregate.append(PIPELINE, pipeline); Expression whereClause = selectStatement.getLogicalExpression(); if (whereClause != null) { BasicDBObject query = (BasicDBObject) selectStatement.getLogicalExpression() .accept(expressionTranslatorVisitor); pipeline.add(new BasicDBObject("$match", query)); } // if group by clause is used, go through tag list expressions // through each tag and prepare the $group pipeline object LimitExpression limitExpression = selectStatement.getLimitExpression(); if (limitExpression != null) { BasicDBObject skipAndLimit = (BasicDBObject) limitExpression.accept(expressionTranslatorVisitor); pipeline.add(new BasicDBObject("$skip", ((IntValue) skipAndLimit.get("skip")).getValueAsObject())); pipeline.add(new BasicDBObject("$limit", ((IntValue) skipAndLimit.get("skip")).getValueAsObject())); } return aggregation; }
From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.jpa.NewsHandler.java
License:Apache License
/** * handle the update and save process for the news. * * @param news/*from ww w . j a va2 s . c o m*/ * the News object * @throws Exception * the exception */ private void handleNews(News news) throws Exception { // 1. save the product DBObject item = getNewsById(news.getFs_id(), news.getLanguage()); if (item != null) { item.put("fs_id", news.getFs_id()); item.put("language", news.getLanguage()); item.put("headline", news.getHeadline()); item.put("subHeadline", news.getSubheadline()); item.put("headline", news.getHeadline()); item.put("teaser", news.getTeaser()); item.put("content", news.getContent()); item.put("date", news.getDate()); item.put("url", news.getUrl()); item.put("version", news.getVersion()); item.put("lastmodified", news.getLastmodified()); BasicDBObject query = new BasicDBObject(); news.setId((Long) item.get("_id")); query.put("_id", news.getId()); dbNews.update(query, item); } else { item = new BasicDBObject(); item.put("fs_id", news.getFs_id()); item.put("language", news.getLanguage()); item.put("headline", news.getHeadline()); item.put("subHeadline", news.getSubheadline()); item.put("headline", news.getHeadline()); item.put("teaser", news.getTeaser()); item.put("content", news.getContent()); item.put("date", news.getDate()); item.put("url", news.getUrl()); item.put("version", news.getVersion()); item.put("lastmodified", news.getLastmodified()); news.setId(generateIdentifier(NEWS_COLLECTION_NAME, mdb)); item.put("_id", news.getId()); dbNews.insert(item); } // 2. save categories // add categories to news BasicDBList catList = new BasicDBList(); if (news.getCategories() != null) { for (NewsCategory cat : news.getCategories()) { handleCategory(cat, news); DBObject tmpCat = getCategoryById(cat.getFs_id(), cat.getLanguage()); //catList.add(new DBRef(this.mdb, this.CATEGORY_COLLECTION_NAME, tmpCat.get("_id"))); catList.add(tmpCat.get("_id")); } } // add list of categories to the news // item.put("categories", catList); item.put("categories_$$manyToManyIds", catList); BasicDBObject query = new BasicDBObject(); query.put("_id", news.getId()); dbNews.update(query, item); }
From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.jpa.NewsHandler.java
License:Apache License
/** * handle the update and save process for the categories. * * @param category//from w w w . j a v a 2s. c o m * the NewsCategory object * @param news * the News object to reference to * @throws Exception * the exception */ private void handleCategory(NewsCategory category, News news) throws Exception { // 1. save the category DBObject item = getCategoryById(category.getFs_id(), category.getLanguage()); if (item != null) { item.put("fs_id", category.getFs_id()); item.put("language", category.getLanguage()); item.put("name", category.getName()); item.put("version", category.getVersion()); item.put("lastmodified", category.getLastmodified()); // newsdrilldown // DBObject tmpNews = getNewsById(news.getFs_id(), news.getLanguage()); // if (tmpNews != null) { // DBRef ref = new DBRef(mdb, NEWS_COLLECTION_NAME, // tmpNews.get("_id")); // item.put("newsdrilldown", ref); // } BasicDBObject query = new BasicDBObject(); category.setId((Long) item.get("_id")); query.put("_id", category.getId()); dbCategories.update(query, item); } else { item = new BasicDBObject(); item.put("fs_id", category.getFs_id()); item.put("language", category.getLanguage()); item.put("name", category.getName()); item.put("version", category.getVersion()); item.put("lastmodified", category.getLastmodified()); // newsdrilldown // DBObject tmpNews = getNewsById(news.getFs_id(), news.getLanguage()); // if (tmpNews != null) { // DBRef ref = new DBRef(mdb, NEWS_COLLECTION_NAME, // tmpNews.get("_id")); // item.put("newsdrilldown", ref); // } category.setId(generateIdentifier(CATEGORY_COLLECTION_NAME, mdb)); item.put("_id", category.getId()); dbCategories.insert(item); } // 2. save the metaCategories if (category.getMetaCategories() != null) { BasicDBList metaCatlist = (BasicDBList) item.get("metaCategories_$$manyToManyIds"); if (metaCatlist == null) { metaCatlist = new BasicDBList(); } for (NewsMetaCategory metaCat : category.getMetaCategories()) { handleMetaCategory(metaCat, category); if (!metaCatlist.contains(metaCat.getId())) { metaCatlist.add(metaCat.getId()); } DBObject obj = getMetaCategoryById(metaCat.getFs_id(), metaCat.getLanguage()); //BasicDBList catlist = (BasicDBList) obj.get("categories"); BasicDBList catlist = (BasicDBList) obj.get("categories_$$manyToManyIds"); if (catlist == null) { catlist = new BasicDBList(); } //DBRef catRef = new DBRef(this.mdb, this.CATEGORY_COLLECTION_NAME, category.getId()); if (!catlist.contains(category.getId())) { catlist.add(category.getId()); } obj.put("categories_$$manyToManyIds", catlist); BasicDBObject query = new BasicDBObject(); query.put("_id", (Long) obj.get("_id")); dbMetaCategories.update(query, obj); } item.put("metaCategories_$$manyToManyIds", metaCatlist); BasicDBObject query = new BasicDBObject(); query.put("_id", (Long) item.get("_id")); dbCategories.update(query, item); } }
From source file:com.eywa.impl.app.mongo.entities.Contact.java
License:Open Source License
private void init() { final String id = createUUID(); this.append(ID, id); this.append(COLLABORATION_HUBS, new BasicDBList()); }
From source file:com.eywa.impl.app.mongo.services.ContactService.java
License:Open Source License
public MongoPage lookup(final String hubId, final int skip, final int limit, final String searchText) { DBObject query1 = null;/*from w w w . j av a 2 s.co m*/ DBObject query2 = null; if (!StringUtils.isNULL(hubId)) { query1 = new BasicDBObject(); // lookup in current hub and between "cross-hub" contacts final BasicDBList conditions = new BasicDBList(); conditions.add(MongoUtils.queryEquals(Contact.HUB_ID, hubId, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryEquals(Contact.HUB_ID, Hub.HUB_ALL, MongoUtils.CASE_INSENSITIVE)); query1.put(MongoUtils.OP_OR, conditions); } if (!StringUtils.isNULL(searchText)) { if (SPECIAL_FILTER_COLLABORATOR.equalsIgnoreCase(searchText)) { query2 = new BasicDBObject(); query2.put(Contact.COLLABORATION_HUBS, hubId); } else if (SPECIAL_FILTER_USER.equalsIgnoreCase(searchText)) { query2 = new BasicDBObject(); MongoUtils.queryNotEmpty(query2, Contact.ACCOUNT_ID); } else if (searchText.startsWith("#")) { query2 = new BasicDBObject(); query2.put(Contact.PARALLEL_ARRAY_KEY, searchText.substring(1)); } else { query2 = new BasicDBObject(); final BasicDBList conditions = new BasicDBList(); conditions.add(MongoUtils.queryEquals(Contact.ID, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryEquals(Contact.OWNER_ID, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryContains(Contact.NAME, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryContains(Contact.SURNAME, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add( MongoUtils.queryContains(Contact.DESCRIPTION, searchText, MongoUtils.CASE_INSENSITIVE)); // conditions.add(MongoUtils.queryEquals(Contact.EMAIL, searchText, MongoUtils.CASE_INSENSITIVE)); //conditions.add(MongoUtils.queryEquals(Contact.KEYWORDS, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryEquals(Contact.PARALLEL_ARRAY_KEY, searchText, MongoUtils.CASE_INSENSITIVE)); query2.put(MongoUtils.OP_OR, conditions); } } DBObject query = null; if (null != query1 && null != query2) { query = new BasicDBObject(); final BasicDBList conditions = new BasicDBList(); conditions.add(query1); conditions.add(query2); query.put(MongoUtils.OP_AND, conditions); } else if (null == query2) { query = query1; } else { query = query2; } final String[] fieldNames = null; final String[] sortAsc = new String[] { Contact.SURNAME, Contact.NAME }; final String[] sortDes = new String[] {}; return super.paged(query, fieldNames, skip, limit, sortAsc, sortDes); }
From source file:com.eywa.impl.app.mongo.services.FileService.java
License:Open Source License
public MongoPage lookup(final String hubId, final int skip, final int limit, final String searchText) { DBObject query1 = null;//from ww w .ja v a 2 s .co m DBObject query2 = null; if (!StringUtils.isNULL(hubId)) { // lookup in current hub query1 = new BasicDBObject(); MongoUtils.queryEquals(query1, File.HUB_ID, hubId, MongoUtils.CASE_INSENSITIVE); } if (!StringUtils.isNULL(searchText)) { if (searchText.startsWith("#")) { query2 = new BasicDBObject(); query2.put(File.PARALLEL_ARRAY_KEY, searchText.substring(1)); } else { query2 = new BasicDBObject(); final BasicDBList conditions = new BasicDBList(); conditions.add(MongoUtils.queryEquals(File.ID, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryEquals(File.OWNER_ID, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryContains(File.NAME, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryContains(File.DESCRIPTION, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add( MongoUtils.queryEquals(File.PARALLEL_ARRAY_KEY, searchText, MongoUtils.CASE_INSENSITIVE)); query2.put(MongoUtils.OP_OR, conditions); } } DBObject query = null; if (null != query1 && null != query2) { query = new BasicDBObject(); final BasicDBList conditions = new BasicDBList(); conditions.add(query1); conditions.add(query2); query.put(MongoUtils.OP_AND, conditions); } else if (null == query2) { query = query1; } else { query = query2; } final String[] fieldNames = null; final String[] sortAsc = new String[] { File.NAME }; final String[] sortDes = new String[] {}; return super.paged(query, fieldNames, skip, limit, sortAsc, sortDes); }
From source file:com.eywa.impl.app.mongo.services.HubService.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[] hubCollaborations = User.getCollaborationsAsArray(user); if (!CollectionUtils.isEmpty(hubCollaborations)) { // user filter final DBObject query_user = this.queryByUserId(userId); // collaboration filter //final Object[] array = hubCollaborations.toArray(new Object[hubCollaborations.size()]); final DBObject query_collaborations = MongoUtils.queryIn(Hub.ID, hubCollaborations); 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 {//w w w . j av a2s.c om 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[] { Hub.NAME }, null); return result; } return new MongoPage(); }
From source file:com.eywa.impl.app.mongo.services.HubService.java
License:Open Source License
private DBObject queryByUserId(final String userId) { final DBObject query = MongoUtils.queryEquals(Hub.USER_ID, userId); // exclude home e recycle_bin final BasicDBList and_conditions = new BasicDBList(); and_conditions.add(MongoUtils.queryNotEquals(Hub.UID, Hub.HUB_HOME)); and_conditions.add(MongoUtils.queryNotEquals(Hub.UID, Hub.HUB_RECYCLE_BIN)); query.put(IMongoConstants.OP_AND, and_conditions); return query; }
From source file:com.eywa.impl.app.mongo.services.HubService.java
License:Open Source License
private static DBObject queryLookup(final String searchText) { if (StringUtils.hasText(searchText)) { final BasicDBList conditions = new BasicDBList(); conditions.add(MongoUtils.queryContains(Hub.NAME, searchText, MongoUtils.CASE_INSENSITIVE)); conditions.add(MongoUtils.queryContains(Hub.DESCRIPTION, searchText, MongoUtils.CASE_INSENSITIVE)); return new BasicDBObject(MongoUtils.OP_OR, conditions); }/*w w w . j a v a 2 s . c o m*/ return null; }