package io.ebeaninternal.server.deploy;
import io.ebean.annotation.Platform;
public class IndexDefinition {
private final String[] columns;
private final String name;
private final Platform[] platforms;
private final boolean unique;
private final boolean concurrent;
private final String definition;
public IndexDefinition(String[] columns, String name, boolean unique, Platform[] platforms, boolean concurrent, String definition) {
this.columns = columns;
this.unique = unique;
this.name = name;
this.platforms = platforms;
this.concurrent = concurrent;
this.definition = definition;
}
public IndexDefinition(String[] columns) {
this.columns = columns;
this.unique = true;
this.name = null;
this.platforms = null;
this.concurrent = false;
this.definition = null;
}
public boolean isUniqueConstraint() {
return unique && !concurrent && noDefinition() && noColumnFormulas();
}
private boolean noDefinition() {
return definition == null || definition.isEmpty();
}
private boolean noColumnFormulas() {
for (String column : columns) {
if (column.contains("(")) {
return false;
}
}
return true;
}
public boolean isUnique() {
return unique;
}
public String getName() {
return name;
}
public String[] getColumns() {
return columns;
}
public Platform[] getPlatforms() {
return platforms;
}
public boolean isConcurrent() {
return concurrent;
}
public String getDefinition() {
return definition;
}
}