mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
ENH: Support @Index platforms attribute - platform specific indexes
This is a potential alternative to using extra-dll.xml. Might be appropriate to use over extra-dll in small simple cases. We might look to extend this in the future to allow full raw platform specific ddl - the ability to specify the entire create index statement.
This commit is contained in:
@@ -9,35 +9,30 @@ public class DbConstraintNamingTest {
|
||||
DbConstraintNaming naming = new DbConstraintNaming();
|
||||
|
||||
@Test
|
||||
public void testPrimaryKeyName() throws Exception {
|
||||
|
||||
public void testPrimaryKeyName() {
|
||||
assertThat(naming.primaryKeyName("[cat].[sce].[foo_bar]")).isEqualTo("pk_foo_bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueConstraintName() throws Exception {
|
||||
|
||||
public void testUniqueConstraintName() {
|
||||
assertThat(naming.uniqueConstraintName("[foo_bar]", "[jim]")).isEqualTo("uq_foo_bar_jim");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConstraintName() throws Exception {
|
||||
|
||||
public void testCheckConstraintName() {
|
||||
assertThat(naming.checkConstraintName("[foo_bar]", "[jim]")).isEqualTo("ck_foo_bar_jim");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalise() throws Exception {
|
||||
|
||||
public void testNormalise() {
|
||||
assertThat(naming.normaliseTable("cat.sch.foo_bar]")).isEqualTo("foo_bar");
|
||||
assertThat(naming.normaliseTable("sch.foo_bar]")).isEqualTo("foo_bar");
|
||||
assertThat(naming.normaliseTable("foo_bar]")).isEqualTo("foo_bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultToLower() throws Exception {
|
||||
public void testDefaultToLower() {
|
||||
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("foo_bar");
|
||||
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
@@ -45,8 +40,7 @@ public class DbConstraintNamingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoLowerCaseTable() throws Exception {
|
||||
|
||||
public void testNoLowerCaseTable() {
|
||||
DbConstraintNaming naming = new DbConstraintNaming(false, true);
|
||||
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("FOO_BAR");
|
||||
assertThat(naming.normaliseColumn("SCH.FOO_BAR]")).isEqualTo("sch.foo_bar");
|
||||
@@ -58,8 +52,7 @@ public class DbConstraintNamingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoLowerCaseColumn() throws Exception {
|
||||
|
||||
public void testNoLowerCaseColumn() {
|
||||
DbConstraintNaming naming = new DbConstraintNaming(true, false);
|
||||
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("foo_bar");
|
||||
assertThat(naming.normaliseColumn("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR");
|
||||
@@ -70,4 +63,8 @@ public class DbConstraintNamingTest {
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR")).isEqualTo("SCH.FOO_BAR");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normaliseColumn_withFormula() {
|
||||
assertThat(naming.normaliseColumn("lower(name)")).isEqualTo("lowername");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ModelContainerTest {
|
||||
assertThat(fkCol.getReferences()).isNull();
|
||||
assertThat(fkCol.getForeignKeyName()).isNull();
|
||||
|
||||
final MIndex index = container.getIndex("ix_ec_table");
|
||||
final MIndex index = container.getIndex(new MIndex("ix_ec_table", "ec_table", "foo"));
|
||||
assertThat(index.getTableName()).isEqualTo("ec_table");
|
||||
assertThat(index.getColumns()).containsOnly("fk_col");
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package misc.migration.v1_0;
|
||||
|
||||
import io.ebean.annotation.Index;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import static io.ebean.annotation.Platform.POSTGRES;
|
||||
|
||||
@Index(columnNames = "lower(name)", platforms = POSTGRES)
|
||||
@Entity
|
||||
@Table(name = "migtest_oto_child")
|
||||
public class OtoChild {
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package misc.migration.v1_1;
|
||||
|
||||
import io.ebean.annotation.Index;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import static io.ebean.annotation.Platform.POSTGRES;
|
||||
|
||||
@Index(columnNames = "name", platforms = POSTGRES)
|
||||
@Entity
|
||||
@Table(name = "migtest_oto_child")
|
||||
public class OtoChild {
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
package misc.migration.v1_2;
|
||||
|
||||
import io.ebean.annotation.Index;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import static io.ebean.annotation.Platform.MYSQL;
|
||||
import static io.ebean.annotation.Platform.POSTGRES;
|
||||
|
||||
@Index(name = "ix_m12_otoc71", columnNames = "foo(name)", platforms = {POSTGRES})
|
||||
@Index(name = "ix_m12_otoc72", columnNames = "bar(name)", platforms = {MYSQL})
|
||||
@Index(unique = true, name = "uq_m12_otoc71", columnNames = "uqFoo(name)", platforms = {POSTGRES})
|
||||
@Index(unique = true, name = "uq_m12_otoc72", columnNames = "uqBar(name)", platforms = {MYSQL})
|
||||
@Index(columnNames = "name", platforms = POSTGRES)
|
||||
@Entity
|
||||
@Table(name = "migtest_oto_child")
|
||||
public class OtoChild {
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
package misc.migration.v1_2;
|
||||
|
||||
import io.ebean.annotation.Index;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import static io.ebean.annotation.Platform.MYSQL;
|
||||
import static io.ebean.annotation.Platform.POSTGRES;
|
||||
|
||||
@Index(columnNames = "foo(name)", platforms = {POSTGRES})
|
||||
@Index(columnNames = "bar(name)", platforms = {MYSQL})
|
||||
@Index(unique = true, columnNames = "foo(name)", platforms = {POSTGRES})
|
||||
@Index(unique = true, columnNames = "bar(name)", platforms = {MYSQL})
|
||||
@Entity
|
||||
@Table(name = "migtest_oto_master")
|
||||
public class OtoMaster {
|
||||
|
||||
Reference in New Issue
Block a user