se.kuseman.payloadbuilder.api.catalog.Index Maven / Gradle / Ivy
package se.kuseman.payloadbuilder.api.catalog;
import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;
import java.util.List;
import se.kuseman.payloadbuilder.api.QualifiedName;
/**
* A table index. Defines columns that can be utilized in batching operators for quicker access to rows.
**/
public class Index
{
private final QualifiedName table;
private final List columns;
private final ColumnsType columnsType;
public Index(QualifiedName table, List columns, ColumnsType columnsType)
{
this.table = requireNonNull(table, "table");
this.columns = unmodifiableList(requireNonNull(columns, "columns"));
this.columnsType = requireNonNull(columnsType, "columnsType");
}
public QualifiedName getTable()
{
return table;
}
public List getColumns()
{
return columns;
}
public ColumnsType getColumnsType()
{
return columnsType;
}
@Override
public int hashCode()
{
return columns.hashCode();
}
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
else if (obj == this)
{
return true;
}
else if (obj instanceof Index that)
{
return table.equals(that.table)
&& columns.equals(that.columns)
&& columnsType == that.columnsType;
}
return false;
}
@Override
public String toString()
{
return table + " " + columns.toString() + " (" + columnsType + ")";
}
/** Type of columns this index supports. */
public enum ColumnsType
{
/**
* A special type of index used by catalogs that can use all found columns for a table. Shortcut type to skip listing all the columns that the table has. Used for example in JDBC-catalog.
*/
WILDCARD,
/**
* Type that specifies that ALL columns must be used to be able to utilize this index
*/
ALL,
/**
* Type that specifies that at least one column (ANY) must be used to be able to utilize this index
*/
ANY,
/**
* Type that specifies that at least one column (ANY) must be used to be able to utilize this index but columns must be used in order from left to right.
*/
ANY_IN_ORDER
}
}