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.ForeignKey; 029 import org.jboss.dna.common.jdbc.model.api.ForeignKeyColumn; 030 import org.jboss.dna.common.jdbc.model.api.KeyDeferrabilityType; 031 import org.jboss.dna.common.jdbc.model.api.KeyModifyRuleType; 032 import org.jboss.dna.common.jdbc.model.api.PrimaryKey; 033 import org.jboss.dna.common.jdbc.model.api.Table; 034 035 /** 036 * Provides database table's foreing key specific metadata. 037 * 038 * @author <a href="mailto:litsenko_sergey@yahoo.com">Sergiy Litsenko</a> 039 */ 040 public class ForeignKeyBean extends SchemaObjectBean implements ForeignKey { 041 private static final long serialVersionUID = 3481927472605189902L; 042 private Set<ForeignKeyColumn> columns = new HashSet<ForeignKeyColumn>(); 043 private Table sourceTable; 044 private PrimaryKey sourcePrimaryKey; 045 private KeyModifyRuleType updateRule; 046 private KeyModifyRuleType deleteRule; 047 private KeyDeferrabilityType deferrability; 048 049 /** 050 * Default constructor 051 */ 052 public ForeignKeyBean() { 053 } 054 055 /** 056 * Retrieves foreign key columns 057 * 058 * @return foreign key columns 059 */ 060 public Set<ForeignKeyColumn> getColumns() { 061 return columns; 062 } 063 064 /** 065 * Adds ForeignKeyColumn 066 * 067 * @param column the ForeignKeyColumn 068 */ 069 public void addColumn( ForeignKeyColumn column ) { 070 columns.add(column); 071 } 072 073 /** 074 * Removes ForeignKeyColumn 075 * 076 * @param column the ForeignKeyColumn 077 */ 078 public void deleteColumn( ForeignKeyColumn column ) { 079 columns.remove(column); 080 } 081 082 /** 083 * Returns table column for specified column name or null 084 * 085 * @param columnName the name of column 086 * @return table column for specified column name or null. 087 */ 088 public ForeignKeyColumn findColumnByName( String columnName ) { 089 for (ForeignKeyColumn fkc : columns) { 090 if (fkc.getName().equals(columnName)) { 091 return fkc; 092 } 093 } 094 // return nothing 095 return null; 096 } 097 098 /** 099 * Returns the scope table of a foreign key. 100 * 101 * @return the scope table of a foreign key. 102 */ 103 public Table getSourceTable() { 104 return sourceTable; 105 } 106 107 /** 108 * Sets the scope table of a foreign key. 109 * 110 * @param sourceTable the scope table of a foreign key. 111 */ 112 public void setSourceTable( Table sourceTable ) { 113 this.sourceTable = sourceTable; 114 } 115 116 /** 117 * Returns the PK of scope table. 118 * 119 * @return the PK of scope table. 120 */ 121 public PrimaryKey getSourcePrimaryKey() { 122 return sourcePrimaryKey; 123 } 124 125 /** 126 * Sets the PK of scope table. 127 * 128 * @param primaryKey the PK of scope table. 129 */ 130 public void setSourcePrimaryKey( PrimaryKey primaryKey ) { 131 this.sourcePrimaryKey = primaryKey; 132 } 133 134 /** 135 * What happens to a foreign key when the primary key is updated 136 * 137 * @return what happens to a foreign key when the primary key is updated 138 */ 139 public KeyModifyRuleType getUpdateRule() { 140 return updateRule; 141 } 142 143 /** 144 * What happens to a foreign key when the primary key is updated 145 * 146 * @param updateRule what happens to a foreign key when the primary key is updated 147 */ 148 public void setUpdateRule( KeyModifyRuleType updateRule ) { 149 this.updateRule = updateRule; 150 } 151 152 /** 153 * What happens to a foreign key when the primary key is deleted 154 * 155 * @return what happens to a foreign key when the primary key is deleted 156 */ 157 public KeyModifyRuleType getDeleteRule() { 158 return deleteRule; 159 } 160 161 /** 162 * What happens to a foreign key when the primary key is deleted 163 * 164 * @param deleteRule what happens to a foreign key when the primary key is deleted 165 */ 166 public void setDeleteRule( KeyModifyRuleType deleteRule ) { 167 this.deleteRule = deleteRule; 168 } 169 170 /** 171 * Can the evaluation of foreign key constraints be deferred until commit 172 * 173 * @return the evaluation of foreign key constraints be deferred until commit 174 */ 175 public KeyDeferrabilityType getDeferrability() { 176 return deferrability; 177 } 178 179 /** 180 * Can the evaluation of foreign key constraints be deferred until commit 181 * 182 * @param deferrability the evaluation of foreign key constraints be deferred until commit 183 */ 184 public void setDeferrability( KeyDeferrabilityType deferrability ) { 185 this.deferrability = deferrability; 186 } 187 }