public LocalRepoTransactionImpl(
     final LocalRepoManagerImpl localRepoManager, final boolean write) {
   this.localRepoManager = AssertUtil.assertNotNull("localRepoManager", localRepoManager);
   this.persistenceManagerFactory =
       AssertUtil.assertNotNull(
           "localRepoManager.persistenceManagerFactory",
           localRepoManager.getPersistenceManagerFactory());
   this.lock = localRepoManager.getLock();
   this.write = write;
   begin();
 }
  protected void createAndPersistPreliminaryCollision(
      final LocalRepoManager localRepoManager,
      final File file,
      String localPath,
      Uid cryptoRepoFileId) {
    assertNotNull("localRepoManager", localRepoManager);
    if (localPath == null) assertNotNull("localPath/file", file);

    logger.debug(
        "createAndPersistPreliminaryCollision: localRoot='{}' localRepositoryId={} file='{}' localPath='{}' cryptoRepoFileId={}",
        localRepoManager.getLocalRoot(),
        getRepositoryId(),
        (file == null ? "" : file.getAbsolutePath()),
        (localPath == null ? "" : localPath),
        cryptoRepoFileId);

    try (final LocalRepoTransaction tx = localRepoManager.beginWriteTransaction(); ) {
      if (localPath == null)
        localPath =
            '/'
                + localRepoManager
                    .getLocalRoot()
                    .relativize(file)
                    .replace(FILE_SEPARATOR_CHAR, '/');

      final PreliminaryCollisionDao pcDao = tx.getDao(PreliminaryCollisionDao.class);

      PreliminaryCollision preliminaryCollision = pcDao.getPreliminaryCollision(localPath);
      if (preliminaryCollision == null) {
        preliminaryCollision = new PreliminaryCollision();
        preliminaryCollision.setPath(localPath);
        preliminaryCollision = pcDao.makePersistent(preliminaryCollision);
      }

      final CryptoRepoFileDao crfDao = tx.getDao(CryptoRepoFileDao.class);
      if (cryptoRepoFileId != null) {
        CryptoRepoFile cryptoRepoFile = crfDao.getCryptoRepoFileOrFail(cryptoRepoFileId);
        preliminaryCollision.setCryptoRepoFile(cryptoRepoFile);
      } else if (file != null) {
        final RepoFileDao rfDao = tx.getDao(RepoFileDao.class);
        final RepoFile repoFile = rfDao.getRepoFile(localRepoManager.getLocalRoot(), file);
        if (repoFile != null) {
          final CryptoRepoFile cryptoRepoFile = crfDao.getCryptoRepoFileOrFail(repoFile);
          preliminaryCollision.setCryptoRepoFile(cryptoRepoFile);
        }
      }

      tx.commit();
    } catch (IOException x) {
      throw new RuntimeException(x);
    }
  }
  @Override
  public <D> D getDao(final Class<D> daoClass) {
    assertNotNull("daoClass", daoClass);

    @SuppressWarnings("unchecked")
    D dao = (D) daoClass2Dao.get(daoClass);

    if (dao == null) {
      final PersistenceManager pm = getPersistenceManager();
      try {
        dao = daoClass.newInstance();
      } catch (final InstantiationException e) {
        throw new RuntimeException(e);
      } catch (final IllegalAccessException e) {
        throw new RuntimeException(e);
      }

      if (!(dao instanceof Dao))
        throw new IllegalStateException(
            String.format("dao class %s does not extend Dao!", daoClass.getName()));

      ((Dao<?, ?>) dao).setPersistenceManager(pm);
      ((Dao<?, ?>) dao).setDaoProvider(this);

      daoClass2Dao.put(daoClass, dao);
    }
    return dao;
  }
 public synchronized void backupParentFileLastModified(final File parentFile) {
   AssertUtil.assertNotNull("parentFile", parentFile);
   ParentFileEntry parentFileEntry = parentFile2ParentFileEntry.get(parentFile);
   if (parentFileEntry == null) {
     parentFileEntry = new ParentFileEntry(parentFile);
     parentFile2ParentFileEntry.put(parentFile, parentFileEntry);
   }
   ++parentFileEntry.refCount;
 }
示例#5
0
  public void registerWizardPage(final WizardPage wizardPage) {
    assertNotNull("wizardPage", wizardPage);

    if (wizardPage.getWizard() != null) wizardPage.setWizard(this);

    if (knownPages.containsKey(wizardPage)) return;

    wizardPage.completeProperty().addListener(updateCanFinishInvalidationListener);
    knownPages.put(wizardPage, null);
    wizardPage.setVisible(false);
    getChildren().add(0, wizardPage);
  }
  private void putPaddingMetaData(String path, SsNormalFileDto fromNormalFileDto) {
    path = prefixPath(path); // does a null-check
    assertNotNull("fromNormalFileDto", fromNormalFileDto);

    final File file = getFile(path);
    try (final LocalRepoTransaction transaction = getLocalRepoManager().beginWriteTransaction(); ) {
      final RepoFile repoFile =
          transaction
              .getDao(RepoFileDao.class)
              .getRepoFile(getLocalRepoManager().getLocalRoot(), file);
      if (!(repoFile instanceof NormalFile)) {
        throw new IllegalStateException(
            String.format(
                "RepoFile is not an instance of NormalFile! repoFile=%s file=%s", repoFile, file));
      }

      final SsNormalFile normalFile = (SsNormalFile) repoFile;
      normalFile.setLengthWithPadding(fromNormalFileDto.getLengthWithPadding());

      final Map<Long, SsFileChunk> offset2FileChunk =
          new HashMap<>(normalFile.getFileChunks().size());
      for (FileChunk fc : normalFile.getFileChunks())
        offset2FileChunk.put(fc.getOffset(), (SsFileChunk) fc);

      for (final FileChunkDto fcDto : fromNormalFileDto.getFileChunkDtos()) {
        SsFileChunkDto fileChunkDto = (SsFileChunkDto) fcDto;

        // If there is at least 1 byte of real data, the SHA1 (as well as the entire FileChunk
        // object)
        // is created from it and we don't need to store the FileChunk we received from the other
        // side.
        if (fileChunkDto.getLength() > 0) continue;

        boolean isNew = false;
        SsFileChunk fileChunk = offset2FileChunk.get(fileChunkDto.getOffset());
        if (fileChunk == null) {
          isNew = true;
          fileChunk = (SsFileChunk) createObject(FileChunk.class);
          fileChunk.setNormalFile(normalFile);
          fileChunk.setOffset(fileChunkDto.getOffset());
        }
        fileChunk.makeWritable();
        fileChunk.setLength(fileChunkDto.getLength());
        fileChunk.setLengthWithPadding(fileChunkDto.getLengthWithPadding());
        fileChunk.setSha1(fileChunkDto.getSha1());
        fileChunk.makeReadOnly();

        if (isNew) normalFile.getFileChunks().add(fileChunk);
      }

      transaction.commit();
    }
  }
  @Override
  protected RepoFile syncRepoFile(final LocalRepoTransaction transaction, final File file) {
    assertNotNull("transaction", transaction);
    assertNotNull("file", file);

    final File localRoot = getLocalRepoManager().getLocalRoot();
    final RepoFileDao rfDao = transaction.getDao(RepoFileDao.class);
    RepoFile repoFile = rfDao.getRepoFile(localRoot, file);
    // If the type changed, we must delete the RepoFile here before invoking the super-method,
    // because this would otherwise cause an invocation of Cryptree.preDelete(...) causing
    // the actual file to be deleted.

    if (repoFile != null
        && !LocalRepoSync.create(transaction).isRepoFileTypeCorrect(repoFile, file)) {
      rfDao.deletePersistent(repoFile);
      repoFile = null;
      transaction.flush();
    }
    repoFile = super.syncRepoFile(transaction, file);
    return repoFile;
  }
  public synchronized void restoreParentFileLastModified(final File parentFile) {
    AssertUtil.assertNotNull("parentFile", parentFile);
    final ParentFileEntry parentFileEntry = parentFile2ParentFileEntry.get(parentFile);
    if (parentFileEntry == null)
      throw new IllegalStateException(
          "parentFileEntry == null :: less invocations of restore... than of backup...!!! :: parentFile="
              + parentFile);

    if (--parentFileEntry.refCount == 0) {
      if (parentFileEntry.lastModified != Long.MIN_VALUE)
        parentFileEntry.parentFile.setLastModified(parentFileEntry.lastModified);

      parentFile2ParentFileEntry.remove(parentFile);
    }
  }
示例#9
0
  public void setFinishingPage(final Parent finishingPage) {
    assertNotNull("finishingPage", finishingPage);
    PlatformUtil.assertFxApplicationThread();

    if (!(finishingPage instanceof FinishingPage))
      throw new IllegalArgumentException("finishingPage is not an instance of FinishingPage!");

    if (stateProperty.get() == WizardState.FINISHING) hideFinishingPage(); // hide the old one.

    getChildren().remove(this.finishingPage);
    this.finishingPage = finishingPage;
    getChildren().add(0, finishingPage);

    if (stateProperty.get() == WizardState.FINISHING)
      showFinishingPage(); // immediately show the new one.
  }
示例#10
0
  protected void navTo(final WizardPage wizardPage, boolean addToHistory) {
    assertNotNull("wizardPage", wizardPage);
    PlatformUtil.assertFxApplicationThread();

    {
      WizardPage currentPage = getCurrentPage();
      if (currentPage != null) currentPage.onHidden();

      if (currentPage != null && addToHistory) history.addLast(currentPage);
    }

    setCurrentPage(wizardPage);
    for (Node child : getChildren()) child.setVisible(false);

    wizardPage.setVisible(true);
    getChildren().remove(wizardPage); // remove from z-order wherever it is (it might be missing!).
    getChildren().add(wizardPage); // re-add as last, which means top-most z-order.

    wizardPage.updateButtonsDisable();
    updateCanFinish();

    if (getParent() != null) getParent().requestFocus();

    this.requestFocus();
    wizardPage.requestFocus();

    Platform.runLater(
        new Runnable() {
          @Override
          public void run() {
            final Scene scene = getScene();
            final Window window = scene == null ? null : scene.getWindow();
            if (window != null) window.sizeToScene();

            if (getParent() != null) getParent().requestFocus();

            Wizard.this.requestFocus();
            wizardPage.requestFocus();
            wizardPage.onShown();
          }
        });
  }
示例#11
0
 @Override
 public void set(final String useCase) {
   assertNotNull("useCase", useCase);
 }
示例#12
0
 public void setSelectionMode(SelectionMode selectionMode) {
   assertNotNull("selectionMode", selectionMode);
   treeTableView.getSelectionModel().setSelectionMode(selectionMode);
 }
 public ParentFileEntry(final File parentFile) {
   this.parentFile = AssertUtil.assertNotNull("parentFile", parentFile);
   this.lastModified = parentFile.exists() ? parentFile.lastModified() : Long.MIN_VALUE;
 }