diff --git a/src/main/java/com/avaje/ebean/config/DocStoreConfig.java b/src/main/java/com/avaje/ebean/config/DocStoreConfig.java index 36a7f7b05..86efc4857 100644 --- a/src/main/java/com/avaje/ebean/config/DocStoreConfig.java +++ b/src/main/java/com/avaje/ebean/config/DocStoreConfig.java @@ -13,10 +13,20 @@ public class DocStoreConfig { protected boolean active; /** - * When true the Document store should drop and re-create any document mapping (like DDL). + * Set to true means Ebean will generate mapping files on startup. + */ + protected boolean generateMapping; + + /** + * When true the Document store should drop and re-create document indexes. */ protected boolean dropCreate; + /** + * When true the Document store should create any document indexes that don't already exist. + */ + protected boolean create; + /** * The URL of the Document store server. For example: http://localhost:9200. */ @@ -87,19 +97,49 @@ public class DocStoreConfig { } /** - * Return true if the document store should recreate mappings. + * Return true if Ebean should generate mapping files on server startup. + */ + public boolean isGenerateMapping() { + return generateMapping; + } + + /** + * Set to true if Ebean should generate mapping files on server startup. + */ + public void setGenerateMapping(boolean generateMapping) { + this.generateMapping = generateMapping; + } + + /** + * Return true if the document store should recreate mapped indexes. */ public boolean isDropCreate() { return dropCreate; } /** - * Set to true if the document store should recreate mappings. + * Set to true if the document store should recreate mapped indexes. */ public void setDropCreate(boolean dropCreate) { this.dropCreate = dropCreate; } + /** + * Create true if the document store should create mapped indexes that don't yet exist. + * This is only used if dropCreate is false. + */ + public boolean isCreate() { + return create; + } + + /** + * Set to true if the document store should create mapped indexes that don't yet exist. + * This is only used if dropCreate is false. + */ + public void setCreate(boolean create) { + this.create = create; + } + /** * Return the default batch size to use for calls to the Bulk API. */ @@ -198,7 +238,9 @@ public class DocStoreConfig { url = properties.get("docstore.url", url); persist = properties.getEnum(DocStoreMode.class, "docstore.persist", persist); bulkBatchSize = properties.getInt("docstore.bulkBatchSize", bulkBatchSize); + generateMapping = properties.getBoolean("docstore.generateMapping", generateMapping); dropCreate = properties.getBoolean("docstore.dropCreate", dropCreate); + create = properties.getBoolean("docstore.create", create); mappingPath = properties.get("docstore.mappingPath", mappingPath); mappingSuffix = properties.get("docstore.mappingSuffix", mappingSuffix); pathToResources = properties.get("docstore.pathToResources", pathToResources); diff --git a/src/test/java/com/avaje/ebean/config/DocStoreConfigTest.java b/src/test/java/com/avaje/ebean/config/DocStoreConfigTest.java index 48ea8cbb2..033d78c68 100644 --- a/src/test/java/com/avaje/ebean/config/DocStoreConfigTest.java +++ b/src/test/java/com/avaje/ebean/config/DocStoreConfigTest.java @@ -10,7 +10,7 @@ import static org.junit.Assert.*; public class DocStoreConfigTest { @Test - public void testLoadSettings() throws Exception { + public void loadSettings() throws Exception { DocStoreConfig config = new DocStoreConfig(); @@ -25,9 +25,44 @@ public class DocStoreConfigTest { config.loadSettings(wrapper); assertTrue(config.isActive()); + assertFalse(config.isGenerateMapping()); + assertFalse(config.isDropCreate()); assertEquals("http://foo:9800", config.getUrl()); assertEquals(DocStoreMode.IGNORE, config.getPersist()); assertEquals(99, config.getBulkBatchSize()); + } + @Test + public void loadSettings_generateMapping_dropCreate() throws Exception { + + DocStoreConfig config = new DocStoreConfig(); + + Properties properties = new Properties(); + properties.setProperty("ebean.docstore.generateMapping", "true"); + properties.setProperty("ebean.docstore.dropCreate", "true"); + + PropertiesWrapper wrapper = new PropertiesWrapper("ebean", null, properties); + config.loadSettings(wrapper); + + assertTrue(config.isGenerateMapping()); + assertTrue(config.isDropCreate()); + assertFalse(config.isCreate()); + } + + @Test + public void loadSettings_generateMapping_create() throws Exception { + + DocStoreConfig config = new DocStoreConfig(); + + Properties properties = new Properties(); + properties.setProperty("ebean.docstore.generateMapping", "true"); + properties.setProperty("ebean.docstore.create", "true"); + + PropertiesWrapper wrapper = new PropertiesWrapper("ebean", null, properties); + config.loadSettings(wrapper); + + assertTrue(config.isGenerateMapping()); + assertTrue(config.isCreate()); + assertFalse(config.isDropCreate()); } } \ No newline at end of file