1 /* 2 * The contents of this file are subject to the terms 3 * of the Common Development and Distribution License 4 * (the License). You may not use this file except in 5 * compliance with the License. 6 * 7 * You can obtain a copy of the license at 8 * https://glassfish.dev.java.net/public/CDDLv1.0.html or 9 * glassfish/bootstrap/legal/CDDLv1.0.txt. 10 * See the License for the specific language governing 11 * permissions and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL 14 * Header Notice in each file and include the License file 15 * at glassfish/bootstrap/legal/CDDLv1.0.txt. 16 * If applicable, add the following below the CDDL Header, 17 * with the fields enclosed by brackets [] replaced by 18 * you own identifying information: 19 * "Portions Copyrighted [year] [name of copyright owner]" 20 * 21 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 22 */ 23 24 /* 25 * MappingTableElement.java 26 * 27 * Created on March 3, 2000, 1:11 PM 28 */ 29 30 package com.sun.jdo.api.persistence.model.mapping; 31 32 import java.util.ArrayList; 33 34 import org.netbeans.modules.dbschema.TableElement; 35 import org.netbeans.modules.dbschema.ColumnElement; 36 37 import com.sun.jdo.api.persistence.model.ModelException; 38 39 /** 40 * This is an element which represents a database table. It exists (separately 41 * from TableElement in the database model) to allow the runtime to use a 42 * description of the underlying table that differs from the actual database. 43 * For example, mapping table contains a key which can be thought of as a 44 * "fake primary key" and designates the columns which the runtime will use 45 * to identify rows. It is analagous to the primary key of the underlying 46 * database table and is typically the same, however the important point 47 * is that it is not a requirement. The table in the database may have a 48 * different primary key or may have no primary key at all. Similarly, the 49 * mapping table contains a list of reference keys which can be thought of as 50 * "fake foreign key" objects and designate the column pairs used to join 51 * the primary table with a secondary table. These are analagous to 52 * foreign keys and may in fact contain identical pairs as the foreign key, 53 * but again, this is not a requirement. The foreign key may define a 54 * different set of pairs or may not exist at all. Although any set of pairs 55 * is legal, the user should be careful to define pairs which represent a 56 * logical relationship between the two tables. 57 * Any mapping table elements which are designated as primary tables have 58 * their key set up automatically. Any mapping table elements which are 59 * designated as secondary tables should not have their keys set up directly; 60 * the setup is automatically part of the pair definition which makes up the 61 * reference key. 62 * 63 * @author Mark Munro 64 * @author Rochelle Raccah 65 * @version %I% 66 */ 67 public interface MappingTableElement extends MappingMemberElement 68 { 69 //======================= table handling =========================== 70 71 /** Returns the name of the table element used by this mapping table. 72 * @return the table name for this mapping table 73 */ 74 public String getTable (); 75 76 /** Set the table element for this mapping table to the supplied table. 77 * @param table table element to be used by the mapping table. 78 * @exception ModelException if impossible 79 */ 80 public void setTable (TableElement table) throws ModelException; 81 82 /** Returns true if the table element used by this mapping table is equal 83 * to the supplied table. 84 * @return <code>true</code> if table elements are equal, 85 * <code>false</code> otherwise. 86 */ 87 public boolean isEqual (TableElement table); 88 89 //===================== primary key handling =========================== 90 91 /** Returns the list of column names in the primary key for this 92 * mapping table. 93 * @return the names of the columns in the primary key for this 94 * mapping table 95 */ 96 public ArrayList getKey (); 97 98 /** Adds a column to the primary key of columns in this mapping table. 99 * This method should only be used to manipulate the key columns of the 100 * primary table. The secondary table key columns should be manipulated 101 * using MappingReferenceKeyElement methods for pairs. 102 * @param column column element to be added 103 * @exception ModelException if impossible 104 */ 105 public void addKeyColumn (ColumnElement column) throws ModelException; 106 107 /** Removes a column from the primary key of columns in this mapping table. 108 * This method should only be used to manipulate the key columns of the 109 * primary table. The secondary table key columns should be manipulated 110 * using MappingReferenceKeyElement methods for pairs. 111 * @param columnName the relative name of the column to be removed 112 * @exception ModelException if impossible 113 */ 114 public void removeKeyColumn (String columnName) throws ModelException; 115 116 //===================== reference key handling =========================== 117 118 /** Returns the list of keys (MappingReferenceKeyElements) for this 119 * mapping table. There will be keys for foreign keys and "fake" foreign 120 * keys. 121 * @return the reference key elements for this mapping table 122 */ 123 public ArrayList getReferencingKeys (); 124 125 /** Adds a referencing key to the list of keys in this mapping table. 126 * @param referencingKey referencing key element to be added 127 * @exception ModelException if impossible 128 */ 129 public void addReferencingKey (MappingReferenceKeyElement referencingKey) 130 throws ModelException; 131 132 /** Removes the referencing key for the supplied table element from list 133 * of keys in this mapping table. 134 * @param table mapping table element for which to remove referencing keys 135 * @exception ModelException if impossible 136 */ 137 public void removeReference (MappingTableElement table) 138 throws ModelException; 139 } 140