mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
82 lines
1.6 KiB
Java
82 lines
1.6 KiB
Java
package io.ebeaninternal.server.deploy;
|
|
|
|
import io.ebean.annotation.Platform;
|
|
|
|
/**
|
|
* Holds multiple column unique constraints defined for an entity.
|
|
*/
|
|
public class IndexDefinition {
|
|
|
|
private final String[] columns;
|
|
|
|
private final String name;
|
|
|
|
private final Platform[] platforms;
|
|
|
|
private final boolean unique;
|
|
|
|
/**
|
|
* Create from Index annotation.
|
|
*/
|
|
public IndexDefinition(String[] columns, String name, boolean unique, Platform[] platforms) {
|
|
this.columns = columns;
|
|
this.unique = unique;
|
|
this.name = name;
|
|
this.platforms = platforms;
|
|
}
|
|
|
|
/**
|
|
* Create a unique constraint given the column names.
|
|
*/
|
|
public IndexDefinition(String[] columns) {
|
|
this.columns = columns;
|
|
this.unique = true;
|
|
this.name = null;
|
|
this.platforms = null;
|
|
}
|
|
|
|
/**
|
|
* Return true if this can be used as a unique constraint.
|
|
*/
|
|
public boolean isUniqueConstraint() {
|
|
return unique && noColumnFormulas();
|
|
}
|
|
|
|
private boolean noColumnFormulas() {
|
|
for (String column : columns) {
|
|
if (column.contains("(")) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Return true if this is a unique constraint.
|
|
*/
|
|
public boolean isUnique() {
|
|
return unique;
|
|
}
|
|
|
|
/**
|
|
* Return the index name (can be null).
|
|
*/
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* Return the columns that make up this unique constraint.
|
|
*/
|
|
public String[] getColumns() {
|
|
return columns;
|
|
}
|
|
|
|
/**
|
|
* Return the platforms this index applies to.
|
|
*/
|
|
public Platform[] getPlatforms() {
|
|
return platforms;
|
|
}
|
|
}
|