当前位置: 首页>>代码示例>>Java>>正文


Java JacksonDBCollection类代码示例

本文整理汇总了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;
}
 
开发者ID:eeb,项目名称:dropwizard-mongo,代码行数:18,代码来源:CollectionIdsResource.java

示例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());
    }

}
 
开发者ID:eeb,项目名称:dropwizard-mongo-cms,代码行数:25,代码来源:BasicPageResource.java

示例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();
     }

}
 
开发者ID:eeb,项目名称:dropwizard-mongo-cms,代码行数:31,代码来源:BasicPageResource.java

示例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;
   }
 
开发者ID:domguinard,项目名称:mongodb-3-drivers-tutorial,代码行数:19,代码来源:DatasourceProviderMongoJack.java

示例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));
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:10,代码来源:MongoDbRuleService.java

示例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));
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:10,代码来源:MongoDbPipelineService.java

示例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());
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-collector,代码行数:10,代码来源:CollectorConfigurationService.java

示例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());

}
 
开发者ID:Graylog2,项目名称:graylog-plugin-collector,代码行数:16,代码来源:CollectorServiceImpl.java

示例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;
}
 
开发者ID:cvtienhoven,项目名称:graylog-plugin-aggregates,代码行数:14,代码来源:RuleServiceImpl.java

示例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);

}
 
开发者ID:guggens,项目名称:log-dropwizard-eureka-mongo-sample,代码行数:11,代码来源:LogWriterResource.java

示例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;
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:11,代码来源:TruckingManagerBean.java

示例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;
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:11,代码来源:TruckingManagerBean.java

示例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;
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:12,代码来源:TruckingManagerBean.java

示例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);
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:14,代码来源:CivilizationApplication.java


注:本文中的org.mongojack.JacksonDBCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。