public void testDeleteExistingObject() throws Exception { { msg("Open session & local transaction"); CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOPushTransaction pushTransaction = openPushTransaction(transaction); file = pushTransaction.getFile(); CDOResource resource = transaction.getOrCreateResource(getResourcePath(resourcePath)); msg("Remove an existing element"); Supplier supplier = (Supplier) resource.getContents().get(0); resource.getContents().remove(supplier); msg("Commit"); pushTransaction.commit(); session.close(); } { msg("Reload previous local session"); CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOPushTransaction pushTransaction = openPushTransaction(transaction, file); assertEquals(true, transaction.isDirty()); assertEquals(1, transaction.getRevisionDeltas().size()); push(transaction, pushTransaction); session.close(); } CDOSession session = openSession(); CDOView view = session.openView(); CDOResource resource = view.getResource(getResourcePath(resourcePath)); assertEquals(1, resource.getContents().size()); }
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 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 testUnsetValue() throws Exception { { msg("Open session & local transaction"); CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOPushTransaction pushTransaction = openPushTransaction(transaction); file = pushTransaction.getFile(); CDOResource resource = transaction.getOrCreateResource(getResourcePath(resourcePath)); Supplier supplier = (Supplier) resource.getContents().get(0); supplier.setName(null); msg("Commit"); pushTransaction.commit(); session.close(); } { msg("Reload previous local session"); CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOPushTransaction pushTransaction = openPushTransaction(transaction, file); assertEquals(true, transaction.isDirty()); CDOResource resource = transaction.getOrCreateResource(getResourcePath(resourcePath)); Supplier supplier = (Supplier) resource.getContents().get(0); assertNull(supplier.getName()); push(transaction, pushTransaction); session.close(); } CDOSession session = openSession(); CDOView view = session.openView(); CDOResource resource = view.getResource(getResourcePath(resourcePath)); Supplier supplier = (Supplier) resource.getContents().get(0); assertNull(supplier.getName()); }
public void testDirectResource() throws Exception { CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOResource resource1 = transaction.getOrCreateResource(getResourcePath("/test1")); // Resource resource1 = new XMIResourceImpl(); Category cat1 = getModel1Factory().createCategory(); assertTransient(cat1); Category cat2 = getModel1Factory().createCategory(); assertTransient(cat2); // resource1.getContents().add(cat2); resource1.getContents().add(cat1); cat1.getCategories().add(cat2); assertEquals(null, CDOUtil.getCDOObject(cat2).cdoDirectResource()); assertEquals(resource1, CDOUtil.getCDOObject(cat1).cdoDirectResource()); assertEquals(null, ((InternalEObject) cat2).eDirectResource()); assertEquals(resource1, ((InternalEObject) cat1).eDirectResource()); transaction.close(); session.close(); }
@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 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()); }
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 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); }
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 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 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()); }
@Override protected void unhookTransaction(CDOTransaction transaction) { transaction.removeListener(collector); adapter.dispose(); adapter = null; transaction.removeTransactionHandler(handler); }
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); }
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_AUDITING) public void testReloadingRevisions() throws Exception { final String RESOURCE_NAME = "resource"; Set<CDOID> ids = new HashSet<CDOID>(); long timeStampOfHoleCommit; CDOSession initialSession = openSession(); { // create model history CDOTransaction openTransaction = initialSession.openTransaction(); CDOResource resource = openTransaction.getOrCreateResource(getResourcePath(RESOURCE_NAME)); // creating initial commit Company createdCompany = getModel1Factory().createCompany(); createdCompany.setName("CompanyTesting"); createdCompany.setCity("City"); createdCompany.setStreet("Street"); resource.getContents().add(createdCompany); openTransaction.commit(); // collect id's for (TreeIterator<EObject> allContents = resource.getAllContents(); allContents.hasNext(); ) { CDOObject next = CDOUtil.getCDOObject(allContents.next()); ids.add(next.cdoID()); } // making holes - detaching List<EObject> contents = new ArrayList<EObject>(resource.getContents()); for (int i = 0; i < contents.size(); i++) { EcoreUtil.delete(contents.get(i), true); } timeStampOfHoleCommit = openTransaction.commit().getTimeStamp(); } // check when locally cached elements are availabe checkRevisionsOnGivenSession(ids, timeStampOfHoleCommit, 2, initialSession); // turn of revision download by timestamp checkRevisionsOnGivenSession(ids, -1, 2, initialSession); initialSession.close(); checkRevisions(ids, timeStampOfHoleCommit, 2); // turn of revision download by timestamp checkRevisions(ids, -1, 2); // clear caches clearCache(getRepository().getRevisionManager()); checkRevisions(ids, timeStampOfHoleCommit, 2); // turn of revision download by timestamp clearCache(getRepository().getRevisionManager()); checkRevisions(ids, -1, 2); }
public void testStartTransaction() throws Exception { msg("Opening session"); CDOSession session = openSession(); msg("Opening transaction"); CDOTransaction transaction = session.openTransaction(); assertNotNull(transaction); assertEquals(session, transaction.getSession()); }
private void testRepo(String repoName) throws CommitException { CDOSession session = openSession(repoName); CDOTransaction transaction = session.openTransaction(); CDOResource resource = transaction.getResource(getResourcePath("/res1")); for (Object o : resource.getContents()) { final CDOObject cdoObject = CDOUtil.getCDOObject((EObject) o); System.err.println(cdoObject.cdoID()); System.err.println(cdoObject.cdoID()); } CDOResource resource2 = transaction.getResource(getResourcePath("/res2")); CDOResource resource3 = transaction.getResource(getResourcePath("/res3")); assertNotNull(resource2); assertNotNull(resource3); List<Bz380987_Person> persons = new ArrayList<Bz380987_Person>(); List<Bz380987_Place> places = new ArrayList<Bz380987_Place>(); List<Bz380987_Group> groups = new ArrayList<Bz380987_Group>(); for (int i = 0; i < 15; i++) { if (i < 5) { persons.add((Bz380987_Person) resource.getContents().get(i)); } else if (i < 10) { places.add((Bz380987_Place) resource.getContents().get(i)); } else { groups.add((Bz380987_Group) resource.getContents().get(i)); } } assertEquals(5, persons.size()); assertEquals(5, places.size()); assertEquals(5, groups.size()); for (int i = 0; i < 5; i++) { assertEquals(5, persons.get(i).getGroup().size()); assertEquals(5, persons.get(i).getPlaces().size()); assertEquals(5, places.get(i).getPeople().size()); assertEquals(5, groups.get(i).getPeople().size()); } for (int i = 0; i < 5; i++) { for (Object o : persons.get(i).getGroup()) { final Bz380987_Group gr = (Bz380987_Group) o; System.err.println(gr.getPeople().size()); } persons.get(i).getGroup().removeAll(groups); assertEquals(0, persons.get(i).getGroup().size()); persons.get(i).getPlaces().removeAll(places); assertEquals(0, persons.get(i).getPlaces().size()); places.get(i).getPeople().removeAll(persons); assertEquals(0, places.get(i).getPeople().size()); groups.get(i).getPeople().removeAll(persons); assertEquals(0, groups.get(i).getPeople().size()); } transaction.rollback(); session.close(); }
@Override public void run() { for (int i = 0; i < TRANSACTIONS_PER_THREAD; i++) { CDOTransaction transaction = session.openTransaction(); attemptCommit(transaction); transaction.close(); ConcurrencyUtil.sleep(2); } latch.countDown(); }
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 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])); }
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); }
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 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(); }
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(); }
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); }
private void implicitRelease( Company company, LockType type, CDOTransaction tx, TestListener2 controlViewListener, boolean mustReceiveNotifications) throws CommitException { CDOViewLocksChangedEvent e; CDOObject cdoCompany = CDOUtil.getCDOObject(company); company.setName(company.getName() + "x"); // Make name field dirty cdoCompany.cdoWriteLock().lock(); if (mustReceiveNotifications) { controlViewListener.waitFor(1); e = (CDOViewLocksChangedEvent) controlViewListener.getEvents().get(0); assertSame(Operation.LOCK, e.getOperation()); assertSame(LockType.WRITE, e.getLockType()); } tx.commit(); if (mustReceiveNotifications) { controlViewListener.waitFor(2); e = (CDOViewLocksChangedEvent) controlViewListener.getEvents().get(1); assertSame(Operation.UNLOCK, e.getOperation()); assertNull(e.getLockType()); } if (!mustReceiveNotifications) { assertEquals(0, controlViewListener.getEvents().size()); } }
@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(); } }
@Override protected void doRun(DIModel selection, CDOTransaction transaction, IProgressMonitor monitor) throws CoreException { List<IStatus> failures = Lists.newArrayListWithExpectedSize(1); for (Object next : selection.getChildren()) { if (next instanceof CDOResource) { // get the resource local to this transaction CDOID oid = ((CDOResource) next).cdoID(); CDOResource toRename = (CDOResource) transaction.getObject(oid); if (toRename != null) { try { toRename.setName(getNewName(toRename.getName())); } catch (Exception e) { failures.add( error("Failed to rename resource " + toRename.getPath(), e)); // $NON-NLS-1$ } } } } if (!failures.isEmpty()) { throw new CoreException(wrap(failures, "Errors occurred in renaming model.")); // $NON-NLS-1$ } }
@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(); }