Examples of Mongo


Examples of com.mongodb.Mongo

            String host = String.valueOf(properties.get(HOST));
            int port = Integer.parseInt(String.valueOf(properties.get(PORT)));
            String db = String.valueOf(properties.get(DB));
            int cache = Integer.parseInt(String.valueOf(properties.get(CACHE)));

            mongo = new Mongo(host, port);
            store = new MongoStore(mongo.getDB(db), cache * MB);
        }

        delegate = new SegmentNodeStore(store);
    }
View Full Code Here

Examples of com.mongodb.Mongo

    public OakSegmentMKRepositoryStub(Properties settings) throws RepositoryException {
        super(settings);

        Session session = null;
        try {
            this.connection = new Mongo(HOST, PORT);
            Jcr jcr = new Jcr(new Oak(new SegmentNodeStore(
                    new MongoStore(connection.getDB(DB), 100 * 1024 * 1024))));
            jcr.with(Executors.newScheduledThreadPool(1));
            this.repository = jcr.createRepository();

View Full Code Here

Examples of com.mongodb.Mongo

        }));
    }

    public static boolean isAvailable() {
        try {
            Mongo mongo = new Mongo(HOST, PORT);
            try {
                mongo.getDatabaseNames();
                return true;
            } finally {
                mongo.close();
            }
        } catch (Exception e) {
            return false;
        }
    }
View Full Code Here

Examples of com.mongodb.Mongo

    private DBCollection nodesStore;
    private DBCollection settingsStore;

    NodeMapInMongoDb(String dir) {
        try {
            con = new Mongo();
            db = con.getDB(DB);
            db.setWriteConcern(WriteConcern.SAFE);
            nodesStore = db.getCollection(NODES_COLLECTION);
            nodesStore.ensureIndex(
                    new BasicDBObject(KEY_FIELD, 1),
View Full Code Here

Examples of com.mongodb.Mongo

public class MongoApp2 {
  private static final Log log = LogFactory.getLog(MongoApp.class);

  public static void main(String[] args) throws Exception {
    MongoOperations mongoOps = new MongoTemplate(new SimpleMongoDbFactory(
        new Mongo(), "database"));
    Person p = new Person("Joe", 34);
    // Insert is used to initially store the object into the database.
    mongoOps.insert(p);
    log.info("Insert: " + p); // Find
    p = mongoOps.findById(p.getId(), Person.class);
View Full Code Here

Examples of com.mongodb.Mongo

public class MongoApp {
  private static final Log log = LogFactory.getLog(MongoApp.class);

  public static void main(String[] args) throws Exception {
    MongoOperations mongoOps = new MongoTemplate(new Mongo(), "database");
    mongoOps.insert(new Person("Joe", 34));
    log.info(mongoOps.findOne(new Query(where("name").is("Joe")),
        Person.class));
//    mongoOps.dropCollection("person");
  }
View Full Code Here

Examples of com.mongodb.Mongo

    private Mongo con;
    private DB db;
    private DBCollection dataStore;

    public MongoBlobStore() throws IOException {
        con = new Mongo();
        db = con.getDB(DB);
        db.setWriteConcern(WriteConcern.SAFE);
        dataStore = db.getCollection(DATASTORE_COLLECTION);
        dataStore.ensureIndex(
                new BasicDBObject(DIGEST_FIELD, 1),
View Full Code Here

Examples of com.mongodb.Mongo

    // TODO: make this configurable
    private IdFactory idFactory = IdFactory.getDigestFactory();
   
    public void initialize(File homeDir) throws Exception {
        con = new Mongo();
        //con = new Mongo("localhost", 27017);

        db = con.getDB("mk");
        db.setWriteConcern(WriteConcern.SAFE);
View Full Code Here

Examples of com.mongodb.Mongo

            String dbName = getProperty(properties, "dbName", "test");
            String username = getProperty(properties, "username", null);
            String password = getProperty(properties, "password", null);
           
            try {
                Mongo mongo;
                if (mongoURI != null) {
                    MongoURI uri = new MongoURI(mongoURI);
                    mongo = new Mongo(uri);
                }
                else {
                    MongoOptions mongoOptions = createMongoOptions(properties);
                   
                    mongo = createMongo(host, port, mongoOptions);
                }

                mongo.setWriteConcern(WriteConcern.valueOf(writeConcern));
                if (readPreference.equals("PrimaryReadPreference")) {
                    mongo.setReadPreference(ReadPreference.PRIMARY);
                }
                else if (readPreference.equals("PrimaryReadPreference")) {
                    mongo.setReadPreference(ReadPreference.SECONDARY);
                } else {
                    m_logService.log(LogService.LOG_ERROR, "ReadPreference '" + readPreference + "' is not supported and was ignored." );
                }
               
                if(username != null) {
                    mongo.getDB(dbName).authenticate(username, password.toCharArray());
                    m_logService.log(LogService.LOG_INFO, "Authenticated as '" + username + "'");
                }
               
                MongoDBServiceImpl instance = new MongoDBServiceImpl(mongo, mongo.getDB(dbName));
               
                Properties serviceProperties = new Properties();
                serviceProperties.put("dbName", dbName);
                Component component = m_dependencyManager.createComponent().setInterface(MongoDBService.class.getName(), serviceProperties).setImplementation(instance);
                m_dependencyManager.add(component);
View Full Code Here

Examples of com.mongodb.Mongo

            }
        }
    }

    private Mongo createMongo(String host, int port, MongoOptions mongoOptions) throws UnknownHostException {
        Mongo mongo;
        if(host.contains(",")) {
            String[] hosts = host.split(",");
            List<ServerAddress> addresses = new ArrayList<ServerAddress>();
            for (String hostUrl : hosts) {
                ServerAddress serverAddress;
                if(hostUrl.contains(":")) {
                    String[] hostUrlParts = hostUrl.split(":");
                    port = Integer.parseInt(hostUrlParts[1]);
                    serverAddress = new ServerAddress(hostUrlParts[0], port);
                } else {
                    serverAddress = new ServerAddress(hostUrl);
                }
               
                addresses.add(serverAddress);
            }
           
            mongo = new Mongo(addresses, mongoOptions);
        } else {
            mongo = new Mongo(new ServerAddress(host, port), mongoOptions);
        }
        return mongo;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.