List of usage examples for com.mongodb BasicDBList get
public Object get(final String key)
From source file:org.eclipse.birt.data.oda.mongodb.internal.impl.QueryProperties.java
License:Open Source License
static DBObject getFirstObjectSet(DBObject exprObj) { if (exprObj == null) return null; DBObject firstObj = null;/*from www . j ava 2 s . co m*/ if (exprObj instanceof BasicDBList) { BasicDBList objList = (BasicDBList) exprObj; if (objList.size() >= 1) { Object value = objList.get(0); if (value instanceof DBObject) firstObj = (DBObject) value; else // log and ignore logInvalidTagValue(value); } } else firstObj = exprObj; return firstObj; }
From source file:org.eclipse.birt.data.oda.mongodb.internal.impl.QueryProperties.java
License:Open Source License
static DBObject[] getSecondaryObjectSets(DBObject exprObj) { if (!(exprObj instanceof BasicDBList)) return null; // no secondary element(s) BasicDBList objList = (BasicDBList) exprObj; if (objList.size() <= 1) return null; // return the second and remaining DBObject(s) from the list List<DBObject> secondaryObjList = new ArrayList<DBObject>(objList.size() - 1); for (int i = 1; i < objList.size(); i++) { Object value = objList.get(i); if (value instanceof DBObject) secondaryObjList.add((DBObject) value); else // ignore elements that are not DBObject logInvalidTagValue(value);// w w w .ja v a 2 s . c o m } if (secondaryObjList.isEmpty()) return null; return (DBObject[]) secondaryObjList.toArray(new DBObject[secondaryObjList.size()]); }
From source file:org.eclipse.birt.data.oda.mongodb.internal.impl.ResultDataHandler.java
License:Open Source License
private static BasicDBList fetchFieldValuesFromList(String fieldFullName, BasicDBList fromDBList) { if (fromDBList == null || fromDBList.size() == 0) return null; // get the named field value from each element in given array list BasicDBList fieldValuesList = new BasicDBList(); if (fromDBList.isPartialObject()) fieldValuesList.markAsPartialObject(); for (int index = 0; index < fromDBList.size(); index++) { Object listElementObj = fromDBList.get(String.valueOf(index)); if (listElementObj instanceof DBObject) // nested complex object, e.g. document listElementObj = fetchFieldValues(fieldFullName, (DBObject) listElementObj); fieldValuesList.put(index, listElementObj); }/*from www . j a v a2 s .c o m*/ // check if at least one field value in list is not null, return the list for (Object elementValue : fieldValuesList.toMap().values()) { if (elementValue != null) return fieldValuesList; } return null; // all values in list is null }
From source file:org.eclipse.emf.cdo.server.internal.mongodb.Commits.java
License:Open Source License
public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, final CDOCommitInfoHandler handler) { if (endTime < CDOBranchPoint.UNSPECIFIED_DATE) { throw new IllegalArgumentException("Counting not supported"); }/*from w w w. jav a2 s . com*/ DBObject query = new BasicDBObject(); if (branch != null && store.isBranching()) { query.put(COMMITS_BRANCH, branch.getID()); } BasicDBList list = new BasicDBList(); if (startTime != CDOBranchPoint.UNSPECIFIED_DATE) { list.add(new BasicDBObject(QueryOperators.GTE, startTime)); } if (endTime != CDOBranchPoint.UNSPECIFIED_DATE) { list.add(new BasicDBObject(QueryOperators.LTE, endTime)); } int size = list.size(); if (size == 2) { query.put(COMMITS_ID, list); } else if (size == 1) { query.put(COMMITS_ID, list.get(0)); } InternalRepository repository = store.getRepository(); final InternalCDOBranchManager branchManager = repository.getBranchManager(); final InternalCDOCommitInfoManager commitManager = repository.getCommitInfoManager(); new Query<Object>(query) { @Override public Object execute() { return execute(collection.find(getRef()).sort(new BasicDBObject(COMMITS_ID, 1))); } @Override protected Object handleDoc(DBObject doc) { long time = (Long) doc.get(COMMITS_ID); Object value = doc.get(COMMITS_PREVIOUS); long previous = value == null ? 0L : (Long) value; CDOBranch commitBranch; if (store.isBranching()) { int branchID = (Integer) doc.get(COMMITS_BRANCH); commitBranch = branchManager.getBranch(branchID); } else { commitBranch = branchManager.getMainBranch(); } String user = (String) doc.get(COMMITS_USER); String comment = (String) doc.get(COMMITS_COMMENT); CDOCommitInfo commitInfo = commitManager.createCommitInfo(commitBranch, time, previous, user, comment, null); handler.handleCommitInfo(commitInfo); return null; } }.execute(); }
From source file:org.envirocar.server.mongo.dao.MongoMeasurementDao.java
License:Open Source License
protected List<Key<MongoTrack>> toKeyList(Iterable<DBObject> res) { List<Key<MongoTrack>> keys = Lists.newLinkedList(); for (DBObject obj : res) { BasicDBList list = (BasicDBList) obj.get(TRACKS); for (int i = 0; i < list.size(); i++) { DBRef ref = (DBRef) list.get(i); Key<MongoTrack> key = getMapper().refToKey(ref); keys.add(key);/*w w w. j a va2 s . co m*/ } } return keys; }
From source file:org.envirocar.server.mongo.util.GeoBSON.java
License:Open Source License
protected Coordinate decodeCoordinate(BasicDBList list) throws GeometryConverterException { if (list.size() != 2) { throw new GeometryConverterException("coordinates may only have 2 dimensions"); }//w w w. j a v a 2s. c om Object x = list.get(0); Object y = list.get(1); if (!(x instanceof Number) || !(y instanceof Number)) { throw new GeometryConverterException("x and y have to be numbers"); } return new Coordinate(((Number) x).doubleValue(), ((Number) y).doubleValue()); }
From source file:org.envirocar.server.mongo.util.GeoBSON.java
License:Open Source License
protected Coordinate[] decodeCoordinates(BasicDBList list) throws GeometryConverterException { Coordinate[] coordinates = new Coordinate[list.size()]; for (int i = 0; i < list.size(); ++i) { coordinates[i] = decodeCoordinate(toList(list.get(i))); }//from ww w.java2s. c om return coordinates; }
From source file:org.envirocar.server.mongo.util.GeoBSON.java
License:Open Source License
protected Polygon decodePolygonCoordinates(BasicDBList coordinates) throws GeometryConverterException { if (coordinates.size() < 1) { throw new GeometryConverterException("missing polygon shell"); }/* w w w . j a v a 2 s .c o m*/ LinearRing shell = factory.createLinearRing(decodeCoordinates(toList(coordinates.get(0)))); LinearRing[] holes = new LinearRing[coordinates.size() - 1]; for (int i = 1; i < coordinates.size(); ++i) { holes[i - 1] = factory.createLinearRing(decodeCoordinates(toList(coordinates.get(i)))); } return factory.createPolygon(shell, holes); }
From source file:org.envirocar.server.mongo.util.GeoBSON.java
License:Open Source License
@Override public MultiLineString decodeMultiLineString(BSONObject bson) throws GeometryConverterException { BasicDBList coordinates = requireCoordinates(bson); LineString[] lineStrings = new LineString[coordinates.size()]; for (int i = 0; i < coordinates.size(); ++i) { Object coords = coordinates.get(i); lineStrings[i] = factory.createLineString(decodeCoordinates(toList(coords))); }/* w w w . j ava 2 s . c om*/ return factory.createMultiLineString(lineStrings); }
From source file:org.envirocar.server.mongo.util.GeoBSON.java
License:Open Source License
@Override public MultiPolygon decodeMultiPolygon(BSONObject bson) throws GeometryConverterException { BasicDBList coordinates = requireCoordinates(bson); Polygon[] polygons = new Polygon[coordinates.size()]; for (int i = 0; i < coordinates.size(); ++i) { polygons[i] = decodePolygonCoordinates(toList(coordinates.get(i))); }/*from w ww.j ava 2s . c o m*/ return factory.createMultiPolygon(polygons); }