private Map.Entry<OIdentifiable, Integer> nextChangedNotRemovedSBTreeEntry(
      Iterator<Map.Entry<OIdentifiable, Integer>> iterator) {
    while (iterator.hasNext()) {
      final Map.Entry<OIdentifiable, Integer> entry = iterator.next();
      final Change change = changes.get(entry.getKey());
      if (change == null) return entry;

      final int newValue = change.applyTo(entry.getValue());

      if (newValue > 0)
        return new Map.Entry<OIdentifiable, Integer>() {
          @Override
          public OIdentifiable getKey() {
            return entry.getKey();
          }

          @Override
          public Integer getValue() {
            return newValue;
          }

          @Override
          public Integer setValue(Integer value) {
            throw new UnsupportedOperationException();
          }
        };
    }

    return null;
  }
  public void add(final OIdentifiable identifiable) {
    if (identifiable == null)
      throw new NullPointerException("Impossible to add a null identifiable in a ridbag");
    if (identifiable.getIdentity().isValid()) {
      Change counter = changes.get(identifiable);
      if (counter == null) changes.put(identifiable, new DiffChange(1));
      else {
        if (counter.isUndefined()) {
          counter = getAbsoluteValue(identifiable);
          changes.put(identifiable, counter);
        }
        counter.increment();
      }
    } else {
      final OModifiableInteger counter = newEntries.get(identifiable);
      if (counter == null) newEntries.put(identifiable, new OModifiableInteger(1));
      else counter.increment();
    }

    if (size >= 0) size++;

    if (this.owner != null) ORecordInternal.track(this.owner, identifiable);

    if (updateOwner)
      fireCollectionChangedEvent(
          new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(
              OMultiValueChangeEvent.OChangeType.ADD, identifiable, identifiable, null, false));
  }
Example #3
0
  /*
   * Generates rollback statements from the inverse changes returned by createInverses().
   * Throws RollbackImpossibleException if the changes created by createInverses() is not supported for the passed database.
   *
   */
  private SqlStatement[] generateRollbackStatementsFromInverse(Database database)
      throws RollbackImpossibleException {
    Change[] inverses = createInverses();
    if (inverses == null) {
      throw new RollbackImpossibleException("No inverse to " + getClass().getName() + " created");
    }

    List<SqlStatement> statements = new ArrayList<SqlStatement>();

    try {
      for (Change inverse : inverses) {
        if (!inverse.supports(database)) {
          throw new RollbackImpossibleException(
              ChangeFactory.getInstance().getChangeMetaData(inverse).getName()
                  + " is not supported on "
                  + database.getShortName());
        }
        statements.addAll(Arrays.asList(inverse.generateStatements(database)));
      }
    } catch (LiquibaseException e) {
      throw new RollbackImpossibleException(e);
    }

    return statements.toArray(new SqlStatement[statements.size()]);
  }
  /** @param oper Data value for comparison. */
  @SuppressWarnings({"rawtypes", "unchecked"})
  public <V extends Number> void testNodeProcessingSchema(Change<V> oper) {
    CollectorTestSink changeSink = new CollectorTestSink();
    CollectorTestSink percentSink = new CollectorTestSink();

    oper.change.setSink(changeSink);
    oper.percent.setSink(percentSink);

    oper.beginWindow(0);
    oper.base.process(oper.getValue(10));
    oper.data.process(oper.getValue(5));
    oper.data.process(oper.getValue(15));
    oper.data.process(oper.getValue(20));
    oper.endWindow();

    Assert.assertEquals("number emitted tuples", 3, changeSink.collectedTuples.size());
    Assert.assertEquals("number emitted tuples", 3, percentSink.collectedTuples.size());

    log.debug("\nLogging tuples");
    for (Object o : changeSink.collectedTuples) {
      log.debug(String.format("change %s", o));
    }
    for (Object o : percentSink.collectedTuples) {
      log.debug(String.format("percent change %s", o));
    }
  }
 protected static boolean canShowDiff(Change[] changes) {
   if (changes == null || changes.length == 0) return false;
   for (Change change : changes) {
     if (!ChangesUtil.getFilePath(change).isDirectory() || change.hasOtherLayers()) return true;
   }
   return false;
 }
  public void remove(OIdentifiable identifiable) {
    if (removeFromNewEntries(identifiable)) {
      if (size >= 0) size--;
    } else {
      final Change counter = changes.get(identifiable);
      if (counter == null) {
        // Not persistent keys can only be in changes or newEntries
        if (identifiable.getIdentity().isPersistent()) {
          changes.put(identifiable, new DiffChange(-1));
          size = -1;
        } else
          // Return immediately to prevent firing of event
          return;
      } else {
        counter.decrement();

        if (size >= 0)
          if (counter.isUndefined()) size = -1;
          else size--;
      }
    }

    if (this.owner != null) ORecordInternal.unTrack(this.owner, identifiable);

    if (updateOwner)
      fireCollectionChangedEvent(
          new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(
              OMultiValueChangeEvent.OChangeType.REMOVE, identifiable, null, identifiable, false));
  }
 public void processChangeLists(final List<LocalChangeList> lists) {
   final ProjectLevelVcsManager plVcsManager =
       ProjectLevelVcsManager.getInstanceChecked(myProject);
   plVcsManager.startBackgroundVcsOperation();
   try {
     final SVNChangelistClient client = createChangelistClient();
     for (LocalChangeList list : lists) {
       if (!list.isDefault()) {
         final Collection<Change> changes = list.getChanges();
         for (Change change : changes) {
           correctListForRevision(
               plVcsManager, change.getBeforeRevision(), client, list.getName());
           correctListForRevision(plVcsManager, change.getAfterRevision(), client, list.getName());
         }
       }
     }
   } finally {
     final Application appManager = ApplicationManager.getApplication();
     if (appManager.isDispatchThread()) {
       appManager.executeOnPooledThread(
           new Runnable() {
             @Override
             public void run() {
               plVcsManager.stopBackgroundVcsOperation();
             }
           });
     } else {
       plVcsManager.stopBackgroundVcsOperation();
     }
   }
 }
Example #8
0
  public void redo() {

    // add the endChange marker to redo if we can undo
    if (!redoStack.empty()) {
      undoStack.push(endChange);
      undoNotifyStack.push(endChange);
    }

    // keep undoing until the undo stack is empty, or we hit a stop action
    while (!redoStack.empty()) {

      // get the current change
      Change currentChange = redoStack.pop();

      // if it is a stop action, break the loop
      if (currentChange == endChange) break;
      currentChange.redo();

      // add the change to the redo stack
      undoStack.push(currentChange);
    }

    // find everyone to notify
    while (!redoNotifyStack.empty()) {
      ChangeNotification currentNotification = redoNotifyStack.pop();
      if (currentNotification == endChange) break;
      currentNotification.notifyChange();
      undoNotifyStack.push(currentNotification);
    }
  }
 /**
  * Adds the given change to the list of children. The change to be added can be <code>null</code>.
  * Adding a "null" change does nothing.
  *
  * @param change the change to add
  */
 public void add(Change change) {
   if (change != null) {
     Assert.isTrue(change.getParent() == null);
     fChanges.add(change);
     change.setParent(this);
   }
 }
 @Override
 public void run(ContinuationContext context) {
   final List<Change> changesForPatch;
   try {
     final List<CommittedChangeList> lst = loadSvnChangeListsForPatch(myDescription);
     changesForPatch = CommittedChangesTreeBrowser.collectChanges(lst, true);
     for (Change change : changesForPatch) {
       if (change.getBeforeRevision() != null) {
         preloadRevisionContents(change.getBeforeRevision());
       }
       if (change.getAfterRevision() != null) {
         preloadRevisionContents(change.getAfterRevision());
       }
     }
   } catch (VcsException e) {
     context.handleException(e, true);
     return;
   }
   final List<Change> binaryChanges = filterOutBinary(changesForPatch);
   if (binaryChanges != null && !binaryChanges.isEmpty()) {
     myTheirsBinaryChanges.addAll(binaryChanges);
   }
   if (!changesForPatch.isEmpty()) {
     myTheirsChanges.addAll(changesForPatch);
   }
 }
 /**
  * Sort changes by roots
  *
  * @param changes a change list
  * @param exceptions exceptions to collect
  * @return sorted changes
  */
 private static Map<VirtualFile, Collection<Change>> sortChangesByGitRoot(
     @NotNull List<Change> changes, List<VcsException> exceptions) {
   Map<VirtualFile, Collection<Change>> result = new HashMap<VirtualFile, Collection<Change>>();
   for (Change change : changes) {
     final ContentRevision afterRevision = change.getAfterRevision();
     final ContentRevision beforeRevision = change.getBeforeRevision();
     // nothing-to-nothing change cannot happen.
     assert beforeRevision != null || afterRevision != null;
     // note that any path will work, because changes could happen within single vcs root
     final FilePath filePath =
         afterRevision != null ? afterRevision.getFile() : beforeRevision.getFile();
     final VirtualFile vcsRoot;
     try {
       // the parent paths for calculating roots in order to account for submodules that contribute
       // to the parent change. The path "." is never is valid change, so there should be no
       // problem
       // with it.
       vcsRoot = GitUtil.getGitRoot(filePath.getParentPath());
     } catch (VcsException e) {
       exceptions.add(e);
       continue;
     }
     Collection<Change> changeList = result.get(vcsRoot);
     if (changeList == null) {
       changeList = new ArrayList<Change>();
       result.put(vcsRoot, changeList);
     }
     changeList.add(change);
   }
   return result;
 }
  public static boolean isBinaryChange(Change change) {
    if (change.hasOtherLayers()) return false; // +-
    final ContentRevision bRev = change.getBeforeRevision();
    final ContentRevision aRev = change.getAfterRevision();

    return (aRev == null || aRev instanceof BinaryContentRevision)
        && (bRev == null || bRev instanceof BinaryContentRevision);
  }
 private static String debugRealListContent(final LocalChangeList list) {
   final StringBuilder sb = new StringBuilder(list.getName() + ": ");
   final Collection<Change> changeCollection = list.getChanges();
   for (Change change : changeCollection) {
     sb.append(change.toString()).append(' ');
   }
   return sb.toString();
 }
