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


Java MongoClientURI类代码示例

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


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

示例1: BingoChessChallenge

import com.mongodb.MongoClientURI; //导入依赖的package包/类
public BingoChessChallenge(String[] args) {
	announcer = new Chatter(args[0]);
	lichs = new HashMap<String,Lichesser>();
	chessplayers = new HashMap<String,ChessPlayer>();
	chessgames = new HashMap<String,LichessGame>();
	BingoPlayer.SQUARE_BAG = new Vector<Dimension>();
	for (int x=0;x<8;x++)
	for (int y=0;y<8;y++)
	BingoPlayer.SQUARE_BAG.add(new Dimension(x,y));
	initIRC(args[0], args[1], args[2], args[3]);
	loadAdmins("res/admins.txt");
	serv = new BingoServ(Integer.parseInt(args[4]),this);
	serv.startSrv();
	bingoURL = args[5];
	MongoClientURI connStr = new MongoClientURI("mongodb://bingobot:" + args[6] + "@localhost:27017/BingoBase");
	MongoClient mongoClient = new MongoClient(connStr);
	MongoDatabase bingoBase = mongoClient.getDatabase("BingoBase");
	playData = bingoBase.getCollection("players");
}
 
开发者ID:JohnChernoff,项目名称:BingoChess,代码行数:20,代码来源:BingoChessChallenge.java

示例2: connect

