#368 - ENH: Enhance @Index to support multiple columns, unique flag and hence also be able to put on the class (annotation target TYPE)

This commit is contained in:
Robin Bygrave committed 2015-08-28 21:56:38 +12:00
1 parent 641ada001e
commit ccba5d08ef
14 files changed
+152 -53

No files matched your search

@@ -11,13 +11,14 @@ import com.avaje.ebean.annotation.CacheStrategy;
import com.avaje.ebean.annotation.CacheTuning;
import com.avaje.ebean.annotation.EntityConcurrencyMode;
import com.avaje.ebean.annotation.History;
import com.avaje.ebean.annotation.Index;
import com.avaje.ebean.annotation.NamedUpdate;
import com.avaje.ebean.annotation.NamedUpdates;
import com.avaje.ebean.annotation.UpdateMode;
import com.avaje.ebean.config.TableName;
import com.avaje.ebeaninternal.server.core.CacheOptions;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.deploy.CompoundUniqueContraint;
import com.avaje.ebeaninternal.server.deploy.CompoundUniqueConstraint;
import com.avaje.ebeaninternal.server.deploy.DeployNamedQuery;
import com.avaje.ebeaninternal.server.deploy.DeployNamedUpdate;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
@@ -76,9 +77,14 @@ public class AnnotationClass extends AnnotationParser {
descriptor.setName("Embeddable:" + cls.getSimpleName());
}
Index index = cls.getAnnotation(Index.class);
if (index != null) {
descriptor.addCompoundUniqueConstraint(new CompoundUniqueConstraint(index.columnNames(), index.name(), index.unique()));
}
UniqueConstraint uc = cls.getAnnotation(UniqueConstraint.class);
if (uc != null) {
descriptor.addCompoundUniqueConstraint(new CompoundUniqueContraint(uc.columnNames()));
descriptor.addCompoundUniqueConstraint(new CompoundUniqueConstraint(uc.columnNames()));
}
Table table = cls.getAnnotation(Table.class);
@@ -86,7 +92,7 @@ public class AnnotationClass extends AnnotationParser {
UniqueConstraint[] uniqueConstraints = table.uniqueConstraints();
if (uniqueConstraints != null) {
for (UniqueConstraint c : uniqueConstraints) {
descriptor.addCompoundUniqueConstraint(new CompoundUniqueContraint(c.columnNames()));
descriptor.addCompoundUniqueConstraint(new CompoundUniqueConstraint(c.columnNames()));
}
}
}
@@ -287,7 +287,7 @@ public class AnnotationFields extends AnnotationParser {
throw new RuntimeException("Can't use Index on foreign key relationships.");
}
prop.setIndexed();
prop.setIndexName(index.value());
prop.setIndexName(index.name());
}
}