diff --git a/.gitignore b/.gitignore index 861a33064..a95675f95 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ ebean-profiling*.xml /db /mydb.db profiling/ +.DS_Store # Intellij project files *.iml diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 46be98f0b..0c9df93eb 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -4,13 +4,13 @@ Overview of ebean.properties file ### DbMigration options -You can set individual values for different platforms when generating migrations +You can set individual values for different platforms when generating migrations. `dbmigration.platform..databaseSequenceBatchSize` For DB's using sequences this is the number of sequence values prefetched. `dbmigration.platform..dbuuid` -Control, how UUID generation should work - it affects DDL which column type is generated. Possible values: +Control, how UUID generation should work - it affects which column type is generated in DDL. Possible values: - BINARY enforces binary UUID - VARCHAR enforces varchar UUID - BINARY_OPTIMIZED enforces binary-optimized UUID (makes sense only with Type1 ID) @@ -19,7 +19,7 @@ Control, how UUID generation should work - it affects DDL which column type is g - AUTO_VARCHAR (default) use varchar when platform does not support UUID `dbmigration.platform..uuidStoreAsBinary` -Same as setting dbuuid to BINARY +Same as setting dbuuid to BINARY. `dbmigration.platform..geometrySRID` The Geometry SRID value (default 4326). @@ -30,7 +30,6 @@ The ID type (IDENTITY, SEQUENCE, GENERATOR, EXTERNAL) `dbmigration.platform..mapping` Adjust the mapping. For example `BOOLEAN=integer(32);BIT=tinyint(3)` - `ebean.migration.applyPrefix` Set this to "V" to be compatible with FlywayDB. @@ -50,7 +49,7 @@ Set to true if the DB migration should be generated on server start. The version of a pending drop that should be generated as the next migration. `ebean.migration.includeGeneratedFileComment` -TODO +Adds the header about the migration files being generated when true. Reading 'THIS IS A GENERATED FILE - DO NOT MODIFY' `ebean.migration.metaTable` For running migration the DB table that holds migration execution status. Default 'db_migration' @@ -65,17 +64,17 @@ Subdirectory the model xml files go into. Default 'model' Suffix. Default '.model.xml' `ebean.migration.name` -Description text that can be appended to the version to become the ddl script file name +Description text that can be appended to the version to become the ddl script file name. `ebean.migration.patchInsertOn` -migration versions that should be added to history without running. +Migration versions that should be added to history without running. `ebean.migration.patchResetChecksumOn` migration versions that should have their checksum reset and not run. Use this if you get a 'Checksum mismatch' error. `ebean.migration.placeholders` -A comma and equals delimited placeholders that are substituted in SQL scripts when running migration (used by DB Migration runner only). +A comma and equals delimited map of placeholders that are substituted in SQL scripts when running migration (used by DB Migration runner only). `ebean.migration.platform` The database platform to generate migration DDL for. @@ -90,7 +89,7 @@ The migration version name (typically FlywayDb compatible). Example: 1.1.1_2 ### Ebean UUID options `ebean.uuidVersion` -Controls, how the UUIDs are generated. Possible values +Controls how the UUIDs are generated. Possible values: - VERSION4 (default) generate random V4 UUIDs, - VERSION1 generate rfc4122 compliant Type 1 UUIDs (requires a state file) - VERSION1RND generate fake Type 1 UUIDs @@ -98,7 +97,7 @@ Controls, how the UUIDs are generated. Possible values Note, that V1 UUIDs in conjunction with AUTO_BINARY_OPTIMIZED will give you the best index performance, but you MUST understand how this works to avoid collisions. `ebean.uuidStateFile` -The state file that is Required to generate V1 UUIDs +The state file that is required to generate V1 UUIDs. ### DocStoreConfig @@ -107,7 +106,7 @@ The state file that is Required to generate V1 UUIDs True when the Document store integration is active/on. `ebean.docstore.allowAllCertificates` -Set to true such that the client allows connections to invalid/self signed SSL certificates. +Set to true such that the client allows connections to invalid/self-signed SSL certificates. `ebean.docstore.bulkBatchSize` The default batch size to use for the Bulk API calls. @@ -192,7 +191,7 @@ Suffix appended to the base table to derive the view that contains the union of Set to true if the DataSource uses autoCommit. Indicates that Ebean should use autoCommit friendly Transactions and TransactionManager. `ebean.autoReadOnlyDataSource` -When true create a read only DataSource using readOnlyDataSourceConfig defaulting values from dataSourceConfig +When true create a read only DataSource using readOnlyDataSourceConfig defaulting values from dataSourceConfig. `ebean.autostart` Should the server start all diff --git a/ebean-api/src/main/java/io/ebean/config/DbConstraintNaming.java b/ebean-api/src/main/java/io/ebean/config/DbConstraintNaming.java index 7b23244cb..310ec1d7c 100644 --- a/ebean-api/src/main/java/io/ebean/config/DbConstraintNaming.java +++ b/ebean-api/src/main/java/io/ebean/config/DbConstraintNaming.java @@ -144,7 +144,7 @@ public class DbConstraintNaming { } sb.append(normaliseColumn(columns[i])); } - return sb.toString(); + return sb.toString().replace(" ", "_"); } /** diff --git a/ebean-api/src/main/java/io/ebean/config/DbConstraintNormalise.java b/ebean-api/src/main/java/io/ebean/config/DbConstraintNormalise.java index c8dd4da60..12c2d703c 100644 --- a/ebean-api/src/main/java/io/ebean/config/DbConstraintNormalise.java +++ b/ebean-api/src/main/java/io/ebean/config/DbConstraintNormalise.java @@ -27,7 +27,6 @@ public class DbConstraintNormalise { * quoted identifier characters (",',[,] etc). */ public String normaliseTable(String tableName) { - tableName = trimQuotes(tableName); int lastPeriod = tableName.lastIndexOf('.'); if (lastPeriod > -1) { @@ -59,7 +58,6 @@ public class DbConstraintNormalise { * Trim off the platform quoted identifier quotes like [ ' and ". */ public String trimQuotes(String identifier) { - if (identifier == null) { return ""; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IndexDefinition.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IndexDefinition.java index c87947386..18f840b4a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IndexDefinition.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IndexDefinition.java @@ -27,17 +27,24 @@ public final class IndexDefinition { } /** - * Create a unique constraint given the column names. + * Create from JPA Index. */ - public IndexDefinition(String name, String[] columns) { + public IndexDefinition(String name, String[] columns, boolean unique) { this.columns = columns; - this.unique = true; + this.unique = unique; this.name = name; this.platforms = null; this.concurrent = false; this.definition = null; } + /** + * Create a unique constraint given the column names. + */ + public IndexDefinition(String name, String[] columns) { + this(name, columns, true); + } + /** * Return true if this can be used as a unique constraint. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java index 662b73be8..fe45a72d8 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java @@ -129,6 +129,10 @@ final class AnnotationClass extends AnnotationParser { for (UniqueConstraint c : uniqueConstraints) { descriptor.addIndex(new IndexDefinition(c.name(), convertColumnNames(c.columnNames()))); } + for (javax.persistence.Index index : table.indexes()) { + final String[] cols = index.columnList().split(","); + descriptor.addIndex(new IndexDefinition(index.name(), convertColumnNames(cols), index.unique())); + } } StorageEngine storage = typeGet(cls, StorageEngine.class); if (storage != null) { diff --git a/ebean-test/src/test/java/io/ebean/xtest/config/DbConstraintNamingTest.java b/ebean-test/src/test/java/io/ebean/xtest/config/DbConstraintNamingTest.java index b08777c04..21f77be2f 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/config/DbConstraintNamingTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/config/DbConstraintNamingTest.java @@ -31,6 +31,11 @@ public class DbConstraintNamingTest { assertThat(naming.normaliseTable("foo_bar]")).isEqualTo("foo_bar"); } + @Test + public void testIndexNameWithSpaces() { + assertThat(naming.indexName("foo", new String[]{"name", "other desc"})).isEqualTo("ix_foo_name_other_desc"); + } + @Test public void testDefaultToLower() { assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("foo_bar"); diff --git a/ebean-test/src/test/java/org/tests/model/basic/FeatureDescription.java b/ebean-test/src/test/java/org/tests/model/basic/FeatureDescription.java index 955b5f7f6..a939f472b 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/FeatureDescription.java +++ b/ebean-test/src/test/java/org/tests/model/basic/FeatureDescription.java @@ -4,11 +4,12 @@ import io.ebean.annotation.Cache; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Index; import javax.persistence.Table; @Cache(readOnly = true) @Entity -@Table(name = "feature_desc") +@Table(name = "feature_desc", indexes = @Index(columnList = "name, description desc")) public class FeatureDescription { @Id