예제 #1
0
  public void testGetResourceClearedCache() throws Exception {
    Supplier supplier = getModel1Factory().createSupplier();
    supplier.setName("Stepper");

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));
    resource.getContents().add(supplier);
    transaction.commit();

    clearCache(getRepository().getRevisionManager());

    // query(new BasicDBObject(Commits.REVISIONS, new BasicDBObject("$elemMatch", new BasicDBObject(
    // Commits.REVISIONS_RESOURCE, 1))));
    transaction = session.openTransaction();

    msg("Getting resource");
    resource = transaction.getResource(getResourcePath("/test1"), true);
    assertNotNull(resource);
    assertEquals(
        URI.createURI("cdo://" + session.getRepositoryInfo().getUUID() + getResourcePath("/test1")),
        resource.getURI());
    assertEquals(transaction.getResourceSet(), resource.getResourceSet());
    assertEquals(1, transaction.getResourceSet().getResources().size());
    assertEquals(CDOState.CLEAN, resource.cdoState());
    assertEquals(transaction, resource.cdoView());
    assertNotNull(resource.cdoRevision());
  }
예제 #2
0
  public void testResourceAccessor() throws Exception {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));

    Supplier supplier = getModel1Factory().createSupplier();
    supplier.setName("Stepper");

    resource.getContents().add(supplier);

    URI supplierTempURI = EcoreUtil.getURI(supplier);

    // Retrieving supplier from URI before commit
    EObject supplier1 = transaction.getResourceSet().getEObject(supplierTempURI, true);
    assertEquals(supplier, CDOUtil.getEObject(supplier1));

    transaction.commit();

    URI supplierURI = EcoreUtil.getURI(supplier);

    // Retrieving supplier from URI after commit
    EObject supplierFromURI = transaction.getResourceSet().getEObject(supplierURI, true);
    assertEquals(supplier, CDOUtil.getEObject(supplierFromURI));

    EObject supplierAfterCommit2 = transaction.getResourceSet().getEObject(supplierTempURI, true);
    if (session.getRepositoryInfo().getIDGenerationLocation() == IDGenerationLocation.STORE) {
      assertEquals(null, supplierAfterCommit2);
    } else {
      assertEquals(supplier, supplierAfterCommit2);
    }
  }
예제 #3
0
    @Override
    protected EObject doRun(CDOTransaction transaction, CDOObject parent, ISelection selection) {
      ComposedAdapterFactory adapterFactory = CDOEditor.createAdapterFactory(true);

      try {
        BasicCommandStack commandStack = new BasicCommandStack();
        ResourceSet resourceSet = transaction.getResourceSet();

        EditingDomain editingDomain =
            new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet);

        CreateChildAction delegate =
            new CreateChildAction(editingDomain, selection, childDescriptor);
        delegate.run();

        if (childDescriptor instanceof CommandParameter) {
          CommandParameter parameter = (CommandParameter) childDescriptor;
          Object value = parameter.getValue();
          if (value instanceof EObject) {
            return (EObject) value;
          }
        }

        return null;
      } finally {
        adapterFactory.dispose();
      }
    }
  private void testCDORevisionPrefetchOnBranch(CDOSession session, CDOBranch cdoBranch)
      throws Exception {
    CDOTransaction view = session.openTransaction(cdoBranch);
    ISignalProtocol<?> protocol =
        ((org.eclipse.emf.cdo.net4j.CDONet4jSession) session).options().getNet4jProtocol();
    SignalCounter signalCounter = new SignalCounter(protocol);
    assertEquals(0, signalCounter.getCountFor(LoadRevisionsRequest.class));

    String resourcePath = getResourcePath(RESOURCE_NAME);
    List<String> pathSegments = CDOURIUtil.analyzePath(resourcePath);
    CDOResource resource = view.getResource(resourcePath);
    assertEquals(pathSegments.size(), signalCounter.getCountFor(LoadRevisionsRequest.class));
    resource.cdoPrefetch(CDORevision.DEPTH_INFINITE);

    assertEquals(pathSegments.size() + 1, signalCounter.getCountFor(LoadRevisionsRequest.class));

    Company company = (Company) resource.getContents().get(0);
    CDOID companyCDOID = CDOUtil.getCDOObject(company).cdoID();

    assertEquals(pathSegments.size() + 1, signalCounter.getCountFor(LoadRevisionsRequest.class));

    view.getRevision(companyCDOID);

    assertEquals(pathSegments.size() + 1, signalCounter.getCountFor(LoadRevisionsRequest.class));

    view.getResourceSet().eAdapters().add(new EContentAdapter());

    assertEquals(pathSegments.size() + 1, signalCounter.getCountFor(LoadRevisionsRequest.class));

    protocol.removeListener(signalCounter);
  }
예제 #5
0
  public void testAttachResource() throws Exception {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));
    assertNew(resource, transaction);
    assertEquals(
        URI.createURI("cdo://" + session.getRepositoryInfo().getUUID() + getResourcePath("/test1")),
        resource.getURI());

    ResourceSet expected = transaction.getResourceSet();
    ResourceSet actual = resource.getResourceSet();
    assertEquals(expected, actual);
  }
예제 #6
0
  public void testLoadResource() throws Exception {
    {
      // disableConsole();
      msg("Opening session");
      CDOSession session = openSession();

      msg("Opening transaction");
      CDOTransaction transaction = session.openTransaction();

      msg("Creating resource");
      CDOResource resource = transaction.createResource(getResourcePath("/test1"));

      msg("Creating supplier");
      Supplier supplier = getModel1Factory().createSupplier();

      msg("Setting name");
      supplier.setName("Stepper");

      msg("Adding supplier");
      resource.getContents().add(supplier);

      msg("Committing");
      transaction.commit();
      // XXX session.close();
      // enableConsole();
    }

    msg("Opening session");
    CDOSession session = openSession();

    msg("Opening transaction");
    CDOTransaction transaction = session.openTransaction();

    msg("Getting resource");
    CDOResource resource = transaction.getResource(getResourcePath("/test1"));
    assertNotNull(resource);

    URI uri =
        URI.createURI("cdo://" + session.getRepositoryInfo().getUUID() + getResourcePath("/test1"));
    URI resourceURI = resource.getURI();
    assertEquals(uri, resourceURI);
    assertEquals(transaction.getResourceSet(), resource.getResourceSet());
    assertEquals(CDOState.CLEAN, resource.cdoState());
    assertEquals(transaction, resource.cdoView());
    assertNotNull(resource.cdoRevision());
  }
예제 #7
0
  public void testGetResource() throws Exception {
    msg("Opening session");
    CDOSession session = openSession();

    {
      disableConsole();
      msg("Opening transaction");
      CDOTransaction transaction = session.openTransaction();

      msg("Creating resource");
      CDOResource resource = transaction.createResource(getResourcePath("/test1"));

      msg("Creating supplier");
      Supplier supplier = getModel1Factory().createSupplier();

      msg("Setting name");
      supplier.setName("Stepper");

      msg("Adding supplier");
      resource.getContents().add(supplier);

      msg("Committing");
      transaction.commit();
      enableConsole();
    }

    {
      msg("Opening transaction");
      CDOTransaction transaction = session.openTransaction();

      msg("Getting resource");
      CDOResource resource = transaction.getResource(getResourcePath("/test1"), true);
      assertNotNull(resource);
      assertEquals(
          URI.createURI(
              "cdo://" + session.getRepositoryInfo().getUUID() + getResourcePath("/test1")),
          resource.getURI());
      assertEquals(transaction.getResourceSet(), resource.getResourceSet());
      assertEquals(1, transaction.getResourceSet().getResources().size());
      assertEquals(CDOState.CLEAN, resource.cdoState());
      assertEquals(transaction, resource.cdoView());
      assertNotNull(resource.cdoRevision());
    }

    {
      msg("Opening transaction");
      CDOTransaction transaction = session.openTransaction();

      msg("Getting resource");
      CDOResource resource =
          (CDOResource)
              transaction
                  .getResourceSet()
                  .getResource(
                      CDOURIUtil.createResourceURI(transaction, getResourcePath("/test1")), true);
      assertNotNull(resource);
      assertEquals(
          URI.createURI(
              "cdo://" + session.getRepositoryInfo().getUUID() + getResourcePath("/test1")),
          resource.getURI());
      assertEquals(transaction.getResourceSet(), resource.getResourceSet());
      assertEquals(1, transaction.getResourceSet().getResources().size());
      assertEquals(CDOState.CLEAN, resource.cdoState());
      assertEquals(transaction, resource.cdoView());
      assertNotNull(resource.cdoRevision());
    }
  }