本文整理汇总了Java中org.mongojack.JacksonDBCollection类的典型用法代码示例。如果您正苦于以下问题:Java JacksonDBCollection类的具体用法?Java JacksonDBCollection怎么用?Java JacksonDBCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JacksonDBCollection类属于org.mongojack包,在下文中一共展示了JacksonDBCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetch
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@GET
public List<MongoDocument> fetch(@PathParam("collection") String collection) {
final JacksonDBCollection<MongoDocument, String> coll = JacksonDBCollection.wrap(mongoDB.getCollection(collection), MongoDocument.class,
String.class);
final DBCursor<MongoDocument> cursor = coll.find();
final List<MongoDocument> l = new ArrayList<>();
try {
while(cursor.hasNext()) {
l.add(cursor.next());
}
}finally {
cursor.close();
}
return l;
}
示例2: put
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public MongoDocument put(@Valid BasicPage newPage) {
try {
final JacksonDBCollection<BasicPage,String> col = JacksonDBCollection.wrap(mongoDb.getCollection("assets"),
BasicPage.class, String.class);
WriteResult<BasicPage, String> res = null;
res = col.insert(newPage);
MongoDocument d = new MongoDocument();
d.setId(((ObjectId)res.getDbObject().get("_id")).toString());
return d;
} catch(Exception e) {
Response.ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
response.entity("{\"message\":\""+e.getMessage()+"\"}");
//TODO: Add logging
throw new WebApplicationException(response.build());
}
}
示例3: get
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
/**
* Returns a {@link com.eeb.dropwizardmongo.cms.api.BasicPage} using the slug as a query parameter.
* @param slug
* @return {@code BasicPage} object or a 403 if the object can not be found.
*/
@GET
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_JSON)
public BasicPageView get(@PathParam("slug") String slug) {
JacksonDBCollection<BasicPage,String> col = JacksonDBCollection.wrap(mongoDb.getCollection("assets"),
BasicPage.class, String.class);
//Note: MongoJack does not support the AutoClose interface
DBCursor<BasicPage> cursor = col.find(new BasicDBObject("metadata.slug",slug));
try {
if(!cursor.hasNext()) {
Response.ResponseBuilder response = Response.status(Response.Status.FORBIDDEN);
response.entity("{\"message\":\"Object not found\"}");
throw new WebApplicationException(response.build());
} else {
return new BasicPageView(cursor.next());
}
} finally {
cursor.close();
}
}
示例4: loadResources
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Override
public <T> List<T> loadResources(String collection, Class<T> cl) {
// Shell query: db.xxx.find();
List<T> results = new ArrayList<T>();
DBCollection collec = db.getCollection("Fridges");
try {
JacksonDBCollection<T, String> collecMj = JacksonDBCollection.wrap(collec,
cl, String.class);
Iterable<T> all = collecMj.find();
for (T current : all) {
results.add(current);
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println(ex);
}
return results;
}
示例5: MongoDbRuleService
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Inject
public MongoDbRuleService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper) {
dbCollection = JacksonDBCollection.wrap(
mongoConnection.getDatabase().getCollection(COLLECTION),
RuleDao.class,
String.class,
mapper.get());
dbCollection.createIndex(DBSort.asc("title"), new BasicDBObject("unique", true));
}
示例6: MongoDbPipelineStreamConnectionsService
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Inject
public MongoDbPipelineStreamConnectionsService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper) {
dbCollection = JacksonDBCollection.wrap(
mongoConnection.getDatabase().getCollection(COLLECTION),
PipelineConnections.class,
String.class,
mapper.get());
dbCollection.createIndex(DBSort.asc("stream_id"), new BasicDBObject("unique", true));
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:10,代码来源:MongoDbPipelineStreamConnectionsService.java
示例7: MongoDbPipelineService
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Inject
public MongoDbPipelineService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper) {
dbCollection = JacksonDBCollection.wrap(
mongoConnection.getDatabase().getCollection(COLLECTION),
PipelineDao.class,
String.class,
mapper.get());
dbCollection.createIndex(DBSort.asc("title"), new BasicDBObject("unique", true));
}
示例8: CollectorConfigurationService
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Inject
public CollectorConfigurationService(MongoConnection mongoConnection,
MongoJackObjectMapperProvider mapper) {
dbCollection = JacksonDBCollection.wrap(
mongoConnection.getDatabase().getCollection(COLLECTION_NAME),
CollectorConfiguration.class,
ObjectId.class,
mapper.get());
}
示例9: CollectorServiceImpl
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Inject
public CollectorServiceImpl(MongoConnection mongoConnection,
MongoJackObjectMapperProvider mapperProvider,
Validator validator) {
this.validator = validator;
final String collectionName = CollectorImpl.class.getAnnotation(CollectionName.class).value();
final DBCollection dbCollection = mongoConnection.getDatabase().getCollection(collectionName);
this.coll = JacksonDBCollection.wrap(dbCollection, CollectorImpl.class, String.class, mapperProvider.get());
this.coll.createIndex(new BasicDBObject("id", 1), new BasicDBObject("unique", true));
final String actionCollectionName = CollectorActions.class.getAnnotation(CollectionName.class).value();
final DBCollection actionDbCollection = mongoConnection.getDatabase().getCollection(actionCollectionName);
this.collActions = JacksonDBCollection.wrap(actionDbCollection, CollectorActions.class, String.class, mapperProvider.get());
}
示例10: RuleServiceImpl
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Inject
public RuleServiceImpl(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapperProvider,
Validator validator, StreamService streamService, AlertConditionFactory alertConditionFactory,
HistoryItemService historyItemService) {
this.validator = validator;
final String collectionName = RuleImpl.class.getAnnotation(CollectionName.class).value();
final DBCollection dbCollection = mongoConnection.getDatabase().getCollection(collectionName);
this.coll = JacksonDBCollection.wrap(dbCollection, RuleImpl.class, String.class, mapperProvider.get());
this.coll.createIndex(new BasicDBObject("name", 1), new BasicDBObject("unique", true));
this.streamService = streamService;
this.alertConditionFactory = alertConditionFactory;
this.historyItemService = historyItemService;
}
示例11: LogWriterResource
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
public LogWriterResource(String template, String defaultName, DB db) {
this.template = template;
this.defaultName = defaultName;
this.counter = new AtomicLong();
this.mongoDB = db;
mongoDB.getCollection(LOG_COLLECTION).createIndex(new BasicDBObject("timestamp", -1));
entries = JacksonDBCollection.wrap(mongoDB.getCollection(LOG_COLLECTION), Log.class,
String.class);
}
示例12: getHubs
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Override
public List<Hub> getHubs() {
JacksonDBCollection<Hub, String> col = JacksonDBCollection.wrap(
mongoDB.getCollection("hubs"), Hub.class, String.class);
List<Hub> res = new ArrayList<Hub>();
for (Hub s : col.find()) {
res.add(s);
}
return res;
}
示例13: getSpokes
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Override
public List<Spoke> getSpokes() {
JacksonDBCollection<Spoke, String> col = JacksonDBCollection.wrap(
mongoDB.getCollection("spokes"), Spoke.class, String.class);
List<Spoke> res = new ArrayList<Spoke>();
for (Spoke s : col.find()) {
res.add(s);
}
return res;
}
示例14: getTruckTypes
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
@Override
public List<TruckType> getTruckTypes() {
JacksonDBCollection<TruckType, String> col = JacksonDBCollection.wrap(
mongoDB.getCollection("truckTypes"), TruckType.class,
String.class);
List<TruckType> res = new ArrayList<TruckType>();
for (TruckType s : col.find()) {
res.add(s);
}
return res;
}
示例15: createUsernameCache
import org.mongojack.JacksonDBCollection; //导入依赖的package包/类
private void createUsernameCache(JacksonDBCollection<Player, String> playerCollection) {
LoadingCache<String, String> usernameCache = CacheBuilder.newBuilder()
.expireAfterWrite(2, TimeUnit.HOURS)
.maximumSize(100)
.removalListener(lis -> log.debug("Removing " + lis.toString() + " from the usernameCache"))
.build(new CacheLoader<String, String>() {
public String load(String playerId) {
return playerCollection.findOneById(playerId).getUsername();
}
});
CivSingleton.instance().setPlayerCache(usernameCache);
}