Example #14
0
 /**
  * Gets the single instance of Change.
  *
  * @param value the value
  * @return single instance of Change
  */
 public static Change getInstance(String value) {
   for (Change erTyp : Change.values()) {
     if (erTyp.getValue().equals(value)) {
       return erTyp;
     }
   }
   return null;
 }
 /**
  * {@inheritDoc}
  *
  * @since 3.2
  */
 public ChangeDescriptor getDescriptor() {
   for (final Iterator iterator = fChanges.iterator(); iterator.hasNext(); ) {
     final Change change = (Change) iterator.next();
     final ChangeDescriptor descriptor = change.getDescriptor();
     if (descriptor != null) return descriptor;
   }
   return null;
 }
 /**
  * {@inheritDoc}
  *
  * <p>The composite change sends <code>initializeValidationData</code> to all its children.
  *
  * <p>Client are allowed to extend this method.
  */
 public void initializeValidationData(IProgressMonitor pm) {
   pm.beginTask("", fChanges.size()); // $NON-NLS-1$
   for (Iterator iter = fChanges.iterator(); iter.hasNext(); ) {
     Change change = (Change) iter.next();
     change.initializeValidationData(new SubProgressMonitor(pm, 1));
     pm.worked(1);
   }
 }
 public void remove(@NotNull Change change) {
   if (change.getType().isApplied()) {
     LOG.assertTrue(myAppliedChanges.remove(change), change);
   } else {
     LOG.assertTrue(myChanges.remove(change), change);
   }
   change.onRemovedFromList();
   fireOnChangeRemoved();
 }
