/** * INTERNAL: * The first table in the tables is always treated as default. */ protected DatabaseTable extractDefaultTable() { if (getTables().isEmpty()) { if (isChildDescriptor()) { return getInheritancePolicy().getParentDescriptor().extractDefaultTable(); } else { return null; } } return (DatabaseTable)getTables().firstElement(); }
boolean excludeEntityListeners = excludeSuperclassListeners(); while (currentDescriptor.isChildDescriptor()) { currentDescriptor = currentDescriptor.getInheritancePolicy().getParentDescriptor();
/** * INTERNAL: * Initialize the descriptor properties such as write lock and sequecning. */ protected void initializeProperties(AbstractSession session) throws DescriptorException { if (!isAggregateDescriptor()) { if (!isChildDescriptor()) { // Initialize the primary key fields List primaryKeyFields = (List)((ArrayList)getPrimaryKeyFields()).clone(); for (int index = 0; index < primaryKeyFields.size(); index++) { DatabaseField primaryKey = (DatabaseField)primaryKeyFields.get(index); initializePrimaryKey(primaryKey); } } // build sequence number field if (getSequenceNumberField() != null) { buildField(getSequenceNumberField()); } } // Set the local session name for the session broker. setSessionName(session.getName()); }
/** * Reset the identity map for only the instances of the class. * For inheritence the user must make sure that they only use the root class. */ public void initializeIdentityMap(Class theClass) throws TopLinkException { ClassDescriptor descriptor = getSession().getDescriptor(theClass); if (descriptor == null) { throw ValidationException.missingDescriptor(String.valueOf(theClass)); } if (descriptor.isChildDescriptor()) { throw ValidationException.childDescriptorsDoNotHaveIdentityMap(); } // Bug 3736313 - look up identity map by descriptor's java class Class javaClass = descriptor.getJavaClass(); // bug 3745484 - clear the cached identity map if we are clearing the associated identity map if (javaClass == lastAccessedIdentityMapClass) { clearLastAccessedIdentityMap(); } IdentityMap identityMap = buildNewIdentityMap(descriptor); getIdentityMaps().put(javaClass, identityMap); }
/** * INTERNAL: * Notify the event listeners. */ public void notifyListeners(DescriptorEvent event) { if (hasAnyListeners()) { for (int index = 0; index < getEventListeners().size(); index++) { DescriptorEventListener listener = (DescriptorEventListener)getEventListeners().get(index); notifyListener(listener, event); } } // Also must notify any inherited listeners. if (getDescriptor().isChildDescriptor()) { getDescriptor().getInheritancePolicy().getParentDescriptor().getEventManager().notifyListeners(event); } }
if (getDescriptor().isChildDescriptor()) { DescriptorEventManager parentEventManager = getDescriptor().getInheritancePolicy().getParentDescriptor().getEventManager();
/** * Hook together the inheritance policy tree. */ protected void preInitializeInheritancePolicy(AbstractSession session) throws DescriptorException { if (isChildDescriptor() && (requiresInitialization())) { if (getInheritancePolicy().getParentClass().equals(getJavaClass())) { throw DescriptorException.parentClassIsSelf(this); } ClassDescriptor parentDescriptor = session.getDescriptor(getInheritancePolicy().getParentClass()); parentDescriptor.getInheritancePolicy().addChildDescriptor(this); getInheritancePolicy().setParentDescriptor(parentDescriptor); parentDescriptor.preInitialize(session); } }
if (descriptor.isAggregateDescriptor() && descriptor.isChildDescriptor()) { descriptor.initializeAggregateInheritancePolicy(session);
public void removeLifecycle(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException { CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps(); EntityManager entityManager = (EntityManager) entityManagerFactory.createEntityManager(); Session session = entityManager.getServerSession(); entityManager.close(); Map descriptors = session.getDescriptors(); for (Object o : descriptors.values()) { ClassDescriptor classDescriptor = (ClassDescriptor) o; Class mappedClass = classDescriptor.getJavaClass(); // if we have a parent class that is mapped in JPA and in Compass, then don't add an event listner // since we will add it to the parent descriptor and it will notify this class as well if (classDescriptor.isChildDescriptor()) { Class parentClass = classDescriptor.getInheritancePolicy().getParentDescriptor().getJavaClass(); if (gps.hasMappingForEntityForMirror(parentClass, Cascade.ALL)) { classDescriptor.getEventManager().removeListener(dummyEventListener); continue; } } if (gps.hasMappingForEntityForMirror(mappedClass, Cascade.ALL)) { classDescriptor.getDescriptorEventManager().removeListener(eventListener); } } } }
/** * INTERNAL: * Verify that an aggregate descriptor's inheritance tree * is full of aggregate descriptors. */ public void checkInheritanceTreeAggregateSettings(AbstractSession session, AggregateMapping mapping) throws DescriptorException { if (!this.hasInheritance()) { return; } if (this.isChildDescriptor()) { Class parentClass = this.getInheritancePolicy().getParentClass(); if (parentClass == this.getJavaClass()) { throw DescriptorException.parentClassIsSelf(this); } // recurse up the inheritance tree to the root descriptor session.getDescriptor(parentClass).checkInheritanceTreeAggregateSettings(session, mapping); } else { // we have a root descriptor, now verify it and all its children, grandchildren, etc. this.checkInheritanceTreeAggregateSettingsForChildren(session, mapping); } }
public void injectLifecycle(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException { CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps(); if (eventListener == null) { eventListener = new TopLinkEssentialsEventListener(device); } EntityManager entityManager = (EntityManager) entityManagerFactory.createEntityManager(); Session session = entityManager.getServerSession(); entityManager.close(); Map descriptors = session.getDescriptors(); for (Object o : descriptors.values()) { ClassDescriptor classDescriptor = (ClassDescriptor) o; Class mappedClass = classDescriptor.getJavaClass(); // if we have a parent class that is mapped in JPA and in Compass, then don't add an event listner // since we will add it to the parent descriptor and it will notify this class as well if (classDescriptor.isChildDescriptor()) { Class parentClass = classDescriptor.getInheritancePolicy().getParentDescriptor().getJavaClass(); if (gps.hasMappingForEntityForMirror(parentClass, Cascade.ALL)) { classDescriptor.getEventManager().addListener(dummyEventListener); continue; } } if (gps.hasMappingForEntityForMirror(mappedClass, Cascade.ALL)) { classDescriptor.getDescriptorEventManager().addListener(eventListener); } } }
if (descriptor.isAggregateDescriptor() && descriptor.isChildDescriptor()) { descriptor.initializeAggregateInheritancePolicy(session);
/** * INTERNAL: * Validate that the descriptor's non-mapping attribute are defined correctly. */ protected void selfValidationBeforeInitialization(AbstractSession session) throws DescriptorException { if (isChildDescriptor()) { ClassDescriptor parentDescriptor = session.getDescriptor(getInheritancePolicy().getParentClass()); if (parentDescriptor == null) { session.getIntegrityChecker().handleError(DescriptorException.parentDescriptorNotSpecified(getInheritancePolicy().getParentClass().getName(), this)); } } else { if (getTables().isEmpty() && (!isAggregateDescriptor())) { session.getIntegrityChecker().handleError(DescriptorException.tableNotSpecified(this)); } } if (!isChildDescriptor() && !isAggregateDescriptor()) { if (getPrimaryKeyFieldNames().isEmpty()) { session.getIntegrityChecker().handleError(DescriptorException.primaryKeyFieldsNotSepcified(this)); } } if ((getIdentityMapClass() == ClassConstants.NoIdentityMap_Class) && (getQueryManager().getDoesExistQuery().shouldCheckCacheForDoesExist())) { session.getIntegrityChecker().handleError(DescriptorException.identityMapNotSpecified(this)); } if (((getSequenceNumberName() != null) && (getSequenceNumberField() == null)) || ((getSequenceNumberName() == null) && (getSequenceNumberField() != null))) { session.getIntegrityChecker().handleError(DescriptorException.sequenceNumberPropertyNotSpecified(this)); } }
if (isChildDescriptor()) { getInheritancePolicy().getParentDescriptor().initialize(session); if (getInheritancePolicy().getParentDescriptor().isIsolated()) { if (!isChildDescriptor()) { if (usesOptimisticLocking() && (!isChildDescriptor())) { getOptimisticLockingPolicy().initialize(session);
Class queryClass = builder.getQueryClass(); if ((queryClass == null) || descriptor.isChildDescriptor()) { builder.setQueryClass(descriptor.getJavaClass());
if (getSelectionCriteria() == null) { if(getDescriptor().isChildDescriptor()) { Vector collectionToInvalidate = identityMapAccessor.getAllFromIdentityMap(null, getReferenceClass(), getTranslationRow(), null); identityMapAccessor.invalidateObjects(collectionToInvalidate);
/** * INTERNAL: * For an aggregate mapping the reference descriptor is cloned. The cloned descriptor is then * assigned primary keys and table names before initialize. Once the cloned descriptor is initialized * it is assigned as reference descriptor in the aggregate mapping. This is a very specific * behaviour for aggregate mappings. The original descriptor is used only for creating clones and * after that the aggregate mapping never uses it. * Some initialization is done in postInitialize to ensure the target descriptor's references are initialized. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); ClassDescriptor clonedDescriptor = (ClassDescriptor)getReferenceDescriptor().clone(); if (clonedDescriptor.isChildDescriptor()) { ClassDescriptor parentDescriptor = session.getDescriptor(clonedDescriptor.getInheritancePolicy().getParentClass()); initializeParentInheritance(parentDescriptor, clonedDescriptor, session); } setReferenceDescriptor(clonedDescriptor); initializeReferenceDescriptor(clonedDescriptor); clonedDescriptor.preInitialize(session); clonedDescriptor.initialize(session); translateFields(clonedDescriptor, session); if (clonedDescriptor.hasInheritance() && clonedDescriptor.getInheritancePolicy().hasChildren()) { //clone child descriptors initializeChildInheritance(clonedDescriptor, session); } setFields(collectFields()); }
if (getDescriptor().isChildDescriptor()) { DescriptorQueryManager parentQueryManager = getDescriptor().getInheritancePolicy().getParentDescriptor().getQueryManager();