Skip to content

Commit

Permalink
Responded to code review
Browse files Browse the repository at this point in the history
removed all references to mongo collection prefix
  • Loading branch information
isper3at committed Oct 1, 2018
1 parent 629a41e commit f9691c7
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 123 deletions.
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 @@ -182,8 +167,7 @@ private C getConf(C conf) {
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 @@ -35,6 +35,7 @@
* 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";
Expand All @@ -45,9 +46,6 @@ public class MongoDBRdfConfiguration extends RdfCloudTripleStoreConfiguration {
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 @@ -105,7 +103,7 @@ public MongoDBRdfConfiguration clone() {
* @param useMock - {@code true} to use an embedded Mongo DB instance; {@code false} to connect to a real server.
*/
public void setUseMock(final boolean useMock) {
this.setBoolean(USE_MOCK_MONGO, useMock);
setBoolean(USE_MOCK_MONGO, useMock);
}

/**
Expand Down Expand Up @@ -212,7 +210,7 @@ public void setRyaInstanceName(final String name) {
* @return The name of the MongoDB Collection that contains Rya statements. (rya_triples)
*/
public String getTriplesCollectionName() {
return "rya_triples";
return RYA_TRIPLES_COLLECTION;
}

/**
Expand Down Expand Up @@ -274,17 +272,17 @@ public boolean getUseAggregationPipeline() {
* on their child subtrees.
* @param value whether to use aggregation pipeline optimization.
*/
public void setUseAggregationPipeline(boolean value) {
public void setUseAggregationPipeline(final boolean value) {
setBoolean(USE_AGGREGATION_PIPELINE, value);
}

@Override
public List<Class<QueryOptimizer>> getOptimizers() {
List<Class<QueryOptimizer>> optimizers = super.getOptimizers();
final List<Class<QueryOptimizer>> optimizers = super.getOptimizers();
if (getUseAggregationPipeline()) {
Class<?> cl = AggregationPipelineQueryOptimizer.class;
final Class<?> cl = AggregationPipelineQueryOptimizer.class;
@SuppressWarnings("unchecked")
Class<QueryOptimizer> optCl = (Class<QueryOptimizer>) cl;
final Class<QueryOptimizer> optCl = (Class<QueryOptimizer>) cl;
optimizers.add(optCl);
}
return optimizers;
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 @@ -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,20 +41,19 @@ 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);
Expand All @@ -64,15 +62,14 @@ public void testBuilder() {
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,7 +83,6 @@ 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);
Expand All @@ -95,7 +91,7 @@ public void testBuilderFromProperties() throws FileNotFoundException, IOExceptio
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 @@ -59,7 +59,6 @@
public abstract class AbstractMongoIndexer<T extends IndexingMongoDBStorageStrategy> implements MongoSecondaryIndex {
private static final Logger LOG = Logger.getLogger(AbstractMongoIndexer.class);

private boolean isInit = false;
private boolean flushEachUpdate = true;
protected StatefulMongoDBRdfConfiguration conf;
protected MongoDBRyaDAO dao;
Expand All @@ -72,12 +71,12 @@ public abstract class AbstractMongoIndexer<T extends IndexingMongoDBStorageStrat
protected T storageStrategy;

private MongoDbBatchWriter<DBObject> mongoDbBatchWriter;
protected String collectionName;

protected void initCore() {
dbName = conf.getMongoDBName();
this.mongoClient = conf.getMongoClient();
db = this.mongoClient.getDB(dbName);
final String collectionName = conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya") + getCollectionName();
collection = db.getCollection(collectionName);

flushEachUpdate = ((MongoDBRdfConfiguration)conf).flushEachUpdate();
Expand Down Expand Up @@ -170,7 +169,7 @@ private DBObject prepareStatementForStorage(final RyaStatement ryaStatement) {
try {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
final boolean isValidPredicate = predicates.isEmpty() || predicates.contains(statement.getPredicate());
if (isValidPredicate && (statement.getObject() instanceof Literal)) {
if (isValidPredicate && statement.getObject() instanceof Literal) {
final DBObject obj = storageStrategy.serialize(ryaStatement);
return obj;
}
Expand Down Expand Up @@ -220,5 +219,7 @@ public void close() throws QueryEvaluationException {
/**
* @return The name of the {@link DBCollection} to use with the storage strategy.
*/
public abstract String getCollectionName();
public String getCollectionName() {
return collectionName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ public static MongoIndexingConfiguration fromProperties(final Properties 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 Down Expand Up @@ -312,7 +310,7 @@ public static MongoIndexingConfiguration fromProperties(final Properties props)
* @return MongoIndexingConfigBuilder for chaining method invocations
*/
public MongoDBIndexingConfigBuilder setUseMongoFreetextIndex(final boolean useFreeText) {
this.useFreetext = useFreeText;
useFreetext = useFreeText;
return this;
}

Expand Down Expand Up @@ -355,7 +353,7 @@ public MongoDBIndexingConfigBuilder setUseMongoEntityIndex(final boolean useEnti
* @return MongoIndexingConfigBuilder for chaining method invocations
*/
public MongoDBIndexingConfigBuilder setMongoFreeTextPredicates(final String... predicates) {
this.freetextPredicates = predicates;
freetextPredicates = predicates;
return this;
}

Expand All @@ -367,7 +365,7 @@ public MongoDBIndexingConfigBuilder setMongoFreeTextPredicates(final String... p
* @return MongoIndexingConfigBuilder for chaining method invocations
*/
public MongoDBIndexingConfigBuilder setMongoTemporalPredicates(final String... predicates) {
this.temporalPredicates = predicates;
temporalPredicates = predicates;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
import com.mongodb.QueryBuilder;

public class MongoFreeTextIndexer extends AbstractMongoIndexer<TextMongoDBStorageStrategy> implements FreeTextIndexer {
private static final String COLLECTION_SUFFIX = "freetext";
private static final String COLLECTION_NAME = "freetext";
private static final Logger logger = Logger.getLogger(MongoFreeTextIndexer.class);

@Override
public void init() {
collectionName = COLLECTION_NAME;
initCore();
predicates = ConfigUtils.getFreeTextPredicates(conf);
if(predicates.size() == 0) {
Expand All @@ -52,9 +53,4 @@ public CloseableIteration<Statement, QueryEvaluationException> queryText(
final QueryBuilder qb = QueryBuilder.start().text(query);
return withConstraints(constraints, qb.get());
}

@Override
public String getCollectionName() {
return ConfigUtils.getTablePrefix(conf) + COLLECTION_SUFFIX;
}
}
Loading

0 comments on commit f9691c7

Please sign in to comment.