com.mongodb.MongoClientOptions.Builder Java Examples
The following examples show how to use
com.mongodb.MongoClientOptions.Builder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoDBFactory.java From database-transform-tool with Apache License 2.0 | 5 votes |
/** * @decription 初始化配置 * @author yi.zhang * @time 2017年6月2日 下午2:15:57 */ public void init(String servers,String database,String schema,String username,String password) { try { List<ServerAddress> saddress = new ArrayList<ServerAddress>(); if (servers != null && !"".equals(servers)) { for (String server : servers.split(",")) { String[] address = server.split(":"); String ip = address[0]; int port = 27017; if (address != null && address.length > 1) { port = Integer.valueOf(address[1]); } saddress.add(new ServerAddress(ip, port)); } } MongoCredential credential = MongoCredential.createScramSha1Credential(username, database,password.toCharArray()); List<MongoCredential> credentials = new ArrayList<MongoCredential>(); credentials.add(credential); Builder builder = new MongoClientOptions.Builder(); builder.maxWaitTime(MAX_WAIT_TIME); // 通过连接认证获取MongoDB连接 MongoClient client = new MongoClient(saddress, credentials, builder.build()); // 连接到数据库 session = client.getDatabase(schema); } catch (Exception e) { logger.error("-----MongoDB Config init Error-----", e); } }
Example #2
Source File: MongoDBDriver.java From birt with Eclipse Public License 1.0 | 5 votes |
private static MongoClientOptions.Builder createDefaultClientOptionsBuilder(Properties connProperties ) { Builder clientOptionsBuilder = new MongoClientOptions.Builder( ); if ( connProperties != null ) { if ( hasKeepSocketAlive( connProperties ) ) // need to change // setting, // as MongoDB default is // false clientOptionsBuilder.socketKeepAlive( true ); } return clientOptionsBuilder; }
Example #3
Source File: MongoDBDriver.java From birt with Eclipse Public License 1.0 | 5 votes |
private static MongoClientURI getMongoURI( Properties connProps, MongoClientOptions.Builder clientOptionsBuilder ) throws Exception { // check if explicitly indicated not to use URI, even if URI value exists Boolean ignoreURI = getBooleanPropValue( connProps, IGNORE_URI_PROP ); if( ignoreURI != null && ignoreURI ) return null; String uri = getStringPropValue( connProps, MONGO_URI_PROP ); if( uri == null || uri.isEmpty() ) return null; try { if ( clientOptionsBuilder != null ) { return new MongoClientURI( uri, clientOptionsBuilder ); } else { return new MongoClientURI( uri ); } } catch( Exception ex ) { // log and ignore getLogger().log( Level.INFO, Messages.bind( "Invalid Mongo Database URI: {0}", uri ), ex ); //$NON-NLS-1$ throw ex; } //return null; }
Example #4
Source File: BeihuMongoClientFactory.java From beihu-boot with Apache License 2.0 | 4 votes |
private Builder builder(MongoClientOptions options) { if (options != null) { return MongoClientOptions.builder(options); } return MongoClientOptions.builder(); }
Example #5
Source File: AbstractMongoProcessor.java From localization_nifi with Apache License 2.0 | 4 votes |
protected Builder getClientOptions(final SSLContext sslContext) { MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.sslEnabled(true); builder.socketFactory(sslContext.getSocketFactory()); return builder; }
Example #6
Source File: AbstractMongoProcessorTest.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override protected Builder getClientOptions(SSLContext sslContext) { return MongoClientOptions.builder(); }
Example #7
Source File: AbstractMongoProcessor.java From nifi with Apache License 2.0 | 4 votes |
protected Builder getClientOptions(final SSLContext sslContext) { MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.sslEnabled(true); builder.socketFactory(sslContext.getSocketFactory()); return builder; }
Example #8
Source File: AbstractMongoProcessorTest.java From nifi with Apache License 2.0 | 4 votes |
@Override protected Builder getClientOptions(SSLContext sslContext) { return MongoClientOptions.builder(); }