mongo

16:39:10.358 INFO  jd.cli.Main - Decompiling mongo.jar
package com.mongodb;

public class AggregationOutput
{
  protected final CommandResult _commandResult;
  protected final DBObject _cmd;
  protected final Iterable<DBObject> _resultSet;
  
  public Iterable<DBObject> results()
  {
    return _resultSet;
  }
  
  public CommandResult getCommandResult()
  {
    return _commandResult;
  }
  
  public DBObject getCommand()
  {
    return _cmd;
  }
  
  public ServerAddress getServerUsed()
  {
    return _commandResult.getServerUsed();
  }
  
  public String toString()
  {
    return _commandResult.toString();
  }
  
  public AggregationOutput(DBObject cmd, CommandResult raw)
  {
    _commandResult = raw;
    _cmd = cmd;
    if (raw.containsField("result")) {
      _resultSet = ((Iterable)raw.get("result"));
    } else {
      throw new IllegalArgumentException("result undefined");
    }
  }
}

/* Location:
 * Qualified Name:     com.mongodb.AggregationOutput
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import com.mongodb.util.JSON;
import org.bson.types.BasicBSONList;

public class BasicDBList
  extends BasicBSONList
  implements DBObject
{
  private static final long serialVersionUID = -4415279469780082174L;
  private boolean _isPartialObject;
  
  public String toString()
  {
    return JSON.serialize(this);
  }
  
  public boolean isPartialObject()
  {
    return _isPartialObject;
  }
  
  public void markAsPartialObject()
  {
    _isPartialObject = true;
  }
  
  public Object copy()
  {
    BasicDBList newobj = new BasicDBList();
    for (int i = 0; i < size(); i++)
    {
      Object val = get(i);
      if ((val instanceof BasicDBObject)) {
        val = ((BasicDBObject)val).copy();
      } else if ((val instanceof BasicDBList)) {
        val = ((BasicDBList)val).copy();
      }
      newobj.add(val);
    }
    return newobj;
  }
}

/* Location:
 * Qualified Name:     com.mongodb.BasicDBList
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import com.mongodb.util.JSON;
import java.util.Map;
import org.bson.BasicBSONObject;

public class BasicDBObject
  extends BasicBSONObject
  implements DBObject
{
  private static final long serialVersionUID = -4415279469780082174L;
  private boolean _isPartialObject;
  
  public BasicDBObject() {}
  
  public BasicDBObject(int size)
  {
    super(size);
  }
  
  public BasicDBObject(String key, Object value)
  {
    super(key, value);
  }
  
  public BasicDBObject(Map m)
  {
    super(m);
  }
  
  public boolean isPartialObject()
  {
    return _isPartialObject;
  }
  
  public void markAsPartialObject()
  {
    _isPartialObject = true;
  }
  
  public String toString()
  {
    return JSON.serialize(this);
  }
  
  public BasicDBObject append(String key, Object val)
  {
    put(key, val);
    return this;
  }
  
  public Object copy()
  {
    BasicDBObject newobj = new BasicDBObject(toMap());
    for (String field : keySet())
    {
      Object val = get(field);
      if ((val instanceof BasicDBObject)) {
        newobj.put(field, ((BasicDBObject)val).copy());
      } else if ((val instanceof BasicDBList)) {
        newobj.put(field, ((BasicDBList)val).copy());
      }
    }
    return newobj;
  }
}

/* Location:
 * Qualified Name:     com.mongodb.BasicDBObject
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class BasicDBObjectBuilder
{
  private final LinkedList<DBObject> _stack;
  
  public BasicDBObjectBuilder()
  {
    _stack = new LinkedList();
    _stack.add(new BasicDBObject());
  }
  
  public static BasicDBObjectBuilder start()
  {
    return new BasicDBObjectBuilder();
  }
  
  public static BasicDBObjectBuilder start(String k, Object val)
  {
    return new BasicDBObjectBuilder().add(k, val);
  }
  
  public static BasicDBObjectBuilder start(Map m)
  {
    BasicDBObjectBuilder b = new BasicDBObjectBuilder();
    Iterator<Map.Entry> i = m.entrySet().iterator();
    while (i.hasNext())
    {
      Map.Entry entry = (Map.Entry)i.next();
      b.add(entry.getKey().toString(), entry.getValue());
    }
    return b;
  }
  
  public BasicDBObjectBuilder append(String key, Object val)
  {
    _cur().put(key, val);
    return this;
  }
  
  public BasicDBObjectBuilder add(String key, Object val)
  {
    return append(key, val);
  }
  
  public BasicDBObjectBuilder push(String key)
  {
    BasicDBObject o = new BasicDBObject();
    _cur().put(key, o);
    _stack.addLast(o);
    return this;
  }
  
  public BasicDBObjectBuilder pop()
  {
    if (_stack.size() <= 1) {
      throw new IllegalArgumentException("can't pop last element");
    }
    _stack.removeLast();
    return this;
  }
  
  public DBObject get()
  {
    return (DBObject)_stack.getFirst();
  }
  
  public boolean isEmpty()
  {
    return ((BasicDBObject)_stack.getFirst()).size() == 0;
  }
  
  private DBObject _cur()
  {
    return (DBObject)_stack.getLast();
  }
}

/* Location:
 * Qualified Name:     com.mongodb.BasicDBObjectBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

class Bytes$OptionHolder
{
  final OptionHolder _parent;
  
  Bytes$OptionHolder(OptionHolder parent)
  {
    _parent = parent;
  }
  
  void set(int options)
  {
    _options = options;
    _hasOptions = true;
  }
  
  int get()
  {
    if (_hasOptions) {
      return _options;
    }
    if (_parent == null) {
      return 0;
    }
    return _parent.get();
  }
  
  void add(int option)
  {
    set(get() | option);
  }
  
  void reset()
  {
    _hasOptions = false;
  }
  
  int _options = 0;
  boolean _hasOptions = false;
}

/* Location:
 * Qualified Name:     com.mongodb.Bytes.OptionHolder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import java.nio.ByteOrder;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.bson.BSON;
import org.bson.types.BSONTimestamp;
import org.bson.types.Code;
import org.bson.types.CodeWScope;
import org.bson.types.ObjectId;

public class Bytes
  extends BSON
{
  static final Logger LOGGER = Logger.getLogger("com.mongodb");
  static final boolean D = Boolean.getBoolean("DEBUG.MONGO");
  
  static
  {
    if (LOGGER.getLevel() == null) {
      if (D) {
        LOGGER.setLevel(Level.ALL);
      } else {
        LOGGER.setLevel(Level.WARNING);
      }
    }
  }
  
  public static final ByteOrder ORDER = ByteOrder.LITTLE_ENDIAN;
  static final int MAX_OBJECT_SIZE = 4194304;
  static final int BATCH_INSERT_SIZE = 8388608;
  static final int CONNECTIONS_PER_HOST = Integer.parseInt(System.getProperty("MONGO.POOLSIZE", "10"));
  public static final int QUERYOPTION_TAILABLE = 2;
  public static final int QUERYOPTION_SLAVEOK = 4;
  public static final int QUERYOPTION_OPLOGREPLAY = 8;
  public static final int QUERYOPTION_NOTIMEOUT = 16;
  public static final int QUERYOPTION_AWAITDATA = 32;
  public static final int QUERYOPTION_EXHAUST = 64;
  public static final int QUERYOPTION_PARTIAL = 128;
  public static final int RESULTFLAG_CURSORNOTFOUND = 1;
  public static final int RESULTFLAG_ERRSET = 2;
  public static final int RESULTFLAG_SHARDCONFIGSTALE = 4;
  public static final int RESULTFLAG_AWAITCAPABLE = 8;
  
  static class OptionHolder
  {
    final OptionHolder _parent;
    
    OptionHolder(OptionHolder parent)
    {
      _parent = parent;
    }
    
    void set(int options)
    {
      _options = options;
      _hasOptions = true;
    }
    
    int get()
    {
      if (_hasOptions) {
        return _options;
      }
      if (_parent == null) {
        return 0;
      }
      return _parent.get();
    }
    
    void add(int option)
    {
      set(get() | option);
    }
    
    void reset()
    {
      _hasOptions = false;
    }
    
    int _options = 0;
    boolean _hasOptions = false;
  }
  
  public static byte getType(Object o)
  {
    if (o == null) {
      return 10;
    }
    if ((o instanceof DBPointer)) {
      return 12;
    }
    if (((o instanceof Integer)) || ((o instanceof Short)) || ((o instanceof Byte)) || ((o instanceof AtomicInteger))) {
      return 16;
    }
    if (((o instanceof Long)) || ((o instanceof AtomicLong))) {
      return 18;
    }
    if ((o instanceof Number)) {
      return 1;
    }
    if ((o instanceof String)) {
      return 2;
    }
    if ((o instanceof List)) {
      return 4;
    }
    if ((o instanceof byte[])) {
      return 5;
    }
    if ((o instanceof ObjectId)) {
      return 7;
    }
    if ((o instanceof Boolean)) {
      return 8;
    }
    if ((o instanceof Date)) {
      return 9;
    }
    if ((o instanceof BSONTimestamp)) {
      return 17;
    }
    if ((o instanceof Pattern)) {
      return 11;
    }
    if (((o instanceof DBObject)) || ((o instanceof DBRefBase))) {
      return 3;
    }
    if ((o instanceof Code)) {
      return 13;
    }
    if ((o instanceof CodeWScope)) {
      return 15;
    }
    return -1;
  }
  
  static final ObjectId COLLECTION_REF_ID = new ObjectId(-1, -1, -1);
}

/* Location:
 * Qualified Name:     com.mongodb.Bytes
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

public class CommandFailureException
  extends MongoException
{
  private static final long serialVersionUID = -1180715413196161037L;
  private final CommandResult commandResult;
  
  public CommandFailureException(CommandResult commandResult)
  {
    super(ServerError.getCode(commandResult), commandResult.toString());
    this.commandResult = commandResult;
  }
  
  public CommandResult getCommandResult()
  {
    return commandResult;
  }
}

/* Location:
 * Qualified Name:     com.mongodb.CommandFailureException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

public class CommandResult
  extends BasicDBObject
{
  private final ServerAddress _host;
  private static final long serialVersionUID = 1L;
  
  CommandResult(ServerAddress srv)
  {
    if (srv == null) {
      throw new IllegalArgumentException("server address is null");
    }
    _host = srv;
    
    put("serverUsed", srv.toString());
  }
  
  public boolean ok()
  {
    Object o = get("ok");
    if (o == null) {
      throw new IllegalArgumentException("'ok' should never be null...");
    }
    if ((o instanceof Boolean)) {
      return ((Boolean)o).booleanValue();
    }
    if ((o instanceof Number)) {
      return ((Number)o).intValue() == 1;
    }
    throw new IllegalArgumentException("can't figure out what to do with: " + o.getClass().getName());
  }
  
  public String getErrorMessage()
  {
    Object errorMessage = get("errmsg");
    if (errorMessage == null) {
      return null;
    }
    return errorMessage.toString();
  }
  
  public MongoException getException()
  {
    if (!ok()) {
      return new CommandFailureException(this);
    }
    if (hasErr())
    {
      if ((getCode() == 11000) || (getCode() == 11001) || (getCode() == 12582)) {
        return new MongoException.DuplicateKey(this);
      }
      return new WriteConcernException(this);
    }
    return null;
  }
  
  int getCode()
  {
    int code = -1;
    if ((get("code") instanceof Number)) {
      code = ((Number)get("code")).intValue();
    }
    return code;
  }
  
  boolean hasErr()
  {
    Object o = get("err");
    return (o != null) && (((String)o).length() > 0);
  }
  
  public void throwOnError()
  {
    if ((!ok()) || (hasErr())) {
      throw getException();
    }
  }
  
  public ServerAddress getServerUsed()
  {
    return _host;
  }
}

/* Location:
 * Qualified Name:     com.mongodb.CommandResult
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

class ConnectionStatus$BackgroundUpdater
  extends Thread
{
  public ConnectionStatus$BackgroundUpdater(String name)
  {
    super(name);
    setDaemon(true);
  }
}

/* Location:
 * Qualified Name:     com.mongodb.ConnectionStatus.BackgroundUpdater
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

class ConnectionStatus$Node
{
  protected final ServerAddress _addr;
  protected final float _pingTime;
  protected final boolean _ok;
  protected final int _maxBsonObjectSize;
  
  ConnectionStatus$Node(float pingTime, ServerAddress addr, int maxBsonObjectSize, boolean ok)
  {
    _pingTime = pingTime;
    _addr = addr;
    _maxBsonObjectSize = maxBsonObjectSize;
    _ok = ok;
  }
  
  public boolean isOk()
  {
    return _ok;
  }
  
  public int getMaxBsonObjectSize()
  {
    return _maxBsonObjectSize;
  }
  
  public ServerAddress getServerAddress()
  {
    return _addr;
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((o == null) || (getClass() != o.getClass())) {
      return false;
    }
    Node node = (Node)o;
    if (_maxBsonObjectSize != _maxBsonObjectSize) {
      return false;
    }
    if (_ok != _ok) {
      return false;
    }
    if (Float.compare(_pingTime, _pingTime) != 0) {
      return false;
    }
    if (!_addr.equals(_addr)) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int result = _addr.hashCode();
    result = 31 * result + (_pingTime != 0.0F ? Float.floatToIntBits(_pingTime) : 0);
    result = 31 * result + (_ok ? 1 : 0);
    result = 31 * result + _maxBsonObjectSize;
    return result;
  }
  
  public String toJSON()
  {
    StringBuilder buf = new StringBuilder();
    buf.append("{");
    buf.append("address:'").append(_addr).append("', ");
    buf.append("ok:").append(_ok).append(", ");
    buf.append("ping:").append(_pingTime).append(", ");
    buf.append("maxBsonObjectSize:").append(_maxBsonObjectSize).append(", ");
    buf.append("}");
    
    return buf.toString();
  }
}

/* Location:
 * Qualified Name:     com.mongodb.ConnectionStatus.Node
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

abstract class ConnectionStatus$UpdatableNode
{
  final ServerAddress _addr;
  final MongoOptions _mongoOptions;
  final Mongo _mongo;
  DBPort _port;
  
  ConnectionStatus$UpdatableNode(ServerAddress addr, Mongo mongo, MongoOptions mongoOptions)
  {
    _addr = addr;
    _mongo = mongo;
    _mongoOptions = mongoOptions;
    _port = new DBPort(addr, null, mongoOptions);
  }
  
  public CommandResult update()
  {
    CommandResult res = null;
    try
    {
      long start = System.nanoTime();
      res = _port.runCommand(_mongo.getDB("admin"), ConnectionStatus.isMasterCmd);
      long end = System.nanoTime();
      float newPingMS = (float)(end - start) / 1000000.0F;
      if (!successfullyContacted) {
        _pingTimeMS = newPingMS;
      } else {
        _pingTimeMS += (newPingMS - _pingTimeMS) / ConnectionStatus.latencySmoothFactor;
      }
      getLogger().log(Level.FINE, "Latency to " + _addr + " actual=" + newPingMS + " smoothed=" + _pingTimeMS);
      
      successfullyContacted = true;
      if (res == null) {
        throw new MongoInternalException("Invalid null value returned from isMaster");
      }
      if (!_ok) {
        getLogger().log(Level.INFO, "Server seen up: " + _addr);
      }
      _ok = true;
      if (res.containsField("maxBsonObjectSize")) {
        _maxBsonObjectSize = ((Integer)res.get("maxBsonObjectSize")).intValue();
      } else {
        _maxBsonObjectSize = 4194304;
      }
    }
    catch (Exception e)
    {
      if ((!_ok) && (Math.random() <= 0.1D)) {
        return res;
      }
      StringBuilder logError = new StringBuilder("Server seen down: ").append(_addr);
      if ((e instanceof IOException))
      {
        logError.append(" - ").append(IOException.class.getName());
        if (e.getMessage() != null) {
          logError.append(" - message: ").append(e.getMessage());
        }
        getLogger().log(Level.WARNING, logError.toString());
      }
      else
      {
        getLogger().log(Level.WARNING, logError.toString(), e);
      }
      _ok = false;
    }
    return res;
  }
  
  boolean successfullyContacted = false;
  boolean _ok = false;
  float _pingTimeMS = 0.0F;
  int _maxBsonObjectSize;
  
  protected abstract Logger getLogger();
}

/* Location:
 * Qualified Name:     com.mongodb.ConnectionStatus.UpdatableNode
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

abstract class ConnectionStatus
{
  ConnectionStatus(List<ServerAddress> mongosAddresses, Mongo mongo)
  {
    _mongoOptions = mongoOptionsDefaults.copy();
    _mongoOptions.socketFactory = _options.socketFactory;
    _mongosAddresses = new ArrayList(mongosAddresses);
    _mongo = mongo;
  }
  
  protected static final MongoOptions mongoOptionsDefaults = new MongoOptions();
  protected static final DBObject isMasterCmd = new BasicDBObject("ismaster", Integer.valueOf(1));
  
  void start()
  {
    if (_updater != null) {
      _updater.start();
    }
  }
  
  void close()
  {
    _closed = true;
    if (_updater != null) {
      _updater.interrupt();
    }
  }
  
  abstract List<ServerAddress> getServerAddressList();
  
  abstract boolean hasServerUp();
  
  abstract Node ensureMaster();
  
  void checkClosed()
  {
    if (_closed) {
      throw new IllegalStateException("ReplicaSetStatus closed");
    }
  }
  
  static
  {
    updaterIntervalMS = Integer.parseInt(System.getProperty("com.mongodb.updaterIntervalMS", "5000"));
    updaterIntervalNoMasterMS = Integer.parseInt(System.getProperty("com.mongodb.updaterIntervalNoMasterMS", "10"));
    mongoOptionsDefaultsconnectTimeout = Integer.parseInt(System.getProperty("com.mongodb.updaterConnectTimeoutMS", "20000"));
    mongoOptionsDefaultssocketTimeout = Integer.parseInt(System.getProperty("com.mongodb.updaterSocketTimeoutMS", "20000"));
  }
  
  protected static final float latencySmoothFactor = Float.parseFloat(System.getProperty("com.mongodb.latencySmoothFactor", "4"));
  protected BackgroundUpdater _updater;
  protected final Mongo _mongo;
  protected final List<ServerAddress> _mongosAddresses;
  protected volatile boolean _closed;
  protected final MongoOptions _mongoOptions;
  protected static int updaterIntervalMS;
  protected static int updaterIntervalNoMasterMS;
  
  static class Node
  {
    protected final ServerAddress _addr;
    protected final float _pingTime;
    protected final boolean _ok;
    protected final int _maxBsonObjectSize;
    
    Node(float pingTime, ServerAddress addr, int maxBsonObjectSize, boolean ok)
    {
      _pingTime = pingTime;
      _addr = addr;
      _maxBsonObjectSize = maxBsonObjectSize;
      _ok = ok;
    }
    
    public boolean isOk()
    {
      return _ok;
    }
    
    public int getMaxBsonObjectSize()
    {
      return _maxBsonObjectSize;
    }
    
    public ServerAddress getServerAddress()
    {
      return _addr;
    }
    
    public boolean equals(Object o)
    {
      if (this == o) {
        return true;
      }
      if ((o == null) || (getClass() != o.getClass())) {
        return false;
      }
      Node node = (Node)o;
      if (_maxBsonObjectSize != _maxBsonObjectSize) {
        return false;
      }
      if (_ok != _ok) {
        return false;
      }
      if (Float.compare(_pingTime, _pingTime) != 0) {
        return false;
      }
      if (!_addr.equals(_addr)) {
        return false;
      }
      return true;
    }
    
    public int hashCode()
    {
      int result = _addr.hashCode();
      result = 31 * result + (_pingTime != 0.0F ? Float.floatToIntBits(_pingTime) : 0);
      result = 31 * result + (_ok ? 1 : 0);
      result = 31 * result + _maxBsonObjectSize;
      return result;
    }
    
    public String toJSON()
    {
      StringBuilder buf = new StringBuilder();
      buf.append("{");
      buf.append("address:'").append(_addr).append("', ");
      buf.append("ok:").append(_ok).append(", ");
      buf.append("ping:").append(_pingTime).append(", ");
      buf.append("maxBsonObjectSize:").append(_maxBsonObjectSize).append(", ");
      buf.append("}");
      
      return buf.toString();
    }
  }
  
  static class BackgroundUpdater
    extends Thread
  {
    public BackgroundUpdater(String name)
    {
      super();
      setDaemon(true);
    }
  }
  
  static abstract class UpdatableNode
  {
    final ServerAddress _addr;
    final MongoOptions _mongoOptions;
    final Mongo _mongo;
    DBPort _port;
    
    UpdatableNode(ServerAddress addr, Mongo mongo, MongoOptions mongoOptions)
    {
      _addr = addr;
      _mongo = mongo;
      _mongoOptions = mongoOptions;
      _port = new DBPort(addr, null, mongoOptions);
    }
    
    public CommandResult update()
    {
      CommandResult res = null;
      try
      {
        long start = System.nanoTime();
        res = _port.runCommand(_mongo.getDB("admin"), ConnectionStatus.isMasterCmd);
        long end = System.nanoTime();
        float newPingMS = (float)(end - start) / 1000000.0F;
        if (!successfullyContacted) {
          _pingTimeMS = newPingMS;
        } else {
          _pingTimeMS += (newPingMS - _pingTimeMS) / ConnectionStatus.latencySmoothFactor;
        }
        getLogger().log(Level.FINE, "Latency to " + _addr + " actual=" + newPingMS + " smoothed=" + _pingTimeMS);
        
        successfullyContacted = true;
        if (res == null) {
          throw new MongoInternalException("Invalid null value returned from isMaster");
        }
        if (!_ok) {
          getLogger().log(Level.INFO, "Server seen up: " + _addr);
        }
        _ok = true;
        if (res.containsField("maxBsonObjectSize")) {
          _maxBsonObjectSize = ((Integer)res.get("maxBsonObjectSize")).intValue();
        } else {
          _maxBsonObjectSize = 4194304;
        }
      }
      catch (Exception e)
      {
        if ((!_ok) && (Math.random() <= 0.1D)) {
          return res;
        }
        StringBuilder logError = new StringBuilder("Server seen down: ").append(_addr);
        if ((e instanceof IOException))
        {
          logError.append(" - ").append(IOException.class.getName());
          if (e.getMessage() != null) {
            logError.append(" - message: ").append(e.getMessage());
          }
          getLogger().log(Level.WARNING, logError.toString());
        }
        else
        {
          getLogger().log(Level.WARNING, logError.toString(), e);
        }
        _ok = false;
      }
      return res;
    }
    
    boolean successfullyContacted = false;
    boolean _ok = false;
    float _pingTimeMS = 0.0F;
    int _maxBsonObjectSize;
    
    protected abstract Logger getLogger();
  }
}

/* Location:
 * Qualified Name:     com.mongodb.ConnectionStatus
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

class DB$CommandResultPair
{
  CommandResult result;
  CommandFailureException failure;
  
  public DB$CommandResultPair(DB paramDB, CommandResult result)
  {
    this.result = result;
  }
  
  public DB$CommandResultPair(DB paramDB, CommandFailureException failure)
  {
    this.failure = failure;
  }
}

/* Location:
 * Qualified Name:     com.mongodb.DB.CommandResultPair
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import com.mongodb.util.Util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import org.bson.BSONObject;

public abstract class DB
{
  private static final Set<String> _obedientCommands = new HashSet();
  final Mongo _mongo;
  final String _name;
  
  static
  {
    _obedientCommands.add("group");
    _obedientCommands.add("aggregate");
    _obedientCommands.add("collstats");
    _obedientCommands.add("dbstats");
    _obedientCommands.add("count");
    _obedientCommands.add("distinct");
    _obedientCommands.add("geonear");
    _obedientCommands.add("geosearch");
    _obedientCommands.add("geowalk");
  }
  
  public DB(Mongo mongo, String name)
  {
    _mongo = mongo;
    _name = name;
    _options = new Bytes.OptionHolder(_mongo._netOptions);
  }
  
  ReadPreference getCommandReadPreference(DBObject command, ReadPreference requestedPreference)
  {
    String comString = (String)command.keySet().iterator().next();
    if ((comString.equals("getnonce")) || (comString.equals("authenticate"))) {
      return ReadPreference.primaryPreferred();
    }
    boolean primaryRequired;
    boolean primaryRequired;
    if (comString.equals("mapreduce"))
    {
      Object out = command.get("out");
      boolean primaryRequired;
      if ((out instanceof BSONObject))
      {
        BSONObject outMap = (BSONObject)out;
        primaryRequired = outMap.get("inline") == null;
      }
      else
      {
        primaryRequired = true;
      }
    }
    else
    {
      primaryRequired = !_obedientCommands.contains(comString.toLowerCase());
    }
    if (primaryRequired) {
      return ReadPreference.primary();
    }
    if (requestedPreference == null) {
      return ReadPreference.primary();
    }
    return requestedPreference;
  }
  
  public DBCollection getCollection(String name)
  {
    DBCollection c = doGetCollection(name);
    return c;
  }
  
  public DBCollection createCollection(String name, DBObject options)
  {
    if (options != null)
    {
      DBObject createCmd = new BasicDBObject("create", name);
      createCmd.putAll(options);
      CommandResult result = command(createCmd);
      result.throwOnError();
    }
    return getCollection(name);
  }
  
  public DBCollection getCollectionFromString(String s)
  {
    DBCollection foo = null;
    
    int idx = s.indexOf(".");
    while (idx >= 0)
    {
      String b = s.substring(0, idx);
      s = s.substring(idx + 1);
      if (foo == null) {
        foo = getCollection(b);
      } else {
        foo = foo.getCollection(b);
      }
      idx = s.indexOf(".");
    }
    if (foo != null) {
      return foo.getCollection(s);
    }
    return getCollection(s);
  }
  
  public CommandResult command(DBObject cmd)
  {
    return command(cmd, 0);
  }
  
  public CommandResult command(DBObject cmd, DBEncoder encoder)
  {
    return command(cmd, 0, encoder);
  }
  
  public CommandResult command(DBObject cmd, int options, DBEncoder encoder)
  {
    return command(cmd, options, getReadPreference(), encoder);
  }
  
  public CommandResult command(DBObject cmd, int options, ReadPreference readPrefs)
  {
    return command(cmd, options, readPrefs, DefaultDBEncoder.FACTORY.create());
  }
  
  public CommandResult command(DBObject cmd, int options, ReadPreference readPrefs, DBEncoder encoder)
  {
    readPrefs = getCommandReadPreference(cmd, readPrefs);
    cmd = wrapCommand(cmd, readPrefs);
    
    Iterator<DBObject> i = getCollection("$cmd").__find(cmd, new BasicDBObject(), 0, -1, 0, options, readPrefs, DefaultDBDecoder.FACTORY.create(), encoder);
    if ((i == null) || (!i.hasNext())) {
      return null;
    }
    DBObject res = (DBObject)i.next();
    ServerAddress sa = (i instanceof DBApiLayer.Result) ? ((DBApiLayer.Result)i).getServerAddress() : null;
    CommandResult cr = new CommandResult(sa);
    cr.putAll(res);
    return cr;
  }
  
  private DBObject wrapCommand(DBObject cmd, ReadPreference readPrefs)
  {
    if ((getMongo().isMongosConnection()) && (!ReadPreference.primary().equals(readPrefs)) && (!ReadPreference.secondaryPreferred().equals(readPrefs)) && ((cmd instanceof BasicDBObject))) {
      cmd = new BasicDBObject("$query", cmd).append("$readPreference", readPrefs.toDBObject());
    }
    return cmd;
  }
  
  public CommandResult command(DBObject cmd, int options)
  {
    return command(cmd, options, getReadPreference());
  }
  
  public CommandResult command(String cmd)
  {
    return command(new BasicDBObject(cmd, Boolean.TRUE));
  }
  
  public CommandResult command(String cmd, int options)
  {
    return command(new BasicDBObject(cmd, Boolean.TRUE), options);
  }
  
  public CommandResult doEval(String code, Object... args)
  {
    return command(BasicDBObjectBuilder.start().add("$eval", code).add("args", args).get());
  }
  
  public Object eval(String code, Object... args)
  {
    CommandResult res = doEval(code, args);
    res.throwOnError();
    return res.get("retval");
  }
  
  public CommandResult getStats()
  {
    return command("dbstats");
  }
  
  public String getName()
  {
    return _name;
  }
  
  public void setReadOnly(Boolean b)
  {
    _readOnly = b.booleanValue();
  }
  
  public Set<String> getCollectionNames()
  {
    DBCollection namespaces = getCollection("system.namespaces");
    if (namespaces == null) {
      throw new RuntimeException("this is impossible");
    }
    Iterator<DBObject> i = namespaces.__find(new BasicDBObject(), null, 0, 0, 0, getOptions(), getReadPreference(), null);
    if (i == null) {
      return new HashSet();
    }
    List<String> tables = new ArrayList();
    while (i.hasNext())
    {
      DBObject o = (DBObject)i.next();
      if (o.get("name") == null) {
        throw new MongoException("how is name null : " + o);
      }
      String n = o.get("name").toString();
      int idx = n.indexOf(".");
      
      String root = n.substring(0, idx);
      if ((root.equals(_name)) && 
      
        (n.indexOf("$") < 0))
      {
        String table = n.substring(idx + 1);
        
        tables.add(table);
      }
    }
    Collections.sort(tables);
    
    return new LinkedHashSet(tables);
  }
  
  public boolean collectionExists(String collectionName)
  {
    if ((collectionName == null) || ("".equals(collectionName))) {
      return false;
    }
    Set<String> collections = getCollectionNames();
    if (collections.isEmpty()) {
      return false;
    }
    for (String collection : collections) {
      if (collectionName.equalsIgnoreCase(collection)) {
        return true;
      }
    }
    return false;
  }
  
  public String toString()
  {
    return _name;
  }
  
  public CommandResult getLastError()
  {
    return command(new BasicDBObject("getlasterror", Integer.valueOf(1)));
  }
  
  public CommandResult getLastError(WriteConcern concern)
  {
    return command(concern.getCommand());
  }
  
  public CommandResult getLastError(int w, int wtimeout, boolean fsync)
  {
    return command(new WriteConcern(w, wtimeout, fsync).getCommand());
  }
  
  public void setWriteConcern(WriteConcern concern)
  {
    if (concern == null) {
      throw new IllegalArgumentException();
    }
    _concern = concern;
  }
  
  public WriteConcern getWriteConcern()
  {
    if (_concern != null) {
      return _concern;
    }
    return _mongo.getWriteConcern();
  }
  
  public void setReadPreference(ReadPreference preference)
  {
    _readPref = preference;
  }
  
  public ReadPreference getReadPreference()
  {
    if (_readPref != null) {
      return _readPref;
    }
    return _mongo.getReadPreference();
  }
  
  public void dropDatabase()
  {
    CommandResult res = command(new BasicDBObject("dropDatabase", Integer.valueOf(1)));
    res.throwOnError();
    _mongo._dbs.remove(getName());
  }
  
  public boolean isAuthenticated()
  {
    return getAuthenticationCredentials() != null;
  }
  
  public boolean authenticate(String username, char[] password)
  {
    return authenticateCommandHelperfailure == null;
  }
  
  public synchronized CommandResult authenticateCommand(String username, char[] password)
  {
    CommandResultPair commandResultPair = authenticateCommandHelper(username, password);
    if (failure != null) {
      throw failure;
    }
    return result;
  }
  
  private CommandResultPair authenticateCommandHelper(String username, char[] password)
  {
    MongoCredential credentials = MongoCredential.createMongoCRCredential(username, getName(), password);
    if (getAuthenticationCredentials() != null) {
      if (getAuthenticationCredentials().equals(credentials))
      {
        if (authenticationTestCommandResult != null) {
          return new CommandResultPair(authenticationTestCommandResult);
        }
      }
      else {
        throw new IllegalStateException("can't authenticate twice on the same database");
      }
    }
    try
    {
      authenticationTestCommandResult = doAuthenticate(credentials);
      return new CommandResultPair(authenticationTestCommandResult);
    }
    catch (CommandFailureException commandFailureException)
    {
      return new CommandResultPair(commandFailureException);
    }
  }
  
  class CommandResultPair
  {
    CommandResult result;
    CommandFailureException failure;
    
    public CommandResultPair(CommandResult result)
    {
      this.result = result;
    }
    
    public CommandResultPair(CommandFailureException failure)
    {
      this.failure = failure;
    }
  }
  
  public WriteResult addUser(String username, char[] passwd)
  {
    return addUser(username, passwd, false);
  }
  
  public WriteResult addUser(String username, char[] passwd, boolean readOnly)
  {
    DBCollection c = getCollection("system.users");
    DBObject o = c.findOne(new BasicDBObject("user", username));
    if (o == null) {
      o = new BasicDBObject("user", username);
    }
    o.put("pwd", _hash(username, passwd));
    o.put("readOnly", Boolean.valueOf(readOnly));
    return c.save(o);
  }
  
  public WriteResult removeUser(String username)
  {
    DBCollection c = getCollection("system.users");
    return c.remove(new BasicDBObject("user", username));
  }
  
  String _hash(String username, char[] passwd)
  {
    ByteArrayOutputStream bout = new ByteArrayOutputStream(username.length() + 20 + passwd.length);
    try
    {
      bout.write(username.getBytes());
      bout.write(":mongo:".getBytes());
      for (int i = 0; i < passwd.length; i++)
      {
        if (passwd[i] >= '?') {
          throw new IllegalArgumentException("can't handle non-ascii passwords yet");
        }
        bout.write((byte)passwd[i]);
      }
    }
    catch (IOException ioe)
    {
      throw new RuntimeException("impossible", ioe);
    }
    return Util.hexMD5(bout.toByteArray());
  }
  
  public CommandResult getPreviousError()
  {
    return command(new BasicDBObject("getpreverror", Integer.valueOf(1)));
  }
  
  public void resetError()
  {
    command(new BasicDBObject("reseterror", Integer.valueOf(1)));
  }
  
  public void forceError()
  {
    command(new BasicDBObject("forceerror", Integer.valueOf(1)));
  }
  
  public Mongo getMongo()
  {
    return _mongo;
  }
  
  public DB getSisterDB(String name)
  {
    return _mongo.getDB(name);
  }
  
  @Deprecated
  public void slaveOk()
  {
    addOption(4);
  }
  
  public void addOption(int option)
  {
    _options.add(option);
  }
  
  public void setOptions(int options)
  {
    _options.set(options);
  }
  
  public void resetOptions()
  {
    _options.reset();
  }
  
  public int getOptions()
  {
    return _options.get();
  }
  
  MongoCredential getAuthenticationCredentials()
  {
    return getMongo().getAuthority().getCredentialsStore().get(getName());
  }
  
  protected boolean _readOnly = false;
  private WriteConcern _concern;
  private ReadPreference _readPref;
  final Bytes.OptionHolder _options;
  private volatile CommandResult authenticationTestCommandResult;
  
  public abstract void requestStart();
  
  public abstract void requestDone();
  
  public abstract void requestEnsureConnection();
  
  protected abstract DBCollection doGetCollection(String paramString);
  
  abstract CommandResult doAuthenticate(MongoCredential paramMongoCredential);
  
  public abstract void cleanCursors(boolean paramBoolean);
}

/* Location:
 * Qualified Name:     com.mongodb.DB
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class DBAddress
  extends ServerAddress
{
  final String _db;
  
  public DBAddress(String urlFormat)
    throws UnknownHostException
  {
    super(_getHostSection(urlFormat));
    
    _check(urlFormat, "urlFormat");
    _db = _fixName(_getDBSection(urlFormat));
    
    _check(_host, "host");
    _check(_db, "db");
  }
  
  static String _getHostSection(String urlFormat)
  {
    if (urlFormat == null) {
      throw new NullPointerException("urlFormat can't be null");
    }
    int idx = urlFormat.indexOf("/");
    if (idx >= 0) {
      return urlFormat.substring(0, idx);
    }
    return null;
  }
  
  static String _getDBSection(String urlFormat)
  {
    if (urlFormat == null) {
      throw new NullPointerException("urlFormat can't be null");
    }
    int idx = urlFormat.indexOf("/");
    if (idx >= 0) {
      return urlFormat.substring(idx + 1);
    }
    return urlFormat;
  }
  
  static String _fixName(String name)
  {
    name = name.replace('.', '-');
    return name;
  }
  
  public DBAddress(DBAddress other, String dbname)
    throws UnknownHostException
  {
    this(_host, _port, dbname);
  }
  
  public DBAddress(String host, String dbname)
    throws UnknownHostException
  {
    this(host, 27017, dbname);
  }
  
  public DBAddress(String host, int port, String dbname)
    throws UnknownHostException
  {
    super(host, port);
    _db = dbname.trim();
  }
  
  public DBAddress(InetAddress addr, int port, String dbname)
  {
    super(addr, port);
    _check(dbname, "name");
    _db = dbname.trim();
  }
  
  static void _check(String thing, String name)
  {
    if (thing == null) {
      throw new NullPointerException(name + " can't be null ");
    }
    thing = thing.trim();
    if (thing.length() == 0) {
      throw new IllegalArgumentException(name + " can't be empty");
    }
  }
  
  public int hashCode()
  {
    return super.hashCode() + _db.hashCode();
  }
  
  public boolean equals(Object other)
  {
    if ((other instanceof DBAddress))
    {
      DBAddress a = (DBAddress)other;
      return (_port == _port) && (_db.equals(_db)) && (_host.equals(_host));
    }
    if ((other instanceof ServerAddress)) {
      return other.equals(this);
    }
    return false;
  }
  
  public DBAddress getSister(String name)
  {
    try
    {
      return new DBAddress(_host, _port, name);
    }
    catch (UnknownHostException uh)
    {
      throw new MongoInternalException("shouldn't be possible", uh);
    }
  }
  
  public String getDBName()
  {
    return _db;
  }
  
  public String toString()
  {
    return super.toString() + "/" + _db;
  }
}

/* Location:
 * Qualified Name:     com.mongodb.DBAddress
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

class DBApiLayer$1 {}

/* Location:
 * Qualified Name:     com.mongodb.DBApiLayer.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

class DBApiLayer$DeadCursor
{
  final long id;
  final ServerAddress host;
  
  DBApiLayer$DeadCursor(long a, ServerAddress b)
  {
    id = a;
    host = b;
  }
}

/* Location:
 * Qualified Name:     com.mongodb.DBApiLayer.DeadCursor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.mongodb;

import com.mongodb.util.JSON;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bson.BSONObject;
import org.bson.types.ObjectId;

class DBApiLayer$MyCollection
  extends DBCollection
{
  final String _fullNameSpace;
  
  DBApiLayer$MyCollection(DB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd