예제 #1
0
  public void addCommitInfo(CDOBranchPoint branchPoint, long pointer) {
    if (TRACER.isEnabled()) {
      TRACER.format("addCommitInfo: {0}, {1}", branchPoint, pointer); // $NON-NLS-1$
    }

    try {
      if (addCommitInfoStatement == null) {
        String sql = index.commitInfos.sqlAddCommitInfo();
        addCommitInfoStatement = connection.prepareStatement(sql);
      }

      int column = 0;

      long timeStamp = branchPoint.getTimeStamp();
      addCommitInfoStatement.setLong(++column, timeStamp);

      if (supportingBranches) {
        CDOBranch branch = branchPoint.getBranch();
        int branchID = branch.getID();
        addCommitInfoStatement.setInt(++column, branchID);
      }

      addCommitInfoStatement.setLong(++column, pointer);
      execute(addCommitInfoStatement);
    } catch (SQLException ex) {
      throw new DBException(ex);
    }
  }
  private CDOID setUpChangesOnBranches() throws Exception {
    CDOSession session = openSession();
    CDOBranch b1Branch = session.getBranchManager().getMainBranch().createBranch(B1_BRANCH_NAME);

    CDOTransaction transaction = session.openTransaction(b1Branch);
    CDOResource resource = transaction.getResource(getResourcePath(RESOURCE_NAME));
    Company company = (Company) resource.getContents().get(0);
    for (int i = 0; i < NB_CATEGORY; i++) {
      company.getCategories().add(getModel1Factory().createCategory());
    }
    transaction.commit();
    transaction.close();

    CDOBranch b2Branch = b1Branch.createBranch(B11_BRANCH_NAME);

    transaction = session.openTransaction(b2Branch);
    resource = transaction.getResource(getResourcePath(RESOURCE_NAME));
    company = (Company) resource.getContents().get(0);
    for (int i = 0; i < NB_CATEGORY; i++) {
      company.getCategories().add(getModel1Factory().createCategory());
    }
    transaction.commit();
    transaction.close();
    session.close();

    return CDOUtil.getCDOObject(company).cdoID();
  }
  /** Test {@link CDOCollectionLoadingPolicy} on different branches with each having changes. */
  public void testCDORevisionCDOFetchRuleOnOtherBranchWithChanges() throws Exception {
    // Setup
    CDOID companyCDOID = setUpChangesOnBranches();

    // Test
    CDOSession session = openSession();
    InternalCDOSession internalCDOSession = (InternalCDOSession) session;
    CDOFetchRuleManager fetchRuleManager = new CustomCDOFetchRuleManager(companyCDOID);
    internalCDOSession.setFetchRuleManager(fetchRuleManager);
    ISignalProtocol<?> protocol =
        ((org.eclipse.emf.cdo.net4j.CDONet4jSession) session).options().getNet4jProtocol();
    SignalCounter signalCounter = new SignalCounter(protocol);

    CDOBranch currentBranch = session.getBranchManager().getMainBranch();
    testCDORevisionFetchWithChangesOnAllBranches(
        session, currentBranch, signalCounter, companyCDOID, NB_CATEGORY, false);

    currentBranch = currentBranch.getBranch(B1_BRANCH_NAME);
    testCDORevisionFetchWithChangesOnAllBranches(
        session, currentBranch, signalCounter, companyCDOID, 2 * NB_CATEGORY, false);

    currentBranch = currentBranch.getBranch(B11_BRANCH_NAME);
    testCDORevisionFetchWithChangesOnAllBranches(
        session, currentBranch, signalCounter, companyCDOID, 3 * NB_CATEGORY, false);

    protocol.removeListener(signalCounter);
  }
  /**
   * * Find all objects in the ooTreeListX that's between startTime and endTime inclusive, and have
   * branch.getID() if branch is not null We don't have any optimization for time, but we could make
   * the treeset use custom comparator.
   */
  public List<ObjyCommitInfo> getCommitInfo(CDOBranch branch, long startTime, long endTime) {
    ooTreeSetX treeSet = getTreeSet();
    ObjyCommitInfo ooCommitInfo = null;
    List<ObjyCommitInfo> results = new ArrayList<ObjyCommitInfo>();

    boolean getIt = false;

    @SuppressWarnings("unchecked")
    Iterator<ObjyCommitInfo> itr = treeSet.iterator();
    while (itr.hasNext()) {
      ooCommitInfo = itr.next();
      getIt = true; // assume it's what we need, then we filter below.
      long timeStamp = ooCommitInfo.getTimeStamp();
      long branchId = ooCommitInfo.getBranchId();

      if (branch != null && branch.getID() != branchId) {
        getIt = false;
      }
      if (getIt && startTime != CDOBranchPoint.UNSPECIFIED_DATE && timeStamp < startTime) {
        getIt = false;
      }
      if (getIt && endTime != CDOBranchPoint.UNSPECIFIED_DATE && timeStamp > endTime) {
        getIt = false;
      }

      if (getIt) {
        results.add(ooCommitInfo);
      }
    }

    return results;
  }
예제 #5
0
  public static InternalView openViewWithLockArea(
      InternalSession session,
      InternalLockManager lockManager,
      CDOBranch viewedBranch,
      String lockAreaID) {
    LockArea lockArea;
    InternalView view;

    try {
      lockArea = lockManager.getLockArea(lockAreaID);

      // If we get here, the lockArea already exists.
      view =
          (InternalView)
              lockManager.openView(session, InternalSession.TEMP_VIEW_ID, true, lockAreaID);
    } catch (LockAreaNotFoundException e) {
      // If we get here, the lockArea does not yet exist, so we open
      // a view without a lockArea first, then create a lockArea with the given ID,
      // and associate it with the view.
      view = session.openView(InternalSession.TEMP_VIEW_ID, viewedBranch.getHead());
      lockArea = lockManager.createLockArea(view, lockAreaID);
      view.setDurableLockingID(lockAreaID);
    }

    CheckUtil.checkNull(lockAreaID, "lockAreaID");
    CheckUtil.checkNull(lockArea, "lockArea");
    CheckUtil.checkState(
        lockAreaID.equals(lockArea.getDurableLockingID()), "lockAreaID has incorrect value");

    return view;
  }
  private void checkRevisionsOnGivenSession(
      Set<CDOID> ids, long timeStampOfHoleCommit, int version, CDOSession session) {
    CDORevisionManager revisionManager = session.getRevisionManager();
    CDOBranch mainBranch = session.getBranchManager().getMainBranch();
    CDOBranchPoint branchPoint = mainBranch.getPoint(timeStampOfHoleCommit);
    CDOBranchVersion branchVersion = mainBranch.getVersion(version);

    for (Iterator<CDOID> it = ids.iterator(); it.hasNext(); ) {
      CDOID next = it.next();
      if (timeStampOfHoleCommit != -1) {
        CDORevision revision =
            revisionManager.getRevision(next, branchPoint, CDORevision.DEPTH_NONE, 0, true);
        assertNull(revision);
      }

      CDORevision revision =
          revisionManager.getRevisionByVersion(next, branchVersion, CDORevision.DEPTH_NONE, true);
      assertInstanceOf(DetachedCDORevision.class, revision);
    }
  }
예제 #7
0
 @Override
 protected void writeCommitInfo(
     CDOBranch branch,
     long timeStamp,
     long previousTimeStamp,
     String userID,
     String comment,
     OMMonitor monitor) {
   DB4OCommitInfo commitInfo =
       new DB4OCommitInfo(branch.getID(), timeStamp, previousTimeStamp, userID, comment);
   writeObject(commitInfo, monitor);
 }
예제 #8
0
 @Override
 public String toString() {
   return MessageFormat.format("{0}:{1}", id, branch.getID()); // $NON-NLS-1$
 }
예제 #9
0
 @Override
 public int hashCode() {
   return id.hashCode() ^ branch.hashCode();
 }