1 23 24 29 30 package com.sun.jdo.api.persistence.model.mapping.impl; 31 32 import java.util.*; 33 import java.beans.PropertyVetoException ; 34 35 import org.netbeans.modules.dbschema.*; 36 import org.netbeans.modules.dbschema.util.NameUtil; 37 38 import com.sun.jdo.api.persistence.model.ModelException; 39 import com.sun.jdo.api.persistence.model.ModelVetoException; 40 import com.sun.jdo.api.persistence.model.mapping.*; 41 import com.sun.jdo.api.persistence.model.jdo.RelationshipElement; 42 import com.sun.jdo.spi.persistence.utility.I18NHelper; 43 44 50 public class MappingRelationshipElementImpl extends MappingFieldElementImpl 51 implements MappingRelationshipElement 52 { 53 private ArrayList _associatedColumns; private transient ArrayList _associatedColumnObjects; 58 64 65 69 public MappingRelationshipElementImpl () 70 { 71 this(null, null); 72 } 73 74 79 public MappingRelationshipElementImpl (String name, 80 MappingClassElement declaringClass) 81 { 82 super(name, declaringClass); 83 setFetchGroupInternal(GROUP_NONE); 84 } 85 86 92 94 96 101 public ArrayList getAssociatedColumns () 102 { 103 if (_associatedColumns == null) 104 _associatedColumns = new ArrayList(); 105 106 return _associatedColumns; 107 } 108 109 119 public void addLocalColumn (ColumnPairElement column) 120 throws ModelException 121 { 122 super.addColumn(column); 125 } 126 127 137 public void addAssociatedColumn (ColumnPairElement column) 138 throws ModelException 139 { 140 if (column != null) 141 { 142 ArrayList columns = getAssociatedColumns(); 143 String columnName = NameUtil.getRelativeMemberName( 144 column.getName().getFullName()); 145 146 if (!columns.contains(columnName)) 148 { 149 try 150 { 151 fireVetoableChange(PROP_ASSOCIATED_COLUMNS, null, null); 152 columns.add(columnName); 153 firePropertyChange(PROP_ASSOCIATED_COLUMNS, null, null); 154 155 _associatedColumnObjects = null; 157 } 158 catch (PropertyVetoException e) 159 { 160 throw new ModelVetoException(e); 161 } 162 } 163 else 164 { 165 throw new ModelException(I18NHelper.getMessage(getMessages(), 166 "mapping.column.column_defined", columnName)); } 168 } 169 else 170 { 171 throw new ModelException(I18NHelper.getMessage(getMessages(), 172 "mapping.element.null_argument")); } 174 } 175 176 178 184 public void addColumn (DBMemberElement column) throws ModelException 185 { 186 if (column instanceof ColumnPairElement) 187 { 188 if (!getAssociatedColumns().isEmpty()) 189 { 190 throw new ModelException(I18NHelper.getMessage(getMessages(), 191 "mapping.column.associated_columns_defined", NameUtil.getRelativeMemberName( 193 column.getName().getFullName()))); 194 } 195 196 super.addColumn(column); 197 } 198 else 199 { 200 throw new ModelException(I18NHelper.getMessage(getMessages(), 201 "mapping.column.column_invalid", NameUtil.getRelativeMemberName( 203 column.getName().getFullName()))); 204 } 205 } 206 207 214 public void removeColumn (String columnName) throws ModelException 215 { 216 try 217 { 218 super.removeColumn(columnName); 219 } 220 catch (ModelException e) { 222 try 223 { 224 fireVetoableChange(PROP_ASSOCIATED_COLUMNS, null, null); 225 226 if (!getAssociatedColumns().remove(columnName)) 227 { 228 throw new ModelException( 229 I18NHelper.getMessage(getMessages(), 230 "mapping.element.element_not_removed", columnName)); 232 } 233 234 firePropertyChange(PROP_ASSOCIATED_COLUMNS, null, null); 235 236 _associatedColumnObjects = null; 238 } 239 catch (PropertyVetoException ve) 240 { 241 throw new ModelVetoException(ve); 242 } 243 } 244 } 245 246 248 254 public ArrayList getAssociatedColumnObjects () 255 { 256 if (_associatedColumnObjects == null) 257 { 258 _associatedColumnObjects = MappingClassElementImpl. 259 toColumnObjects(getDeclaringClass().getDatabaseRoot(), 260 getAssociatedColumns()); 261 } 262 263 return _associatedColumnObjects; 264 } 265 266 268 final RelationshipElement getRelationshipElement () 269 { 270 return ((MappingClassElementImpl)getDeclaringClass()). 271 getPersistenceElement().getRelationship(getName()); 272 } 273 274 279 public String getElementClass () 280 { 281 return getRelationshipElement().getElementClass(); 282 } 283 284 292 public int getUpdateAction () 293 { 294 return getRelationshipElement().getUpdateAction(); 295 } 296 297 305 public int getDeleteAction () 306 { 307 return getRelationshipElement().getDeleteAction(); 308 } 309 310 314 public int getUpperBound () 315 { 316 return getRelationshipElement().getUpperBound(); 317 } 318 319 322 public int getLowerBound () 323 { 324 return getRelationshipElement().getLowerBound(); 325 } 326 327 329 335 public void setAssociatedColumns (ArrayList associatedColumns) 336 { 337 _associatedColumns = associatedColumns; 338 } 339 340 342 344 346 349 protected void stripSchemaName () 350 { 351 super.stripSchemaName(); 353 354 if (_associatedColumns != null) 356 { 357 ListIterator i = _associatedColumns.listIterator(); 361 362 while (i.hasNext()) 363 i.set(NameUtil.getRelativeMemberName((String )i.next())); 364 } 365 } 366 } 367 | Popular Tags |