List of usage examples for com.mongodb DBCollection getName
public String getName()
From source file:org.broad.igv.plugin.mongocollab.MongoFeatureSource.java
License:Open Source License
public static FeatureTrack loadFeatureTrack(MongoCollabPlugin.Locator locator, List<Track> newTracks) { DBCollection collection = MongoCollabPlugin.getCollection(locator); //TODO Make this more flexible collection.setObjectClass(DBFeature.class); MongoFeatureSource source = new MongoFeatureSource(collection, locator.buildLocusIndex); FeatureTrack track = new MongoFeatureTrack(collection.getFullName(), collection.getName(), source); SearchCommand.registerNamedFeatureSearcher(source); newTracks.add(track);/*from www . j a va2 s.c o m*/ track.setMargin(0); return track; }
From source file:org.eclipse.birt.data.oda.mongodb.internal.impl.MDbOperation.java
License:Open Source License
static MapReduceOutput callMapReduceCmd(DBCollection dbCollection, QueryProperties queryProps) throws OdaException { if (!queryProps.hasMapReduceCommand()) return null; DBObject command = queryProps.getOperationExprAsParsedObject(false); if (command == null) return null; // check if mapreduce key is already specified in user-defined expression DBObject mapReduceCmd;//w ww. jav a 2 s. co m if (command.containsField(QueryModel.MAP_REDUCE_CMD_KEY) || command.containsField(QueryModel.MAP_REDUCE_CMD_KEY2)) mapReduceCmd = command; else { // add MapReduce input collection as first entry in command Map mapReduceCmd = new BasicDBObject(QueryModel.MAP_REDUCE_CMD_KEY, dbCollection.getName()); mapReduceCmd.putAll(command); // copy existing command entries } // mapReduce command's optional "limit" parameter applies to the number // of documents in the *input* collection, and thus cannot be used to apply // the searchLimit property defined for data set // execute the mapreduce command MapReduceOutput output; try { output = dbCollection.mapReduce(mapReduceCmd); output.getCommandResult().throwOnError(); return output; } catch (RuntimeException ex) { OdaException odaEx = new OdaException( Messages.bind(Messages.mDbOp_mapReduceCmdFailed, queryProps.getOperationExpression())); odaEx.initCause(ex); throw odaEx; } }
From source file:org.eclipse.emf.cdo.server.internal.mongodb.MongoDBBrowserPage.java
License:Open Source License
protected boolean showFirstCommit(DBCollection coll) { return coll.getName().equals(Commits.COMMITS) && !SHOW_INITIAL_COMMIT; }
From source file:org.eclipselabs.mongoemf.builders.EObjectBuilderImpl.java
License:Open Source License
/** * Build an EMF EObject from the supplied DBObject from MongoDB. * //www.ja v a2s . com * @param collection the MongoDB collection containing the DBObject * @param dbObject the object read from MongoDB * @param resource the resource that will contain the EMF Object * This function will not add the created to the supplied resource * to support the case where the user wishes to return a collection * of objects such as the result of a query. * @param isProxy true if the object is to be built as a proxy; false otherwise * @return the newly created EMF object instance */ @Override public EObject buildEObject(DBCollection collection, DBObject dbObject, Resource resource, boolean isProxy) { // Build an empty EMF object to hold the data from the MongodDB object // This function should not add the object to the resource since the // object may become part of a collection returned in the resource such // as the result of a query. EObject eObject = createEObject(resource.getResourceSet(), dbObject); EClass eClass = eObject.eClass(); // Load the XML extrinsic id if necessary buildExtransicID(dbObject, resource, eObject); // All attributes are mapped as key / value pairs with the key being the attribute name. for (EAttribute attribute : eClass.getEAllAttributes()) { if (!isProxy || !FeatureMapUtil.isFeatureMap(attribute)) buildAttribute(collection, dbObject, resource, eObject, attribute); } // isProxy will be set to true when the object is being returned as // part of a collection such as the result of a query. if (isProxy) { URI proxyURI = URI.createURI("../" + collection.getName() + "/" + dbObject.get(Keywords.ID_KEY) + "#/"); ((InternalEObject) eObject).eSetProxyURI(uriHandler.resolve(proxyURI)); return eObject; } // All references are mapped as key / value pairs with the key being the reference name. for (EReference reference : eClass.getEAllReferences()) buildReference(collection, dbObject, resource, eObject, reference); return eObject; }
From source file:org.eclipselabs.mongoemf.builders.EObjectBuilderImpl.java
License:Open Source License
@Override public URI buildURI(DBCollection collection, DBObject object) { URI uri = URI.createURI("../" + collection.getName() + "/" + object.get(Keywords.ID_KEY)); return uriHandler.resolve(uri); }
From source file:org.envirocar.server.mongo.dao.MongoMeasurementDao.java
License:Open Source License
private Measurements query(DBObject query, Pagination p) { final Mapper mapper = this.mongoDB.getMapper(); final Datastore ds = this.mongoDB.getDatastore(); final DBCollection coll = ds.getCollection(MongoMeasurement.class); DBCursor cursor = coll.find(query, null); long count = 0; cursor.setDecoderFactory(ds.getDecoderFact()); if (p != null) { count = coll.count(query);//from ww w . j av a2 s .c o m if (p.getOffset() > 0) { cursor.skip(p.getOffset()); } if (p.getLimit() > 0) { cursor.limit(p.getLimit()); } } cursor.sort(QueryImpl.parseFieldsString(MongoMeasurement.TIME, MongoMeasurement.class, mapper, true)); Iterable<MongoMeasurement> i = new MorphiaIterator<MongoMeasurement, MongoMeasurement>(cursor, mapper, MongoMeasurement.class, coll.getName(), mapper.createEntityCache()); return createPaginatedIterable(i, p, count); }
From source file:org.eobjects.analyzer.storage.MongoDbRowAnnotationFactory.java
License:Open Source License
public MongoDbRowAnnotationFactory(DBCollection dbCollection) { super(1000);//from w w w . ja v a2 s . co m logger.info("Creating new MongoDB RowAnnotationFactory collection: {}", dbCollection.getName()); _dbCollection = dbCollection; _dbCollection.createIndex(new BasicDBObject(ROW_ID_KEY, 1)); }
From source file:org.forgerock.openidm.repo.mongodb.impl.query.Queries.java
License:Open Source License
/** * Execute a query, either a pre-configured query by using the query ID, or a query expression passed as * part of the params./*w w w.ja va 2 s . c om*/ * * The keys for the input parameters as well as the return map entries are in QueryConstants. * * @param params the parameters which include the query id, or the query expression, as well as the * token key/value pairs to replace in the query * @param collection a handle to a MongoDB collection instance for exclusive use by the query method whilst it is executing. * @return The query result, which includes meta-data about the query, and the result set itself. * @throws BadRequestException if the passed request parameters are invalid, e.g. missing query id or query expression or tokens. */ public List<DBObject> query(Map<String, Object> params, DBCollection collection) throws BadRequestException { List<DBObject> result = null; QueryInfo foundQuery = null; params.put(QueryConstants.RESOURCE_NAME, collection.getName()); String queryExpression = (String) params.get(QueryConstants.QUERY_EXPRESSION); String queryId = null; if (queryExpression != null) { String queryString = (String) params.get(QueryConstants.QUERY_EXPRESSION); foundQuery = new QueryInfo(false); foundQuery.setQuery(queryString); } else { queryId = (String) params.get(QueryConstants.QUERY_ID); if (queryId == null) { throw new BadRequestException( "Either " + QueryConstants.QUERY_ID + " or " + QueryConstants.QUERY_EXPRESSION + " to identify/define a query must be passed in the parameters. " + params); } foundQuery = configuredQueries.get(queryId); if (foundQuery == null) { throw new BadRequestException("The passed query identifier " + queryId + " does not match any configured queries on the MongoDB repository service."); } } if (foundQuery != null) { DBObject query = null; logger.debug("Evaluate query {}", query); Name eventName = getEventName(queryExpression, queryId); EventEntry measure = Publisher.start(eventName, foundQuery, null); try { result = executeQuery(foundQuery, params, collection); measure.setResult(result); } catch (BadRequestException e) { throw new BadRequestException( "Failed to resolve and parse the query " + queryId + " with params: " + params); } catch (RuntimeException ex) { logger.warn("Unexpected failure during DB query: {}", ex.getMessage()); throw ex; } finally { measure.end(); } } return result; }
From source file:org.geotools.data.mongodb.MongoLayer.java
License:LGPL
public MongoLayer(DBCollection coll, MongoPluginConfig config) { this.config = config; layerName = coll.getName(); log.fine("MongoLayer; layerName " + layerName); keywords = new HashSet<String>(); SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(layerName);// w ww .ja v a 2s .co m builder.setNamespaceURI(config.getNamespace()); // Always add _id... AttributeTypeBuilder b = new AttributeTypeBuilder(); b.setBinding(String.class); b.setName("_id"); b.setNillable(false); b.setDefaultValue(null); b.setLength(1024); AttributeDescriptor a = b.buildDescriptor("_id"); builder.add(a); // We could get this out of the table, exercise for the reader... TODO try { crs = CRS.decode("EPSG:4326"); } catch (Throwable t) { crs = DefaultGeographicCRS.WGS84; } b = new AttributeTypeBuilder(); b.setName("geometry"); b.setNillable(false); b.setDefaultValue(null); b.setCRS(crs); // determine metadata for this collection metaData = getCollectionModel(coll, buildRule); // determine geometry type setGeometryType(metaData); switch (geometryType) { case GeometryCollection: b.setBinding(GeometryCollection.class); break; case LineString: b.setBinding(LineString.class); break; case Point: b.setBinding(Point.class); break; case Polygon: b.setBinding(Polygon.class); break; case MultiLineString: b.setBinding(MultiLineString.class); break; case MultiPoint: b.setBinding(MultiPoint.class); break; case MultiPolygon: b.setBinding(MultiPolygon.class); break; case Unknown: log.warning("Unknown geometry for layer " + layerName + " (but has valid distinct geometry.type)"); return; } a = b.buildDescriptor("geometry"); builder.add(a); // Add the 2 known keywords... keywords.add("_id"); keywords.add("geometry"); // Now get all the properties... DBObject props = (DBObject) metaData.get("properties"); addAttributes(builder, props, "properties"); schema = builder.buildFeatureType(); }
From source file:org.hibernate.ogm.datastore.mongodb.impl.MongoDBSchemaDefiner.java
License:LGPL
public void createIndex(DB database, MongoDBIndexSpec indexSpec) { DBCollection collection = database.getCollection(indexSpec.getCollection()); Map<String, DBObject> preexistingIndexes = getIndexes(collection); String preexistingTextIndex = getPreexistingTextIndex(preexistingIndexes); // if a text index already exists in the collection, MongoDB silently ignores the creation of the new text index // so we might as well log a warning about it if (indexSpec.isTextIndex() && preexistingTextIndex != null && !preexistingTextIndex.equalsIgnoreCase(indexSpec.getIndexName())) { throw log.unableToCreateTextIndex(collection.getName(), indexSpec.getIndexName(), preexistingTextIndex); }//from w w w.j ava 2s.c om try { // if the index is already present and with the same definition, MongoDB simply ignores the call // if the definition is not the same, MongoDB throws an error, except in the case of a text index // where it silently ignores the creation collection.createIndex(indexSpec.getIndexKeysDBObject(), indexSpec.getOptions()); } catch (MongoException e) { String indexName = indexSpec.getIndexName(); if (e.getCode() == INDEX_CREATION_ERROR_CODE && !StringHelper.isNullOrEmptyString(indexName) && preexistingIndexes.containsKey(indexName)) { // The index already exists with a different definition and has a name: we drop it and we recreate it collection.dropIndex(indexName); collection.createIndex(indexSpec.getIndexKeysDBObject(), indexSpec.getOptions()); } else { throw log.unableToCreateIndex(collection.getName(), indexName, e); } } }