use of com.mongodb.DBCollection in project sling by apache.
the class MongoDBResourceProvider method listChildren.
/**
* TODO - we have to check for deleted and added resources
* @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
*/
public Iterator<Resource> listChildren(final Resource parent) {
final String[] info = this.extractResourceInfo(parent.getPath());
if (info != null) {
if (info.length == 0) {
// all collections
final Set<String> names = new HashSet<String>(context.getDatabase().getCollectionNames());
names.removeAll(this.context.getFilterCollectionNames());
final Iterator<String> i = names.iterator();
return new Iterator<Resource>() {
public boolean hasNext() {
return i.hasNext();
}
public Resource next() {
final String name = i.next();
return new MongoDBCollectionResource(parent.getResourceResolver(), parent.getPath() + '/' + name);
}
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
}
final DBCollection col = this.getCollection(info[0]);
if (col != null) {
final String pattern;
if (info.length == 1) {
pattern = "^([^/])*$";
} else {
pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
}
final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
final DBCursor cur = col.find(query).sort(BasicDBObjectBuilder.start(getPROP_PATH(), 1).get());
return new Iterator<Resource>() {
public boolean hasNext() {
return cur.hasNext();
}
public Resource next() {
final DBObject obj = cur.next();
final String objPath = obj.get(getPROP_PATH()).toString();
final int lastSlash = objPath.lastIndexOf('/');
final String name;
if (lastSlash == -1) {
name = objPath;
} else {
name = objPath.substring(lastSlash + 1);
}
return new MongoDBResource(parent.getResourceResolver(), parent.getPath() + '/' + name, info[0], obj, MongoDBResourceProvider.this);
}
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
}
}
return null;
}
use of com.mongodb.DBCollection in project sling by apache.
the class MongoDBResourceProvider method getResource.
/**
* Get a resource
*/
protected Resource getResource(final ResourceResolver resourceResolver, final String path, final String[] info) {
if (info.length == 0) {
// special resource : all collections
return new MongoDBCollectionResource(resourceResolver, path);
} else if (info.length == 1) {
// special resource : collection
if (this.hasCollection(info[0])) {
return new MongoDBCollectionResource(resourceResolver, path);
}
return null;
}
logger.debug("Searching {} in {}", info[1], info[0]);
final DBCollection col = this.getCollection(info[0]);
if (col != null) {
final DBObject obj = col.findOne(QueryBuilder.start(getPROP_PATH()).is(info[1]).get());
logger.debug("Found {}", obj);
if (obj != null) {
return new MongoDBResource(resourceResolver, path, info[0], obj, this);
}
}
return null;
}
use of com.mongodb.DBCollection in project spring-data-mongodb by spring-projects.
the class PerformanceTests method writingObjectsUsingPlainDriver.
private long writingObjectsUsingPlainDriver(int numberOfPersons) {
DBCollection collection = mongo.getDB(DATABASE_NAME).getCollection("driver");
List<Person> persons = getPersonObjects(numberOfPersons);
executeWatched(() -> persons.stream().map(it -> collection.save(new BasicDBObject(it.toDocument()))));
return watch.getLastTaskTimeMillis();
}
use of com.mongodb.DBCollection in project spring-data-mongodb by spring-projects.
the class PerformanceTests method queryUsingPlainDriver.
private long queryUsingPlainDriver() {
executeWatched(() -> {
DBCollection collection = mongo.getDB(DATABASE_NAME).getCollection("driver");
BasicDBObject regex = new BasicDBObject("$regex", Pattern.compile(".*1.*"));
BasicDBObject query = new BasicDBObject("addresses.zipCode", regex);
return toPersons(collection.find(query));
});
return watch.getLastTaskTimeMillis();
}
use of com.mongodb.DBCollection in project cas by apereo.
the class MongoDbTicketRegistry method createTicketCollections.
private void createTicketCollections() {
final Collection<TicketDefinition> definitions = ticketCatalog.findAll();
final MongoDbConnectionFactory factory = new MongoDbConnectionFactory();
definitions.forEach(t -> {
final DBCollection c = createTicketCollection(t, factory);
LOGGER.debug("Created MongoDb collection configuration for [{}]", c.getFullName());
});
}
Aggregations