Repository: gora Updated Branches: refs/heads/master 92b884158 -> f840b5dda
GORA-354 Project: http://git-wip-us.apache.org/repos/asf/gora/repo Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/f840b5dd Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/f840b5dd Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/f840b5dd Branch: refs/heads/master Commit: f840b5dda8856d09aa2e919e1d96ac7d0f26c233 Parents: 92b8841 Author: Renato Marroquin <[email protected]> Authored: Mon Aug 18 00:26:29 2014 +0200 Committer: Renato Marroquin <[email protected]> Committed: Mon Aug 18 00:26:29 2014 +0200 ---------------------------------------------------------------------- .../org/apache/gora/store/DataStoreFactory.java | 16 ++-- gora-core/src/test/conf/gora.properties | 5 +- .../apache/gora/store/TestDataStoreFactory.java | 83 +++++++++++--------- .../org/apache/gora/solr/store/SolrStore.java | 6 +- gora-solr/src/test/conf/gora.properties | 2 +- 5 files changed, 64 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/gora/blob/f840b5dd/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java ---------------------------------------------------------------------- diff --git a/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java b/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java index 8de133e..4408e80 100644 --- a/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java +++ b/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java @@ -20,6 +20,8 @@ package org.apache.gora.store; import java.io.IOException; import java.io.InputStream; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -292,17 +294,11 @@ public class DataStoreFactory{ //recursively try the class names until the base class Class<?> clazz = store.getClass(); while(true) { - String fullKey = GORA + "." + org.apache.gora.util.StringUtils.getClassname(clazz) + "." + baseKey; + String fullKey = GORA + "." + org.apache.gora.util.StringUtils.getClassname(clazz).toLowerCase() + "." + baseKey; String value = getProperty(properties, fullKey); if(value != null) { return value; } - //try once with lowercase - value = getProperty(properties, fullKey.toLowerCase()); - if(value != null) { - return value; - } - if(clazz.equals(DataStoreBase.class)) { break; } @@ -395,9 +391,15 @@ public class DataStoreFactory{ } private static String getProperty(Properties properties, String key, String defaultValue) { + String regex = "[a-z_\\.]*"; if (properties == null) { return defaultValue; } + if (!key.matches(regex)) { + log.warn("Keys should be LOWERCASE. Please change that!"); + log.warn("Using lowecase for key " + key); + key = key.toLowerCase(); + } String result = properties.getProperty(key); if (result == null) { return defaultValue; http://git-wip-us.apache.org/repos/asf/gora/blob/f840b5dd/gora-core/src/test/conf/gora.properties ---------------------------------------------------------------------- diff --git a/gora-core/src/test/conf/gora.properties b/gora-core/src/test/conf/gora.properties index 9ee87f1..8cf975c 100644 --- a/gora-core/src/test/conf/gora.properties +++ b/gora-core/src/test/conf/gora.properties @@ -18,5 +18,6 @@ gora.datastore.autocreateschema=true gora.avrostore.output.path=file:///tmp/gora.avrostore.test.output gora.datafileavrostore.foo_property=foo_value -gora.avrostore.baz_property=baz_value -gora.datastore.bar_property=bar_value +gora.datafileavrostore.baz_property=baz_value +gora.datafileavrostore.bar_property=bar_value +gora.datafileavrostore.cap_property=cap_value \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/f840b5dd/gora-core/src/test/java/org/apache/gora/store/TestDataStoreFactory.java ---------------------------------------------------------------------- diff --git a/gora-core/src/test/java/org/apache/gora/store/TestDataStoreFactory.java b/gora-core/src/test/java/org/apache/gora/store/TestDataStoreFactory.java index a50fd71..f5e2305 100644 --- a/gora-core/src/test/java/org/apache/gora/store/TestDataStoreFactory.java +++ b/gora-core/src/test/java/org/apache/gora/store/TestDataStoreFactory.java @@ -34,7 +34,7 @@ import org.junit.Test; public class TestDataStoreFactory { private Configuration conf; - + @Before public void setUp() { conf = new Configuration(); @@ -42,66 +42,79 @@ public class TestDataStoreFactory { @Test public void testGetDataStore() throws GoraException { - DataStore<?,?> dataStore = DataStoreFactory.getDataStore("org.apache.gora.mock.store.MockDataStore" - , String.class, MockPersistent.class, conf); + DataStore<?, ?> dataStore = DataStoreFactory.getDataStore( + "org.apache.gora.mock.store.MockDataStore", String.class, + MockPersistent.class, conf); assertNotNull(dataStore); } - + @Test public void testGetClasses() throws GoraException { - DataStore<?,?> dataStore = DataStoreFactory.getDataStore("org.apache.gora.mock.store.MockDataStore" - , String.class, MockPersistent.class, conf); + DataStore<?, ?> dataStore = DataStoreFactory.getDataStore( + "org.apache.gora.mock.store.MockDataStore", String.class, + MockPersistent.class, conf); assertNotNull(dataStore); assertEquals(String.class, dataStore.getKeyClass()); assertEquals(MockPersistent.class, dataStore.getPersistentClass()); } - + @Test public void testGetDataStore2() throws GoraException { - DataStore<?,?> dataStore = DataStoreFactory.getDataStore(MockDataStore.class - , String.class, MockPersistent.class, conf); + DataStore<?, ?> dataStore = DataStoreFactory.getDataStore( + MockDataStore.class, String.class, MockPersistent.class, conf); assertNotNull(dataStore); } - + @Test public void testGetDataStore3() throws GoraException { - DataStore<?,?> dataStore1 = DataStoreFactory.getDataStore("org.apache.gora.mock.store.MockDataStore" - , Object.class, MockPersistent.class, conf); - DataStore<?,?> dataStore2 = DataStoreFactory.getDataStore("org.apache.gora.mock.store.MockDataStore" - , Object.class, MockPersistent.class, conf); - DataStore<?,?> dataStore3 = DataStoreFactory.getDataStore("org.apache.gora.mock.store.MockDataStore" - , String.class, MockPersistent.class, conf); - + DataStore<?, ?> dataStore1 = DataStoreFactory.getDataStore( + "org.apache.gora.mock.store.MockDataStore", Object.class, + MockPersistent.class, conf); + DataStore<?, ?> dataStore2 = DataStoreFactory.getDataStore( + "org.apache.gora.mock.store.MockDataStore", Object.class, + MockPersistent.class, conf); + DataStore<?, ?> dataStore3 = DataStoreFactory.getDataStore( + "org.apache.gora.mock.store.MockDataStore", String.class, + MockPersistent.class, conf); + assertNotSame(dataStore1, dataStore2); assertNotSame(dataStore1, dataStore3); } - + @Test - public void testReadProperties() throws GoraException{ - //indirect testing - DataStore<?,?> dataStore = DataStoreFactory.getDataStore(String.class, - MockPersistent.class, conf); + public void testReadProperties() throws GoraException { + // indirect testing + DataStore<?, ?> dataStore = DataStoreFactory.getDataStore(String.class, + MockPersistent.class, conf); assertNotNull(dataStore); assertEquals(MockDataStore.class, dataStore.getClass()); } - + @Test public void testFindProperty() { Properties properties = DataStoreFactory.createProps(); - - DataStore<String, MockPersistent> store = new DataFileAvroStore<String,MockPersistent>(); - - String fooValue = DataStoreFactory.findProperty(properties, store - , "foo_property", "foo_default"); + + DataStore<String, MockPersistent> store = new DataFileAvroStore<String, MockPersistent>(); + + String fooValue = DataStoreFactory.findProperty(properties, store, + "foo_property", "foo_default"); assertEquals("foo_value", fooValue); - - String bazValue = DataStoreFactory.findProperty(properties, store - , "baz_property", "baz_default"); + + String bazValue = DataStoreFactory.findProperty(properties, store, + "baz_property", "baz_default"); assertEquals("baz_value", bazValue); - - String barValue = DataStoreFactory.findProperty(properties, store - , "bar_property", "bar_default"); + + String barValue = DataStoreFactory.findProperty(properties, store, + "bar_property", "bar_default"); assertEquals("bar_value", barValue); + + String capValue = DataStoreFactory.findProperty(properties, store, + "cap_property", "cap_default"); + assertEquals("cap_value", capValue); + + String secondCapValue = DataStoreFactory.findProperty(properties, store, + "CAP_property", "cap_default"); + assertEquals("cap_value", secondCapValue); } - + } http://git-wip-us.apache.org/repos/asf/gora/blob/f840b5dd/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java ---------------------------------------------------------------------- diff --git a/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java b/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java index bee3d43..37db1e8 100644 --- a/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java +++ b/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java @@ -83,7 +83,7 @@ public class SolrStore<K, T extends PersistentBase> extends DataStoreBase<K, T> * Should be defined in <code>gora.properties</code>. * A default value of 100 is used if this value is absent. This value must be of type <b>Integer</b>. */ - protected static final String SOLR_BATCH_SIZE_PROPERTY = "solr.batchSize"; + protected static final String SOLR_BATCH_SIZE_PROPERTY = "solr.batch_size"; /** The solrj implementation to use. This has a default value of <i>http</i> for HttpSolrServer. * Available options include <b>http</b>, <b>cloud</b>, <b>concurrent</b> and <b>loadbalance</b>. @@ -96,13 +96,13 @@ public class SolrStore<K, T extends PersistentBase> extends DataStoreBase<K, T> * Should be defined in <code>gora.properties</code>. * A default value of 1000 is used if this value is absent. This value must be of type <b>Integer</b>. */ - protected static final String SOLR_COMMIT_WITHIN_PROPERTY = "solr.commitWithin"; + protected static final String SOLR_COMMIT_WITHIN_PROPERTY = "solr.commit_within"; /** The maximum number of result to return when we make a call to * {@link org.apache.gora.solr.store.SolrStore#execute(Query)}. This should be * defined in <code>gora.properties</code>. This value must be of type <b>Integer</b>. */ - protected static final String SOLR_RESULTS_SIZE_PROPERTY = "solr.resultsSize"; + protected static final String SOLR_RESULTS_SIZE_PROPERTY = "solr.results_size"; /** The default batch size (ArrayList) of SolrDocuments to be used in the event of an absent * value for <code>solr.batchSize</code>. http://git-wip-us.apache.org/repos/asf/gora/blob/f840b5dd/gora-solr/src/test/conf/gora.properties ---------------------------------------------------------------------- diff --git a/gora-solr/src/test/conf/gora.properties b/gora-solr/src/test/conf/gora.properties index d64e267..e53fc95 100644 --- a/gora-solr/src/test/conf/gora.properties +++ b/gora-solr/src/test/conf/gora.properties @@ -15,5 +15,5 @@ gora.solrstore.solr.solrjserver=http # limitations under the License. gora.solrstore.solr.url=http://localhost:9876/solr -gora.datastore.solr.commitWithin=0 +gora.datastore.solr.commit_within=0 gora.solrstore.solr.solrjserver=http
