DBVIEW
|
00001 /* 00002 DbView - Graph Visualization 00003 Copyright (C) 2012 Denis BEURIVE 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 /** 00020 * @author Denis Beurive 00021 */ 00022 package org.dbview.input_addons; 00023 00024 import java.util.ArrayList; 00025 import org.dbview.db.structure.*; 00026 00027 /** 00028 * This class represents an index. 00029 * @author Denis Beurive 00030 */ 00031 public class DbIndex 00032 { 00033 /** 00034 * Name of the table that contains the index. 00035 */ 00036 public String table_name = null; 00037 00038 /** 00039 * Name of the index. 00040 */ 00041 public String index_name = null; 00042 00043 /** 00044 * List of fields that are part of the index. 00045 */ 00046 public ArrayList<Field> fields = new ArrayList<Field>(); 00047 00048 /** 00049 * This field indicates whether the index is unique or not. 00050 */ 00051 public Boolean unique = Boolean.FALSE; 00052 00053 /** 00054 * Create an index. 00055 * @param in_table_name Name of the table. 00056 * @param in_unique This argument indicates whether the index is unique or not. 00057 * <ul> 00058 * <li>TRUE: The index is unique.</li> 00059 * <li>FALSE: The index is not unique.</li> 00060 * </ul> 00061 * @param in_index_name Name of the index. 00062 */ 00063 public DbIndex(String in_table_name, Boolean in_unique, String in_index_name) 00064 { 00065 this.table_name = in_table_name; 00066 this.index_name = in_index_name; 00067 this.unique = in_unique; 00068 } 00069 00070 /** 00071 * This method tests whether the index is unique or not. 00072 * @return If the index is unique, then the method returns the value TRUE. 00073 * Otherwise, it returns the value FALSE. 00074 */ 00075 public Boolean isUnique() { return this.unique; } 00076 00077 /** 00078 * This method returns the name of the index. 00079 * @return This method returns the name of the index. 00080 */ 00081 public String getIndexName() { return this.index_name; } 00082 00083 /** 00084 * This method adds a field to the list of fields that compose the index. 00085 * @param in_field Field to add. 00086 */ 00087 public void addField(Field in_field) { this.fields.add(in_field); } 00088 00089 /** 00090 * This method tests if a given field, represented by its name, is part of the index. 00091 * @param in_field Field to add. 00092 * @return 00093 */ 00094 public Boolean containsField(Field in_field) { return this.fields.contains(in_field); } 00095 00096 /** 00097 * This method returns the number of fields that compose the index. 00098 * @return The method returns the number of fields that compose the index. 00099 */ 00100 public Integer fieldCount() { return this.fields.size(); } 00101 00102 /** 00103 * This method returns a field given its position in the list of fields that composes the index. 00104 * @param in_pos Position of the field to extract. 00105 * @return The method returns the field at the given position. 00106 * @throws Exception 00107 */ 00108 public Field getField(Integer in_pos) throws Exception 00109 { 00110 if (in_pos >= this.fields.size()) { throw new Exception("You try to extract a field from an index at an invalid position (" + in_pos.toString() + ")"); } 00111 return this.fields.get(in_pos); 00112 } 00113 }