本文整理汇总了Java中com.mongodb.WriteResult.getError方法的典型用法代码示例。如果您正苦于以下问题:Java WriteResult.getError方法的具体用法?Java WriteResult.getError怎么用?Java WriteResult.getError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.WriteResult
的用法示例。
在下文中一共展示了WriteResult.getError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCall
import com.mongodb.WriteResult; //导入方法依赖的package包/类
/**
* Add the specified mvc to the specified database
*
* @param dbSpecPath
* @param mvc
* @return
*/
static String addCall(String dbSpecPath, MongoVariantContext mvc) {
NA12878DBArgumentCollection args = new NA12878DBArgumentCollection(dbSpecPath);
String errorMessage = null;
NA12878KnowledgeBase kb = null;
try {
kb = new NA12878KnowledgeBase(null, args);
WriteResult wr = kb.addCall(mvc);
errorMessage = wr.getError();
} catch (Exception ex) {
errorMessage = ex.getMessage();
if (errorMessage == null) errorMessage = "" + ex;
} finally {
if (kb != null) kb.close();
}
return errorMessage;
}
示例2: insertJetStreamConfiguration
import com.mongodb.WriteResult; //导入方法依赖的package包/类
/**
* UPLOAD TO DB
*/
public static void insertJetStreamConfiguration(BasicDBObject dbObject,
MongoLogConnection mongoLogConnection) {
JetStreamBeanConfigurationLogDo beanConfig = null;
DBCollection dbCol = mongoLogConnection.getDBCollection();
if (dbCol == null) {
throw new MongoConfigRuntimeException(
"jetstreamconfig collection is unknown");
}
WriteResult result = dbCol.insert(dbObject);
if (result.getError() != null) {
throw new MongoConfigRuntimeException(result.getError());
}
}
示例3: execute
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
public Result execute() {
List<Column> colNames = update.getColumns();
List<Expression> values = update.getExpressions();
BasicDBObject updateExpr = new BasicDBObject();
for (int i = 0; i < colNames.size(); ++i) {
updateExpr.append(colNames.get(i).getColumnName(),
MongoStringUtils.trimSingleQuotes(values.get(i).toString()));
}
MongoWhereExpressionVisitor whereExprVisitor = new MongoWhereExpressionVisitor();
Expression updateWhere = update.getWhere();
if (updateWhere != null) {
updateWhere.accept(whereExprVisitor);
}
DBCollection coll = MongoClient.getDatastore().getCollection(collection);
WriteResult wr = coll.update(whereExprVisitor.getExpression(), new BasicDBObject("$set", updateExpr));
return new MongoResult<String>(wr.getError() == null ? "" : wr.getError());
}
示例4: insertJetStreamConfiguration
import com.mongodb.WriteResult; //导入方法依赖的package包/类
/**
* UPLOAD TO DB
*/
public static void insertJetStreamConfiguration(BasicDBObject dbObject, MongoConnection mongoConnection) {
JetStreamBeanConfigurationDo beanConfig = null;
DBCollection dbCol = mongoConnection.getDBCollection();
if (dbCol == null) {
throw new MongoConfigRuntimeException("jetstreamconfig collection is unknown");
}
WriteResult result = dbCol.insert(dbObject);
if (result.getError() != null) {
throw new MongoConfigRuntimeException(result.getError());
}
}
示例5: mark
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
protected void mark(BlockId blockId) throws Exception {
if (minLastModified == 0) {
return;
}
String id = StringUtils.convertBytesToHex(blockId.getDigest());
DBObject query = getBlobQuery(id, minLastModified);
DBObject update = new BasicDBObject("$set",
new BasicDBObject(MongoBlob.KEY_LAST_MOD, System.currentTimeMillis()));
WriteResult writeResult = getBlobCollection().update(query, update);
if (writeResult.getError() != null) {
LOG.error("Mark failed for blob %s: %s", id, writeResult.getError());
}
}
示例6: sweep
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
public int sweep() throws IOException {
DBObject query = getBlobQuery(null, minLastModified);
long countBefore = getBlobCollection().count(query);
WriteResult writeResult = getBlobCollection().remove(query);
if (writeResult.getError() != null) {
LOG.error("Sweep failed: %s", writeResult.getError());
}
long countAfter = getBlobCollection().count(query);
minLastModified = 0;
return (int) (countBefore - countAfter);
}
示例7: deleteSplitDocuments
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
public int deleteSplitDocuments(Set<SplitDocType> gcTypes, long oldestRevTimeStamp) {
//OR condition has to be first as we have a index for that
//((type == DEFAULT_NO_CHILD || type == PROP_COMMIT_ONLY ..) && _sdMaxRevTime < oldestRevTimeStamp(in secs)
QueryBuilder orClause = start();
for(SplitDocType type : gcTypes){
orClause.or(start(NodeDocument.SD_TYPE).is(type.typeCode()).get());
}
DBObject query = start()
.and(
orClause.get(),
start(NodeDocument.SD_MAX_REV_TIME_IN_SECS)
.lessThan(NodeDocument.getModifiedInSecs(oldestRevTimeStamp))
.get()
).get();
if(log.isDebugEnabled()){
//if debug level logging is on then determine the id of documents to be deleted
//and log them
logSplitDocIdsTobeDeleted(query);
}
WriteResult writeResult = getNodeCollection().remove(query, WriteConcern.SAFE);
if (writeResult.getError() != null) {
//TODO This might be temporary error or we fail fast and let next cycle try again
log.warn("Error occurred while deleting old split documents from Mongo {}", writeResult.getError());
}
return writeResult.getN();
}
示例8: remove
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
public <T extends Document> void remove(Collection<T> collection, String key) {
log("remove", key);
DBCollection dbCollection = getDBCollection(collection);
long start = start();
try {
WriteResult writeResult = dbCollection.remove(getByKeyQuery(key).get(), WriteConcern.SAFE);
invalidateCache(collection, key);
if (writeResult.getError() != null) {
throw new MicroKernelException("Remove failed: " + writeResult.getError());
}
} finally {
end("remove", start);
}
}
示例9: insert
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
/**
* Insert a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified
* record key.
*
* @param table The name of the table
* @param key The record key of the record to insert.
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
*/
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
com.mongodb.DB db = null;
try {
db = mongo.getDB(database);
db.requestStart();
DBCollection collection = db.getCollection(table);
DBObject r = new BasicDBObject().append("_id", key);
for(String k: values.keySet()) {
r.put(k, values.get(k).toArray());
}
WriteResult res = collection.insert(r,writeConcern);
return res.getError() == null ? 0 : 1;
} catch (Exception e) {
System.err.println(e.toString());
return 1;
} finally {
if (db!=null)
{
db.requestDone();
}
}
}
示例10: insertObject
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
public void insertObject(final NoSQLObject<BasicDBObject> object) {
try {
final WriteResult result = this.collection.insert(object.unwrap(), this.writeConcern);
if (result.getError() != null && result.getError().length() > 0) {
throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " +
result.getError() + ".");
}
} catch (final MongoException e) {
throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " + e.getMessage(),
e);
}
}
示例11: insertNodeAspect
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
protected void insertNodeAspect(Long nodeId, Long qnameId)
{
// Get the current transaction ID.
Long txnId = getCurrentTransactionId(true);
// Resolve the QName
QName qname = qnameDAO.getQName(qnameId).getSecond();
String qnameStr = qname.toString();
DBObject insertObj = BasicDBObjectBuilder
.start()
.add(FIELD_NODE_ID, nodeId)
.add(FIELD_TXN_ID, txnId)
.add(FIELD_QNAME, qnameStr)
.get();
WriteResult result = aspects.insert(insertObj);
if (result.getError() != null)
{
throw new ConcurrencyFailureException(
"Failed to insert aspect: " + result + "\n" +
" Node ID: " + nodeId + "\n" +
" QName: " + qnameStr + "\n" +
" Txn ID: " + txnId);
}
if (duplicateToSql)
{
// Duplicate
super.insertNodeAspect(nodeId, qnameId);
}
}
示例12: insert
import com.mongodb.WriteResult; //导入方法依赖的package包/类
@Override
/**
* Insert a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified
* record key.
*
* @param table The name of the table
* @param key The record key of the record to insert.
* @param values A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
*/
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
com.mongodb.DB db = null;
try {
db = mongo.getDB(database);
db.requestStart();
DBCollection collection = db.getCollection(table);
DBObject r = new BasicDBObject().append("_id", key);
for(String k: values.keySet()) {
r.put(k, values.get(k).toArray());
}
WriteResult res = collection.insert(r,writeConcern);
return res.getError() == null ? 0 : 1;
} catch (Exception e) {
e.printStackTrace();
return 1;
} finally {
if (db!=null)
{
db.requestDone();
}
}
}
示例13: Result
import com.mongodb.WriteResult; //导入方法依赖的package包/类
public Result(WriteResult result) {
error = result.getError();
count = result.getN();
}
示例14: upsert
import com.mongodb.WriteResult; //导入方法依赖的package包/类
private boolean upsert(DBCollection collection, DBObject dbObject) {
WriteResult result = collection.update(dbObject, dbObject, true, false,
WriteConcern.UNACKNOWLEDGED);
return result.getError() == null;
}
示例15: runCommand
import com.mongodb.WriteResult; //导入方法依赖的package包/类
public ArrayList<String> runCommand(List<String> params) {
ArrayList<String> path = GetPath.getSearchPath(params.get(0));
ArrayList<String> result=new ArrayList<String>();
//Search if file exists
Map<String, Object> constraints = new HashMap<String, Object>();
constraints.put("name", path.get(0));
constraints.put("path", path.get(1));
constraints.put("isDirectory", false);
ArrayList<UserFile> receivedFile = mongoConnect.getFiles(constraints);
if(receivedFile.size()!=0) //File exists.. change the timestamp
{
receivedFile.get(0).setTimestamp(new Date());
result.add(ICommand.SUCCESS);
}
else //create new userfile and add it to db
{
UserFile file = new UserFile();
Date date = new Date();
long range = 123456L;
Random r = new Random();
long number = (long)(r.nextDouble()*range);
file.setId(number);
file.setName(path.get(0));
file.setFiletypeId(1);
file.setPath(path.get(1));
file.setFile_size(1234);
file.setTimestamp(date);
file.setDate_created(date);
file.setDate_updated(date);
file.setUser_created(1); //get userid
file.setUser_updated(1);
file.setDirectory(false);
file.setData(null);
WriteResult createResult = mongoConnect.createFile(file);
if(createResult.getError()==null)
result.add(ICommand.SUCCESS);
else
{
result.add(ICommand.FAILURE);
result.add("touch: Unable to create new file.");
}
}
result.add("touch is used to create a new empty file.\nThe operating system creates a file descriptor for the file and sets the location of the file within the diectory structure.\nThe file now has all the properties of any other file except the actual data, which can now be added to it.");
return result;
}