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


Java CommandResult.getException方法代码示例

本文整理汇总了Java中com.mongodb.CommandResult.getException方法的典型用法代码示例。如果您正苦于以下问题:Java CommandResult.getException方法的具体用法?Java CommandResult.getException怎么用?Java CommandResult.getException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.CommandResult的用法示例。


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

示例1: insert

import com.mongodb.CommandResult; //导入方法依赖的package包/类
@Override
public String insert(String statement, Object parameter) {
  logger.debug("Execute 'insert' mongodb command. Statement '" + statement + "'.");

  InsertConfig config = (InsertConfig) configuration.getConfig(statement);
  if (config == null) {
    throw new MongoDaoException(statement, "Insert statement id '" + statement + "' not found.");
  }

  String collection = config.getCollection();
  NodeEntry document = config.getDocument();
  Entry selectKey = config.getSelectKey();

  DB db = factory.getDataSource().getDB();

  DBCollection coll = db.getCollection(collection);
  
  Map<String, Object> doc = (Map<String, Object>) document.executorNode(configuration, parameter);

  DBObject docDbo = new BasicDBObject(doc);
  logger.debug("Execute 'insert' mongodb command. Doc '" + docDbo + "'.");

  WriteResult writeResult = coll.insert(docDbo, WriteConcern.SAFE);
  CommandResult commandResult = writeResult.getLastError(WriteConcern.SAFE);
  if (commandResult.getException() != null) {
    throw new MongoDaoException(statement, "Execute 'insert' mongodb command has exception. Cause: " + commandResult.getErrorMessage());
  }

  String newId = docDbo.get("_id").toString();
  logger.debug("Execute 'insert' mongodb command. ObjectId is '" + newId + "'.");

  if (selectKey != null) {
    helper.setSelectKey(selectKey, newId, parameter);
  }
  return newId;
}
 
开发者ID:yuxiangping,项目名称:mongodb-orm,代码行数:37,代码来源:MongoClientTemplet.java

示例2: update

import com.mongodb.CommandResult; //导入方法依赖的package包/类
@Override
public int update(String statement, Object parameter) {
  logger.debug("Execute 'update' mongodb command. Statement '" + statement + "'.");

  UpdateConfig config = (UpdateConfig) configuration.getConfig(statement);
  if (config == null) {
    throw new MongoDaoException(statement, "Update statement id '" + statement + "' not found.");
  }

  String collection = config.getCollection();
  NodeEntry query = config.getQuery();
  NodeEntry action = config.getAction();

  DB db = factory.getDataSource().getDB();

  DBCollection coll = db.getCollection(collection);

  Map<String, Object> q = (Map<String, Object>) query.executorNode(configuration, parameter);
  Map<String, Object> a = (Map<String, Object>) action.executorNode(configuration, parameter);
  
  DBObject queryDbo = new BasicDBObject(q);
  logger.debug("Execute 'update' mongodb command. Query '" + queryDbo + "'.");

  DBObject actionDbo = (a == null) ? null : new BasicDBObject(a);
  logger.debug("Execute 'update' mongodb command. Action '" + actionDbo + "'.");

  WriteResult writeResult = coll.update(queryDbo, actionDbo, false, true, WriteConcern.SAFE);
  CommandResult commandResult = writeResult.getLastError(WriteConcern.SAFE);
  if (commandResult.getException() != null) {
    throw new MongoDaoException(statement, "Execute 'update' mongodb command has exception. Cause: " + commandResult.getErrorMessage());
  }
  return writeResult.getN();
}
 
开发者ID:yuxiangping,项目名称:mongodb-orm,代码行数:34,代码来源:MongoClientTemplet.java

示例3: delete

import com.mongodb.CommandResult; //导入方法依赖的package包/类
@Override
public int delete(String statement, Object parameter) {
  logger.debug("Execute 'delete' mongodb command. Statement '" + statement + "'.");

  DeleteConfig config = (DeleteConfig) configuration.getConfig(statement);
  if (config == null) {
    throw new MongoDaoException(statement, "Delete statement id '" + statement + "' not found.");
  }

  String collection = config.getCollection();
  NodeEntry query = config.getQuery();

  DB db = factory.getDataSource().getDB();

  DBCollection coll = db.getCollection(collection);

  Map<String, Object> q = (Map<String, Object>) query.executorNode(configuration, parameter);

  DBObject queryDbo = new BasicDBObject(q);
  logger.debug("Execute 'delete' mongodb command. Query '" + queryDbo + "'.");

  WriteResult writeResult = coll.remove(queryDbo, WriteConcern.SAFE);
  CommandResult commandResult = writeResult.getLastError(WriteConcern.SAFE);
  if (commandResult.getException() != null) {
    throw new MongoDaoException(statement, "Execute 'delete' mongodb command has exception. Cause: " + commandResult.getErrorMessage());
  }
  return writeResult.getN();
}
 
开发者ID:yuxiangping,项目名称:mongodb-orm,代码行数:29,代码来源:MongoClientTemplet.java


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