Example #18
0
 public static boolean canCreateRequest(Change change) {
   if (ChangesUtil.isTextConflictingChange(change)
       || change.isTreeConflict()
       || change.isPhantom()) return false;
   if (ShowDiffAction.isBinaryChange(change)) return false;
   final FilePath filePath = ChangesUtil.getFilePath(change);
   if (filePath.isDirectory()) return false;
   return true;
 }
 private void correctScopeForMoves(
     final VcsModifiableDirtyScope scope, final Collection<Change> changes) {
   if (scope == null) return;
   for (Change change : changes) {
     if (change.isMoved() || change.isRenamed()) {
       scope.addDirtyFile(change.getBeforeRevision().getFile());
       scope.addDirtyFile(change.getAfterRevision().getFile());
     }
   }
 }
 private boolean containAdditions(final List<Change> changes) {
   boolean addFound = false;
   for (Change change : changes) {
     if (change.getBeforeRevision() == null || change.isMoved() || change.isRenamed()) {
       addFound = true;
       break;
     }
   }
   return addFound;
 }
  /**
   * This method test when there is a deletion change with primary key.
   *
   * @throws SQLException
   */
  @Test
  @NeedReload
  public void test_when_there_is_deletion_change_with_primary_key() throws SQLException {
    Changes changes =
        new Changes(new Request(dataSource, "select * from interpretation").setPksName("id"));
    changes.setStartPointNow();
    update("delete interpretation where id = 3");
    changes.setEndPointNow();

    assertThat(changes.getChangesList()).hasSize(1);
    Change change = changes.getChangesList().get(0);
    assertThat(change.getDataName()).isEqualTo("select * from interpretation");
    assertThat(change.getChangeType()).isEqualTo(ChangeType.DELETION);
    assertThat(change.getColumnsNameList())
        .containsExactly("ID", "ID_MOVIE", "ID_ACTOR", "CHARACTER");
    assertThat(change.getRowAtStartPoint().getValuesList().get(0).getValue())
        .isEqualTo(new BigDecimal(3));
    assertThat(change.getRowAtStartPoint().getValuesList().get(1).getValue())
        .isEqualTo(new BigDecimal(3));
    assertThat(change.getRowAtStartPoint().getValuesList().get(2).getValue())
        .isEqualTo(new BigDecimal(1));
    assertThat(change.getRowAtStartPoint().getValuesList().get(3).getValue())
        .isEqualTo("Dr Grace Augustine");
    assertThat(change.getRowAtEndPoint()).isNull();
  }
  /**
   * This method test when there is a creation change with primary key.
   *
   * @throws SQLException
   */
  @Test
  @NeedReload
  public void test_when_there_is_creation_change_with_primary_key() throws SQLException {
    Changes changes = new Changes(new Request(dataSource, "select * from movie").setPksName("id"));
    changes.setStartPointNow();
    update(
        "insert into movie values(4, 'Ghostbusters', 1984, '16319617-AE95-4087-9264-D3D21BF611B6')");
    changes.setEndPointNow();

    assertThat(changes.getChangesList()).hasSize(1);
    Change change = changes.getChangesList().get(0);
    assertThat(change.getDataName()).isEqualTo("select * from movie");
    assertThat(change.getChangeType()).isEqualTo(ChangeType.CREATION);
    assertThat(change.getColumnsNameList()).containsExactly("ID", "TITLE", "YEAR", "MOVIE_IMDB");
    assertThat(change.getRowAtStartPoint()).isNull();

    assertThat(change.getRowAtEndPoint().getValuesList().get(0).getValue())
        .isEqualTo(new BigDecimal(4));
    assertThat(change.getRowAtEndPoint().getValuesList().get(1).getValue())
        .isEqualTo("Ghostbusters");
    assertThat(change.getRowAtEndPoint().getValuesList().get(2).getValue())
        .isEqualTo(new BigDecimal(1984));
    assertThat(change.getRowAtEndPoint().getValuesList().get(3).getValue())
        .isEqualTo(UUID.fromString("16319617-AE95-4087-9264-D3D21BF611B6"));
  }
  public ShelvedChangeList shelveChanges(
      final Collection<Change> changes, final String commitMessage, final boolean rollback)
      throws IOException, VcsException {
    final List<Change> textChanges = new ArrayList<Change>();
    final List<ShelvedBinaryFile> binaryFiles = new ArrayList<ShelvedBinaryFile>();
    for (Change change : changes) {
      if (ChangesUtil.getFilePath(change).isDirectory()) {
        continue;
      }
      if (change.getBeforeRevision() instanceof BinaryContentRevision
          || change.getAfterRevision() instanceof BinaryContentRevision) {
        binaryFiles.add(shelveBinaryFile(change));
      } else {
        textChanges.add(change);
      }
    }

    final ShelvedChangeList changeList;
    try {
      File patchPath = getPatchPath(commitMessage);
      ProgressManager.checkCanceled();
      final List<FilePatch> patches =
          IdeaTextPatchBuilder.buildPatch(
              myProject, textChanges, myProject.getBaseDir().getPresentableUrl(), false);
      ProgressManager.checkCanceled();

      CommitContext commitContext = new CommitContext();
      baseRevisionsOfDvcsIntoContext(textChanges, commitContext);
      myFileProcessor.savePathFile(
          new CompoundShelfFileProcessor.ContentProvider() {
            public void writeContentTo(final Writer writer, CommitContext commitContext)
                throws IOException {
              UnifiedDiffWriter.write(myProject, patches, writer, "\n", commitContext);
            }
          },
          patchPath,
          commitContext);

      changeList =
          new ShelvedChangeList(
              patchPath.toString(), commitMessage.replace('\n', ' '), binaryFiles);
      myShelvedChangeLists.add(changeList);
      ProgressManager.checkCanceled();

      if (rollback) {
        new RollbackWorker(myProject, false)
            .doRollback(changes, true, null, VcsBundle.message("shelve.changes.action"));
      }
    } finally {
      notifyStateChanged();
    }

    return changeList;
  }
 /** {@inheritDoc} */
 public Object[] getAffectedObjects() {
   if (fChanges.size() == 0) return new Object[0];
   List result = new ArrayList();
   for (Iterator iter = fChanges.iterator(); iter.hasNext(); ) {
     Change change = (Change) iter.next();
     Object[] affectedObjects = change.getAffectedObjects();
     if (affectedObjects == null) return null;
     result.addAll(Arrays.asList(affectedObjects));
   }
   return result.toArray();
 }
 public static BeforeAfter<DiffContent> createBinaryDiffContents(
     final Project project, final Change change) throws VcsException {
   final FilePath filePath = ChangesUtil.getFilePath(change);
   try {
     return new BeforeAfter<DiffContent>(
         createBinaryFileContent(project, change.getBeforeRevision(), filePath.getName()),
         createBinaryFileContent(project, change.getAfterRevision(), filePath.getName()));
   } catch (IOException e) {
     throw new VcsException(e);
   }
 }
 /**
  * {@inheritDoc}
  *
  * <p>The composite change sends <code>isValid</code> to all its children until the first one
  * returns a status with a severity of <code>FATAL
  * </code>. If one of the children throws an exception the remaining children will not receive the
  * <code>isValid</code> call.
  *
  * <p>Client are allowed to extend this method.
  */
 public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
   RefactoringStatus result = new RefactoringStatus();
   pm.beginTask("", fChanges.size()); // $NON-NLS-1$
   for (Iterator iter = fChanges.iterator(); iter.hasNext() && !result.hasFatalError(); ) {
     Change change = (Change) iter.next();
     if (change.isEnabled()) result.merge(change.isValid(new SubProgressMonitor(pm, 1)));
     else pm.worked(1);
     if (pm.isCanceled()) throw new OperationCanceledException();
   }
   pm.done();
   return result;
 }
