• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MongoClientException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.mongodb.MongoClientException的典型用法代码示例。如果您正苦于以下问题:Java MongoClientException类的具体用法?Java MongoClientException怎么用?Java MongoClientException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoClientException类属于com.mongodb包,在下文中一共展示了MongoClientException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: insertData

import com.mongodb.MongoClientException; //导入依赖的package包/类
public void insertData(String schemaName, String tableName, DBObject naive, DBObject complete) {
    int i = 0;
    DBObject logObj = (DBObject) ObjectUtils.clone(complete);
    //保存原始数据
    try {
        String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.INSERT.getNumber();
        i++;
        naiveMongoTemplate.getCollection(tableName).insert(naive);
        i++;
        SpringUtil.doEvent(path, complete);
        i++;
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 1, i, logObj, e);
    }
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:19,代码来源:DataService.java


示例2: updateData

import com.mongodb.MongoClientException; //导入依赖的package包/类
public void updateData(String schemaName, String tableName, DBObject query, DBObject obj) {
    String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.UPDATE.getNumber();
    int i = 0;
    DBObject newObj = (DBObject) ObjectUtils.clone(obj);
    DBObject logObj = (DBObject) ObjectUtils.clone(obj);
    //保存原始数据
    try {
        obj.removeField("id");
        i++;
        naiveMongoTemplate.getCollection(tableName).update(query, obj);
        i++;
        SpringUtil.doEvent(path, newObj);
        i++;
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 2, i, logObj, e);
    }
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:21,代码来源:DataService.java


示例3: deleteData

import com.mongodb.MongoClientException; //导入依赖的package包/类
public void deleteData(String schemaName, String tableName, DBObject obj) {
    int i = 0;
    String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.DELETE.getNumber();
    DBObject newObj = (DBObject) ObjectUtils.clone(obj);
    DBObject logObj = (DBObject) ObjectUtils.clone(obj);
    //保存原始数据
    try {
        i++;
        if (obj.containsField("id")) {
            naiveMongoTemplate.getCollection(tableName).remove(new BasicDBObject("_id", obj.get("id")));
        }
        i++;
        SpringUtil.doEvent(path, newObj);
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 3, i, logObj, e);
    }
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:21,代码来源:DataService.java


示例4: createMongoDatabase

import com.mongodb.MongoClientException; //导入依赖的package包/类
private MongoDatabase createMongoDatabase(
    Stage.Context context,
    List<Stage.ConfigIssue> issues,
    ReadPreference readPreference,
    WriteConcern writeConcern
) {
  MongoDatabase mongoDatabase = null;
  try {
    if (readPreference != null) {
      mongoDatabase = mongoClient.getDatabase(database).withReadPreference(readPreference);
    } else if (writeConcern != null) {
      mongoDatabase = mongoClient.getDatabase(database).withWriteConcern(writeConcern);
    }
  } catch (MongoClientException e) {
    issues.add(context.createConfigIssue(
        Groups.MONGODB.name(),
        MONGO_CONFIG_PREFIX + "database",
        Errors.MONGODB_02,
        database,
        e.toString()
    ));
  }
  return mongoDatabase;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:25,代码来源:MongoDBConfig.java


示例5: createMongoCollection

import com.mongodb.MongoClientException; //导入依赖的package包/类
private MongoCollection createMongoCollection(
    Stage.Context context,
    List<Stage.ConfigIssue> issues,
    ReadPreference readPreference,
    WriteConcern writeConcern
) {
  MongoCollection mongoCollection = null;
  try {
    if (readPreference != null) {
      mongoCollection = mongoDatabase.getCollection(collection).withReadPreference(readPreference);
    } else if (writeConcern != null) {
      mongoCollection = mongoDatabase.getCollection(collection).withWriteConcern(writeConcern);
    }
  } catch (MongoClientException e) {
    issues.add(context.createConfigIssue(
        Groups.MONGODB.name(),
        MONGO_CONFIG_PREFIX + "collection",
        Errors.MONGODB_03,
        collection,
        e.toString()
    ));
  }
  return mongoCollection;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:25,代码来源:MongoDBConfig.java


示例6: check

import com.mongodb.MongoClientException; //导入依赖的package包/类
/**
 * Checks if the system database, available in all MongoDB instances can be
 * reached.
 */
@Override
protected Result check() throws Exception {
  try {
    final Document result = mongoDatabase.runCommand(new Document("dbStats", 1));
    return Result.healthy(result.toJson());
  } catch (MongoClientException exc) {
    logger.warn("Unhealthy database", exc);
    return Result.unhealthy(exc);
  }
}
 
开发者ID:atgse,项目名称:sam,代码行数:15,代码来源:MongoDatabaseHealthCheck.java


示例7: deleteArtifact

import com.mongodb.MongoClientException; //导入依赖的package包/类
private void deleteArtifact(final GridFSDBFile dbFile) {
    if (dbFile != null) {
        try {
            gridFs.delete(new Query().addCriteria(Criteria.where(ID).is(dbFile.getId())));
        } catch (final MongoClientException e) {
            throw new ArtifactStoreException(e.getMessage(), e);
        }
    }

}
 
开发者ID:eclipse,项目名称:hawkbit-extensions,代码行数:11,代码来源:MongoDBArtifactStore.java


示例8: deleteByTenant

import com.mongodb.MongoClientException; //导入依赖的package包/类
@Override
public void deleteByTenant(final String tenant) {
    try {
        gridFs.delete(new Query().addCriteria(Criteria.where(TENANT_QUERY).is(sanitizeTenant(tenant))));
    } catch (final MongoClientException e) {
        throw new ArtifactStoreException(e.getMessage(), e);
    }
}
 
开发者ID:eclipse,项目名称:hawkbit-extensions,代码行数:9,代码来源:MongoDBArtifactStore.java


示例9: check

import com.mongodb.MongoClientException; //导入依赖的package包/类
/**
 * Checks if the system database, which exists in all MongoDB instances can be reached.
 * @return A Result object
 * @throws Exception
 */
@Override
protected Result check() throws Exception {

    try {
        mongoClient.getDB("system").getStats();
    }catch(MongoClientException ex) {
        return Result.unhealthy(ex.getMessage());
    }
    return Result.healthy();
}
 
开发者ID:guggens,项目名称:log-dropwizard-eureka-mongo-sample,代码行数:16,代码来源:MongoHealthCheck.java


示例10: check

import com.mongodb.MongoClientException; //导入依赖的package包/类
/**
 * Checks if the system database, which exists in all MongoDB instances can be reached.
 * @return A Result object
 * @throws Exception
 */
@Override
protected Result check() throws Exception {

    try {
        mongoClient.getDB("system").getStats();
    }catch(MongoClientException ex) {
        return Result.unhealthy(ex.getMessage());
    }


    return Result.healthy();
}
 
开发者ID:eeb,项目名称:dropwizard-mongo,代码行数:18,代码来源:MongoHealthCheck.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JarClassSource类代码示例发布时间:2022-05-23
下一篇:
Java Mark类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap