Example #1
0
  @Override
  protected void doRun(IProgressMonitor progressMonitor) throws Exception {
    CDOTransaction transaction = getTransaction();
    CDOResourceNode node = null;

    if (createFolder) {
      node = EresourceFactory.eINSTANCE.createCDOResourceFolder();
      node.setName(resourceNodeName);
      if (selectedNode instanceof CDOResourceFolder) {
        ((CDOResourceFolder) selectedNode).getNodes().add(node);
      } else {
        ((CDOResource) selectedNode).getContents().add(node);
      }
    } else {
      if (selectedNode instanceof CDOResourceFolder) {
        node =
            transaction.createResource(
                selectedNode.getPath() + "/" + resourceNodeName); // $NON-NLS-1$
      } else {
        node = transaction.createResource(resourceNodeName);
      }
    }

    transaction.commit();

    itemProvider.refreshViewer(true);
    itemProvider.selectElement(node, true);

    if (!createFolder) {
      String resourcePath = node.getPath();
      CDOEditorUtil.openEditor(getPage(), transaction, resourcePath);
    }
  }
  public void test_Bugzilla_271861_Case1() throws Exception {
    CDOSession session = openSession();

    CDOTransaction trans = session.openTransaction();
    CDOResource res = trans.createResource(getResourcePath("/test/RESOURCE"));
    trans.commit();

    res.delete(null);
    res = trans.createResource(getResourcePath("/test/RESOURCE"));
    trans.commit();

    trans.close();
    session.close();
  }
  public void testLockStateNewAndTransient() throws CommitException {
    Company company1 = getModel1Factory().createCompany();
    CDOObject cdoObj = CDOUtil.getCDOObject(company1);
    assertTransient(cdoObj);
    assertNull(cdoObj.cdoLockState());

    CDOSession session1 = openSession();
    CDOTransaction tx1 = session1.openTransaction();
    CDOResource res1 = tx1.createResource(getResourcePath("r1"));
    res1.getContents().add(company1);
    assertNew(cdoObj, tx1);
    assertNotNull(cdoObj.cdoLockState());

    res1.getContents().remove(company1);
    assertTransient(cdoObj);
    assertNull(cdoObj.cdoLockState());

    res1.getContents().add(company1);
    tx1.commit();
    assertClean(cdoObj, tx1);
    assertNotNull(cdoObj.cdoLockState());

    res1.getContents().remove(company1);
    assertTransient(cdoObj);
    assertNull(cdoObj.cdoLockState());

    session1.close();
  }
  public void testCustomDefaultLiteral() throws CommitException {
    // valid default literal
    att.setDefaultValueLiteral("1;2");

    EObject obj = EcoreUtil.create(cls);
    obj.eUnset(att);

    {
      CDOSession session = openSession();
      session.getPackageRegistry().putEPackage(pkg);
      CDOTransaction tx = session.openTransaction();
      CDOResource res = tx.createResource(getResourcePath("/test"));
      res.getContents().add(obj);
      tx.commit();
      tx.close();
      session.close();
    }

    clearCache(getRepository().getRevisionManager());

    {
      CDOSession session = openSession();
      session.getPackageRegistry().putEPackage(pkg);
      CDOView v = session.openView();
      CDOResource res = v.getResource(getResourcePath("/test"));
      EObject persistent = res.getContents().get(0);

      CustomType pCustom = (CustomType) persistent.eGet(att);
      assertEquals(1, pCustom.getA());
      assertEquals(2, pCustom.getB());

      v.close();
      session.close();
    }
  }
  public void testSameSession_WithoutPolicy() throws Exception {
    final Category category1A = getModel1Factory().createCategory();
    category1A.setName("category1");

    final Company companyA = getModel1Factory().createCompany();
    companyA.getCategories().add(category1A);

    final CDOSession session = openSession();

    // ************************************************************* //

    final CDOTransaction transaction = session.openTransaction();

    final CDOResource resourceA = transaction.createResource(getResourcePath("/test1"));
    resourceA.getContents().add(companyA);

    transaction.commit();
    final TestAdapter adapter = new TestAdapter();
    category1A.eAdapters().add(adapter);

    // ************************************************************* //

    final CDOTransaction transaction2 = session.openTransaction();

    final Category category1B =
        (Category)
            CDOUtil.getEObject(
                transaction2.getObject(CDOUtil.getCDOObject(category1A).cdoID(), true));
    category1B.setName("CHANGED NAME");
    assertEquals(0, adapter.getNotifications().length);

    transaction2.commit();

    new PollingTimeOuter() {
      @Override
      protected boolean successful() {
        // Commit notifications from the same session always have full deltas
        Notification[] notifications = adapter.getNotifications();
        return notifications.length == 1;
      }
    }.assertNoTimeOut();

    // Adding policy
    transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
    adapter.clearNotifications();

    category1B.setName("CHANGED NAME_VERSION 2");
    assertEquals(0, adapter.getNotifications().length);

    transaction2.commit();

    new PollingTimeOuter() {
      @Override
      protected boolean successful() {
        // Commit notifications from the same session always have full deltas
        Notification[] notifications = adapter.getNotifications();
        return notifications.length == 1;
      }
    }.assertNoTimeOut();
  }
