1 21 package oracle.toplink.essentials.descriptors; 23 24 import com.sun.jndi.ldap.EntryChangeResponseControl; 25 26 import java.security.AccessController ; 27 import java.security.PrivilegedActionException ; 28 import java.util.*; 29 import java.io.*; 30 import java.lang.reflect.*; 31 32 import oracle.toplink.essentials.internal.descriptors.*; 33 import oracle.toplink.essentials.internal.expressions.SQLSelectStatement; 34 import oracle.toplink.essentials.internal.expressions.SQLStatement; 35 import oracle.toplink.essentials.internal.helper.*; 36 import oracle.toplink.essentials.internal.identitymaps.*; 37 import oracle.toplink.essentials.mappings.*; 38 import oracle.toplink.essentials.mappings.foundation.AbstractDirectMapping; 39 import oracle.toplink.essentials.queryframework.FetchGroup; 40 import oracle.toplink.essentials.querykeys.*; 41 import oracle.toplink.essentials.expressions.*; 42 import oracle.toplink.essentials.internal.databaseaccess.*; 43 import oracle.toplink.essentials.exceptions.*; 44 import oracle.toplink.essentials.descriptors.copying.*; 45 import oracle.toplink.essentials.descriptors.changetracking.*; 46 import oracle.toplink.essentials.descriptors.invalidation.*; 47 import oracle.toplink.essentials.descriptors.FetchGroupManager; 48 import oracle.toplink.essentials.descriptors.InheritancePolicy; 49 import oracle.toplink.essentials.descriptors.DescriptorEvent; 50 import oracle.toplink.essentials.descriptors.DescriptorEventManager; 51 import oracle.toplink.essentials.descriptors.DescriptorQueryManager; 52 import oracle.toplink.essentials.internal.security.PrivilegedAccessHelper; 53 import oracle.toplink.essentials.internal.security.PrivilegedClassForName; 54 import oracle.toplink.essentials.internal.security.PrivilegedMethodInvoker; 55 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 56 import oracle.toplink.essentials.internal.sessions.AbstractSession; 57 import oracle.toplink.essentials.internal.helper.MappingCompare; 58 import oracle.toplink.essentials.internal.helper.DatabaseTable; 59 import oracle.toplink.essentials.internal.helper.DatabaseField; 60 61 72 public class ClassDescriptor implements Cloneable , Serializable { 73 protected Class javaClass; 74 protected String javaClassName; 75 protected Vector tables; 76 protected transient DatabaseTable defaultTable; 77 protected List primaryKeyFields; 78 protected transient Map additionalTablePrimaryKeyFields; 79 protected transient Vector multipleTableInsertOrder; 80 protected transient Map multipleTableForeignKeys; 81 protected transient Vector fields; 82 protected transient Vector allFields; 83 protected Vector mappings; 84 85 protected List lockableMappings; 88 protected Map queryKeys; 89 90 protected Class identityMapClass; 92 protected int identityMapSize; 93 protected String sequenceNumberName; 94 protected DatabaseField sequenceNumberField; 95 protected transient String sessionName; 96 protected boolean shouldAlwaysRefreshCache; 97 protected boolean shouldOnlyRefreshCacheIfNewerVersion; 98 protected boolean shouldDisableCacheHits; 99 protected transient Vector constraintDependencies; 100 protected transient String amendmentMethodName; 101 protected transient Class amendmentClass; 102 protected transient String amendmentClassName; 103 protected String alias; 104 protected boolean shouldBeReadOnly; 105 protected boolean shouldAlwaysConformResultsInUnitOfWork; 106 107 protected boolean isIsolated; 109 110 protected boolean shouldRegisterResultsInUnitOfWork = true; 112 113 protected DescriptorEventManager eventManager; 115 protected DescriptorQueryManager queryManager; 116 protected ObjectBuilder objectBuilder; 117 protected CopyPolicy copyPolicy; 118 protected InstantiationPolicy instantiationPolicy; 119 protected InheritancePolicy inheritancePolicy; 120 protected OptimisticLockingPolicy optimisticLockingPolicy; 121 protected Vector cascadeLockingPolicies; 122 protected WrapperPolicy wrapperPolicy; 123 protected ObjectChangePolicy changePolicy; 124 protected CMPPolicy cmpPolicy; 125 126 protected FetchGroupManager fetchGroupManager; 128 129 130 protected Map properties; 131 132 protected static final int UNINITIALIZED = 0; 134 protected static final int PREINITIALIZED = 1; 135 protected static final int INITIALIZED = 2; 136 protected static final int POST_INITIALIZED = 3; 137 protected static final int ERROR = -1; 138 139 protected static final int NORMAL = 0; 141 protected static final int AGGREGATE = 2; 142 protected static final int AGGREGATE_COLLECTION = 3; 143 protected transient int initializationStage; 144 protected int descriptorType; 145 protected boolean shouldOrderMappings; 146 protected CacheInvalidationPolicy cacheInvalidationPolicy = null; 147 148 149 protected boolean shouldAcquireCascadedLocks = false; 150 151 152 protected boolean hasSimplePrimaryKey = false; 153 154 158 public ClassDescriptor() { 159 this.tables = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(3); 161 this.mappings = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 162 this.primaryKeyFields = new ArrayList(2); 163 this.fields = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 164 this.allFields = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 165 this.constraintDependencies = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(2); 166 this.multipleTableForeignKeys = new HashMap(5); 167 this.queryKeys = new HashMap(5); 168 this.initializationStage = UNINITIALIZED; 169 this.shouldAlwaysRefreshCache = false; 170 this.shouldOnlyRefreshCacheIfNewerVersion = false; 171 this.shouldDisableCacheHits = false; 172 this.identityMapSize = 100; 173 this.identityMapClass = IdentityMap.getDefaultIdentityMapClass(); 174 this.descriptorType = NORMAL; 175 this.shouldOrderMappings = true; 176 this.shouldBeReadOnly = false; 177 this.shouldAlwaysConformResultsInUnitOfWork = false; 178 this.shouldAcquireCascadedLocks = false; 179 this.hasSimplePrimaryKey = false; 180 this.isIsolated = false; 181 182 this.objectBuilder = new ObjectBuilder(this); 184 setCopyPolicy(new InstantiationCopyPolicy()); 185 setInstantiationPolicy(new InstantiationPolicy()); 186 setEventManager(new oracle.toplink.essentials.descriptors.DescriptorEventManager()); 187 setQueryManager(new oracle.toplink.essentials.descriptors.DescriptorQueryManager()); 188 189 changePolicy = new DeferredChangeDetectionPolicy(); 190 this.cascadeLockingPolicies = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 191 } 192 193 200 public void addAbstractQueryKey(String queryKeyName) { 201 QueryKey queryKey = new QueryKey(); 202 queryKey.setName(queryKeyName); 203 addQueryKey(queryKey); 204 } 205 206 213 public void addConstraintDependencies(Class dependencies) { 214 getConstraintDependencies().addElement(dependencies); 215 } 216 217 229 public DatabaseMapping addDirectMapping(String attributeName, String fieldName) { 230 DirectToFieldMapping mapping = new DirectToFieldMapping(); 231 232 mapping.setAttributeName(attributeName); 233 mapping.setFieldName(fieldName); 234 235 return addMapping(mapping); 236 } 237 238 245 public DatabaseMapping addDirectMapping(String attributeName, String getMethodName, String setMethodName, String fieldName) { 246 DirectToFieldMapping mapping = new DirectToFieldMapping(); 247 248 mapping.setAttributeName(attributeName); 249 mapping.setSetMethodName(setMethodName); 250 mapping.setGetMethodName(getMethodName); 251 mapping.setFieldName(fieldName); 252 253 return addMapping(mapping); 254 } 255 256 260 public void addDirectQueryKey(String queryKeyName, String fieldName) { 261 DirectQueryKey queryKey = new DirectQueryKey(); 262 DatabaseField field = new DatabaseField(fieldName); 263 264 queryKey.setName(queryKeyName); 265 queryKey.setField(field); 266 getQueryKeys().put(queryKeyName, queryKey); 267 } 268 269 275 public DatabaseMapping addMapping(DatabaseMapping mapping) { 276 if (mapping.getDescriptor() == null) { 278 mapping.setDescriptor(this); 279 } 280 getMappings().addElement(mapping); 281 return mapping; 282 } 283 284 protected void validateMappingType(DatabaseMapping mapping) { 285 if (!(mapping.isRelationalMapping())) { 286 throw DescriptorException.invalidMappingType(mapping); 287 } 288 } 289 290 297 public void addMultipleTableForeignKeyField(DatabaseField sourceField, DatabaseField targetField) throws DescriptorException { 298 addMultipleTableForeignKeys(sourceField, targetField, true); 299 } 300 301 308 public void addMultipleTableForeignKeyFieldName(String sourceFieldName, String targetFieldName) throws DescriptorException { 309 addMultipleTableForeignKeyField(new DatabaseField(sourceFieldName), new DatabaseField(targetFieldName)); 310 } 311 312 317 protected void addMultipleTableForeignKeys(DatabaseField sourceField, DatabaseField targetField, boolean isForeignKey) throws DescriptorException { 318 if ((!sourceField.hasTableName()) || (!targetField.hasTableName())) { 320 throw DescriptorException.multipleTablePrimaryKeyMustBeFullyQualified(this); 321 } 322 323 DatabaseTable sourceTable = sourceField.getTable(); 324 DatabaseTable targetTable = targetField.getTable(); 325 setAdditionalTablePrimaryKeyFields(targetTable, sourceField, targetField); 326 327 if (isForeignKey) { 328 getMultipleTableForeignKeys().put(sourceTable, targetTable); 329 } 330 } 331 332 337 protected void addMultipleTableForeignKeys(String fieldNameInSourceTable, String fieldNameInTargetTable, boolean isForeignKey) throws DescriptorException { 338 addMultipleTableForeignKeys(new DatabaseField(fieldNameInSourceTable), new DatabaseField(fieldNameInTargetTable), isForeignKey); 339 } 340 341 347 public void addMultipleTablePrimaryKeyField(DatabaseField sourceField, DatabaseField targetField) throws DescriptorException { 348 addMultipleTableForeignKeys(sourceField, targetField, false); 349 } 350 351 357 public void addMultipleTablePrimaryKeyFieldName(String sourceFieldName, String targetFieldName) throws DescriptorException { 358 addMultipleTablePrimaryKeyField(new DatabaseField(sourceFieldName), new DatabaseField(targetFieldName)); 359 } 360 361 370 public void addPrimaryKeyFieldName(String fieldName) { 371 getPrimaryKeyFields().add(new DatabaseField(fieldName)); 372 } 373 374 380 public void addPrimaryKeyField(DatabaseField field) { 381 getPrimaryKeyFields().add(field); 382 } 383 384 388 public void addQueryKey(QueryKey queryKey) { 389 getQueryKeys().put(queryKey.getName(), queryKey); 390 } 391 392 397 public void addTable(DatabaseTable table) { 398 getTables().addElement(table); 399 } 400 401 407 public void addTableName(String tableName) { 408 addTable(new DatabaseTable(tableName)); 409 } 410 411 418 public void adjustMultipleTableInsertOrder() { 419 if ((getMultipleTableInsertOrder() == null) || getMultipleTableInsertOrder().isEmpty()) { 421 setMultipleTableInsertOrder((Vector) getTables().clone()); 422 423 checkMultipleTableForeignKeys(false); 424 } else { 425 if (getMultipleTableInsertOrder().size() != getTables().size()) { 426 throw DescriptorException.multipleTableInsertOrderMismatch(this); 427 } 428 429 checkMultipleTableForeignKeys(true); 430 } 431 } 432 433 438 public void alwaysConformResultsInUnitOfWork() { 439 setShouldAlwaysConformResultsInUnitOfWork(true); 440 } 441 442 460 public void alwaysRefreshCache() { 461 setShouldAlwaysRefreshCache(true); 462 } 463 464 469 public void applyAmendmentMethod() { 470 applyAmendmentMethod(null); 471 } 472 473 478 public void applyAmendmentMethod(DescriptorEvent event) { 479 if ((getAmendmentClass() == null) || (getAmendmentMethodName() == null)) { 480 return; 481 } 482 483 Method method = null; 484 Class [] argTypes = new Class [1]; 485 486 argTypes[0] = ClassDescriptor.class; 489 try { 490 method = Helper.getDeclaredMethod(getAmendmentClass(), getAmendmentMethodName(), argTypes); 491 } catch (Exception ignore) { 492 argTypes[0] = ClassDescriptor.class; 494 try { 495 method = Helper.getDeclaredMethod(getAmendmentClass(), getAmendmentMethodName(), argTypes); 496 } catch (Exception exception) { 497 throw DescriptorException.invalidAmendmentMethod(getAmendmentClass(), getAmendmentMethodName(), exception, this); 498 } 499 } 500 501 Object [] args = new Object [1]; 502 args[0] = this; 503 504 try { 505 if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ 506 try { 507 AccessController.doPrivileged(new PrivilegedMethodInvoker(method, null, args)); 508 } catch (PrivilegedActionException exception) { 509 Exception throwableException = exception.getException(); 510 if (throwableException instanceof IllegalAccessException ) { 511 throw (IllegalAccessException )throwableException; 512 } else { 513 throw (InvocationTargetException)throwableException; 514 } 515 } 516 } else { 517 PrivilegedAccessHelper.invokeMethod(method, null, args); 518 } 519 } catch (Exception exception) { 520 throw DescriptorException.errorOccuredInAmendmentMethod(getAmendmentClass(), getAmendmentMethodName(), exception, this); 521 } 522 } 523 524 528 public boolean arePrimaryKeyFields(Vector fields) { 529 if (!(fields.size() == (getPrimaryKeyFields().size()))) { 530 return false; 531 } 532 533 for (Enumeration enumFields = fields.elements(); enumFields.hasMoreElements();) { 534 DatabaseField field = (DatabaseField)enumFields.nextElement(); 535 536 if (!getPrimaryKeyFields().contains(field)) { 537 return false; 538 } 539 } 540 541 return true; 542 } 543 544 549 public DatabaseCall buildCallFromStatement(SQLStatement statement, AbstractSession session) { 550 return statement.buildCall(session); 551 } 552 553 558 public Vector buildDirectValuesFromFieldValue(Object fieldValue) throws DatabaseException { 559 throw DescriptorException.normalDescriptorsDoNotSupportNonRelationalExtensions(this); 560 } 561 562 566 567 public DatabaseField buildField(String fieldName) { 570 DatabaseField field = new DatabaseField(fieldName); 571 DatabaseTable table; 572 573 if (field.hasTableName()) { 574 table = getTable(field.getTableName()); 575 } else if (getDefaultTable() != null) { 576 table = getDefaultTable(); 577 } else { 578 table = getTable(getTableName()); 579 } 580 581 field.setTable(table); 582 return field; 583 } 584 585 591 public void buildField(DatabaseField field) { 592 DatabaseTable table; 593 if (field.hasTableName()) { 594 table = getTable(field.getTableName()); 595 } else { 596 table = getDefaultTable(); 597 } 598 599 field.setTable(table); 600 } 601 602 607 public Object buildFieldValueFromDirectValues(Vector directValues, String elementDataTypeName, AbstractSession session) throws DatabaseException { 608 throw DescriptorException.normalDescriptorsDoNotSupportNonRelationalExtensions(this); 609 } 610 611 617 public Object buildFieldValueFromForeignKeys(Vector foreignKeys, String referenceDataTypeName, AbstractSession session) throws DatabaseException { 618 throw DescriptorException.normalDescriptorsDoNotSupportNonRelationalExtensions(this); 619 } 620 621 625 public Object buildFieldValueFromNestedRow(AbstractRecord nestedRow, AbstractSession session) throws DatabaseException { 626 throw DescriptorException.normalDescriptorsDoNotSupportNonRelationalExtensions(this); 627 } 628 629 634 public Object buildFieldValueFromNestedRows(Vector nestedRows, String structureName, AbstractSession session) throws DatabaseException { 635 throw DescriptorException.normalDescriptorsDoNotSupportNonRelationalExtensions(this); 636 } 637 638 642 public AbstractRecord buildNestedRowFromFieldValue(Object fieldValue) throws DatabaseException { 643 throw DescriptorException.normalDescriptorsDoNotSupportNonRelationalExtensions(this); 644 } 645 646 650 public Vector buildNestedRowsFromFieldValue(Object fieldValue, AbstractSession session) throws DatabaseException { 651 throw DescriptorException.normalDescriptorsDoNotSupportNonRelationalExtensions(this); 652 } 653 654 657 protected void checkDatabase(AbstractSession session) { 658 if (session.getIntegrityChecker().shouldCheckDatabase()) { 659 for (Enumeration enumTable = getTables().elements(); enumTable.hasMoreElements();) { 660 DatabaseTable table = (DatabaseTable)enumTable.nextElement(); 661 if (session.getIntegrityChecker().checkTable(table, session)) { 662 Vector databaseFields = new Vector(); 664 Vector result = session.getAccessor().getColumnInfo(null, null, table.getName(), null, session); 665 for (Enumeration resultEnum = result.elements(); resultEnum.hasMoreElements();) { 666 AbstractRecord row = (AbstractRecord)resultEnum.nextElement(); 667 databaseFields.addElement(row.get("COLUMN_NAME")); 668 } 669 670 for (Enumeration row = getFields().elements(); row.hasMoreElements();) { 672 DatabaseField field = (DatabaseField)row.nextElement(); 673 if (field.getTable().equals(table) && (!databaseFields.contains(field.getName()))) { 674 session.getIntegrityChecker().handleError(DescriptorException.fieldIsNotPresentInDatabase(this, table.getName(), field.getName())); 675 } 676 } 677 } else { 678 session.getIntegrityChecker().handleError(DescriptorException.tableIsNotPresentInDatabase(this)); 679 } 680 } 681 } 682 } 683 684 689 public void checkInheritanceTreeAggregateSettings(AbstractSession session, AggregateMapping mapping) throws DescriptorException { 690 if (!this.hasInheritance()) { 691 return; 692 } 693 694 if (this.isChildDescriptor()) { 695 Class parentClass = this.getInheritancePolicy().getParentClass(); 696 if (parentClass == this.getJavaClass()) { 697 throw DescriptorException.parentClassIsSelf(this); 698 } 699 700 session.getDescriptor(parentClass).checkInheritanceTreeAggregateSettings(session, mapping); 702 } else { 703 this.checkInheritanceTreeAggregateSettingsForChildren(session, mapping); 705 } 706 } 707 708 712 private void checkInheritanceTreeAggregateSettingsForChildren(AbstractSession session, AggregateMapping mapping) throws DescriptorException { 713 if (!this.isAggregateDescriptor()) { 714 session.getIntegrityChecker().handleError(DescriptorException.referenceDescriptorIsNotAggregate(this.getJavaClass().getName(), mapping)); 715 } 716 for (Enumeration stream = this.getInheritancePolicy().getChildDescriptors().elements(); 717 stream.hasMoreElements();) { 718 ClassDescriptor childDescriptor = (ClassDescriptor)stream.nextElement(); 719 720 childDescriptor.checkInheritanceTreeAggregateSettingsForChildren(session, mapping); 722 } 723 } 724 725 728 protected void checkMultipleTableForeignKeys(boolean userSpecifiedOrder) { 729 Map foreignKeyTableRelationships = getMultipleTableForeignKeys(); 735 736 for (int i = 0; i < foreignKeyTableRelationships.size(); i++) { 737 for (Iterator sourceTables = foreignKeyTableRelationships.entrySet().iterator(); sourceTables.hasNext();) { 738 Map.Entry entry = (Map.Entry)sourceTables.next(); 739 DatabaseTable sourceTable = (DatabaseTable) entry.getKey(); 740 DatabaseTable targetTable = (DatabaseTable) entry.getValue(); 741 742 if (getMultipleTableInsertOrder().indexOf(sourceTable) == -1) { 744 throw DescriptorException.illegalTableNameInMultipleTableForeignKeyField(this, sourceTable); 745 } 746 747 if (getMultipleTableInsertOrder().indexOf(targetTable) == -1) { 749 throw DescriptorException.illegalTableNameInMultipleTableForeignKeyField(this, targetTable); 750 } 751 752 int sourceTableIndex = getTables().indexOf(sourceTable); 753 int targetTableIndex = getTables().indexOf(targetTable); 754 755 if (targetTableIndex < sourceTableIndex) { 759 if (userSpecifiedOrder) { 760 toggleAdditionalTablePrimaryKeyFields(targetTable, sourceTable); 761 } else { 762 int sti = getMultipleTableInsertOrder().indexOf(sourceTable); 763 int tti = getMultipleTableInsertOrder().indexOf(targetTable); 764 765 if (tti < sti) { 766 toggleAdditionalTablePrimaryKeyFields(targetTable, sourceTable); 767 getMultipleTableInsertOrder().removeElementAt(tti); 768 getMultipleTableInsertOrder().insertElementAt(targetTable, sti); 769 } 770 } 771 } 772 } 773 } 774 } 775 776 780 public Object clone() { 781 ClassDescriptor clonedDescriptor = null; 782 783 try { 785 clonedDescriptor = (ClassDescriptor)super.clone(); 786 } catch (Exception exception) { 787 ; 788 } 789 790 Vector mappingsVector = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 791 792 for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { 794 DatabaseMapping mapping; 795 796 mapping = (DatabaseMapping)((DatabaseMapping)mappingsEnum.nextElement()).clone(); 797 mapping.setDescriptor(clonedDescriptor); 798 mappingsVector.addElement(mapping); 799 } 800 clonedDescriptor.setMappings(mappingsVector); 801 802 Map queryKeyVector = new HashMap(getQueryKeys().size() + 2); 803 804 for (Iterator queryKeysEnum = getQueryKeys().values().iterator();queryKeysEnum.hasNext();){ 806 QueryKey queryKey = (QueryKey)((QueryKey)queryKeysEnum.next()).clone(); 807 queryKey.setDescriptor(clonedDescriptor); 808 queryKeyVector.put(queryKey.getName(), queryKey); 809 } 810 clonedDescriptor.setQueryKeys(queryKeyVector); 811 812 List primaryKeyVector = new ArrayList(getPrimaryKeyFields().size()); 814 List primaryKeyFields = getPrimaryKeyFields(); 815 for (int index = 0; index < primaryKeyFields.size(); index++) { 816 DatabaseField primaryKey = (DatabaseField)((DatabaseField)primaryKeyFields.get(index)).clone(); 817 primaryKeyVector.add(primaryKey); 818 } 819 clonedDescriptor.setPrimaryKeyFields(primaryKeyVector); 820 821 clonedDescriptor.setFields(oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance()); 823 824 if (clonedDescriptor.hasInheritance()) { 826 clonedDescriptor.setInheritancePolicy((InheritancePolicy)getInheritancePolicy().clone()); 827 clonedDescriptor.getInheritancePolicy().setDescriptor(clonedDescriptor); 828 } 829 830 clonedDescriptor.setObjectBuilder((ObjectBuilder)getObjectBuilder().clone()); 832 clonedDescriptor.getObjectBuilder().setDescriptor(clonedDescriptor); 833 834 clonedDescriptor.setEventManager((DescriptorEventManager)getEventManager().clone()); 835 clonedDescriptor.getEventManager().setDescriptor(clonedDescriptor); 836 837 clonedDescriptor.setQueryManager((DescriptorQueryManager)getQueryManager().clone()); 839 clonedDescriptor.getQueryManager().setDescriptor(clonedDescriptor); 840 841 if (hasFetchGroupManager()) { 843 clonedDescriptor.setFetchGroupManager((FetchGroupManager)getFetchGroupManager().clone()); 844 } 845 846 clonedDescriptor.setIsIsolated(this.isIsolated()); 847 848 clonedDescriptor.setInstantiationPolicy((InstantiationPolicy)this.instantiationPolicy.clone()); 850 clonedDescriptor.setCopyPolicy((CopyPolicy)this.copyPolicy.clone()); 851 if (getOptimisticLockingPolicy() != null) { 852 clonedDescriptor.setOptimisticLockingPolicy((OptimisticLockingPolicy)this.getOptimisticLockingPolicy().clone()); 853 } 854 855 return (Object )clonedDescriptor; 856 } 857 858 865 public void convertClassNamesToClasses(ClassLoader classLoader){ 866 Class descriptorClass = null; 867 Class amendmentClass = null; 868 try{ 869 if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ 870 try { 871 descriptorClass = (Class )AccessController.doPrivileged(new PrivilegedClassForName(getJavaClassName(), true, classLoader)); 872 } catch (PrivilegedActionException exception) { 873 throw ValidationException.classNotFoundWhileConvertingClassNames(getAmendmentClassName(), exception.getException()); 874 } 875 } else { 876 descriptorClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(getJavaClassName(), true, classLoader); 877 } 878 if (getAmendmentClassName() != null){ 879 if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ 880 try { 881 amendmentClass = (Class )AccessController.doPrivileged(new PrivilegedClassForName(getAmendmentClassName(), true, classLoader)); 882 } catch (PrivilegedActionException exception) { 883 throw ValidationException.classNotFoundWhileConvertingClassNames(getAmendmentClassName(), exception.getException()); 884 } 885 } else { 886 amendmentClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(getAmendmentClassName(), true, classLoader); 887 } 888 } 889 } catch (ClassNotFoundException exc){ 890 throw ValidationException.classNotFoundWhileConvertingClassNames(getAmendmentClassName(), exc); 891 } 892 setJavaClass(descriptorClass); 893 if (amendmentClass != null){ 894 setAmendmentClass(amendmentClass); 895 } 896 Iterator mappings = getMappings().iterator(); 897 while (mappings.hasNext()){ 898 ((DatabaseMapping)mappings.next()).convertClassNamesToClasses(classLoader); 899 } 900 if (inheritancePolicy != null){ 901 inheritancePolicy.convertClassNamesToClasses(classLoader); 902 } 903 if (instantiationPolicy != null){ 904 instantiationPolicy.convertClassNamesToClasses(classLoader); 905 } 906 if (hasCMPPolicy()) { 907 getCMPPolicy().convertClassNamesToClasses(classLoader); 908 } 909 queryManager.convertClassNamesToClasses(classLoader); 910 } 911 912 916 public void createCopyPolicy(String policyType) { 917 if (policyType.equals("clone")) { 918 useCloneCopyPolicy(); 919 return; 920 } 921 if (policyType.equals("constructor")) { 922 useInstantiationCopyPolicy(); 923 return; 924 } 925 } 926 927 931 public void createInstantiationPolicy(String policyType) { 932 if (policyType.equals("static method")) { 933 return; 935 } 936 if (policyType.equals("constructor")) { 937 useDefaultConstructorInstantiationPolicy(); 938 return; 939 } 940 if (policyType.equals("factory")) { 941 return; 943 } 944 } 945 946 954 public void descriptorIsAggregate() { 955 setDescriptorType(AGGREGATE); 956 } 957 958 966 public void descriptorIsAggregateCollection() { 967 setDescriptorType(AGGREGATE_COLLECTION); 968 } 969 970 975 public void descriptorIsNormal() { 976 setDescriptorType(NORMAL); 977 } 978 979 984 public void disableCacheHits() { 985 setShouldDisableCacheHits(true); 986 } 987 988 993 public void dontAlwaysConformResultsInUnitOfWork() { 994 setShouldAlwaysConformResultsInUnitOfWork(false); 995 } 996 997 1004 public void dontAlwaysRefreshCache() { 1005 setShouldAlwaysRefreshCache(false); 1006 } 1007 1008 1014 public void dontDisableCacheHits() { 1015 setShouldDisableCacheHits(false); 1016 } 1017 1018 1026 public void dontOnlyRefreshCacheIfNewerVersion() { 1027 setShouldOnlyRefreshCacheIfNewerVersion(false); 1028 } 1029 1030 1034 protected DatabaseTable extractDefaultTable() { 1035 if (getTables().isEmpty()) { 1036 return getInheritancePolicy().getParentDescriptor().extractDefaultTable(); 1037 } 1038 1039 return (DatabaseTable)getTables().firstElement(); 1040 } 1041 1042 1046 public Map getAdditionalTablePrimaryKeyFields() { 1047 if (additionalTablePrimaryKeyFields == null) { 1048 additionalTablePrimaryKeyFields = new HashMap(5); 1049 } 1050 return additionalTablePrimaryKeyFields; 1051 } 1052 1053 1057 public String getAlias() { 1058 1059 1062 if ((alias == null) && (getJavaClassName() != null)) { 1063 alias = oracle.toplink.essentials.internal.helper.Helper.getShortClassName(getJavaClassName()); 1064 } 1065 return alias; 1066 } 1067 1068 1073 public Vector getAllFields() { 1074 return allFields; 1075 } 1076 1077 1083 public Class getAmendmentClass() { 1084 return amendmentClass; 1085 } 1086 1087 1091 public String getAmendmentClassName() { 1092 if ((amendmentClassName == null) && (amendmentClass != null)) { 1093 amendmentClassName = amendmentClass.getName(); 1094 } 1095 return amendmentClassName; 1096 } 1097 1098 1104 public String getAmendmentMethodName() { 1105 return amendmentMethodName; 1106 } 1107 1108 1112 public ObjectChangePolicy getObjectChangePolicy() { 1113 if (changePolicy == null) { 1116 changePolicy = new DeferredChangeDetectionPolicy(); 1117 } 1118 return changePolicy; 1119 } 1120 1121 1128 public CacheInvalidationPolicy getCacheInvalidationPolicy() { 1129 if (cacheInvalidationPolicy == null) { 1130 cacheInvalidationPolicy = new NoExpiryCacheInvalidationPolicy(); 1131 } 1132 return cacheInvalidationPolicy; 1133 } 1134 1135 1138 public Vector getCascadeLockingPolicies() { 1139 return cascadeLockingPolicies; 1140 } 1141 1142 1149 public Vector getConstraintDependencies() { 1150 return constraintDependencies; 1151 } 1152 1153 1157 public CopyPolicy getCopyPolicy() { 1158 return copyPolicy; 1159 } 1160 1161 1165 public DatabaseTable getDefaultTable() { 1166 return defaultTable; 1167 } 1168 1169 1173 public int getDescriptorType() { 1174 return descriptorType; 1175 } 1176 1177 1181 public String getDescriptorTypeValue() { 1182 if (isAggregateCollectionDescriptor()) { 1183 return "Aggregate collection"; 1184 } else if (isAggregateDescriptor()) { 1185 return "Aggregate"; 1186 } else { 1187 return "Normal"; 1189 } 1190 } 1191 1192 1197 public DescriptorEventManager getDescriptorEventManager() { 1198 return getEventManager(); 1199 } 1200 1201 1206 public DescriptorEventManager getEventManager() { 1207 return eventManager; 1208 } 1209 1210 1214 public Vector getFields() { 1215 return fields; 1216 } 1217 1218 1223 public Class getIdentityMapClass() { 1224 return identityMapClass; 1225 } 1226 1227 1231 public int getIdentityMapSize() { 1232 return identityMapSize; 1233 } 1234 1235 1242 public InheritancePolicy getDescriptorInheritancePolicy() { 1243 return getInheritancePolicy(); 1244 } 1245 1246 1253 public InheritancePolicy getInheritancePolicy() { 1254 if (inheritancePolicy == null) { 1255 setInheritancePolicy(new oracle.toplink.essentials.descriptors.InheritancePolicy(this)); 1257 } 1258 return inheritancePolicy; 1259 } 1260 1261 1265 public InheritancePolicy getInheritancePolicyOrNull() { 1266 return inheritancePolicy; 1267 } 1268 1269 1273 public InstantiationPolicy getInstantiationPolicy() { 1274 return instantiationPolicy; 1275 } 1276 1277 1281 public Class getJavaClass() { 1282 return javaClass; 1283 } 1284 1285 1288 public String getJavaClassName() { 1289 if ((javaClassName == null) && (javaClass != null)) { 1290 javaClassName = javaClass.getName(); 1291 } 1292 return javaClassName; 1293 } 1294 1295 1299 public List getLockableMappings() { 1300 if (this.lockableMappings == null) { 1301 this.lockableMappings = new ArrayList(); 1302 } 1303 return this.lockableMappings; 1304 } 1305 1306 1311 public DatabaseMapping getMappingForAttributeName(String attributeName) { 1312 for (Enumeration mappingsNum = mappings.elements(); mappingsNum.hasMoreElements();) { 1314 DatabaseMapping mapping = (DatabaseMapping)mappingsNum.nextElement(); 1315 if ((mapping.getAttributeName() != null) && mapping.getAttributeName().equals(attributeName)) { 1316 return mapping; 1317 } 1318 } 1319 return null; 1320 } 1321 1322 1327 public DatabaseMapping removeMappingForAttributeName(String attributeName) { 1328 DatabaseMapping mapping = getMappingForAttributeName(attributeName); 1329 getMappings().remove(mapping); 1330 return mapping; 1331 } 1332 1333 1337 public Vector getMappings() { 1338 return mappings; 1339 } 1340 1341 1349 public Vector getMultipleTableForeignKeyAssociations() { 1350 Vector associations = new Vector(getAdditionalTablePrimaryKeyFields().size() * 2); 1351 Iterator tablesHashtable = getAdditionalTablePrimaryKeyFields().values().iterator(); 1352 while (tablesHashtable.hasNext()) { 1353 Map tableHash = (Map)tablesHashtable.next(); 1354 Iterator fieldEnumeration = tableHash.keySet().iterator(); 1355 while (fieldEnumeration.hasNext()) { 1356 DatabaseField keyField = (DatabaseField)fieldEnumeration.next(); 1357 1358 if (getMultipleTableForeignKeys().containsKey(keyField.getTable())) { 1360 Association association = new Association(keyField.getQualifiedName(), ((DatabaseField)tableHash.get(keyField)).getQualifiedName()); 1361 associations.addElement(association); 1362 } 1363 } 1364 } 1365 return associations; 1366 } 1367 1368 1376 public Map getMultipleTableForeignKeys() { 1377 return multipleTableForeignKeys; 1378 } 1379 1380 1387 public Vector getMultipleTableInsertOrder() throws DescriptorException { 1388 return multipleTableInsertOrder; 1389 } 1390 1391 1398 public Vector getMultipleTablePrimaryKeyAssociations() { 1399 Vector associations = new Vector(getAdditionalTablePrimaryKeyFields().size() * 2); 1400 Iterator tablesHashtable = getAdditionalTablePrimaryKeyFields().values().iterator(); 1401 while (tablesHashtable.hasNext()) { 1402 Map tableHash = (Map)tablesHashtable.next(); 1403 Iterator fieldEnumeration = tableHash.keySet().iterator(); 1404 while (fieldEnumeration.hasNext()) { 1405 DatabaseField keyField = (DatabaseField)fieldEnumeration.next(); 1406 1407 if (!getMultipleTableForeignKeys().containsKey(keyField.getTable())) { 1409 Association association = new Association(keyField.getQualifiedName(), ((DatabaseField)tableHash.get(keyField)).getQualifiedName()); 1410 associations.addElement(association); 1411 } 1412 } 1413 } 1414 return associations; 1415 } 1416 1417 1421 public ObjectBuilder getObjectBuilder() { 1422 return objectBuilder; 1423 } 1424 1425 1429 public OptimisticLockingPolicy getOptimisticLockingPolicy() { 1430 return optimisticLockingPolicy; 1431 } 1432 1433 1437 public Vector getPrimaryKeyFieldNames() { 1438 Vector result = new Vector(getPrimaryKeyFields().size()); 1439 List primaryKeyFields = getPrimaryKeyFields(); 1440 for (int index = 0; index < primaryKeyFields.size(); index++) { 1441 result.addElement(((DatabaseField)primaryKeyFields.get(index)).getQualifiedName()); 1442 } 1443 1444 return result; 1445 } 1446 1447 1451 public List getPrimaryKeyFields() { 1452 return primaryKeyFields; 1453 } 1454 1455 1459 public Map getProperties() { 1460 if (properties == null) { 1461 properties = new HashMap(5); 1462 } 1463 return properties; 1464 } 1465 1466 1470 public Object getProperty(String name) { 1471 return getProperties().get(name); 1472 } 1473 1474 1478 public QueryKey getQueryKeyNamed(String queryKeyName) { 1479 return (QueryKey)this.getQueryKeys().get(queryKeyName); 1480 } 1481 1482 1486 public Map getQueryKeys() { 1487 return queryKeys; 1488 } 1489 1490 1496 public DescriptorQueryManager getDescriptorQueryManager() { 1497 return queryManager; 1498 } 1499 1500 1506 public DescriptorQueryManager getQueryManager() { 1507 return queryManager; 1508 } 1509 1510 1514 public DatabaseField getSequenceNumberField() { 1515 return sequenceNumberField; 1516 } 1517 1518 1522 public String getSequenceNumberFieldName() { 1523 if (getSequenceNumberField() == null) { 1524 return null; 1525 } 1526 return getSequenceNumberField().getQualifiedName(); 1527 } 1528 1529 1533 public String getSequenceNumberName() { 1534 return sequenceNumberName; 1535 } 1536 1537 1542 public String getSessionName() { 1543 return sessionName; 1544 } 1545 1546 1550 public DatabaseTable getTable(String tableName) throws DescriptorException { 1551 if (getTables().isEmpty()) { 1552 return null; } 1554 1555 for (Enumeration tables = getTables().elements(); tables.hasMoreElements();) { 1556 DatabaseTable table = (DatabaseTable)tables.nextElement(); 1557 1558 if (table.getName().equals(tableName)) { 1559 return table; 1560 } 1561 } 1562 1563 if (isAggregateDescriptor()) { 1564 return getDefaultTable(); 1565 } 1566 throw DescriptorException.tableNotPresent(tableName, this); 1567 } 1568 1569 1574 public String getTableName() { 1575 if (getTables().isEmpty()) { 1576 return null; 1577 } else { 1578 return ((DatabaseTable)getTables().firstElement()).getName(); 1579 } 1580 } 1581 1582 1586 public Vector getTableNames() { 1587 Vector tableNames = new Vector(getTables().size()); 1588 for (Enumeration fieldsEnum = getTables().elements(); fieldsEnum.hasMoreElements();) { 1589 tableNames.addElement(((DatabaseTable)fieldsEnum.nextElement()).getQualifiedName()); 1590 } 1591 1592 return tableNames; 1593 } 1594 1595 1599 public Vector getTables() { 1600 return tables; 1601 } 1602 1603 1607 public DatabaseField getTypedField(DatabaseField field) { 1608 boolean mayBeMoreThanOne = hasMultipleTables() && !field.hasTableName(); 1609 DatabaseField foundField = null; 1610 for (int j = 0; j < getFields().size(); j++) { 1611 DatabaseField descField = (DatabaseField)getFields().elementAt(j); 1612 if (field.equals(descField)) { 1613 if (descField.getType() != null) { 1614 foundField = descField; 1615 if (!mayBeMoreThanOne || descField.getTable().equals(getDefaultTable())) { 1616 break; 1617 } 1618 } 1619 } 1620 } 1621 if (foundField != null) { 1622 foundField = (DatabaseField)foundField.clone(); 1623 if (!field.hasTableName()) { 1624 foundField.setTableName(""); 1625 } 1626 } 1627 1628 return foundField; 1629 } 1630 1631 1636 public WrapperPolicy getWrapperPolicy() { 1637 return wrapperPolicy; 1638 } 1639 1640 1644 public boolean hasDependencyOnParts() { 1645 for (Enumeration mappings = getMappings().elements(); mappings.hasMoreElements();) { 1646 DatabaseMapping mapping = (DatabaseMapping)mappings.nextElement(); 1647 if (mapping.hasDependency()) { 1648 return true; 1649 } 1650 } 1651 1652 return false; 1653 } 1654 1655 1659 public boolean hasInheritance() { 1660 return (inheritancePolicy != null); 1661 } 1662 1663 1667 public boolean hasMultipleTables() { 1668 return (getTables().size() > 1); 1669 } 1670 1671 1675 public boolean hasPrivatelyOwnedParts() { 1676 for (Enumeration mappings = getMappings().elements(); mappings.hasMoreElements();) { 1677 DatabaseMapping mapping = (DatabaseMapping)mappings.nextElement(); 1678 if (mapping.isPrivateOwned()) { 1679 return true; 1680 } 1681 } 1682 1683 return false; 1684 } 1685 1686 1690 public boolean hasQueryKeyOrMapping(String attributeName) { 1691 return (getQueryKeys().containsKey(attributeName) || (getObjectBuilder().getMappingForAttributeName(attributeName) != null)); 1692 } 1693 1694 1698 public boolean hasWrapperPolicy() { 1699 return getWrapperPolicy() != null; 1700 } 1701 1702 1707 public void initialize(AbstractSession session) throws DescriptorException { 1708 if (shouldBeReadOnly() && (!session.getDefaultReadOnlyClasses().contains(getJavaClass()))) { 1711 session.getDefaultReadOnlyClasses().add(getJavaClass()); 1712 } 1713 if (isIsolated()) { 1715 session.getProject().setHasIsolatedClasses(true); 1716 } 1717 if ((! hasCMPPolicy()) || getCMPPolicy().isCMP3Policy()) { 1719 session.getProject().setIsPureCMP2Project(false); 1720 } 1721 1722 if (isInitialized(INITIALIZED) || isInvalid()) { 1724 return; 1725 } 1726 1727 setInitializationStage(INITIALIZED); 1728 1729 if (isChildDescriptor()) { 1731 getInheritancePolicy().getParentDescriptor().initialize(session); 1732 if (getInheritancePolicy().getParentDescriptor().isIsolated()) { 1733 this.setIsIsolated(true); 1735 } 1736 } 1737 1738 if (shouldOrderMappings()) { 1742 Vector mappings = getMappings(); 1743 Object [] mappingsArray = new Object [mappings.size()]; 1744 for (int index = 0; index < mappings.size(); index++) { 1745 mappingsArray[index] = mappings.elementAt(index); 1746 } 1747 TOPSort.quicksort(mappingsArray, new MappingCompare()); 1748 mappings = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(mappingsArray.length); 1749 for (int index = 0; index < mappingsArray.length; index++) { 1750 mappings.addElement(mappingsArray[index]); 1751 } 1752 setMappings(mappings); 1753 } 1754 1755 for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { 1756 DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); 1757 validateMappingType(mapping); 1758 mapping.initialize(session); 1759 if (mapping.isAggregateObjectMapping() || ((mapping.isForeignReferenceMapping() && (!mapping.isDirectCollectionMapping())) && (!((ForeignReferenceMapping)mapping).usesIndirection()))) { 1760 getLockableMappings().add(mapping); 1761 } 1762 1763 Helper.addAllUniqueToVector(getFields(), mapping.getFields()); 1765 } 1766 1767 if (!isAggregateDescriptor()) { 1770 if (!isChildDescriptor()) { 1771 if (usesOptimisticLocking()) { 1773 getOptimisticLockingPolicy().initializeProperties(); 1774 } 1775 } 1776 } 1777 1778 for (Iterator queryKeys = getQueryKeys().values().iterator(); queryKeys.hasNext();) { 1780 QueryKey queryKey = (QueryKey)queryKeys.next(); 1781 queryKey.initialize(this); 1782 } 1783 1784 if (hasInheritance()) { 1786 getInheritancePolicy().initialize(session); 1787 if (getInheritancePolicy().isChildDescriptor()) { 1788 for (Iterator iterator = getInheritancePolicy().getParentDescriptor().getMappings().iterator(); 1789 iterator.hasNext();) { 1790 DatabaseMapping mapping = (DatabaseMapping)iterator.next(); 1791 if (mapping.isAggregateObjectMapping() || ((mapping.isForeignReferenceMapping() && (!mapping.isDirectCollectionMapping())) && (!((ForeignReferenceMapping)mapping).usesIndirection()))) { 1792 getLockableMappings().add(mapping); } 1794 } 1795 } 1796 } 1797 1798 if (this.hasInheritance() && shouldOrderMappings()) { 1804 Vector mappings = getMappings(); 1805 Object [] mappingsArray = new Object [mappings.size()]; 1806 for (int index = 0; index < mappings.size(); index++) { 1807 mappingsArray[index] = mappings.elementAt(index); 1808 } 1809 TOPSort.quicksort(mappingsArray, new MappingCompare()); 1810 mappings = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(mappingsArray.length); 1811 for (int index = 0; index < mappingsArray.length; index++) { 1812 mappings.addElement(mappingsArray[index]); 1813 } 1814 setMappings(mappings); 1815 } 1816 1817 setAllFields((Vector)getFields().clone()); 1819 1820 getObjectBuilder().initialize(session); 1821 1822 if (shouldOrderMappings()) { 1823 for (int index = getObjectBuilder().getPrimaryKeyMappings().size() - 1; index >= 0; index--) { 1825 DatabaseMapping mapping = (DatabaseMapping) getObjectBuilder().getPrimaryKeyMappings().get(index); 1826 if ((mapping != null) && mapping.isDirectToFieldMapping()) { 1827 getMappings().remove(mapping); 1828 getMappings().add(0, mapping); 1829 DatabaseField field = ((AbstractDirectMapping) mapping).getField(); 1830 getFields().remove(field); 1831 getFields().add(0, field); 1832 getAllFields().remove(field); 1833 getAllFields().add(0, field); 1834 } 1835 } 1836 } 1837 1838 if (usesOptimisticLocking() && (!isChildDescriptor())) { 1839 getOptimisticLockingPolicy().initialize(session); 1840 } 1841 if (hasWrapperPolicy()) { 1842 getWrapperPolicy().initialize(session); 1843 } 1844 getQueryManager().initialize(session); 1845 getEventManager().initialize(session); 1846 getCopyPolicy().initialize(session); 1847 getInstantiationPolicy().initialize(session); 1848 1849 if (this.getCMPPolicy() != null) { 1850 this.getCMPPolicy().initialize(this, session); 1851 } 1852 1853 if (hasFetchGroupManager() && !(Helper.classImplementsInterface(javaClass, ClassConstants.FetchGroupTracker_class))) { 1855 session.getIntegrityChecker().handleError(DescriptorException.needToImplementFetchGroupTracker(javaClass, this)); 1857 } 1858 } 1859 1860 1868 public void initializeAggregateInheritancePolicy(AbstractSession session) { 1869 ClassDescriptor parentDescriptor = session.getDescriptor(getInheritancePolicy().getParentClass()); 1870 parentDescriptor.getInheritancePolicy().addChildDescriptor(this); 1871 } 1872 1873 1877 public void initializeMultipleTablePrimaryKeyFields() { 1878 int additionalTablesSize = getTables().size() - 1; 1879 boolean isChild = hasInheritance() && getInheritancePolicy().isChildDescriptor(); 1880 if (isChild) { 1881 additionalTablesSize = getTables().size() - getInheritancePolicy().getParentDescriptor().getTables().size(); 1882 } 1883 if (additionalTablesSize < 1) { 1884 return; 1885 } 1886 ExpressionBuilder builder = new ExpressionBuilder(); 1887 Expression joinExpression = getQueryManager().getMultipleTableJoinExpression(); 1888 for (int index = getTables().size() - additionalTablesSize; index < getTables().size(); 1889 index++) { 1890 DatabaseTable table = (DatabaseTable)getTables().elementAt(index); 1891 Map oldKeyMapping = (Map)getAdditionalTablePrimaryKeyFields().get(table); 1892 if (oldKeyMapping != null) { 1893 if (!getQueryManager().hasCustomMultipleTableJoinExpression()) { 1894 for (Iterator enumtr = oldKeyMapping.keySet().iterator(); enumtr.hasNext();) { 1896 DatabaseField sourceTableField = (DatabaseField)enumtr.next(); 1897 DatabaseField targetTableField = (DatabaseField)oldKeyMapping.get(sourceTableField); 1898 DatabaseTable sourceTable = sourceTableField.getTable(); 1899 DatabaseTable targetTable = targetTableField.getTable(); 1900 1901 if (!getFields().contains(sourceTableField)) { 1903 getFields().addElement(sourceTableField); 1904 } 1905 if (!getFields().contains(targetTableField)) { 1906 getFields().addElement(targetTableField); 1907 } 1908 1909 Expression keyJoinExpression = builder.getField(targetTableField).equal(builder.getField(sourceTableField)); 1910 joinExpression = keyJoinExpression.and(joinExpression); 1911 1912 getQueryManager().getTablesJoinExpressions().put(targetTable, keyJoinExpression); 1913 if(isChild) { 1914 getInheritancePolicy().addChildTableJoinExpressionToAllParents(targetTable, keyJoinExpression); 1915 } 1916 } 1917 } 1918 } else { 1919 Map newKeyMapping = new HashMap(getPrimaryKeyFields().size() + 1); 1922 getAdditionalTablePrimaryKeyFields().put(table, newKeyMapping); 1923 1924 List primaryKeyFields = getPrimaryKeyFields(); 1926 for (int pkIndex = 0; pkIndex < primaryKeyFields.size(); pkIndex++) { 1927 DatabaseField primaryKeyField = (DatabaseField)primaryKeyFields.get(pkIndex); 1928 DatabaseField secondaryKeyField = (DatabaseField)primaryKeyField.clone(); 1929 secondaryKeyField.setTable(table); 1930 newKeyMapping.put(primaryKeyField, secondaryKeyField); 1931 getFields().addElement(secondaryKeyField); 1933 1934 if (!getQueryManager().hasCustomMultipleTableJoinExpression()) { 1935 Expression keyJoinExpression = builder.getField(secondaryKeyField).equal(builder.getField(primaryKeyField)); 1936 joinExpression = keyJoinExpression.and(joinExpression); 1937 1938 getQueryManager().getTablesJoinExpressions().put(table, keyJoinExpression); 1939 if(isChild) { 1940 getInheritancePolicy().addChildTableJoinExpressionToAllParents(table, keyJoinExpression); 1941 } 1942 } 1943 } 1944 } 1945 } 1946 if (joinExpression != null) { 1947 getQueryManager().setInternalMultipleTableJoinExpression(joinExpression); 1948 } 1949 if (getQueryManager().hasCustomMultipleTableJoinExpression()) { 1950 Map tablesJoinExpressions = SQLSelectStatement.mapTableToExpression(joinExpression, getTables()); 1951 getQueryManager().getTablesJoinExpressions().putAll(tablesJoinExpressions); 1952 if(isChild) { 1953 for (int index = getTables().size() - additionalTablesSize; index < getTables().size(); 1954 index++) { 1955 DatabaseTable table = (DatabaseTable)getTables().elementAt(index); 1956 getInheritancePolicy().addChildTableJoinExpressionToAllParents(table, (Expression)tablesJoinExpressions.get(table)); 1957 } 1958 } 1959 } 1960 } 1961 1962 1966 protected void initializeProperties(AbstractSession session) throws DescriptorException { 1967 if (!isAggregateDescriptor()) { 1968 if (!isChildDescriptor()) { 1969 List primaryKeyFields = (List)((ArrayList)getPrimaryKeyFields()).clone(); 1971 for (int index = 0; index < primaryKeyFields.size(); index++) { 1972 DatabaseField primaryKey = (DatabaseField)primaryKeyFields.get(index); 1973 initializePrimaryKey(primaryKey); 1974 } 1975 } 1976 1977 if (getSequenceNumberField() != null) { 1979 buildField(getSequenceNumberField()); 1980 } 1981 } 1982 1983 setSessionName(session.getName()); 1985 } 1986 1987 1990 protected void initializePrimaryKey(DatabaseField primaryKey) { 1991 buildField(primaryKey); 1992 if (!primaryKey.getTable().equals(getDefaultTable())) { 1993 getPrimaryKeyFields().remove(primaryKey); 1994 } 1995 } 1996 1997 2001 public boolean isAggregateCollectionDescriptor() { 2002 return (getDescriptorType() == AGGREGATE_COLLECTION); 2003 } 2004 2005 2009 public boolean isAggregateDescriptor() { 2010 return (getDescriptorType() == AGGREGATE); 2011 } 2012 2013 2017 public boolean isChildDescriptor() { 2018 return hasInheritance() && getInheritancePolicy().isChildDescriptor(); 2019 } 2020 2021 2025 public boolean isFullyInitialized() { 2026 return this.initializationStage == POST_INITIALIZED; 2027 } 2028 2029 2036 protected boolean isInitialized(int initializationStage) { 2037 return this.initializationStage >= initializationStage; 2038 } 2039 2040 2044 public boolean isInvalid() { 2045 return this.initializationStage == ERROR; 2046 } 2047 2048 2052 public boolean isIsolated() { 2053 return this.isIsolated; 2054 } 2055 2056 2060 public boolean isMultipleTableDescriptor() { 2061 return getTables().size() > 1; 2062 } 2063 2064 2070 public boolean isPrimaryKeySetAfterInsert(AbstractSession session) { 2071 return (usesSequenceNumbers() && session.getSequencing().shouldAcquireValueAfterInsert(getJavaClass())); 2072 } 2073 2074 2097 public void onlyRefreshCacheIfNewerVersion() { 2098 setShouldOnlyRefreshCacheIfNewerVersion(true); 2099 } 2100 2101 2105 public void postInitialize(AbstractSession session) throws DescriptorException { 2106 if (isInitialized(POST_INITIALIZED) || isInvalid()) { 2108 return; 2109 } 2110 2111 setInitializationStage(POST_INITIALIZED); 2112 2113 if (hasInheritance()) { 2116 for (Enumeration childEnum = getInheritancePolicy().getChildDescriptors().elements(); 2117 childEnum.hasMoreElements();) { 2118 ((ClassDescriptor)childEnum.nextElement()).postInitialize(session); 2119 } 2120 } 2121 2122 for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { 2124 DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); 2125 2126 mapping.postInitialize(session); 2128 if (!shouldAcquireCascadedLocks()) { 2130 if ((mapping instanceof ForeignReferenceMapping) && (!((ForeignReferenceMapping)mapping).usesIndirection())) { 2131 setShouldAcquireCascadedLocks(true); 2132 } 2133 if ((mapping instanceof AggregateObjectMapping) && ((AggregateObjectMapping)mapping).getDescriptor().shouldAcquireCascadedLocks()) { 2134 setShouldAcquireCascadedLocks(true); 2135 } 2136 } 2137 } 2138 2139 if (hasInheritance()) { 2140 getInheritancePolicy().postInitialize(session); 2141 } 2142 2143 for (int index = (getPrimaryKeyFields().size() - 1); index >= 0; index--) { 2145 DatabaseField primaryKeyField = (DatabaseField)getPrimaryKeyFields().get(index); 2146 int fieldIndex = getFields().indexOf(primaryKeyField); 2147 2148 if (fieldIndex != -1) { 2150 primaryKeyField = (DatabaseField)getFields().get(fieldIndex); 2151 getPrimaryKeyFields().set(index, primaryKeyField); 2152 } 2153 } 2154 2155 for (int index = 0; index < getFields().size(); index++) { 2161 DatabaseField field = (DatabaseField)getFields().elementAt(index); 2162 DatabaseMapping mapping = getObjectBuilder().getMappingForField(field); 2163 if ((mapping != null) && (!(mapping.isAggregateMapping()))) { 2164 field.setType(mapping.getFieldClassification(field)); 2165 } 2166 field.setIndex(index); 2167 } 2168 2169 validateAfterInitialization(session); 2170 2171 checkDatabase(session); 2172 } 2173 2174 2178 public void preInitialize(AbstractSession session) throws DescriptorException { 2179 getObjectChangePolicy().initialize(session, this); 2181 2182 if (isInitialized(PREINITIALIZED)) { 2184 return; 2185 } 2186 2187 setInitializationStage(PREINITIALIZED); 2188 2189 for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { 2191 try { 2192 DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); 2193 mapping.preInitialize(session); 2194 } catch (DescriptorException exception) { 2195 session.getIntegrityChecker().handleError(exception); 2196 } 2197 } 2198 2199 validateBeforeInitialization(session); 2200 2201 preInitializeInheritancePolicy(session); 2202 2203 if (getDefaultTable() == null) { setDefaultTable(extractDefaultTable()); 2206 } 2207 2208 if (hasInheritance()) { 2210 getInheritancePolicy().preInitialize(session); 2211 } 2212 2213 verifyTableQualifiers(session.getDatasourcePlatform()); 2214 initializeProperties(session); 2215 if (!isAggregateDescriptor()) { 2216 adjustMultipleTableInsertOrder(); 2218 initializeMultipleTablePrimaryKeyFields(); 2219 } 2220 2221 getQueryManager().preInitialize(session); 2222 2223 } 2224 2225 2228 protected void prepareCascadeLockingPolicy(DatabaseMapping mapping) { 2229 if (mapping.isPrivateOwned() && mapping.isForeignReferenceMapping()) { 2230 if (mapping.isCascadedLockingSupported()) { 2231 if (((ForeignReferenceMapping) mapping).hasCustomSelectionQuery()) { 2234 throw ValidationException.unsupportedCascadeLockingMappingWithCustomQuery(mapping); 2235 } else if (isAggregateDescriptor() || isAggregateCollectionDescriptor()) { 2236 throw ValidationException.unsupportedCascadeLockingDescriptor(this); 2237 } else { 2238 mapping.prepareCascadeLockingPolicy(); 2239 } 2240 } else { 2241 throw ValidationException.unsupportedCascadeLockingMapping(mapping); 2242 } 2243 } 2244 } 2245 2246 2249 protected void preInitializeInheritancePolicy(AbstractSession session) throws DescriptorException { 2250 if (isChildDescriptor() && (requiresInitialization())) { 2251 if (getInheritancePolicy().getParentClass().equals(getJavaClass())) { 2252 throw DescriptorException.parentClassIsSelf(this); 2253 } 2254 ClassDescriptor parentDescriptor = session.getDescriptor(getInheritancePolicy().getParentClass()); 2255 parentDescriptor.getInheritancePolicy().addChildDescriptor(this); 2256 getInheritancePolicy().setParentDescriptor(parentDescriptor); 2257 parentDescriptor.preInitialize(session); 2258 } 2259 } 2260 2261 2267 public void rehashFieldDependancies(AbstractSession session) { 2268 getObjectBuilder().rehashFieldDependancies(session); 2269 2270 for (Enumeration enumtr = getMappings().elements(); enumtr.hasMoreElements();) { 2271 ((DatabaseMapping)enumtr.nextElement()).rehashFieldDependancies(session); 2272 } 2273 } 2274 2275 2280 public void reInitializeJoinedAttributes() { 2281 if (!isInitialized(POST_INITIALIZED)) { 2282 return; 2284 } 2285 getObjectBuilder().initializeJoinedAttributes(); 2286 if (hasInheritance()) { 2287 Vector children = getInheritancePolicy().getChildDescriptors(); 2288 2289 for (int i = 0; i < children.size(); i++) { 2291 InheritancePolicy child = (InheritancePolicy)children.elementAt(0); 2292 child.getDescriptor().reInitializeJoinedAttributes(); 2293 } 2294 } 2295 } 2296 2297 2301 public void removeProperty(String property) { 2302 getProperties().remove(property); 2303 } 2304 2305 2310 public boolean requiresInitialization() { 2311 return !(isAggregateDescriptor()); 2312 } 2313 2314 2319 protected void selfValidationAfterInitialization(AbstractSession session) throws DescriptorException { 2320 if (!(hasInheritance() && (getInheritancePolicy().shouldReadSubclasses() || java.lang.reflect.Modifier.isAbstract(getJavaClass().getModifiers())))) { 2322 if (session.getIntegrityChecker().shouldCheckInstantiationPolicy()) { 2323 getInstantiationPolicy().buildNewInstance(); 2324 } 2325 } 2326 getObjectBuilder().validate(session); 2327 } 2328 2329 2333 protected void selfValidationBeforeInitialization(AbstractSession session) throws DescriptorException { 2334 if (isChildDescriptor()) { 2335 ClassDescriptor parentDescriptor = session.getDescriptor(getInheritancePolicy().getParentClass()); 2336 2337 if (parentDescriptor == null) { 2338 session.getIntegrityChecker().handleError(DescriptorException.parentDescriptorNotSpecified(getInheritancePolicy().getParentClass().getName(), this)); 2339 } 2340 } else { 2341 if (getTables().isEmpty() && (!isAggregateDescriptor())) { 2342 session.getIntegrityChecker().handleError(DescriptorException.tableNotSpecified(this)); 2343 } 2344 } 2345 2346 if (!isChildDescriptor() && !isAggregateDescriptor()) { 2347 if (getPrimaryKeyFieldNames().isEmpty()) { 2348 session.getIntegrityChecker().handleError(DescriptorException.primaryKeyFieldsNotSepcified(this)); 2349 } 2350 } 2351 2352 if ((getIdentityMapClass() == ClassConstants.NoIdentityMap_Class) && (getQueryManager().getDoesExistQuery().shouldCheckCacheForDoesExist())) { 2353 session.getIntegrityChecker().handleError(DescriptorException.identityMapNotSpecified(this)); 2354 } 2355 2356 if (((getSequenceNumberName() != null) && (getSequenceNumberField() == null)) || ((getSequenceNumberName() == null) && (getSequenceNumberField() != null))) { 2357 session.getIntegrityChecker().handleError(DescriptorException.sequenceNumberPropertyNotSpecified(this)); 2358 } 2359 } 2360 2361 2366 protected void setAdditionalTablePrimaryKeyFields(DatabaseTable table, DatabaseField field1, DatabaseField field2) { 2367 Map tableAdditionalPKFields = (Map)getAdditionalTablePrimaryKeyFields().get(table); 2368 2369 if (tableAdditionalPKFields == null) { 2370 tableAdditionalPKFields = new HashMap(2); 2371 getAdditionalTablePrimaryKeyFields().put(table, tableAdditionalPKFields); 2372 } 2373 2374 tableAdditionalPKFields.put(field1, field2); 2375 } 2376 2377 2384 protected void toggleAdditionalTablePrimaryKeyFields(DatabaseTable targetTable, DatabaseTable sourceTable) { 2385 Map targetTableAdditionalPKFields = (Map)getAdditionalTablePrimaryKeyFields().get(targetTable); 2386 2387 if (targetTableAdditionalPKFields != null) { 2388 Iterator e = targetTableAdditionalPKFields.keySet().iterator(); 2389 2390 while (e.hasNext()) { 2391 DatabaseField sourceField = (DatabaseField)e.next(); 2392 DatabaseField targetField = (DatabaseField) targetTableAdditionalPKFields.get(sourceField); 2393 2394 setAdditionalTablePrimaryKeyFields(sourceTable, targetField, sourceField); 2395 } 2396 2397 targetTableAdditionalPKFields.clear(); 2398 } 2399 } 2400 2401 2406 public void setAdditionalTablePrimaryKeyFields(Map additionalTablePrimaryKeyFields) { 2407 this.additionalTablePrimaryKeyFields = additionalTablePrimaryKeyFields; 2408 } 2409 2410 2414 public void setAlias(String alias) { 2415 this.alias = alias; 2416 } 2417 2418 2422 protected void setAllFields(Vector allFields) { 2423 this.allFields = allFields; 2424 } 2425 2426 2432 public void setAmendmentClass(Class amendmentClass) { 2433 this.amendmentClass = amendmentClass; 2434 } 2435 2436 2440 public void setAmendmentClassName(String amendmentClassName) { 2441 this.amendmentClassName = amendmentClassName; 2442 } 2443 2444 2450 public void setAmendmentMethodName(String amendmentMethodName) { 2451 this.amendmentMethodName = amendmentMethodName; 2452 } 2453 2454 2458 public void setObjectChangePolicy(ObjectChangePolicy policy) { 2459 this.changePolicy = policy; 2460 } 2461 2462 2468 public void setCacheInvalidationPolicy(CacheInvalidationPolicy policy) { 2469 cacheInvalidationPolicy = policy; 2470 } 2471 2472 2479 public void setConstraintDependencies(Vector constraintDependencies) { 2480 this.constraintDependencies = constraintDependencies; 2481 } 2482 2483 2489 public void setCopyPolicy(CopyPolicy policy) { 2490 copyPolicy = policy; 2491 if (policy != null) { 2492 policy.setDescriptor(this); 2493 } 2494 } 2495 2496 2500 public void setDefaultTable(DatabaseTable defaultTable) { 2501 this.defaultTable = defaultTable; 2502 } 2503 2504 2508 public void setDefaultTableName(String defaultTableName) { 2509 setDefaultTable(new DatabaseTable(defaultTableName)); 2510 } 2511 2512 2516 public void setDescriptorType(int descriptorType) { 2517 this.descriptorType = descriptorType; 2518 } 2519 2520 2524 public void setDescriptorTypeValue(String value) { 2525 if (value.equals("Aggregate collection")) { 2526 descriptorIsAggregateCollection(); 2527 } else if (value.equals("Aggregate")) { 2528 descriptorIsAggregate(); 2529 } else { 2530 descriptorIsNormal(); 2531 } 2532 } 2533 2534 2539 public void setEventManager(DescriptorEventManager eventManager) { 2540 this.eventManager = eventManager; 2541 if (eventManager != null) { 2542 eventManager.setDescriptor(this); 2543 } 2544 } 2545 2546 2550 public void setExistenceChecking(String token) throws DescriptorException { 2551 getQueryManager().setExistenceCheck(token); 2552 } 2553 2554 2558 public void setFields(Vector fields) { 2559 this.fields = fields; 2560 } 2561 2562 2567 public void setIdentityMapClass(Class theIdentityMapClass) { 2568 identityMapClass = theIdentityMapClass; 2569 } 2570 2571 2576 public void setIdentityMapSize(int identityMapSize) { 2577 this.identityMapSize = identityMapSize; 2578 } 2579 2580 2584 public void setInheritancePolicy(InheritancePolicy inheritancePolicy) { 2585 this.inheritancePolicy = inheritancePolicy; 2586 if (inheritancePolicy != null) { 2587 inheritancePolicy.setDescriptor(this); 2588 } 2589 } 2590 2591 2594 protected void setInitializationStage(int initializationStage) { 2595 this.initializationStage = initializationStage; 2596 } 2597 2598 2602 public void setInstantiationPolicy(InstantiationPolicy instantiationPolicy) { 2603 this.instantiationPolicy = instantiationPolicy; 2604 if (instantiationPolicy != null) { 2605 instantiationPolicy.setDescriptor(this); 2606 } 2607 } 2608 2609 2616 public void setIsIsolated(boolean isIsolated) { 2617 this.isIsolated = isIsolated; 2618 } 2619 2620 2625 public void setJavaClass(Class theJavaClass) { 2626 javaClass = theJavaClass; 2627 } 2628 2629 2633 public void setJavaClassName(String theJavaClassName) { 2634 javaClassName = theJavaClassName; 2635 } 2636 2637 2643 public void setLockableMappings(ArrayList lockableMappings) { 2644 this.lockableMappings = lockableMappings; 2645 } 2646 2647 2651 public void setMappings(Vector mappings) { 2652 for (Enumeration mappingsEnum = mappings.elements(); mappingsEnum.hasMoreElements();) { 2654 DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); 2655 2656 if (mapping.getDescriptor() == null) { 2658 mapping.setDescriptor(this); 2659 } 2660 } 2661 this.mappings = mappings; 2662 } 2663 2664 2668 public void setMultipleTableForeignKeyFieldNames(Vector associations) throws DescriptorException { 2669 Enumeration foreignKeys = associations.elements(); 2670 while (foreignKeys.hasMoreElements()) { 2671 Association association = (Association)foreignKeys.nextElement(); 2672 addMultipleTableForeignKeys((String )association.getKey(), (String )association.getValue(), true); 2673 } 2674 } 2675 2676 2681 protected void setMultipleTableForeignKeys(Map newValue) { 2682 this.multipleTableForeignKeys = newValue; 2683 } 2684 2685 2690 public void setMultipleTableInsertOrder(Vector newValue) { 2691 this.multipleTableInsertOrder = newValue; 2692 } 2693 2694 2698 public void setMultipleTablePrimaryKeyFieldNames(Vector associations) throws DescriptorException { 2699 Enumeration foreignKeys = associations.elements(); 2700 while (foreignKeys.hasMoreElements()) { 2701 Association association = (Association)foreignKeys.nextElement(); 2702 addMultipleTableForeignKeys((String )association.getKey(), (String )association.getValue(), true); 2703 } 2704 } 2705 2706 2710 protected void setObjectBuilder(ObjectBuilder builder) { 2711 objectBuilder = builder; 2712 } 2713 2714 2722 public void setOptimisticLockingPolicy(OptimisticLockingPolicy optimisticLockingPolicy) { 2723 this.optimisticLockingPolicy = optimisticLockingPolicy; 2724 if (optimisticLockingPolicy != null) { 2725 optimisticLockingPolicy.setDescriptor(this); 2726 } 2727 } 2728 2729 2738 public void setPrimaryKeyFieldName(String fieldName) { 2739 addPrimaryKeyFieldName(fieldName); 2740 } 2741 2742 2748 public void setPrimaryKeyFieldNames(Vector primaryKeyFieldsName) { 2749 setPrimaryKeyFields(new ArrayList(primaryKeyFieldsName.size())); 2750 for (Enumeration keyEnum = primaryKeyFieldsName.elements(); keyEnum.hasMoreElements();) { 2751 addPrimaryKeyFieldName((String )keyEnum.nextElement()); 2752 } 2753 } 2754 2755 2759 public void setPrimaryKeyFields(List thePrimaryKeyFields) { 2760 primaryKeyFields = thePrimaryKeyFields; 2761 } 2762 2763 2767 public void setProperties(Map properties) { 2768 this.properties = properties; 2769 } 2770 2771 2775 public void setProperty(String name, Object value) { 2776 getProperties().put(name, value); 2777 } 2778 2779 2783 public void setQueryKeys(Map queryKeys) { 2784 this.queryKeys = queryKeys; 2785 } 2786 2787 2791 public void setQueryManager(DescriptorQueryManager queryManager) { 2792 this.queryManager = queryManager; 2793 if (queryManager != null) { 2794 queryManager.setDescriptor(this); 2795 } 2796 } 2797 2798 2802 public void setSequenceNumberField(DatabaseField sequenceNumberField) { 2803 this.sequenceNumberField = sequenceNumberField; 2804 } 2805 2806 2812 public void setSequenceNumberFieldName(String fieldName) { 2813 if (fieldName == null) { 2814 setSequenceNumberField(null); 2815 } else { 2816 setSequenceNumberField(new DatabaseField(fieldName)); 2817 } 2818 } 2819 2820 2829 public void setSequenceNumberName(String name) { 2830 sequenceNumberName = name; 2831 } 2832 2833 2838 protected void setSessionName(String sessionName) { 2839 this.sessionName = sessionName; 2840 } 2841 2842 2847 public void setShouldAlwaysConformResultsInUnitOfWork(boolean shouldAlwaysConformResultsInUnitOfWork) { 2848 this.shouldAlwaysConformResultsInUnitOfWork = shouldAlwaysConformResultsInUnitOfWork; 2849 } 2850 2851 2874 public void setShouldAlwaysRefreshCache(boolean shouldAlwaysRefreshCache) { 2875 this.shouldAlwaysRefreshCache = shouldAlwaysRefreshCache; 2876 } 2877 2878 2882 public void setShouldBeReadOnly(boolean shouldBeReadOnly) { 2883 this.shouldBeReadOnly = shouldBeReadOnly; 2884 } 2885 2886 2893 public void setReadOnly() { 2894 setShouldBeReadOnly(true); 2895 } 2896 2897 2903 public void setShouldDisableCacheHits(boolean shouldDisableCacheHits) { 2904 this.shouldDisableCacheHits = shouldDisableCacheHits; 2905 } 2906 2907 2934 public void setShouldOnlyRefreshCacheIfNewerVersion(boolean shouldOnlyRefreshCacheIfNewerVersion) { 2935 this.shouldOnlyRefreshCacheIfNewerVersion = shouldOnlyRefreshCacheIfNewerVersion; 2936 } 2937 2938 2945 public void setShouldOrderMappings(boolean shouldOrderMappings) { 2946 this.shouldOrderMappings = shouldOrderMappings; 2947 } 2948 2949 2956 public void setShouldRegisterResultsInUnitOfWork(boolean shouldRegisterResultsInUnitOfWork) { 2957 this.shouldRegisterResultsInUnitOfWork = shouldRegisterResultsInUnitOfWork; 2958 } 2959 2960 2966 public void setTableName(String tableName) throws DescriptorException { 2967 if (getTables().isEmpty()) { 2968 addTableName(tableName); 2969 } else { 2970 throw DescriptorException.onlyOneTableCanBeAddedWithThisMethod(this); 2971 } 2972 } 2973 2974 2980 public void setTableNames(Vector tableNames) { 2981 setTables(oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(tableNames.size())); 2982 for (Enumeration tableEnum = tableNames.elements(); tableEnum.hasMoreElements();) { 2983 addTableName((String )tableEnum.nextElement()); 2984 } 2985 } 2986 2987 2991 public void setTableQualifier(String tableQualifier) { 2992 for (Enumeration enumtr = getTables().elements(); enumtr.hasMoreElements();) { 2993 DatabaseTable table = (DatabaseTable)enumtr.nextElement(); 2994 table.setTableQualifier(tableQualifier); 2995 } 2996 } 2997 2998 3002 public void setTables(Vector theTables) { 3003 tables = theTables; 3004 } 3005 3006 3011 public void setWrapperPolicy(WrapperPolicy wrapperPolicy) { 3012 this.wrapperPolicy = wrapperPolicy; 3013 3014 if (wrapperPolicy != null) { 3017 wrapperPolicy.setDescriptor(this); 3018 } 3019 } 3020 3021 3026 public boolean shouldAlwaysConformResultsInUnitOfWork() { 3027 return shouldAlwaysConformResultsInUnitOfWork; 3028 } 3029 3030 3037 public boolean shouldAlwaysRefreshCache() { 3038 return shouldAlwaysRefreshCache; 3039 } 3040 3041 3046 public boolean shouldBeReadOnly() { 3047 return shouldBeReadOnly; 3048 } 3049 3050 3056 public boolean shouldDisableCacheHits() { 3057 return shouldDisableCacheHits; 3058 } 3059 3060 3068 public boolean shouldOnlyRefreshCacheIfNewerVersion() { 3069 return shouldOnlyRefreshCacheIfNewerVersion; 3070 } 3071 3072 3078 public boolean shouldOrderMappings() { 3079 return shouldOrderMappings; 3080 } 3081 3082 3086 public boolean hasSimplePrimaryKey() { 3087 return hasSimplePrimaryKey; 3088 } 3089 3090 3094 public void setHasSimplePrimaryKey(boolean hasSimplePrimaryKey) { 3095 this.hasSimplePrimaryKey = hasSimplePrimaryKey; 3096 } 3097 3098 3104 public boolean shouldAcquireCascadedLocks() { 3105 return shouldAcquireCascadedLocks; 3106 } 3107 3108 3114 public void setShouldAcquireCascadedLocks(boolean shouldAcquireCascadedLocks) { 3115 this.shouldAcquireCascadedLocks = shouldAcquireCascadedLocks; 3116 } 3117 3118 3122 public boolean shouldUseCacheIdentityMap() { 3123 return (getIdentityMapClass() == ClassConstants.CacheIdentityMap_Class); 3124 } 3125 3126 3130 public boolean shouldUseFullIdentityMap() { 3131 return (getIdentityMapClass() == ClassConstants.FullIdentityMap_Class); 3132 } 3133 3134 3138 public boolean shouldUseHardCacheWeakIdentityMap() { 3139 return (getIdentityMapClass() == ClassConstants.HardCacheWeakIdentityMap_Class); 3140 } 3141 3142 3146 public boolean shouldUseNoIdentityMap() { 3147 return (getIdentityMapClass() == ClassConstants.NoIdentityMap_Class); 3148 } 3149 3150 3165 public boolean shouldRegisterResultsInUnitOfWork() { 3166 return shouldRegisterResultsInUnitOfWork; 3167 } 3168 3169 3173 public boolean shouldUseSoftCacheWeakIdentityMap() { 3174 return (getIdentityMapClass() == ClassConstants.SoftCacheWeakIdentityMap_Class); 3175 } 3176 3177 3181 public boolean shouldUseWeakIdentityMap() { 3182 return (getIdentityMapClass() == ClassConstants.WeakIdentityMap_Class); 3183 } 3184 3185 3189 public String toString() { 3190 return Helper.getShortClassName(getClass()) + "(" + getJavaClassName() + " --> " + getTables() + ")"; 3191 } 3192 3193 3199 public void useCacheIdentityMap() { 3200 setIdentityMapClass(ClassConstants.CacheIdentityMap_Class); 3201 } 3202 3203 3213 public void useCloneCopyPolicy() { 3214 useCloneCopyPolicy("clone"); 3215 } 3216 3217 3227 public void useCloneCopyPolicy(String cloneMethodName) { 3228 CloneCopyPolicy policy = new CloneCopyPolicy(); 3229 policy.setMethodName(cloneMethodName); 3230 setCopyPolicy(policy); 3231 } 3232 3233 3252 public void useInstantiationCopyPolicy() { 3253 setCopyPolicy(new InstantiationCopyPolicy()); 3254 } 3255 3256 3268 public void useDefaultConstructorInstantiationPolicy() { 3269 getInstantiationPolicy().useDefaultConstructorInstantiationPolicy(); 3270 } 3271 3272 3285 public void useFactoryInstantiationPolicy(Class factoryClass, String methodName) { 3286 getInstantiationPolicy().useFactoryInstantiationPolicy(factoryClass, methodName); 3287 } 3288 3289 3293 public void useFactoryInstantiationPolicy(String factoryClassName, String methodName) { 3294 getInstantiationPolicy().useFactoryInstantiationPolicy(factoryClassName, methodName); 3295 } 3296 3297 3310 public void useFactoryInstantiationPolicy(Class factoryClass, String methodName, String factoryMethodName) { 3311 getInstantiationPolicy().useFactoryInstantiationPolicy(factoryClass, methodName, factoryMethodName); 3312 } 3313 3314 3318 public void useFactoryInstantiationPolicy(String factoryClassName, String methodName, String factoryMethodName) { 3319 getInstantiationPolicy().useFactoryInstantiationPolicy(factoryClassName, methodName, factoryMethodName); 3320 } 3321 3322 3334 public void useFactoryInstantiationPolicy(Object factory, String methodName) { 3335 getInstantiationPolicy().useFactoryInstantiationPolicy(factory, methodName); 3336 } 3337 3338 3344 public void useFullIdentityMap() { 3345 setIdentityMapClass(ClassConstants.FullIdentityMap_Class); 3346 } 3347 3348 3356 public void useHardCacheWeakIdentityMap() { 3357 setIdentityMapClass(ClassConstants.HardCacheWeakIdentityMap_Class); 3358 } 3359 3360 3371 public void useMethodInstantiationPolicy(String staticMethodName) { 3372 getInstantiationPolicy().useMethodInstantiationPolicy(staticMethodName); 3373 } 3374 3375 3381 public void useNoIdentityMap() { 3382 setIdentityMapClass(ClassConstants.NoIdentityMap_Class); 3383 } 3384 3385 3392 public void useSoftCacheWeakIdentityMap() { 3393 setIdentityMapClass(ClassConstants.SoftCacheWeakIdentityMap_Class); 3394 } 3395 3396 3400 public boolean usesOptimisticLocking() { 3401 return (optimisticLockingPolicy != null); 3402 } 3403 3404 3408 public boolean usesVersionLocking() { 3409 return (usesOptimisticLocking() && (getOptimisticLockingPolicy() instanceof VersionLockingPolicy)); 3410 } 3411 3412 3416 public boolean usesSequenceNumbers() { 3417 return ((getSequenceNumberField() != null) && (getSequenceNumberName() != null)); 3418 } 3419 3420 3425 public void useTimestampLocking(String writeLockFieldName) { 3426 useTimestampLocking(writeLockFieldName, true); 3427 } 3428 3429 3440 public void useTimestampLocking(String writeLockFieldName, boolean shouldStoreInCache) { 3441 TimestampLockingPolicy policy = new TimestampLockingPolicy(writeLockFieldName); 3442 if (shouldStoreInCache) { 3443 policy.storeInCache(); 3444 } else { 3445 policy.storeInObject(); 3446 } 3447 setOptimisticLockingPolicy(policy); 3448 } 3449 3450 3455 public void useVersionLocking(String writeLockFieldName) { 3456 useVersionLocking(writeLockFieldName, true); 3457 } 3458 3459 3469 public void useVersionLocking(String writeLockFieldName, boolean shouldStoreInCache) { 3470 VersionLockingPolicy policy = new VersionLockingPolicy(writeLockFieldName); 3471 if (shouldStoreInCache) { 3472 policy.storeInCache(); 3473 } else { 3474 policy.storeInObject(); 3475 } 3476 setOptimisticLockingPolicy(policy); 3477 } 3478 3479 3484 public void useWeakIdentityMap() { 3485 setIdentityMapClass(ClassConstants.WeakIdentityMap_Class); 3486 } 3487 3488 3492 protected void validateAfterInitialization(AbstractSession session) { 3493 selfValidationAfterInitialization(session); 3494 for (Enumeration mappings = getMappings().elements(); mappings.hasMoreElements();) { 3495 ((DatabaseMapping)mappings.nextElement()).validateAfterInitialization(session); 3496 } 3497 } 3498 3499 3503 protected void validateBeforeInitialization(AbstractSession session) { 3504 selfValidationBeforeInitialization(session); 3505 for (Enumeration mappings = getMappings().elements(); mappings.hasMoreElements();) { 3506 ((DatabaseMapping)mappings.nextElement()).validateBeforeInitialization(session); 3507 } 3508 } 3509 3510 3514 protected void verifyTableQualifiers(Platform platform) { 3515 DatabaseTable table; 3516 Enumeration tableEnumeration; 3517 String tableQualifier = platform.getTableQualifier(); 3518 3519 if (tableQualifier.length() == 0) { 3520 return; 3521 } 3522 3523 tableEnumeration = getTables().elements(); 3524 while (tableEnumeration.hasMoreElements()) { 3525 table = (DatabaseTable)tableEnumeration.nextElement(); 3526 if (table.getTableQualifier().length() == 0) { 3527 table.setTableQualifier(tableQualifier); 3528 } 3529 } 3530 } 3531 3532 3540 public CMPPolicy getCMPPolicy() { 3541 return cmpPolicy; 3542 } 3543 3544 3551 public void setCMPPolicy(CMPPolicy newCMPPolicy) { 3552 cmpPolicy = newCMPPolicy; 3553 if (cmpPolicy != null){ 3554 cmpPolicy.setDescriptor(this); 3555 } 3556 } 3557 3558 3567 public FetchGroupManager getFetchGroupManager() { 3568 return fetchGroupManager; 3569 } 3570 3571 3576 public void setFetchGroupManager(FetchGroupManager fetchGroupManager) { 3577 this.fetchGroupManager = fetchGroupManager; 3578 if (fetchGroupManager != null) { 3579 fetchGroupManager.setDescriptor(this); 3581 } 3582 } 3583 3584 3588 public boolean isDescriptorForCMP() { 3589 return (this.getCMPPolicy() != null); 3590 } 3591 3592 3596 public boolean hasFetchGroupManager() { 3597 return (fetchGroupManager != null); 3598 } 3599 3600 3603 public boolean hasCascadeLockingPolicies() { 3604 return !cascadeLockingPolicies.isEmpty(); 3605 } 3606 3607 3611 public boolean hasCMPPolicy() { 3612 return (cmpPolicy != null); 3613 } 3614 3615 3622 public FetchGroup getDefaultFetchGroup() { 3623 if (!hasFetchGroupManager()) { 3624 return null; 3626 } 3627 return getFetchGroupManager().getDefaultFetchGroup(); 3628 } 3629} 3630 | Popular Tags |