protected PersistentType buildSuperPersistentType() {
   PersistentType spt = this.buildSuperPersistentType_();
   if (spt == null) {
     return null;
   }
   // check for circular inheritance
   return IterableTools.contains(spt.getInheritanceHierarchy(), this) ? null : spt;
 }
 protected Iterable<ReplaceEdit> createMapKeyClassRenamePackageEdits(
     IPackageFragment originalPackage, String newName) {
   if (this.specifiedMapKeyClass != null) {
     PersistentType mapKeyType = this.getResolvedMapKeyType();
     if ((mapKeyType != null) && mapKeyType.isIn(originalPackage)) {
       return new SingleElementIterable<ReplaceEdit>(
           this.createMapKeyClassRenamePackageEdit(newName));
     }
   }
   return EmptyIterable.<ReplaceEdit>instance();
 }
 protected Iterable<ReplaceEdit> createMapKeyClassMoveTypeEdits(
     IType originalType, IPackageFragment newPackage) {
   if (this.specifiedMapKeyClass != null) {
     PersistentType mapKeyType = this.getResolvedMapKeyType();
     if ((mapKeyType != null) && mapKeyType.isFor(originalType.getFullyQualifiedName('.'))) {
       return new SingleElementIterable<ReplaceEdit>(
           this.createMapKeyClassRenamePackageEdit(newPackage.getElementName()));
     }
   }
   return EmptyIterable.<ReplaceEdit>instance();
 }
  public void execute(
      ICustomContext context, String newName, ICompilationUnit cu, PersistentType originalJPT) {
    IProject project = originalJPT.getJpaProject().getProject();
    final Diagram d = ModelIntegrationUtil.getDiagramByProject(project);
    if (d == null) return;
    final JPAEditorDiagramTypeProvider provider =
        ModelIntegrationUtil.getProviderByDiagram(d.getName());

    PictogramElement pe =
        provider.getFeatureProvider().getPictogramElementForBusinessObject(originalJPT);

    provider.getDiagramEditor().selectPictogramElements(new PictogramElement[] {null});

    final Semaphore s = new Semaphore(0);
    ShowBusy showBusy = new ShowBusy(s);
    JPASolver.ignoreEvents = true;
    Command renameEntityCommand = new RenameEntityClass(originalJPT, newName);
    try {
      getJpaProjectManager().execute(renameEntityCommand, SynchronousUiCommandContext.instance());
    } catch (InterruptedException e) {
      JPADiagramEditorPlugin.logError("Cannot delete attribute with name ", e); // $NON-NLS-1$
    }

    BusyIndicator.showWhile(Display.getCurrent(), showBusy);
    JPASolver.ignoreEvents = false;

    provider.getDiagramEditor().setPictogramElementForSelection(pe);
  }
 protected TypeMapping getResolvedMapKeyTypeMapping() {
   PersistentType resolvedMapKeyType = this.getResolvedMapKeyType();
   return (resolvedMapKeyType == null) ? null : resolvedMapKeyType.getMapping();
 }
    private void exec() {
      try {
        synchronized (jptsToUpdate) {
          Iterator<String> itr = jptsToUpdate.iterator();
          if (itr.hasNext()) {
            String jptName = itr.next();
            PersistentType jpt = (PersistentType) featureProvider.getBusinessObjectForKey(jptName);
            try {
              JpaArtifactFactory.instance().remakeRelations(featureProvider, null, jpt);
              jptsToUpdate.remove(jptName);
            } catch (RuntimeException e) {
            }
          }
        }
        Collection<Object> vals = solver.getVisualizedObjects();
        Iterator<Object> it = vals.iterator();
        while (it.hasNext()) {
          Object o = it.next();
          if (o instanceof PersistentType) {
            PersistentType jpt = (PersistentType) o;
            final ContainerShape entShape =
                (ContainerShape) featureProvider.getPictogramElementForBusinessObject(o);
            if (entShape == null) continue;
            PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt);
            PersistentType pt = pu.getPersistentType(jpt.getName());

            if ((pt == null) || !JpaArtifactFactory.instance().isAnyKindPersistentType(jpt)) {

              JpaArtifactFactory.instance().forceSaveEntityClass(jpt, featureProvider);

              if (jpt.getMapping() == null || (jpt.getMapping() instanceof JavaNullTypeMapping)) {
                if (!JpaPreferences.getDiscoverAnnotatedClasses(jpt.getJpaProject().getProject())) {
                  JPAEditorUtil.createUnregisterEntityFromXMLJob(
                      jpt.getJpaProject(), jpt.getName());
                }
              }

              RemoveContext ctx = new RemoveContext(entShape);
              RemoveAndSaveEntityFeature ft = new RemoveAndSaveEntityFeature(featureProvider);
              ft.remove(ctx);
              break;
            }
          }
        }
        synchronized (attribsToUpdate) {
          Set<String> atSet = attribsToUpdate.keySet();
          Iterator<String> iter = atSet.iterator();
          while (iter.hasNext()) {
            String jptAtMB = iter.next();
            String[] jptAndAttrib = jptAtMB.split(SEPARATOR);
            PersistenceUnit pu = attribsToUpdate.get(jptAtMB);
            String entityName = jptAndAttrib[0];
            String attribName = jptAndAttrib[1];
            String mappedBy = jptAndAttrib[2];
            String oldMappedBy = jptAndAttrib[3];
            PersistentType jpt = pu.getPersistentType(entityName);
            if (jpt != null) {
              PersistentAttribute jpa = jpt.getAttributeNamed(attribName);
              if (jpa != null) {
                AttributeMapping mapping = JpaArtifactFactory.instance().getAttributeMapping(jpa);
                if (mapping instanceof RelationshipMapping) {
                  RelationshipMapping relationshipMapping = (RelationshipMapping) mapping;
                  MappedByRelationship ownableRef =
                      (MappedByRelationship) relationshipMapping.getRelationship();
                  SpecifiedMappedByRelationshipStrategy mappedByStrategy =
                      ownableRef.getMappedByStrategy();
                  String mappedByAttr = mappedByStrategy.getMappedByAttribute();

                  String[] mappedByAttrs =
                      mappedByAttr.split(JPAEditorConstants.MAPPED_BY_ATTRIBUTE_SPLIT_SEPARATOR);
                  if (mappedByAttrs.length > 1) {
                    if (mappedByAttrs[0].equals(oldMappedBy)) {
                      mappedByAttr =
                          mappedBy
                              + JPAEditorConstants.MAPPED_BY_ATTRIBUTE_SEPARATOR
                              + mappedByAttrs[1];
                    } else if (mappedByAttrs[1].equals(oldMappedBy)) {
                      mappedByAttr =
                          mappedByAttrs[0]
                              + JPAEditorConstants.MAPPED_BY_ATTRIBUTE_SEPARATOR
                              + mappedBy;
                    }
                  } else {
                    mappedByAttr = mappedBy;
                  }
                  mappedByStrategy.setMappedByAttribute(mappedByAttr);
                  attribsToUpdate.remove(jptAtMB);
                }
              }
            }
          }
        }
      } catch (Exception e) {
        // ignore
      }
    }