import com.mongodb.MongoClientURI; //导入依赖的package包/类
@Override
public Connection connect(String url, Properties info) throws SQLException {
	MongoClientURI mcu = null;
	if ((mcu = parseURL(url, info)) == null) {
		return null;
	}
	
	MongoConnection result = null;
	//System.out.print(info);
	try{
		result = new MongoConnection(mcu, url);
	}catch (Exception e){
		throw new SQLException("Unexpected exception: " + e.getMessage(), e);
	}
	
	return result;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:18,代码来源:MongoDriver.java

示例3: parseURL

import com.mongodb.MongoClientURI; //导入依赖的package包/类
private MongoClientURI parseURL(String url, Properties defaults) {
	if (url == null) {
		return null;
	}
	
	if (!StringUtils.startsWithIgnoreCase(url, PREFIX)) {	
		return null;
	}
	
	//删掉开头的 jdbc:
	//url = url.replace(URL_JDBC, "");
	
	try {
		//FIXME 判断defaults中的参数,写入URL中?
		return new MongoClientURI(url);
	} catch (Exception e) {
        LOGGER.error("parseURLError",e);
		return null;
	}
	
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:22,代码来源:MongoDriver.java

示例4: Connect

import com.mongodb.MongoClientURI; //导入依赖的package包/类
public void Connect(String user, String pass) {
	try {
		logger.info("Connecting to " + connectionString);

		// Authaenticate
		// MongoCredential credential =
		// MongoCredential.createCredential(user,
		// "admin",
		// pass); //Only users on admin as that will be mandatory in 3.6

		mongoClient = new MongoClient(new MongoClientURI(connectionString));

		mongoClient.getDatabase("admin")
				.runCommand(new Document("ping", 1));

	} catch (Exception e) {
		logger.error("Unable to connect to MongoDB");
		logger.error(e.getMessage());
		System.exit(1);
	}
	this.user = user;
	this.pass = pass;
}
 
开发者ID:johnlpage,项目名称:MongoSyphon,代码行数:24,代码来源:MongoConnection.java

示例5: BingoChess

import com.mongodb.MongoClientURI; //导入依赖的package包/类
public BingoChess(String[] args) {
	tv_client = new GameClient();
	twits = new HashMap<String,Chatter>();
	bingoers = new HashMap<String,BingoPlayer>();
	BingoPlayer.SQUARE_BAG = new Vector<Dimension>();
	for (int x=0;x<8;x++)
	for (int y=0;y<8;y++)
	BingoPlayer.SQUARE_BAG.add(new Dimension(x,y));
	initIRC(args[0], args[1], args[2], args[3]);
	loadAdmins("res/admins.txt");
	serv = new BingoServ(Integer.parseInt(args[4]),this);
	serv.startSrv();
	bingoURL = args[5];
	followTVGame();
	MongoClientURI connStr = new MongoClientURI("mongodb://bingobot:" + args[6] + "@localhost:27017/BingoBase");
	mongoClient = new MongoClient(connStr);
	bingoBase = mongoClient.getDatabase("BingoBase");
	playData = bingoBase.getCollection("players");
}
 
开发者ID:JohnChernoff,项目名称:BingoChess,代码行数:20,代码来源:BingoChess.java

示例6: doInBackground

import com.mongodb.MongoClientURI; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params)
{
    //MongoClientURI uri = new MongoClientURI("mongodb://random:[email protected]:45273/glugmvitappdb");
    MongoClientURI uri = new MongoClientURI("mongodb://mobile-user:[email protected]:39267/glug");
    Shared.client = new MongoClient(uri);

    //Shared.db = Shared.client.getDatabase("glugmvitappdb");
    Shared.db=Shared.client.getDatabase("glug");
    //Shared.TestCollection = Shared.db.getCollection("TestCollection");
    //Shared.TestCollection=Shared.db.getCollection("events");
    //Shared.UECollection = Shared.db.getCollection("UpcomingEventsCollection");
    Shared.UECollection = Shared.db.getCollection("events");
    Shared.CPCollection = Shared.db.getCollection("projects");
    return null;
}
 
开发者ID:GlugMVIT,项目名称:GLUG_MVIT_APP,代码行数:17,代码来源:SplashActivity.java

示例7: create

import com.mongodb.MongoClientURI; //导入依赖的package包/类
@Override
public void create(JSONObject config) {
    String key = config.getString("key");
    if (mongos.containsKey(key))
        return;

    String schema = config.getString("schema");
    if (validator.isEmpty(schema))
        throw new NullPointerException("未设置schema值[" + config + "]!");

    JSONArray array = config.getJSONArray("ips");
    if (array == null || array.size() == 0)
        throw new NullPointerException("未设置ips值[" + config + "]!");

    String username = config.getString("username");
    String password = config.getString("password");
    MongoClientOptions.Builder builder = MongoClientOptions.builder().connectionsPerHost(maxActive).maxWaitTime(maxWait);
    List<MongoClient> list = new ArrayList<>();
    for (int i = 0; i < array.size(); i++)
        list.add(new MongoClient(new MongoClientURI("mongodb://" + username + ":" + password + "@" + array.getString(i) + "/" + schema, builder)));
    schemas.put(key, schema);
    mongos.put(key, list);

    if (logger.isDebugEnable())
        logger.debug("Mongo数据库[{}]初始化完成。", config);
}
 
开发者ID:heisedebaise,项目名称:tephra,代码行数:27,代码来源:MongoImpl.java

示例8: connectionTest

import com.mongodb.MongoClientURI; //导入依赖的package包/类
public static boolean connectionTest(MongoDBConfig mongoDBConfig) {
	Logging.disableMongoDBLogging();
	boolean success = true;
	MongoClient mongoClient = null;
	try {
		mongoClient = new MongoClient(new MongoClientURI("mongodb://" + mongoDBConfig.getIp() + ":" + mongoDBConfig.getPort()));
		mongoClient.getDatabaseNames();
	} catch (MongoException e) {
		success = false;
	} finally {
		if (mongoClient != null) {
			mongoClient.close();
		}
		Logging.enableMongoDBLogging();
	}
	return success;
}
 
开发者ID:MinecraftCloudSystem,项目名称:MCS-Master,代码行数:18,代码来源:MongoDBConnectionTest.java

示例9: determineTargetDataSource

import com.mongodb.MongoClientURI; //导入依赖的package包/类
/**
 * 指定使用的mongouri key
 *
 * @return key
 */
private MongoClientURI determineTargetDataSource() {
    String currentKey = MongoDataSourceHolder.get();
    MongoClientURI mongoURI;

    mongoURI = mongoURIs.get(currentKey);

    if (null == mongoURI) {
        mongoURI = defaultMongoURI;
    }

    if (null == mongoURI) {
        throw new CannotGetMongoDbConnectionException(String.format("determine current lookup key '%s' not exist!", currentKey));
    }

    return mongoURI;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:22,代码来源:DynamicMongoConnection.java

示例10: DBManager

import com.mongodb.MongoClientURI; //导入依赖的package包/类
public DBManager(String host, int port, String dbname, String username, String password) {
	// Construct mongo url
	if (dbname == null || dbname.isEmpty()) dbname = "Grimoire";
	if (host == null || host.isEmpty()) host = "127.0.0.1";
	if (port <= 0 || port >= 65535) port = 27017;
	String mongoURL = host + ":" + port + "/" + dbname;
	if (username != null && !username.isEmpty()) {
		String auth = username;
		if (password != null && !password.isEmpty()) auth += ":" + password;
		mongoURL = auth + "@" + mongoURL;
	}
	mongoURL = "mongodb://" + mongoURL;

	// Construct client
	MongoClient client = new MongoClient(new MongoClientURI(mongoURL));

	// Wrap with jongo
	jongo = new Jongo(client.getDB(dbname));
}
 
开发者ID:BeMacized,项目名称:Grimoire,代码行数:20,代码来源:DBManager.java

示例11: createUser

import com.mongodb.MongoClientURI; //导入依赖的package包/类
public static void createUser() throws IOException, InterruptedException {
    String mongoHost = MultiValueConfigLoader.getConfig("MONGODB-integrationTest");
    log.info("Host is " + mongoHost);
    if (mongoHost != null) {
        MongoClientURI uri = new MongoClientURI(mongoHost);
        List<String> hosts = uri.getHosts();
        for (String host : hosts) {
            String[] cmdarray = createSetupCommand(host, uri.getDatabase(), uri.getUsername(), new String(uri.getPassword()));
            Process process = Runtime.getRuntime().exec(cmdarray);
            int retVal = process.waitFor();
            log.info(String.format("retVal=%s", retVal));
            log.info("output is " + IOUtils.toString(process.getInputStream()));
            if (retVal != 0) {
                log.info("error is " + IOUtils.toString(process.getErrorStream()));
            }
        }
    } else {
        log.error("mongo host is not defined!");
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:21,代码来源:LocalTestSetup.java

示例12: initConnection

import com.mongodb.MongoClientURI; //导入依赖的package包/类
@PostConstruct
public void initConnection() {
    String mongoHost = env.getProperty("mongodb.server.host", "127.0.0.1"); // env var MONGODB_SERVER_HOST takes precedence
    String mongoPort = env.getProperty("mongodb.server.port", "27017"); // env var MONGODB_SERVER_PORT takes precedence
    String mongoUser = env.getProperty("mongodb.user", "mongodb"); // env var MONGODB_USER takes precedence
    String mongoPassword = env.getProperty("mongodb.password", "mongodb"); // env var MONGODB_PASSWORD takes precedence
    String mongoDBName = env.getProperty("mongodb.database", "mongodb"); // env var MONGODB_DATABASE takes precedence

    try {
        String mongoURI = "mongodb://" + mongoUser + ":" + mongoPassword + "@" + mongoHost + ":" + mongoPort + "/" + mongoDBName;
        System.out.println("[INFO] Connection string: " + mongoURI);
        MongoClient mongoClient = new MongoClient(new MongoClientURI(mongoURI));
        mongoDB = mongoClient.getDatabase(mongoDBName);
    } catch (Exception e) {
        System.out.println("[ERROR] Creating the mongoDB. " + e.getMessage());
        mongoDB = null;
    }
}
 
开发者ID:openshift-roadshow,项目名称:nationalparks,代码行数:19,代码来源:MongoDBConnection.java

示例13: doInBackground

import com.mongodb.MongoClientURI; //导入依赖的package包/类
@Override
protected Integer doInBackground(User... params) {
    try {
        MongoClientURI mongoClientURI = new MongoClientURI(Variables.mongo_uri);
        MongoClient mongoClient = new MongoClient(mongoClientURI);
        MongoDatabase dbMongo = mongoClient.getDatabase(mongoClientURI.getDatabase());
        MongoCollection<Document> coll = dbMongo.getCollection("users");
        User local_user = params[0];
        if (!local_user.getEmail().equals(original_email)) {
            Document user = coll.find(eq("email", local_user.getEmail())).first();
            if (user != null) {
                return 1; // Repeated email
            }
        }

        Document search = new Document("_id", new ObjectId(local_user.getId()));
        Document replacement = new Document("$set", local_user.getRegisterDocument());
        // We update some fields of the documents without affecting the rest
        coll.updateOne(search, replacement);
        mongoClient.close();
        return 0; //Successfully saved
    } catch (Exception e) {
        return 2; // Error
    }
}
 
开发者ID:Ana06,项目名称:medical-data-android,代码行数:26,代码来源:ProfileActivity.java

示例14: doInBackground

import com.mongodb.MongoClientURI; //导入依赖的package包/类
@Override
protected Integer doInBackground(User... params) {
    try {
        MongoClientURI mongoClientURI = new MongoClientURI(Variables.mongo_uri);
        MongoClient mongoClient = new MongoClient(mongoClientURI);
        MongoDatabase dbMongo = mongoClient.getDatabase(mongoClientURI.getDatabase());
        MongoCollection<Document> coll = dbMongo.getCollection("users");
        User local_user = params[0];
        Document user = coll.find(eq("email", local_user.getEmail())).first();
        mongoClient.close();
        if (user == null || !(user.get("pin").equals(local_user.getPin()))) {
            return 1; // Wrong data
        }
        Date d = (Date) user.get("birthDate");
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        // WARNING: Calendar.MONTH starts in 0 Calendar.DAY_OF_MONTH starts in 1
        local_user.completeSignIn((String) user.get("name"), cal.get(Calendar.DAY_OF_MONTH) - 1, cal.get(Calendar.MONTH), cal.get(Calendar.YEAR), (Boolean) user.get("gender"), user.getObjectId("_id").toString());
        return 0; //Successfully saved
    } catch (Exception e) {
        return 2; // Error
    }
}
 
开发者ID:Ana06,项目名称:medical-data-android,代码行数:24,代码来源:MainActivity.java

示例15: doInBackground

import com.mongodb.MongoClientURI; //导入依赖的package包/类
@Override
protected Integer doInBackground(User... params) {
    try {
        MongoClientURI mongoClientURI = new MongoClientURI(Variables.mongo_uri);
        MongoClient mongoClient = new MongoClient(mongoClientURI);
        MongoDatabase dbMongo = mongoClient.getDatabase(mongoClientURI.getDatabase());
        MongoCollection<Document> coll = dbMongo.getCollection("users");
        User local_user = params[0];
        if (coll.find(eq("email", local_user.getEmail())).first() != null) {
            mongoClient.close();
            return 1; // Repeated email
        }
        Document document = local_user.getRegisterDocument();
        coll.insertOne(document);
        local_user.setId(document.getObjectId("_id").toString());
        mongoClient.close();
        return 0; //Successfully saved
    } catch (Exception e) {
        return 2; // Error
    }
}
 
开发者ID:Ana06,项目名称:medical-data-android,代码行数:22,代码来源:RegisterActivity.java


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