All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.curs.celesta.dbutils.meta.DbIndexInfo Maven / Gradle / Ivy

The newest version!
package ru.curs.celesta.dbutils.meta;

import ru.curs.celesta.score.Index;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * Index information taken from metadata of the database.
 */
public final class DbIndexInfo {
    private final String tableName;
    private final String indexName;
    private final List columnNames = new LinkedList<>();

    public DbIndexInfo(String tableName, String indexName) {
        this.tableName = tableName;
        this.indexName = indexName;
    }

    /**
     * Table name for which index is defined.
     *
     * @return
     */
    public String getTableName() {
        return tableName;
    }

    /**
     * Index name.
     *
     * @return
     */
    public String getIndexName() {
        return indexName;
    }

    /**
     * Column names of the index.
     *
     * @return
     */
    public List getColumnNames() {
        return columnNames;
    }

    @Override
    public String toString() {
        return String.format("%s.%s", tableName, indexName);
    }

    public boolean reflects(Index ind) {
        boolean result = ind.getName().equals(indexName) && ind.getTable().getName().equals(tableName);
        if (!result) {
            return false;
        }
        Collection dbIndexCols = columnNames;
        Collection metaIndexCols = ind.getColumns().keySet();
        Iterator i1 = dbIndexCols.iterator();
        Iterator i2 = metaIndexCols.iterator();
        result = dbIndexCols.size() == metaIndexCols.size();
        if (!result) {
            return false;
        }
        while (i1.hasNext() && result) {
            result = i1.next().equals(i2.next());
        }
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy