mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#3101 - Support JPA Indexes
This commit is contained in:
@@ -11,6 +11,7 @@ ebean-profiling*.xml
|
||||
/db
|
||||
/mydb.db
|
||||
profiling/
|
||||
.DS_Store
|
||||
|
||||
# Intellij project files
|
||||
*.iml
|
||||
|
||||
@@ -144,7 +144,7 @@ public class DbConstraintNaming {
|
||||
}
|
||||
sb.append(normaliseColumn(columns[i]));
|
||||
}
|
||||
return sb.toString();
|
||||
return sb.toString().replace(" ", "_");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user