/** * Gets the collection name. * * @return the collection name */ @Nullable public String getCollection() { return proxied.getCollection(); }
@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 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 MongoSchemaDBStore(MongoClientURI uri) throws IOException { client = new MongoClient(uri); String databaseName = uri.getDatabase(); if (databaseName == null) { databaseName = DEFAULT_databaseName; } DB database = client.getDB(databaseName); String collectionName = uri.getCollection(); if (collectionName == null) { collectionName = DEFAULT_collectionName; } collection = database.getCollection(collectionName); collection.createIndex( new BasicDBObject(FeatureTypeDBObject.KEY_typeName, 1), new BasicDBObject("unique", true)); }
/** * Gets the collection name. * * @return the collection name */ @Nullable public String getCollection() { return proxied.getCollection(); }
public static DBCollection getCollection(final MongoClientURI uri) { try { return new MongoClient(uri).getDB(uri.getDatabase()).getCollection(uri.getCollection()); } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
public static DBCollection getCollection(final MongoClientURI uri) { try { return new MongoClient(uri).getDB(uri.getDatabase()).getCollection(uri.getCollection()); } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
@Override public List<InputSplit> calculateSplits() { if (LOG.isDebugEnabled()) { MongoClientURI inputURI = MongoConfigUtil.getInputURI(getConfiguration()); LOG.debug(format("SingleMongoSplitter calculating splits for namespace: %s.%s; hosts: %s", inputURI.getDatabase(), inputURI.getCollection(), inputURI.getHosts())); } return Collections.singletonList( (InputSplit) new MongoInputSplit(getConfiguration())); }
public static DBCollection getCollectionWithAuth(final MongoClientURI uri, final MongoClientURI authURI) { //Make sure auth uri is valid and actually has a username/pw to use if (authURI == null || authURI.getUsername() == null || authURI.getPassword() == null) { throw new IllegalArgumentException("auth URI is empty or does not contain a valid username/password combination."); } DBCollection coll; try { Mongo mongo = new MongoClient(authURI); coll = mongo.getDB(uri.getDatabase()).getCollection(uri.getCollection()); return coll; } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
public static DBCollection getCollectionWithAuth(final MongoClientURI uri, final MongoClientURI authURI) { //Make sure auth uri is valid and actually has a username/pw to use if (authURI == null || authURI.getUsername() == null || authURI.getPassword() == null) { throw new IllegalArgumentException("auth URI is empty or does not contain a valid username/password combination."); } DBCollection coll; try { Mongo mongo = new MongoClient(authURI); coll = mongo.getDB(uri.getDatabase()).getCollection(uri.getCollection()); return coll; } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
private void initMongo(String mongoUri) { this.mongoClientURI = new MongoClientURI( mongoUri, MongoClientOptions.builder().writeConcern(WriteConcern.SAFE)); try { this.mongoClient = new MongoClient(mongoClientURI); } catch (UnknownHostException e) { e.printStackTrace(); } if (mongoClientURI.getDatabase() != null) { this.mongoDb = mongoClient.getDB(mongoClientURI.getDatabase()); } if (mongoClientURI.getCollection() != null) { this.mongoCollection = mongoDb.getCollection(mongoClientURI.getCollection()); } }
@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; }
/** * Retrieve a DBCollection from a MongoDB URI. * @param uri the MongoDB URI * @return the DBCollection in the URI */ public static DBCollection getCollection(final MongoClientURI uri) { try { return getMongoClient(uri).getDB(uri.getDatabase()).getCollection(uri.getCollection()); } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
collection = mongoClientURI.getCollection(); userName = mongoClientURI.getUsername(); if (mongoClientURI.getPassword() != null) {
private void initMongo(String mongoUri) { this.mongoClientURI = new MongoClientURI( mongoUri, MongoClientOptions.builder().writeConcern(WriteConcern.SAFE)); try { this.mongoClient = new MongoClient(mongoClientURI); } catch (UnknownHostException e) { e.printStackTrace(); } if (mongoClientURI.getDatabase() != null) { this.mongoDb = mongoClient.getDB(mongoClientURI.getDatabase()); } if (mongoClientURI.getCollection() != null) { this.mongoCollection = mongoDb.getCollection(mongoClientURI.getCollection()); } }
@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 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]); } } }
/** * Get an authenticated DBCollection from a MongodB URI. * @param authURI the URI with which to authenticate * @param uri the MongoDB URI * @return the authenticated DBCollection */ public static DBCollection getCollectionWithAuth(final MongoClientURI uri, final MongoClientURI authURI) { //Make sure auth uri is valid and actually has a username/pw to use if (authURI == null || authURI.getUsername() == null || authURI.getPassword() == null) { throw new IllegalArgumentException("auth URI is empty or does not contain a valid username/password combination."); } DBCollection coll; try { Mongo mongo = getMongoClient(authURI); coll = mongo.getDB(uri.getDatabase()).getCollection(uri.getCollection()); return coll; } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
@Override public String toString() { String result = "MongoInputSplit{inputURI hosts=" + this.inputURI.getHosts() + ", inputURI namespace=" + this.inputURI.getDatabase() + "." + this.inputURI.getCollection(); if (authURI != null) { result += "authURI hosts=" + authURI.getHosts() + ", authURI database=" + authURI.getDatabase(); } return result + ", min=" + this.min + ", max=" + this.max + ", query=" + this.query + ", sort=" + this.sort + ", fields=" + this.fields + ", limit=" + this.limit + ", skip=" + this.skip + ", notimeout=" + this.notimeout + '}'; }
this.mongoDefaultDb = mongoClient.getDB(mongoClientURI.getDatabase()); if (mongoClientURI.getCollection() != null) { this.mongoDefaultCollection = mongoDefaultDb.getCollection(mongoClientURI.getCollection());