Example #27
0
        @Override
        public void onChanged(Change<? extends String> c) {
          while (c.next()) {
            if (c.wasRemoved()) {
              getStyleClass().removeAll(c.getRemoved());
            }

            if (c.wasAdded()) {
              getStyleClass().addAll(c.getAddedSubList());
            }
          }
        }
 private static SimpleDiffRequest createBinaryDiffRequest(
     final Project project, final Change change) throws VcsException {
   final FilePath filePath = ChangesUtil.getFilePath(change);
   final SimpleDiffRequest request = new SimpleDiffRequest(project, filePath.getPath());
   try {
     request.setContents(
         createBinaryFileContent(project, change.getBeforeRevision(), filePath.getName()),
         createBinaryFileContent(project, change.getAfterRevision(), filePath.getName()));
     return request;
   } catch (IOException e) {
     throw new VcsException(e);
   }
 }
Example #29
0
 private void setPkgs() {
   final Change event = fRTaskEvent;
   if (event.fNewPkgs instanceof FullRPkgSet) {
     fPkgsExt = (FullRPkgSet) event.fNewPkgs;
     fPkgsLight = null;
   } else if (event.fNewPkgs instanceof RPkgSet) {
     fPkgsExt = null;
     fPkgsLight = (RPkgSet) event.fNewPkgs;
   }
   if (event.fInstalledPkgs != null) {
     event.fPkgs |= INSTALLED;
   }
 }
 private File[] getSelectedIoFiles() {
   final List<Change> changes = getSelectedChanges();
   final List<File> files = new ArrayList<>();
   for (Change change : changes) {
     final ContentRevision afterRevision = change.getAfterRevision();
     if (afterRevision != null) {
       final FilePath file = afterRevision.getFile();
       final File ioFile = file.getIOFile();
       files.add(ioFile);
     }
   }
   return files.toArray(new File[files.size()]);
 }