List of usage examples for com.mongodb DBCollection getName
public String getName()
From source file:org.i3xx.step.clockmongo.service.impl.ClockPersistenceServiceImpl.java
License:Apache License
/** * @param col The collection to get the object from * @param symbol The symbol (key)/* w w w . j a va 2 s . com*/ * @param timeout The timeout or -1 for no timeout * @return The DBObject */ private DBObject ensureObject(DBCollection col, String symbol) { DBObject dbo = null; DBObject query = new BasicDBObject("symbol", symbol); dbo = col.findOne(query); if (dbo == null) { String nspc = col.getName(); dbo = new BasicDBObject(); dbo.put("nspc", nspc); dbo.put("symbol", symbol); dbo.put("born", new Long(System.currentTimeMillis())); dbo.put("statement", ""); col.insert(dbo); } return dbo; }
From source file:org.iternine.jeppetto.dao.mongodb.BasicDBObjectCommand.java
License:Apache License
@SuppressWarnings({ "unchecked" }) @Override//from w ww . ja v a 2 s. co m public Object singleResult(DBCollection dbCollection) throws NoSuchItemException { DBCursor cursor = cursor(dbCollection); cursor.limit(2); if (!cursor.hasNext()) { throw new NoSuchItemException(dbCollection.getName(), query.toString()); } Object result = cursor.next(); if (cursor.hasNext()) { throw new RuntimeException("More than one " + dbCollection.getName() + " matches query: " + query); } ((DirtyableDBObject) result).markPersisted(); return result; }
From source file:org.iternine.jeppetto.dao.mongodb.enhance.MongoDBCallback.java
License:Apache License
public MongoDBCallback(DBCollection dbCollection) { super(dbCollection); if (dbCollection != null && !dbCollection.getName().equals("$cmd")) { this.dbCollection = dbCollection; if (!perCollectionClassCache.containsKey(dbCollection.getName())) { perCollectionClassCache.put(dbCollection.getName(), new HashMap<String, Class>()); }// ww w . j a v a2s. c o m } }
From source file:org.iternine.jeppetto.dao.mongodb.QueryLoggingCommand.java
License:Apache License
@Override public Object singleResult(DBCollection dbCollection) throws NoSuchItemException { logger.debug("Executing {} for single {}", delegate, dbCollection.getName()); return delegate.singleResult(dbCollection); }
From source file:org.jeo.mongo.MongoDataset.java
License:Open Source License
MongoDataset(DBCollection dbcol, MongoWorkspace mongo) { this.dbcol = dbcol; this.mongo = mongo; this.schema = new SchemaBuilder(dbcol.getName()).field("geometry", Geometry.class).schema(); }
From source file:org.mongolink.domain.updateStrategy.DiffStrategy.java
License:Open Source License
@Override public void update(DBObject initialValue, DBObject updatedValue, DBCollection collection) { final DBObject diff = new DbObjectDiff(initialValue).compareWith(updatedValue); final DBObject q = updateQuery(initialValue); executePushAndPull(collection, diff, q); if (!diff.keySet().isEmpty()) { LOGGER.debug("Updating : collection {} : query {} : modifiers : {}", collection.getName(), q, diff); collection.update(q, diff);// w w w . j a v a2 s . c o m } }
From source file:org.mongolink.domain.updateStrategy.OverwriteStrategy.java
License:Open Source License
@Override public void update(DBObject initialValue, DBObject updatedValue, DBCollection collection) { DBObject query = new BasicDBObject(); query.put("_id", updatedValue.get("_id")); LOGGER.debug("Updating : collection {} : element {}", collection.getName(), updatedValue); collection.update(updateQuery(initialValue), updatedValue); }
From source file:org.slc.sli.dal.aspect.MongoTrackingAspect.java
License:Apache License
@Around("call(* com.mongodb.DBCollection.*(..)) && !this(MongoTrackingAspect) && !within(org..*Test) && !within(org..*MongoPerfRepository)") public Object trackDBCollection(ProceedingJoinPoint pjp) throws Throwable { long start = System.currentTimeMillis(); Object result = pjp.proceed(); long end = System.currentTimeMillis(); if (isEnabled()) { DBCollection col = (DBCollection) pjp.getTarget(); proceedAndTrack(pjp, col.getDB().getName(), pjp.getSignature().getName(), col.getName(), start, end); }/*from w w w .j a v a2 s.c o m*/ if (Boolean.valueOf(dbCallTracking)) { dbCallTracker.incrementHitCount(); // dbCallTracker.addMetric("t", pjp.getSignature().toShortString(), end-start); } return result; }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
License:Apache License
@Override public <T> CloseableIterator<T> stream(final Query query, final Class<T> entityType, String collectionName) { Assert.notNull(query, "Query must not be null!"); Assert.notNull(entityType, "Entity type must not be null!"); Assert.hasText(collectionName, "Collection name must not be null or empty!"); return execute(collectionName, new CollectionCallback<CloseableIterator<T>>() { @Override//from ww w . ja v a 2s .co m public CloseableIterator<T> doInCollection(DBCollection collection) throws MongoException, DataAccessException { MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityType); DBObject mappedFields = queryMapper.getMappedFields(query.getFieldsObject(), persistentEntity); DBObject mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), persistentEntity); DBCursor cursor = collection.find(mappedQuery, mappedFields); QueryCursorPreparer cursorPreparer = new QueryCursorPreparer(query, entityType); ReadDbObjectCallback<T> readCallback = new ReadDbObjectCallback<T>(mongoConverter, entityType, collection.getName()); return new CloseableIterableCursorAdapter<T>(cursorPreparer.prepare(cursor), exceptionTranslator, readCallback); } }); }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
License:Apache License
protected <T> WriteResult doRemove(final String collectionName, final Query query, final Class<T> entityClass) { if (query == null) { throw new InvalidDataAccessApiUsageException("Query passed in to remove can't be null!"); }//ww w.ja v a 2 s. com Assert.hasText(collectionName, "Collection name must not be null or empty!"); final DBObject queryObject = query.getQueryObject(); final MongoPersistentEntity<?> entity = getPersistentEntity(entityClass); return execute(collectionName, new CollectionCallback<WriteResult>() { public WriteResult doInCollection(DBCollection collection) throws MongoException, DataAccessException { maybeEmitEvent(new BeforeDeleteEvent<T>(queryObject, entityClass, collectionName)); DBObject dboq = queryMapper.getMappedObject(queryObject, entity); MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.REMOVE, collectionName, entityClass, null, queryObject); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Remove using query: {} in collection: {}.", new Object[] { serializeToJsonSafely(dboq), collection.getName() }); } WriteResult wr = writeConcernToUse == null ? collection.remove(dboq) : collection.remove(dboq, writeConcernToUse); handleAnyWriteResultErrors(wr, dboq, MongoActionOperation.REMOVE); maybeEmitEvent(new AfterDeleteEvent<T>(queryObject, entityClass, collectionName)); return wr; } }); }