Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ public abstract class AbstractMongoDBRdfConfigurationBuilder<B extends AbstractM
private String host = "localhost";
private String port = DEFAULT_MONGO_PORT;
public static final String DEFAULT_MONGO_PORT = "27017";
private String mongoCollectionPrefix = "rya_";
private String mongoDBName = "rya";
private boolean usePipeline = false;

public static final String MONGO_USER = "mongo.user";
public static final String MONGO_PASSWORD = "mongo.password";
public static final String MONGO_DB_NAME = "mongo.db.name";
public static final String MONGO_COLLECTION_PREFIX = "mongo.collection.prefix";
public static final String MONGO_HOST = "mongo.host";
public static final String MONGO_PORT = "mongo.port";
public static final String MONGO_AUTHS = "mongo.auths";
Expand All @@ -64,7 +62,7 @@ public abstract class AbstractMongoDBRdfConfigurationBuilder<B extends AbstractM
* @param user - user name used to connect to Mongo
* @return specified builder for chaining method invocations
*/
public B setMongoUser(String user) {
public B setMongoUser(final String user) {
this.user = user;
return confBuilder();
}
Expand All @@ -76,7 +74,7 @@ public B setMongoUser(String user) {
* @param password - password used to connect to Mongo
* @return specified builder for chaining method invocations
*/
public B setMongoPassword(String password) {
public B setMongoPassword(final String password) {
this.pass = password;
return confBuilder();
}
Expand All @@ -88,7 +86,7 @@ public B setMongoPassword(String password) {
* @param port - port used to connect Mongo
* @return specified builder for chaining method invocations
*/
public B setMongoPort(String port) {
public B setMongoPort(final String port) {
this.port = port;
return confBuilder();
}
Expand All @@ -100,7 +98,7 @@ public B setMongoPort(String port) {
* @param host - host used to connect to Mongo
* @return specified builder for chaining method invocations
*/
public B setMongoHost(String host) {
public B setMongoHost(final String host) {
this.host = host;
return confBuilder();
}
Expand All @@ -112,32 +110,19 @@ public B setMongoHost(String host) {
* @param name - name of MongoDB to connect to
* @return specified builder for chaining method invocations
*/
public B setMongoDBName(String name) {
public B setMongoDBName(final String name) {
this.mongoDBName = name;
return confBuilder();
}

/**
* Sets MongoDB Collection prefix. This parameter must be set to connect to
* an instance of MongoDB and will default to "rya_" is no value is
* specified.
*
* @param prefix - name of Collection to connect to
* @return specified builder for chaining method invocations
*/
public B setMongoCollectionPrefix(String prefix) {
this.mongoCollectionPrefix = prefix;
return confBuilder();
}

/**
* Set whether to use instance of embedded Mongo as backend for Rya
* instance.
*
* @param useMock - indicates whether to use embedded Mongo as Rya backing
* @return specified builder for chaining method invocations
*/
public B setUseMockMongo(boolean useMock) {
public B setUseMockMongo(final boolean useMock) {
this.useMock = useMock;
return confBuilder();
}
Expand All @@ -151,7 +136,7 @@ public B setUseMockMongo(boolean useMock) {
* optimization is attempted on their child subtrees.
* @param usePipeline whether to use aggregation pipeline optimization.
*/
public B setUseAggregationPipeline(boolean usePipeline) {
public B setUseAggregationPipeline(final boolean usePipeline) {
this.usePipeline = usePipeline;
return confBuilder();
}
Expand All @@ -170,7 +155,7 @@ public C build() {
* @param conf - Configuration object
* @return - Configuration object with parameters set
*/
private C getConf(C conf) {
private C getConf(final C conf) {

conf.setUseMock(useMock);
conf.set("sc.useMongo", "true");
Expand All @@ -181,9 +166,7 @@ private C getConf(C conf) {
if (pass != null) {
conf.setMongoPassword(pass);
}
conf.setMongoDBName(mongoDBName);
conf.setRyaInstanceName(mongoCollectionPrefix);
conf.setTablePrefix(mongoCollectionPrefix);
conf.setRyaInstanceName(mongoDBName);
conf.setMongoHostname(host);
conf.setMongoPort(port);
conf.setUseAggregationPipeline(usePipeline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ public CloseableIterable<RyaStatement> query(final BatchRyaQuery batchRyaQuery)
}

private MongoCollection<Document> getCollection(final StatefulMongoDBRdfConfiguration conf) {
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.getMongoDBName());
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.getRyaInstanceName());
return db.getCollection(conf.getTriplesCollectionName());
}

@Override
public void close() throws IOException {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@
* A {@link RdfCloudTripleStoreConfiguration} that configures how Rya connects to a MongoDB Rya triple store.
*/
public class MongoDBRdfConfiguration extends RdfCloudTripleStoreConfiguration {
public static final String RYA_TRIPLES_COLLECTION = "rya_triples";

// MongoDB Server connection values.
public static final String MONGO_HOSTNAME = "mongo.db.instance";
public static final String MONGO_PORT = "mongo.db.port";

// MongoDB Database values.
public static final String MONGO_DB_NAME = "mongo.db.name";
public static final String RYA_INSTANCE_NAME = "mongo.db.name";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this field should be renamed. It's still the Mongo DB Name. Elsewhere in the code we should decide that the rya instance name also happens to be the db name. If this is in fact just the instance name, and the DB name isn't allowed to be configured anymore, then the field's value shouldn't be "mongo.db.name" anymore.

public static final String MONGO_USER = "mongo.db.user";
public static final String MONGO_USER_PASSWORD = "mongo.db.userpassword";

// Rya Instance values.
public static final String MONGO_COLLECTION_PREFIX = "mongo.db.collectionprefix";

// Rya Sail configuration values.
public static final String USE_MOCK_MONGO = ".useMockInstance";
public static final String CONF_FLUSH_EACH_UPDATE = "rya.mongodb.dao.flusheachupdate";
Expand Down Expand Up @@ -148,21 +146,6 @@ public void setMongoPort(final String port) {
set(MONGO_PORT, port);
}

/**
* @return The name of the MongoDB Database to connect to. (default: rya)
*/
public String getMongoDBName() {
return get(MONGO_DB_NAME, "rya");
}

/**
* @param database - The name of the MongoDb Database to connect to.
*/
public void setMongoDBName(final String database) {
requireNonNull(database);
set(MONGO_DB_NAME, database);
}

/**
* @param user - The user used to connect to the MongoDB Database that hosts the Rya Instance. (not null)
*/
Expand Down Expand Up @@ -197,22 +180,22 @@ public void setMongoPassword(final String password) {
* @return The name of the Rya instance to connect to. (default: rya)
*/
public String getRyaInstanceName() {
return get(MONGO_COLLECTION_PREFIX, "rya");
return get(RYA_INSTANCE_NAME, "rya");
}

/**
* @param name - The name of the Rya instance to connect to.
*/
public void setRyaInstanceName(final String name) {
requireNonNull(name);
set(MONGO_COLLECTION_PREFIX, name);
set(RYA_INSTANCE_NAME, name);
}

/**
* @return The name of the MongoDB Collection that contains Rya statements. (default: rya_triples)
* @return The name of the MongoDB Collection that contains Rya statements. (rya_triples)
*/
public String getTriplesCollectionName() {
return getRyaInstanceName() + "_triples";
return RYA_TRIPLES_COLLECTION;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MongoDBRdfConfigurationBuilder
* Creates a MongoRdfConfiguration object from a Properties file. This
* method assumes that all values in the Properties file are Strings and
* that the Properties file uses the keys below.
*
*
* <br>
* <ul>
* <li>"mongo.auths" - String of Mongo authorizations. Empty auths used by
Expand All @@ -59,16 +59,16 @@ public class MongoDBRdfConfigurationBuilder
* by default.
* </ul>
* <br>
*
*
* @param props
* - Properties file containing Mongo specific configuration
* parameters
* @return MongoRdfConfiguration with properties set
*/
public static MongoDBRdfConfiguration fromProperties(Properties props) {
public static MongoDBRdfConfiguration fromProperties(final Properties props) {
try {

MongoDBRdfConfigurationBuilder builder = new MongoDBRdfConfigurationBuilder() //
final MongoDBRdfConfigurationBuilder builder = new MongoDBRdfConfigurationBuilder() //
.setAuths(props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_AUTHS, "")) //
.setRyaPrefix(props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_RYA_PREFIX, "rya_"))//
.setVisibilities(props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_VISIBILITIES, ""))
Expand All @@ -78,8 +78,6 @@ public static MongoDBRdfConfiguration fromProperties(Properties props) {
props.getProperty(AbstractMongoDBRdfConfigurationBuilder.USE_DISPLAY_QUERY_PLAN, "true")))//
.setMongoUser(props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_USER)) //
.setMongoPassword(props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_PASSWORD))//
.setMongoCollectionPrefix(
props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_COLLECTION_PREFIX, "rya_"))//
.setMongoDBName(
props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_DB_NAME, "rya_triples"))//
.setMongoHost(props.getProperty(AbstractMongoDBRdfConfigurationBuilder.MONGO_HOST, "localhost"))//
Expand All @@ -89,7 +87,7 @@ public static MongoDBRdfConfiguration fromProperties(Properties props) {
props.getProperty(AbstractMongoDBRdfConfigurationBuilder.USE_MOCK_MONGO, "false")));

return builder.build();
} catch (Exception e) {
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public synchronized void setConf(final StatefulMongoDBRdfConfiguration conf) {
auths = conf.getAuthorizations();
flushEachUpdate.set(conf.flushEachUpdate());
}


public void setDB(final DB db) {
this.db = db;
}
Expand All @@ -107,7 +107,7 @@ public void init() throws RyaDAOException {
index.setConf(conf);
}

db = mongoClient.getDB(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
db = mongoClient.getDB(conf.getRyaInstanceName());
coll = db.getCollection(conf.getTriplesCollectionName());
nameSpaceManager = new SimpleMongoDBNamespaceManager(db.getCollection(conf.getNameSpacesCollectionName()));
queryEngine = new MongoDBQueryEngine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public SparqlToPipelineTransformVisitor(MongoCollection<Document> inputCollectio
public SparqlToPipelineTransformVisitor(StatefulMongoDBRdfConfiguration conf) {
Preconditions.checkNotNull(conf);
MongoClient mongo = conf.getMongoClient();
MongoDatabase db = mongo.getDatabase(conf.getMongoDBName());
MongoDatabase db = mongo.getDatabase(conf.getRyaInstanceName());
this.inputCollection = db.getCollection(conf.getTriplesCollectionName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class MongoDBRdfConfigurationTest {

@Test
public void testBuilder() {
final String prefix = "prefix_";
final String auth = "U,V,W";
final String visibility = "U,W";
final String user = "user";
Expand All @@ -42,37 +41,34 @@ public void testBuilder() {
final boolean useInference = true;
final boolean displayPlan = false;

final MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration().getBuilder()
new MongoDBRdfConfiguration();
final MongoDBRdfConfiguration conf = MongoDBRdfConfiguration.getBuilder()
.setVisibilities(visibility)
.setUseInference(useInference)
.setDisplayQueryPlan(displayPlan)
.setUseMockMongo(useMock)
.setMongoCollectionPrefix(prefix)
.setMongoDBName("dbname")
.setMongoHost("host")
.setMongoPort("1000")
.setAuths(auth)
.setMongoUser(user)
.setMongoPassword(password).build();

assertEquals(conf.getTablePrefix(), prefix);
assertTrue(Arrays.equals(conf.getAuths(), new String[] { "U", "V", "W" }));
assertEquals(conf.getCv(), visibility);
assertEquals(conf.isInfer(), useInference);
assertEquals(conf.isDisplayQueryPlan(), displayPlan);
assertEquals(conf.getMongoHostname(), "host");
assertEquals(conf.getBoolean(".useMockInstance", false), useMock);
assertEquals(conf.getMongoPort(), "1000");
assertEquals(conf.getMongoDBName(), "dbname");
assertEquals(conf.getRyaInstanceName(), "prefix_");
assertEquals(conf.getRyaInstanceName(), "dbname");
assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER), user);
assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER_PASSWORD), password);

}

@Test
public void testBuilderFromProperties() throws FileNotFoundException, IOException {
final String prefix = "prefix_";
final String auth = "U";
final String visibility = "U";
final String user = "user";
Expand All @@ -86,16 +82,14 @@ public void testBuilderFromProperties() throws FileNotFoundException, IOExceptio

final MongoDBRdfConfiguration conf = MongoDBRdfConfiguration.fromProperties(props);

assertEquals(conf.getTablePrefix(), prefix);
assertTrue(Arrays.equals(conf.getAuths(), new String[] { auth }));
assertEquals(conf.getCv(), visibility);
assertEquals(conf.isInfer(), useInference);
assertEquals(conf.isDisplayQueryPlan(), displayPlan);
assertEquals(conf.getMongoHostname(), "host");
assertEquals(conf.getBoolean(".useMockInstance", false), useMock);
assertEquals(conf.getMongoPort(), "1000");
assertEquals(conf.getMongoDBName(), "dbname");
assertEquals(conf.getRyaInstanceName(), "prefix_");
assertEquals(conf.getRyaInstanceName(), "dbname");
assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER), user);
assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER_PASSWORD), password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testAdd() throws RyaDAOException, MongoException, IOException {
builder.setSubject(new RyaIRI("http://subject.com"));
builder.setObject(new RyaIRI("http://object.com"));

final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.getRyaInstanceName());
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());

dao.add(builder.build());
Expand All @@ -94,7 +94,7 @@ public void testDelete() throws RyaDAOException, MongoException, IOException {
builder.setObject(new RyaIRI("http://object.com"));
final RyaStatement statement = builder.build();

final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.RYA_INSTANCE_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());

dao.add(statement);
Expand All @@ -121,7 +121,7 @@ public void testDeleteWildcardSubjectWithContext() throws RyaDAOException, Mongo
builder.setContext(new RyaIRI("http://context.com"));
final RyaStatement statement = builder.build();

final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.RYA_INSTANCE_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());

dao.add(statement);
Expand Down Expand Up @@ -153,7 +153,7 @@ public void testReconstructDao() throws RyaDAOException, IOException {
builder.setObject(new RyaIRI("http://object.com"));
builder.setColumnVisibility(new DocumentVisibility("B").flatten());

final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.RYA_INSTANCE_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());

dao.add(builder.build());
Expand Down Expand Up @@ -186,7 +186,7 @@ public void testReconstructDao() throws RyaDAOException, IOException {
builder.setObject(new RyaIRI("http://object.com"));
builder.setColumnVisibility(new DocumentVisibility("B").flatten());

final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.RYA_INSTANCE_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());

dao.add(builder.build());
Expand Down
Loading