/** * Create a new MongoURI from a MongoClientURI. This class is deprecated, use {@link com.mongodb.MongoClientURI}. * * @param proxied the MongoClientURI to wrap with this deprecated class. * @deprecated Replaced by {@link MongoClientURI}) */ @SuppressWarnings("deprecation") @Deprecated public MongoURI(final MongoClientURI proxied) { this.proxied = proxied; options = new MongoOptions(proxied.getOptions()); }
Mongo(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation) { this(createCluster(mongoURI, mongoDriverInformation), mongoURI.getOptions(), mongoURI.getCredentials() != null ? asList(mongoURI.getCredentials()) : Collections.<MongoCredential>emptyList()); }
readPreference = uri.getOptions().getReadPreference(); writeConcern = uri.getOptions().getWriteConcern();
@Override public int hashCode() { int result = getOptions().hashCode(); result = 31 * result + getHosts().hashCode(); MongoCredential credentials = getCredentials(); result = 31 * result + (credentials != null ? credentials.hashCode() : 0); String database = getDatabase(); result = 31 * result + (database != null ? database.hashCode() : 0); String collection = getCollection(); result = 31 * result + (collection != null ? collection.hashCode() : 0); return result; }
private static Cluster createCluster(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation) { List<MongoCredential> credentialList = mongoURI.getCredentials() != null ? singletonList(mongoURI.getCredentials()) : Collections.<MongoCredential>emptyList(); if (mongoURI.getHosts().size() == 1) { return createCluster(createServerAddress(mongoURI.getHosts().get(0)), credentialList, mongoURI.getOptions(), null); } else { List<ServerAddress> seedList = new ArrayList<ServerAddress>(mongoURI.getHosts().size()); for (final String host : mongoURI.getHosts()) { seedList.add(createServerAddress(host)); } return createCluster(seedList, credentialList, mongoURI.getOptions(), mongoDriverInformation); } }
/** * Creates a MongoURI from a string. * * @param uri the URI * @mongodb.driver.manual reference/connection-string Connection String URI Format * @deprecated Replaced by {@link MongoClientURI#MongoClientURI(String)} */ @SuppressWarnings("deprecation") @Deprecated public MongoURI(final String uri) { this.proxied = new MongoClientURI(uri, MongoClientOptions.builder() .connectionsPerHost(10) .writeConcern(WriteConcern.UNACKNOWLEDGED) ); options = new MongoOptions(proxied.getOptions()); }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MongoClientURI that = (MongoClientURI) o; if (!getHosts().equals(that.getHosts())) { return false; } String database = getDatabase(); if (database != null ? !database.equals(that.getDatabase()) : that.getDatabase() != null) { return false; } String collection = getCollection(); if (collection != null ? !collection.equals(that.getCollection()) : that.getCollection() != null) { return false; } MongoCredential credentials = getCredentials(); if (credentials != null ? !credentials.equals(that.getCredentials()) : that.getCredentials() != null) { return false; } if (!getOptions().equals(that.getOptions())) { return false; } return true; }
/** * Create a new MongoURI from a MongoClientURI. This class is deprecated, use {@link com.mongodb.MongoClientURI}. * * @param proxied the MongoClientURI to wrap with this deprecated class. * @deprecated Replaced by {@link MongoClientURI}) */ @SuppressWarnings("deprecation") @Deprecated public MongoURI(final MongoClientURI proxied) { this.proxied = proxied; options = new MongoOptions(proxied.getOptions()); }
/** * Returns {@code true} if the given {@code uri} has a read concern set. * @param uri the URI to check. * @return {@code true} if the URI has a read concern set, {@code false} * otherwise. */ public static boolean hasReadConcern(@NotNull String uri) { ReadConcern rc = new MongoClientURI(checkNotNull(uri)) .getOptions().getReadConcern(); return readConcernLevel(rc) != null; }
/** * Returns {@code true} if the given {@code uri} has a read concern set. * @param uri the URI to check. * @return {@code true} if the URI has a read concern set, {@code false} * otherwise. */ public static boolean hasReadConcern(@NotNull String uri) { ReadConcern rc = new MongoClientURI(checkNotNull(uri)) .getOptions().getReadConcern(); return readConcernLevel(rc) != null; }
Mongo(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation) { this(createCluster(mongoURI, mongoDriverInformation), mongoURI.getOptions(), mongoURI.getCredentials() != null ? asList(mongoURI.getCredentials()) : Collections.<MongoCredential>emptyList()); }
@Override public int hashCode() { int result = getOptions().hashCode(); result = 31 * result + getHosts().hashCode(); MongoCredential credentials = getCredentials(); result = 31 * result + (credentials != null ? credentials.hashCode() : 0); String database = getDatabase(); result = 31 * result + (database != null ? database.hashCode() : 0); String collection = getCollection(); result = 31 * result + (collection != null ? collection.hashCode() : 0); return result; }
@Override public void setReadWriteMode(String readWriteMode) { if (readWriteMode == null || readWriteMode.equals(lastReadWriteMode)) { return; } lastReadWriteMode = readWriteMode; try { String rwModeUri = readWriteMode; if(!readWriteMode.startsWith("mongodb://")){ rwModeUri = String.format("mongodb://localhost/?%s", readWriteMode); } MongoClientURI uri = new MongoClientURI(rwModeUri); ReadPreference readPref = uri.getOptions().getReadPreference(); if (!readPref.equals(nodes.getReadPreference())) { nodes = nodes.withReadPreference(readPref); LOG.info("Using ReadPreference {} ", readPref); } WriteConcern writeConcern = uri.getOptions().getWriteConcern(); if (!writeConcern.equals(nodes.getWriteConcern())) { nodes = nodes.withWriteConcern(writeConcern); LOG.info("Using WriteConcern " + writeConcern); } } catch (Exception e) { LOG.error("Error setting readWriteMode " + readWriteMode, e); } }
private static Cluster createCluster(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation) { List<MongoCredential> credentialList = mongoURI.getCredentials() != null ? singletonList(mongoURI.getCredentials()) : Collections.<MongoCredential>emptyList(); if (mongoURI.getHosts().size() == 1) { return createCluster(createServerAddress(mongoURI.getHosts().get(0)), credentialList, mongoURI.getOptions(), null); } else { List<ServerAddress> seedList = new ArrayList<ServerAddress>(mongoURI.getHosts().size()); for (final String host : mongoURI.getHosts()) { seedList.add(createServerAddress(host)); } return createCluster(seedList, credentialList, mongoURI.getOptions(), mongoDriverInformation); } }
/** * Returns {@code true} if the given {@code uri} has a write concern set. * @param uri the URI to check. * @return {@code true} if the URI has a write concern set, {@code false} * otherwise. */ public static boolean hasWriteConcern(@NotNull String uri) { MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.writeConcern(WC_UNKNOWN); WriteConcern wc = new MongoClientURI(checkNotNull(uri), builder) .getOptions().getWriteConcern(); return !WC_UNKNOWN.equals(wc); }
/** * Returns {@code true} if the given {@code uri} has a write concern set. * @param uri the URI to check. * @return {@code true} if the URI has a write concern set, {@code false} * otherwise. */ public static boolean hasWriteConcern(@NotNull String uri) { MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.writeConcern(WC_UNKNOWN); WriteConcern wc = new MongoClientURI(checkNotNull(uri), builder) .getOptions().getWriteConcern(); return !WC_UNKNOWN.equals(wc); }
public MongoClientURIBuilder(final MongoClientURI mongoClientURI) { List<String> list = mongoClientURI.getHosts(); for (String s : list) { host(s); } database = mongoClientURI.getDatabase(); collection = mongoClientURI.getCollection(); userName = mongoClientURI.getUsername(); if (mongoClientURI.getPassword() != null) { password = new String(mongoClientURI.getPassword()); } options = mongoClientURI.getOptions(); String uri = mongoClientURI.getURI(); if (uri.contains("?")) { String query = uri.substring(uri.indexOf('?') + 1); String[] pairs = query.split("&"); for (String pair : pairs) { String[] split = pair.split("="); param(split[0], split[1]); } } }
/** * Creates a MongoURI from a string. * * @param uri the URI * @mongodb.driver.manual reference/connection-string Connection String URI Format * @deprecated Replaced by {@link MongoClientURI#MongoClientURI(String)} */ @SuppressWarnings("deprecation") @Deprecated public MongoURI(final String uri) { this.proxied = new MongoClientURI(uri, MongoClientOptions.builder() .connectionsPerHost(10) .writeConcern(WriteConcern.UNACKNOWLEDGED) ); options = new MongoOptions(proxied.getOptions()); }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MongoClientURI that = (MongoClientURI) o; if (!getHosts().equals(that.getHosts())) { return false; } String database = getDatabase(); if (database != null ? !database.equals(that.getDatabase()) : that.getDatabase() != null) { return false; } String collection = getCollection(); if (collection != null ? !collection.equals(that.getCollection()) : that.getCollection() != null) { return false; } MongoCredential credentials = getCredentials(); if (credentials != null ? !credentials.equals(that.getCredentials()) : that.getCredentials() != null) { return false; } if (!getOptions().equals(that.getOptions())) { return false; } return true; }
public RealMongoDBExtendedStoreConnection(MongoURI mongoURI) { MongoClientURI mongoClientUri = null; try { mongoClientUri = new MongoClientURI(mongoURI.getValue()); } catch (Exception e) { throw new BaseException("can not parse:\"" + mongoURI.getValue() + "\" " + MongoParamParser.EXPECTED_PARAMS, e); } Frame frame = new Frame(); frame.add("USE MONGO DB"); frame.add("mongo db has be up and running"); frame.add("uri: " + mongoURI.getValue()); frame.add(" -> database:" + mongoClientUri.getDatabase()); frame.add(" -> user:" + mongoClientUri.getUsername()); mongoClientUri.getHosts().forEach(host -> { frame.add(" -> host:" + host); } ); frame.add(" -> ssl:" + mongoClientUri.getOptions().isSslEnabled()); LOGGER.info(frame.toString()); MongoClient mongoClient = new MongoClient(mongoClientUri); database = mongoClient.getDatabase(mongoClientUri.getDatabase()); databaseDeprecated = mongoClient.getDB(mongoClientUri.getDatabase()); }