本文整理汇总了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;未经允许,请勿转载。 |
请发表评论