Example #6
0
  /** bug 226317 */
  public void testMultipleInheritence() throws Exception {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));
    OrderAddress orderAddress = getModel1Factory().createOrderAddress();
    resource.getContents().add(orderAddress);

    assertEquals(
        getModel1Package().getAddress_City().getFeatureID(),
        getModel1Package().getOrderDetail_Price().getFeatureID());

    orderAddress.setCity("ALLO");
    orderAddress.setPrice(2.8f);
    orderAddress.setTestAttribute(true);

    assertEquals(2.8f, orderAddress.getPrice());
    assertEquals("ALLO", orderAddress.getCity());

    OrderDetail orderDetail = getModel1Factory().createOrderDetail();
    resource.getContents().add(orderDetail);
    orderDetail.setPrice(3f);

    transaction.commit();

    orderAddress.setCity("ALLO");

    transaction.commit();
    session.close();

    session = openSession();

    msg("Opening transaction");
    transaction = session.openTransaction();
    orderAddress =
        (OrderAddress)
            CDOUtil.getEObject(
                transaction.getObject(CDOUtil.getCDOObject(orderAddress).cdoID(), true));

    assertEquals(2.8f, orderAddress.getPrice());
    assertEquals("ALLO", orderAddress.getCity());

    orderAddress.setPrice(2.8f);
    transaction.commit();
    session.close();

    session = openSession();

    transaction = session.openTransaction();
    orderAddress =
        (OrderAddress)
            CDOUtil.getEObject(
                transaction.getObject(CDOUtil.getCDOObject(orderAddress).cdoID(), true));

    assertEquals(2.8f, orderAddress.getPrice());
    assertEquals("ALLO", orderAddress.getCity());

    orderAddress.setPrice(2.8f);

    session.close();
  }
Example #7
0
  public void testReadTransientValue() throws Exception {
    CDOSession session = openSession();

    {
      disableConsole();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource(getResourcePath("/test1"));

      Product1 product = getModel1Factory().createProduct1();
      product.setDescription("DESCRIPTION");
      product.setName("McDuff");

      resource.getContents().add(product);

      assertEquals("DESCRIPTION", product.getDescription());

      transaction.commit();
      enableConsole();
    }

    CDOView view = session.openView();
    CDOResource resource = view.getResource(getResourcePath("/test1"));

    EList<EObject> contents = resource.getContents();
    Product1 s = (Product1) contents.get(0);
    assertNotNull(s);

    assertEquals("McDuff", s.getName());
    assertNull(s.getDescription());

    s.setDescription("HELLO");
    assertEquals("HELLO", s.getDescription());
  }
  public void testTemporaryObject() throws Exception {
    msg("Opening session");
    final CDOSession session = openSession();

    // ************************************************************* //

    msg("Creating category1");
    final Category category1A = getModel1Factory().createCategory();
    category1A.setName("category1");

    msg("Creating company");
    final Company companyA = getModel1Factory().createCompany();

    msg("Adding categories");
    companyA.getCategories().add(category1A);

    msg("Opening transaction");
    final CDOTransaction transaction = session.openTransaction();
    transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
    msg("Creating resource");
    final CDOResource resourceA = transaction.createResource(getResourcePath("/test1"));

    msg("Adding company");
    resourceA.getContents().add(companyA);

    msg("Committing");

    final TestAdapter adapter = new TestAdapter();
    category1A.eAdapters().add(adapter);

    transaction.commit();

    // ************************************************************* //

    msg("Opening view");
    final CDOSession session2 = openSession();
    final CDOTransaction transaction2 = session2.openTransaction();
    transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    final Category category1B =
        (Category)
            CDOUtil.getEObject(
                transaction2.getObject(CDOUtil.getCDOObject(category1A).cdoID(), true));

    msg("Changing name");
    category1B.setName("CHANGED NAME");

    assertEquals(0, adapter.getNotifications().length);

    msg("Committing");
    transaction2.commit();

    msg("Checking after commit");
    new PollingTimeOuter() {
      @Override
      protected boolean successful() {
        return adapter.getNotifications().length == 1;
      }
    }.assertNoTimeOut();
  }
Example #9
0
  public void testWriteClean() throws Exception {
    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();

    msg("Getting supplier");
    Supplier s = (Supplier) resource.getContents().get(0);

    msg("Setting name");
    s.setName("Eike");
    assertEquals("Eike", s.getName());
    assertEquals(CDOState.DIRTY, CDOUtil.getCDOObject(supplier).cdoState());
    assertEquals(CDOState.CLEAN, resource.cdoState());
  }
Example #10
0
  public void testReadResourceClean() throws Exception {
    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");
    long commitTime = transaction.commit().getTimeStamp();

    msg("Getting supplier");
    EList<EObject> contents = resource.getContents();
    Supplier s = (Supplier) contents.get(0);
    assertEquals(1, CDOUtil.getCDOObject(s).cdoRevision().getVersion());
    assertEquals(supplier, s);
    assertCreatedTime(s, commitTime);
  }
Example #11
0
  public void testCommitNew() throws Exception {
    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");
    CDOCommitInfo commit = transaction.commit();
    assertEquals(CDOState.CLEAN, resource.cdoState());
    assertEquals(CDOState.CLEAN, CDOUtil.getCDOObject(supplier).cdoState());
    assertEquals(1, CDOUtil.getCDOObject(supplier).cdoRevision().getVersion());
    assertCreatedTime(resource, commit.getTimeStamp());
    assertCreatedTime(supplier, commit.getTimeStamp());
  }
  public void testSimpleTestWithCommit() throws Exception {
    TimeTaker t = start("testBasicCommitPerformance");

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));
    getModel1Factory().createCustomer();
    for (int i = 0; i < 500; i++) {
      Customer customer = getModel1Factory().createCustomer();
      customer.setCity("Barovia");
      customer.setName("Strahd von Zarovich");
      customer.setStreet("Necromancer Road 5");

      for (int c = 0; c < 5; c++) {
        SalesOrder salesOrder = getModel1Factory().createSalesOrder();
        salesOrder.setCustomer(customer);
        salesOrder.setId(c);
        resource.getContents().add(salesOrder);
      }

      resource.getContents().add(customer);
    }

    transaction.commit();

    finish(t);
    msg(t.getTiming());
  }
Example #13
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);
    }
  }
  public void testCustomRegular() throws CommitException {
    EObject obj = EcoreUtil.create(cls);
    obj.eSet(att, new CustomType(23, 42));

    {
      CDOSession session = openSession();
      session.getPackageRegistry().putEPackage(pkg);
      CDOTransaction tx = session.openTransaction();
      CDOResource res = tx.createResource(getResourcePath("/test"));
      res.getContents().add(obj);
      tx.commit();
      tx.close();
      session.close();
    }

    clearCache(getRepository().getRevisionManager());

    {
      CDOSession session = openSession();
      session.getPackageRegistry().putEPackage(pkg);
      CDOView v = session.openView();
      CDOResource res = v.getResource(getResourcePath("/test"));
      EObject persistent = res.getContents().get(0);

      CustomType pCustom = (CustomType) persistent.eGet(att);
      assertEquals(23, pCustom.getA());
      assertEquals(42, pCustom.getB());

      v.close();
      session.close();
    }
  }
  public void testBugzilla_246442() throws Exception {
    CDOID lookupObject = null;

    {
      EPackage topPackage = createDynamicEPackage();

      EPackage subpackage1 = topPackage.getESubpackages().get(0);
      EClass class1Class = (EClass) subpackage1.getEClassifier("class1");

      CDOSession session = openSession();
      session.getPackageRegistry().putEPackage(topPackage);

      CDOTransaction transaction = session.openTransaction();
      CDOObject instance = CDOUtil.getCDOObject(EcoreUtil.create(class1Class));

      CDOResource resource = transaction.createResource(getResourcePath("/test1"));
      resource.getContents().add(instance);
      transaction.commit();

      lookupObject = instance.cdoID();
      session.close();
    }

    CDOSession session = openSession();
    if (session instanceof org.eclipse.emf.cdo.net4j.CDONet4jSession) {
      ((org.eclipse.emf.cdo.net4j.CDONet4jSession) session)
          .options()
          .getNet4jProtocol()
          .setTimeout(2000L);
    }

    CDOTransaction transaction = session.openTransaction();
    transaction.getObject(lookupObject);
  }
  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  public void testXRefMergeManyValueTest() throws Exception {
    // setup transaction.
    final CDOSession session = openSession();
    final CDOTransaction tr1 = session.openTransaction();
    tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    final CDOResource resource = tr1.createResource(getResourcePath("/test1"));
    RefMultiContained container = getModel4Factory().createRefMultiContained();
    resource.getContents().add(container);

    tr1.commit();
    sleep(1000);

    final CDOBranch otherBranch = tr1.getBranch().createBranch("other");
    final CDOTransaction tr2 = session.openTransaction(otherBranch);

    RefMultiContained otherContainer = tr2.getObject(container);
    assertNotNull(otherContainer);

    // add a new element on other branch at index 0.
    otherContainer.getElements().add(0, getModel4Factory().createMultiContainedElement());

    tr2.commit();

    // sleep to have the merger see the changes.
    sleep(1000);

    // merge the other branch to main.
    tr1.merge(tr2.getBranch().getHead(), new DefaultCDOMerger.PerFeature.ManyValued());

    tr1.commit();
    assertEquals(false, tr1.isDirty());
  }
  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());
  }
  public void testSeparateSession() throws Exception {
    Category category1A = getModel1Factory().createCategory();
    category1A.setName("category1");

    Company companyA = getModel1Factory().createCompany();
    companyA.getCategories().add(category1A);

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    CDOResource resourceA = transaction.createResource(getResourcePath("/test1"));
    resourceA.getContents().add(companyA);
    transaction.commit();

    final TestAdapter adapter = new TestAdapter();
    category1A.eAdapters().add(adapter);

    // ************************************************************* //

    CDOSession session2 = openSession();
    CDOTransaction transaction2 = session2.openTransaction();

    Category category1B =
        (Category)
            CDOUtil.getEObject(
                transaction2.getObject(CDOUtil.getCDOObject(category1A).cdoID(), true));
    category1B.setName("CHANGED NAME");
    assertEquals(0, adapter.getNotifications().length);

    transaction2.commit();

    new PollingTimeOuter() {
      @Override
      protected boolean successful() {
        // Change subscription leads to delta nnotification
        Notification[] notifications = adapter.getNotifications();
        return notifications.length == 1;
      }
    }.assertNoTimeOut();

    // Removing policy
    transaction.options().removeChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
    adapter.clearNotifications();

    category1B.setName("CHANGED NAME_VERSION 2");
    assertEquals(0, adapter.getNotifications().length);

    transaction2.commit();

    new PollingTimeOuter() {
      @Override
      protected boolean successful() {
        // No change subscription, other session ==> no delta notification
        Notification[] notifications = adapter.getNotifications();
        return notifications.length != 0;
      }
    }.assertTimeOut();
  }
  public void testLoadAnStoreDataPerformance() throws Exception {
    TimeTaker t = start("testLoadAnStoreDataPerformance");

    {
      CDOSession session = openSession();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource(getResourcePath("/test1"));
      getModel1Factory().createCustomer();
      for (int i = 0; i < 500; i++) {
        Customer customer = getModel1Factory().createCustomer();
        customer.setCity("Barovia");
        customer.setName("Strahd von Zarovich");
        customer.setStreet("Necromancer Road 5");

        for (int c = 0; c < 5; c++) {
          SalesOrder salesOrder = getModel1Factory().createSalesOrder();
          salesOrder.setCustomer(customer);
          salesOrder.setId(c);
          resource.getContents().add(salesOrder);
        }

        resource.getContents().add(customer);
      }

      transaction.commit();
      session.close();
    }

    {
      CDOSession session = openSession();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.getResource(getResourcePath("/test1"));

      int i = 0;
      for (EObject o : resource.getContents()) {
        if (o instanceof Customer) {
          Customer customer = (Customer) o;
          customer.setCity("Dargaard");
          customer.setName("Lord Soth");
          customer.setStreet("Death Knight Alley 7");

          for (SalesOrder salesOrder : customer.getSalesOrders()) {
            salesOrder.setId(salesOrder.getId() + 1);
          }

          i++;
        }
      }

      assertEquals(500, i);

      transaction.commit();
      session.close();
    }

    finish(t);
    msg(t.getTiming());
  }
Example #20
0
  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  public void testTargetGoalDeltaVersion() throws Exception {
    skipStoreWithoutChangeSets();

    // setup 2 transactions.
    final CDOSession session1 = openSession();
    final CDOTransaction s1Tr1 = session1.openTransaction();
    s1Tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
    final CDOTransaction s1Tr2 = session1.openTransaction();
    s1Tr2.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    // create resource, container and 2 elements using transaction 1.
    final CDOResource resource = s1Tr1.createResource(getResourcePath("/test1"));
    RefMultiContained container = getModel4Factory().createRefMultiContained();
    resource.getContents().add(container);
    MultiContainedElement element1 = getModel4Factory().createMultiContainedElement();
    container.getElements().add(element1);
    MultiContainedElement element2 = getModel4Factory().createMultiContainedElement();
    container.getElements().add(element2);

    commitAndSync(s1Tr1, s1Tr2);

    // access container on transaction 2 to have it updated with a RevisionDelta.
    RefMultiContained container2 = s1Tr2.getObject(container);

    // setup another branch.
    final CDOBranch otherBranch = s1Tr1.getBranch().createBranch("other");
    final CDOTransaction s1Tr3 = session1.openTransaction(otherBranch);

    RefMultiContained otherContainer = s1Tr3.getObject(container);
    assertNotSame(null, otherContainer);
    assertEquals(true, otherContainer.getElements().size() > 0);

    // remove an element on the other branch.
    otherContainer.getElements().remove(0);

    commitAndSync(s1Tr3, s1Tr1);

    // merge the other branch to main (this creates the targetGoalDelta for the RevisionDelta).
    s1Tr1.merge(s1Tr3.getBranch().getHead(), new DefaultCDOMerger.PerFeature.ManyValued());

    commitAndSync(s1Tr1, s1Tr2);

    // check the change on tr2 and do another change.
    assertEquals(false, s1Tr1.isDirty());
    container2.getElements().remove(0);

    commitAndSync(s1Tr2, s1Tr1); // <--- this commit will throw the following exception:
    // java.util.ConcurrentModificationException:
    // Attempt by Transaction[2:2] to modify historical revision: RefMultiContained@OID4:0v1
    assertEquals(false, s1Tr1.isDirty());

    // check revision versions.
    assertEquals(
        CDOUtil.getCDOObject(container).cdoRevision().getVersion(),
        CDOUtil.getCDOObject(container2).cdoRevision().getVersion());
  }
