static MongoException parse(final BSONObject o) { final String s = ServerError.getMsg(o, null); if (s == null) { return null; } return new MongoException(ServerError.getCode(o), s); }
public Response call(DB db, DBCollection coll, OutMessage m, int retries) throws MongoException { final MyPort mp = _threadPort.get(); final DBPort port = mp.get(false); port.checkAuth(db); Response res = null; try { res = port.call(m, coll); mp.done(port); } catch (IOException ioe) { mp.error(ioe); if (_error(ioe) && retries > 0) { return call(db, coll, m, retries - 1); } throw new MongoException.Network("can't call something", ioe); } catch (RuntimeException re) { mp.error(re); throw re; } ServerError err = res.getError(); if (err != null && err.isNotMasterError()) { _pickCurrent(); if (retries <= 0) { throw new MongoException("not talking to master and retries used up"); } return call(db, coll, m, retries - 1); } return res; }
private void insert() { if (mID >= 0) { LOGGER.warning("message already in db, ID: " + mID); return; } Database db = Database.getInstance(); List<Object> values = new LinkedList<>(); values.add(mThread.getID()); values.add(mDir); values.add(mUser.getID()); values.add(mJID); values.add(Database.setString(mXMPPID)); values.add(mDate); values.add(mReceiptStatus); // i simply don't like to save all possible content explicitly in the // database, so we use JSON here values.add(mContent.toJSONString()); values.add(mCoderStatus.getEncryption()); values.add(mCoderStatus.getSigning()); values.add(mCoderStatus.getErrors()); values.add(mServerError.toJSON()); values.add(mServerDate); int id = db.execInsert(TABLE, values); if (id <= 0) { LOGGER.log(Level.WARNING, "db, could not insert message"); mID = -2; return; } mID = id; }
public MongoException(final BSONObject o) { this(ServerError.getCode(o), ServerError.getMsg(o, "UNKNOWN")); }