001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.common.jdbc.model.spi; 025 026 import java.util.Set; 027 import java.util.HashSet; 028 import org.jboss.dna.common.jdbc.model.api.Index; 029 import org.jboss.dna.common.jdbc.model.api.IndexColumn; 030 import org.jboss.dna.common.jdbc.model.api.IndexType; 031 032 /** 033 * Provides all database table's index specific metadata. 034 * 035 * @author <a href="mailto:litsenko_sergey@yahoo.com">Sergiy Litsenko</a> 036 */ 037 public class IndexBean extends SchemaObjectBean implements Index { 038 private static final long serialVersionUID = -1217601426100735909L; 039 private Set<IndexColumn> columns = new HashSet<IndexColumn>(); 040 private Boolean unique; 041 private IndexType indexType; 042 private Integer cardinality; 043 private Integer pages; 044 private String filterCondition; 045 046 /** 047 * Default constructor 048 */ 049 public IndexBean() { 050 } 051 052 /** 053 * Retrieves index columns 054 * 055 * @return index columns 056 */ 057 public Set<IndexColumn> getColumns() { 058 return columns; 059 } 060 061 /** 062 * Adds IndexColumn 063 * 064 * @param indexColumn the IndexColumn 065 */ 066 public void addColumn( IndexColumn indexColumn ) { 067 columns.add(indexColumn); 068 } 069 070 /** 071 * delete IndexColumn 072 * 073 * @param indexColumn the IndexColumn 074 */ 075 public void deleteColumn( IndexColumn indexColumn ) { 076 columns.remove(indexColumn); 077 } 078 079 /** 080 * Returns index column for specified column name or null 081 * 082 * @param columnName the name of column 083 * @return index column for specified column name or null. 084 */ 085 public IndexColumn findColumnByName( String columnName ) { 086 for (IndexColumn ic : columns) { 087 if (ic.getName().equals(columnName)) { 088 return ic; 089 } 090 } 091 // return nothing 092 return null; 093 } 094 095 /** 096 * Can index values be non-unique. false when TYPE is tableIndexStatistic. 097 * 098 * @return true if index values can be non-unique. 099 */ 100 public Boolean isUnique() { 101 return unique; 102 } 103 104 /** 105 * Can index values be non-unique. false when TYPE is tableIndexStatistic. 106 * 107 * @param unique true if index values can be non-unique. 108 */ 109 public void setUnique( Boolean unique ) { 110 this.unique = unique; 111 } 112 113 /** 114 * Gets index type 115 * 116 * @return index type 117 */ 118 public IndexType getIndexType() { 119 return indexType; 120 } 121 122 /** 123 * Sets index type 124 * 125 * @param indexType index type 126 */ 127 public void setIndexType( IndexType indexType ) { 128 this.indexType = indexType; 129 } 130 131 /** 132 * When TYPE is tableIndexStatistic, then this is the number of rows in the table; otherwise, it is the number of unique 133 * values in the index. 134 * 135 * @return the number of rows in the table if index type is STATISTICS; otherwise, the number of unique values in the index. 136 */ 137 public Integer getCardinality() { 138 return cardinality; 139 } 140 141 /** 142 * When TYPE is tableIndexStatistic, then this is the number of rows in the table; otherwise, it is the number of unique 143 * values in the index. 144 * 145 * @param cardinality the number of rows in the table if index type is STATISTICS; otherwise, the number of unique values in 146 * the index. 147 */ 148 public void setCardinality( Integer cardinality ) { 149 this.cardinality = cardinality; 150 } 151 152 /** 153 * When TYPE is tableIndexStatisic then this is the number of pages used for the table, otherwise it is the number of pages 154 * used for the current index. 155 * 156 * @return the number of pages used for the table if index type is STATISTICS; otherwise the number of pages used for the 157 * current index. 158 */ 159 public Integer getPages() { 160 return pages; 161 } 162 163 /** 164 * When TYPE is tableIndexStatisic then this is the number of pages used for the table, otherwise it is the number of pages 165 * used for the current index. 166 * 167 * @param pages the number of pages used for the table if index type is STATISTICS; otherwise the number of pages used for the 168 * current index. 169 */ 170 public void setPages( Integer pages ) { 171 this.pages = pages; 172 } 173 174 /** 175 * Returns the filter condition, if any. (may be null) 176 * 177 * @return the filter condition, if any. (may be null) 178 */ 179 public String getFilterCondition() { 180 return filterCondition; 181 } 182 183 /** 184 * Sets the filter condition, if any. (may be null) 185 * 186 * @param filterCondition the filter condition, if any. (may be null) 187 */ 188 public void setFilterCondition( String filterCondition ) { 189 this.filterCondition = filterCondition; 190 } 191 }