Example #21
0
  public void test() throws CommitException {
    {
      CDOSession session = openSession();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource(getResourcePath("test"));

      Category category1 = getModel1Factory().createCategory();
      resource.getContents().add(category1);

      category1.getCategories().add(getModel1Factory().createCategory());

      Category category2 = getModel1Factory().createCategory();
      resource.getContents().add(category2);

      transaction.commit();
      session.close();
    }

    {
      CDOSession session = openSession();
      CDOTransaction transaction = session.openTransaction();

      final CDOObject[] attachedObject = new CDOObject[1];
      transaction.addTransactionHandler(
          new CDOTransactionHandler1() {
            public void modifyingObject(
                CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureDelta) {}

            public void detachingObject(CDOTransaction transaction, CDOObject object) {}

            public void attachingObject(CDOTransaction transaction, CDOObject object) {
              attachedObject[0] = object;
            }
          });

      CDOResource resource = transaction.getResource(getResourcePath("test"));
      Category c1 = (Category) resource.getContents().get(0);
      Category nestedCategory = c1.getCategories().get(0);
      CDOObject cdoCategory = CDOUtil.getCDOObject(nestedCategory);

      // Detach
      EcoreUtil.remove(nestedCategory);

      // Re-attach
      attachedObject[0] = null;
      ((Category) resource.getContents().get(1)).getCategories().add(nestedCategory);

      assertNotNull("CDOTransactionHandler1.attachingObject was not called", attachedObject[0]);
      assertEquals(
          MessageFormat.format("Re-attached object was not the expected object {0}", cdoCategory),
          cdoCategory,
          attachedObject[0]);
    }
  }
  public void testRemoveContained() throws Exception {
    List<Category> categories = new ArrayList<Category>();
    categories.add(getModel1Factory().createCategory());

    Company company = getModel1Factory().createCompany();
    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().addAll(categories);
    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().add(getModel1Factory().createCategory());

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

    CDOSession session2 = openSession();
    CDOView view = session2.openView();
    view.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    CDOResource resource2 = view.getResource(getResourcePath("/test1"));
    Company company2 = (Company) resource2.getContents().get(0);

    Object[] strongRefs = company2.getCategories().toArray(); // Keep those in memory
    msg(strongRefs);

    final TestAdapter adapter = new TestAdapter();
    company2.eAdapters().add(adapter);

    company.getCategories().removeAll(categories);
    transaction.commit();

    final Object[] oldValue = {null};
    new PollingTimeOuter() {
      @Override
      protected boolean successful() {
        for (Notification notification : adapter.getNotifications()) {
          if (notification.getEventType() == Notification.REMOVE
              && notification.getFeature() == getModel1Package().getCompany_Categories()) {
            oldValue[0] = notification.getOldValue();
            return true;
          }
        }

        return false;
      }
    }.assertNoTimeOut();

    assertInstanceOf(Category.class, CDOUtil.getEObject((EObject) oldValue[0]));
  }
Example #23
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);
  }
