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.DBMemberElement; 36 import org.netbeans.modules.dbschema.TableElement; 37 import org.netbeans.modules.dbschema.util.NameUtil; 38 39 import com.sun.jdo.api.persistence.model.*; 40 import com.sun.jdo.api.persistence.model.mapping.*; 41 import com.sun.jdo.api.persistence.model.jdo.*; 42 import com.sun.jdo.spi.persistence.utility.I18NHelper; 43 import com.sun.jdo.spi.persistence.utility.JavaTypeHelper; 44 45 51 public class MappingFieldElementImpl extends MappingMemberElementImpl 52 implements MappingFieldElement 53 { 54 private ArrayList _columns; 56 private transient ArrayList _columnObjects; 59 private int _fetchGroup; 60 private int _properties; 61 62 63 private boolean _isVersion; 64 65 public static final int CLONE_FIELD = 1; 67 public static final int CLONE_DEEP = 2; 68 public static final int CLONE_MASK = 3; 69 public static final int LOG_ON_ACCESS = 4; 70 public static final int LOG_ON_MASK = 48; 71 public static final int LOG_ON_UPDATE = 16; 72 public static final int MOD_BI_ON_UPDATE = 32; 73 public static final int OBSERVE_ON_ACCESS = 8; 74 public static final int RECORD_ON_UPDATE = 64; 75 public static final int SEND_BEFORE_IMAGE = 128; 76 public static final int READ_ONLY = 256; 77 public static final int REF_INTEGRITY_UPDATES = 512; 78 public static final int IN_CONCURRENCY_CHECK = 1024; 79 public static final int XLATE_FIELD = 2048; 80 81 85 public MappingFieldElementImpl () 86 { 87 this(null, null); 88 } 89 90 95 public MappingFieldElementImpl (String name, 96 MappingClassElement declaringClass) 97 { 98 super(name, declaringClass); 99 setFetchGroupInternal(GROUP_DEFAULT); 100 } 101 102 111 113 115 119 public boolean isReadOnly () { return getProperty(READ_ONLY); } 120 121 126 public void setReadOnly (boolean flag) throws ModelException 127 { 128 Boolean old = JavaTypeHelper.valueOf(isReadOnly()); 129 Boolean newFlag = JavaTypeHelper.valueOf(flag); 130 131 try 132 { 133 fireVetoableChange(PROP_READ_ONLY, old, newFlag); 134 setProperty(flag, READ_ONLY); 135 firePropertyChange(PROP_READ_ONLY, old, newFlag); 136 } 137 catch (PropertyVetoException e) 138 { 139 throw new ModelVetoException(e); 140 } 141 } 142 143 147 public boolean isInConcurrencyCheck () 148 { 149 return getProperty(IN_CONCURRENCY_CHECK); 150 } 151 152 157 public void setInConcurrencyCheck (boolean flag) throws ModelException 158 { 159 Boolean old = JavaTypeHelper.valueOf(isInConcurrencyCheck()); 160 Boolean newFlag = JavaTypeHelper.valueOf(flag); 161 162 try 163 { 164 fireVetoableChange(PROP_IN_CONCURRENCY_CHECK, old, newFlag); 165 setProperty(flag, IN_CONCURRENCY_CHECK); 166 firePropertyChange(PROP_IN_CONCURRENCY_CHECK, old, newFlag); 167 } 168 catch (PropertyVetoException e) 169 { 170 throw new ModelVetoException(e); 171 } 172 } 173 174 178 public boolean isVersion () { return _isVersion; } 179 180 185 public void setVersion (boolean flag) throws ModelException 186 { 187 Boolean old = JavaTypeHelper.valueOf(isVersion()); 188 Boolean newFlag = JavaTypeHelper.valueOf(flag); 189 190 try 191 { 192 fireVetoableChange(PROP_VERSION_FIELD, old, newFlag); 193 _isVersion = flag; 194 firePropertyChange(PROP_VERSION_FIELD, old, newFlag); 195 } 196 catch (PropertyVetoException e) 197 { 198 throw new ModelVetoException(e); 199 } 200 } 201 202 204 209 public int getFetchGroup () { return _fetchGroup; } 210 211 217 public void setFetchGroup (int group) throws ModelException 218 { 219 Integer old = new Integer (getFetchGroup()); 220 Integer newGroup = new Integer (group); 221 222 try 223 { 224 fireVetoableChange(PROP_FETCH_GROUP, old, newGroup); 225 setFetchGroupInternal(group); 226 firePropertyChange(PROP_FETCH_GROUP, old, newGroup); 227 } 228 catch (PropertyVetoException e) 229 { 230 throw new ModelVetoException(e); 231 } 232 } 233 234 241 protected void setFetchGroupInternal (int group) 242 { 243 _fetchGroup = group; 244 } 245 246 248 252 public ArrayList getColumns () 253 { 254 if (_columns == null) 255 _columns = new ArrayList(); 256 257 return _columns; 258 } 259 260 264 public void addColumn (DBMemberElement column) throws ModelException 265 { 266 if (column != null) 267 { 268 ArrayList columns = getColumns(); 269 String columnName = NameUtil.getRelativeMemberName( 270 column.getName().getFullName()); 271 272 if (!columns.contains(columnName)) 273 { 274 try 275 { 276 fireVetoableChange(PROP_COLUMNS, null, null); 277 columns.add(columnName); 278 firePropertyChange(PROP_COLUMNS, null, null); 279 280 _columnObjects = null; 282 } 283 catch (PropertyVetoException e) 284 { 285 throw new ModelVetoException(e); 286 } 287 } 288 else 289 { 290 } 292 } 293 else 294 { 295 throw new ModelException(I18NHelper.getMessage(getMessages(), 296 "mapping.element.null_argument")); } 298 } 299 300 307 public void removeColumn (String columnName) throws ModelException 308 { 309 if (columnName != null) 310 { 311 try 312 { 313 fireVetoableChange(PROP_COLUMNS, null, null); 314 315 if (!getColumns().remove(columnName)) 316 { 317 throw new ModelException( 318 I18NHelper.getMessage(getMessages(), 319 "mapping.element.element_not_removed", columnName)); 321 } 322 323 firePropertyChange(PROP_COLUMNS, null, null); 324 325 _columnObjects = null; 327 } 328 catch (PropertyVetoException e) 329 { 330 throw new ModelVetoException(e); 331 } 332 } 333 } 334 335 protected boolean isMappedToTable (MappingTableElement table) 336 { 337 String tableName = table.getName(); 338 Iterator iterator = getColumns().iterator(); 339 340 while (iterator.hasNext()) 341 { 342 String columnName = iterator.next().toString(); 343 344 if (NameUtil.getTableName(columnName).equals(tableName)) 345 return true; 346 } 347 348 return false; 349 } 350 351 353 357 public ArrayList getColumnObjects () 358 { 359 if (_columnObjects == null) 361 { 362 _columnObjects = MappingClassElementImpl.toColumnObjects( 366 getDeclaringClass().getDatabaseRoot(), getColumns()); 367 } 368 369 return _columnObjects; 370 } 371 372 374 final PersistenceFieldElement getPersistenceFieldElement () 375 { 376 return ((MappingClassElementImpl)getDeclaringClass()). 377 getPersistenceElement().getField(getName()); 378 } 379 380 383 public int getFieldNumber () 384 { 385 return getPersistenceFieldElement().getFieldNumber(); 386 } 387 388 392 public ConcurrencyGroupElement[] getConcurrencyGroups () 393 { 394 return getPersistenceFieldElement().getConcurrencyGroups(); 395 } 396 397 399 private boolean getProperty (int propertyBit) 400 { 401 return ((getProperties() & propertyBit) > 0); 402 } 403 404 public void setProperty (boolean flag, int propertyBit) 405 { 406 _properties = 407 (flag) ? (_properties | propertyBit) : (_properties & ~propertyBit); 408 } 409 410 412 public int getProperties () { return _properties;} 413 414 public boolean getLogOnAccess () { return getProperty(LOG_ON_ACCESS); } 415 416 public void setLogOnAccess (boolean flag) 417 { 418 setProperty(flag, LOG_ON_ACCESS); 419 } 420 421 public boolean getLogOnUpdate () { return getProperty(LOG_ON_UPDATE); } 422 423 public void setLogOnUpdate (boolean flag) 424 { 425 setProperty(flag, LOG_ON_UPDATE); 426 } 427 428 public boolean getObserveOnAccess () 429 { 430 return getProperty(OBSERVE_ON_ACCESS); 431 } 432 433 public void setObserveOnAccess (boolean flag) 434 { 435 setProperty(flag, OBSERVE_ON_ACCESS); 436 } 437 438 public boolean getRecordOnUpdate () 439 { 440 return getProperty(RECORD_ON_UPDATE); 441 } 442 443 public void setRecordOnUpdate (boolean flag) 444 { 445 setProperty(flag, RECORD_ON_UPDATE); 446 } 447 448 public boolean getModifyBeforeImageOnUpdate () 449 { 450 return getProperty(MOD_BI_ON_UPDATE); 451 } 452 453 public void setModifyBeforeImageOnUpdate (boolean flag) 454 { 455 setProperty(flag, MOD_BI_ON_UPDATE); 456 } 457 458 public boolean getReferentialIntegrityUpdates () 459 { 460 return getProperty(REF_INTEGRITY_UPDATES); 461 } 462 463 public void setReferentialIntegrityUpdates (boolean flag) 464 { 465 setProperty(flag, REF_INTEGRITY_UPDATES); 466 } 467 468 public boolean getSendBeforeImage () 469 { 470 return getProperty(SEND_BEFORE_IMAGE); 471 } 472 public void setSendBeforeImage (boolean flag) 473 { 474 setProperty(flag, SEND_BEFORE_IMAGE); 475 } 476 477 public int getCloneDepth () { return (_properties & CLONE_MASK); } 478 479 public void setCloneDepth (int cloneDepth) 480 { 481 if (cloneDepth < CLONE_FIELD || cloneDepth > CLONE_DEEP) 482 { 483 } 484 485 _properties = _properties & ~CLONE_MASK | cloneDepth; 486 } 487 488 490 493 protected void stripSchemaName () 494 { 495 if (_columns != null) { 497 ListIterator i = _columns.listIterator(); 501 502 while (i.hasNext()) 503 i.set(NameUtil.getRelativeMemberName((String )i.next())); 504 } 505 } 506 } 507 | Popular Tags |