com.avdheshyadav.spiderdb.dbmodel.Table.java Source code

Java tutorial

Introduction

Here is the source code for com.avdheshyadav.spiderdb.dbmodel.Table.java

Source

/*
 * SpiderDB - Lightweight Database Schema Crawler
 * Copyright (c) 2010, Avdhesh yadav.
 * Contact: avdhesh.yadav@gmail.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.avdheshyadav.spiderdb.dbmodel;

import java.util.Set;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.CompareToBuilder;

/**
 * 
 * @author Avdhesh Yadav
 *
 */
public final class Table implements Comparable<Table> {
    /** */
    private String tableType;
    /** */
    private String name;
    /** */
    private String schema;
    /** */
    private ColumnSet columnSet;
    /** */
    private PrimaryKey primaryKey;
    /** */
    private IndexSet indexSet;
    /** */
    private PrivilegeSet privilegeSet;
    /** */
    private Set<ForeignKey> foreignKeys;

    /**
     * 
     * @param tableType String
     * @param name String
     * @param name schema
     * @param columns Set<Column>
     * @param primaryKey PrimaryKey
     * @param Set<ForeignKey> foreignKeys
     * @param indexSet IndexSet
     * @param privilegeSet PrivilegeSet
     */
    public Table(String tableType, String name, String schema, ColumnSet columnSet, PrimaryKey primaryKey,
            Set<ForeignKey> foreignKeys, IndexSet indexSet, PrivilegeSet privilegeSet) {
        this.tableType = tableType;
        this.name = name;
        this.schema = schema;
        this.columnSet = columnSet;
        this.primaryKey = primaryKey;
        this.foreignKeys = foreignKeys;
        this.indexSet = indexSet;
        this.privilegeSet = privilegeSet;
    }

    /**
     * 
     * @return String
     */
    public String getTableName() {
        return name;
    }

    /**
     * 
     * @return String
     */
    public String getFullName() {
        if (schema != null && !schema.isEmpty())
            return schema + "." + name;

        return name;
    }

    /**
     * 
     * @return ColumnSet
     */
    public ColumnSet getColumnSet() {
        return columnSet;
    }

    /**
     * 
     * @return  String
     */
    public String getTableType() {
        return tableType;
    }

    /**
     * PrimaryKey can be null.If its null means that this table has no PrimaryKey 
        
     * @return PrimaryKey
     */
    public PrimaryKey getPrimaryKey() {
        return primaryKey;
    }

    /**
     * 
     * @return Set<ForeignKey>
     */
    public Set<ForeignKey> getForeignKeys() {
        return foreignKeys;
    }

    /**
     * 
     * @return IndexSet
     */
    public IndexSet getIndexSet() {
        return indexSet;
    }

    /**
     * 
     * @return PrivilegeSet
     */
    public PrivilegeSet getPrivilegeSet() {
        return privilegeSet;
    }

    /**
     * 
     */
    public int compareTo(final Table other) {
        return new CompareToBuilder().append(tableType, other.tableType).append(name, other.name)
                .append(schema, other.schema).append(columnSet, other.columnSet)
                .append(primaryKey, other.primaryKey).append(indexSet, other.indexSet)
                .append(privilegeSet, other.privilegeSet).append(foreignKeys, other.foreignKeys).toComparison();
    }

    @Override
    public boolean equals(final Object other) {
        if (this == other)
            return true;
        if (!(other instanceof Table))
            return false;
        Table castOther = (Table) other;
        return new EqualsBuilder().append(tableType, castOther.tableType).append(name, castOther.name)
                .append(schema, castOther.schema).append(columnSet, castOther.columnSet)
                .append(primaryKey, castOther.primaryKey).append(indexSet, castOther.indexSet)
                .append(privilegeSet, castOther.privilegeSet).append(foreignKeys, castOther.foreignKeys).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(tableType).append(name).append(schema).append(columnSet)
                .append(primaryKey).append(indexSet).append(privilegeSet).append(foreignKeys).toHashCode();
    }
}