Example #24
0
  public void testBugzilla_266982() throws Exception {
    final Customer customer = getModel1Factory().createCustomer();
    final boolean done[] = new boolean[1];
    final Exception exception[] = new Exception[1];
    done[0] = false;
    customer.setName("customer");

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

    Runnable changeObjects =
        new Runnable() {
          public void run() {
            try {
              CDOSession session = openSession();
              CDOTransaction transaction = session.openTransaction();
              Customer customerToLoad =
                  (Customer)
                      CDOUtil.getEObject(
                          transaction.getObject(CDOUtil.getCDOObject(customer).cdoID()));
              while (!done[0]) {
                // Could fail if the attach is not thread safe
                customerToLoad.getName();
              }

              transaction.close();
              session.close();
            } catch (Exception ex) {
              exception[0] = ex;
            }
          }
        };

    new Thread(changeObjects).start();

    for (int i = 0; i < 500 && exception[0] == null; i++) {
      customer.setName("Ottawa" + i);
      transaction.commit();
    }

    done[0] = true;
    if (exception[0] != null) {
      exception[0].printStackTrace();
      fail(exception[0].getMessage());
    }

    session.close();
  }
  public void testBugzilla_289932() throws Exception {
    CDOSession session = openSession();
    session.getPackageRegistry().putEPackage(getModel5Package());
    CDOTransaction transaction = session.openTransaction();
    CDOResource res1 = transaction.createResource(getResourcePath("/res1"));

    TestFeatureMap testFeatureMap = getModel5Factory().createTestFeatureMap();
    Doctor doctor = getModel5Factory().createDoctor();
    testFeatureMap.getDoctors().add(doctor);
    res1.getContents().add(testFeatureMap);
    transaction.commit();

    // Transient feature for Doctor, should not persist it.
    assertTransient(doctor);
  }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   CDOSession session = openSession();
   CDOTransaction transaction = session.openTransaction();
   CDOResource resource = transaction.createResource(getResourcePath(RESOURCE_NAME));
   Company company = getModel1Factory().createCompany();
   for (int i = 0; i < NB_CATEGORY; i++) {
     Category category = getModel1Factory().createCategory();
     company.getCategories().add(category);
   }
   resource.getContents().add(company);
   transaction.commit();
   transaction.close();
   session.close();
 }
Example #27
0
  public void testNullReference() throws Exception {
    {
      msg("Opening session");
      CDOSession session = openSession();

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

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

      msg("Creating orderDetail");
      OrderDetail orderDetail = getModel1Factory().createOrderDetail();

      msg("Setting price");
      orderDetail.setPrice(4.75f);

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

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

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

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

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

    msg("Getting contents");
    EList<EObject> contents = resource.getContents();

    msg("Getting supplier");
    OrderDetail orderDetail = (OrderDetail) contents.get(0);
    assertNotNull(orderDetail);

    msg("Verifying price");
    assertEquals(4.75f, orderDetail.getPrice());

    msg("Verifying product");
    assertEquals(null, orderDetail.getProduct());
  }
Example #28
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());
  }
Example #29
0
  public void testLoadObject() 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"));

    msg("Getting contents");
    EList<EObject> contents = resource.getContents();

    msg("Getting supplier");
    Supplier s = (Supplier) contents.get(0);
    assertNotNull(s);

    msg("Verifying name");
    assertEquals("Stepper", s.getName());
  }
Example #30
0
  public void testAttachObject() throws Exception {
    Supplier supplier = getModel1Factory().createSupplier();
    supplier.setName("Stepper");

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

    EList<EObject> contents = resource.getContents();
    contents.add(supplier);
    assertNew(supplier, transaction);
    assertEquals(transaction, CDOUtil.getCDOObject(supplier).cdoView());
    assertEquals(resource, CDOUtil.getCDOObject(supplier).cdoDirectResource());
    assertEquals(0, CDOUtil.getCDOObject(supplier).cdoRevision().getVersion());
    assertEquals(resource, supplier.eResource());
    assertEquals(null, supplier.eContainer());
  }