/** * Handles the entities that have been orphaned. * * @param entityManager the entity manager * @since 2.0.0 */ public void handleOrphans(EntityManagerImpl entityManager) { ManagedInstance.LOG.debug("Inspecting orphans for instance {0}", this); for (int i = 0; i < this.collectionsChanged.size(); i++) { final PluralMappingEx<?, ?, ?> collection = this.collectionsChanged.get(i); if (collection.isAssociation()) { ((PluralAssociationMappingImpl<?, ?, ?>) collection).removeOrphans(entityManager, this); } } }
/** * Processes the associations. * * @since 2.0.0 */ public void processJoinedMappings() { ManagedInstance.LOG.debug("Post processing associations for instance {0}", this); final HashSet<String> _joinsLoaded = this.joinsLoaded; for (final PluralMappingEx<?, ?, ?> mapping : this.type.getMappingsPlural()) { final HashSet<String> joinsLoaded2 = _joinsLoaded; if (!joinsLoaded2.contains(mapping.getPath())) { if (mapping.isEager()) { mapping.load(this); } else { mapping.setLazy(this); } } } final X _instance = this.instance; final EntityManagerImpl entityManager = this.session.getEntityManager(); for (final SingularAssociationMappingImpl<?, ?> mapping : this.type.getAssociationsSingular()) { if (mapping.isEager()) { if (!_joinsLoaded.contains(mapping.getPath())) { mapping.initialize(this); } else { final Object associate = mapping.get(_instance); if (associate instanceof EnhancedInstance) { final EnhancedInstance enhancedInstance = (EnhancedInstance) associate; if (!enhancedInstance.__enhanced__$$__isInitialized()) { final ManagedInstance<?> associateManagedInstance = enhancedInstance.__enhanced__$$__getManagedInstance(); entityManager.find( associateManagedInstance.getType().getJavaType(), associateManagedInstance.getId().getId()); } } } } } }
/** * Enhances the collections of the managed instance. * * @since 2.0.0 */ public void enhanceCollections() { for (final PluralMappingEx<?, ?, ?> collection : this.type.getMappingsPlural()) { collection.enhance(this); } }
/** * Sorts the list associations. * * @since 2.0.0 */ public void sortLists() { for (final PluralMappingEx<?, ?, ?> mapping : this.type.getMappingsPluralSorted()) { mapping.sortList(this.instance); } }