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(); }
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(); }
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()); }
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 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()); }
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 testAddNewObjectInObjectTwiceBetweenReloadAndPush() 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("Create a new element"); Category category = getModel1Factory().createCategory(); Company company = (Company) resource.getContents().get(1); company.getCategories().add(category); 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()); CDORevisionDelta delta = transaction.getRevisionDeltas().values().iterator().next(); assertNotNull(delta); msg("Create a new element"); Category category = getModel1Factory().createCategory(); CDOResource resource = transaction.getResource(getResourcePath(resourcePath)); resource.getContents().add(category); msg("Commit"); pushTransaction.commit(); msg("Create a new element"); category = getModel1Factory().createCategory(); resource.getContents().add(category); msg("Commit"); pushTransaction.commit(); push(transaction, pushTransaction); session.close(); } CDOSession session = openSession(); CDOView view = session.openView(); CDOResource resource = view.getResource(getResourcePath(resourcePath)); assertEquals(4, resource.getContents().size()); }
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()); }
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()); }
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()); }
public void testGetContentsClearedCache() 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(); session.close(); } clearCache(getRepository().getRevisionManager()); 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(); assertNotNull(contents); Supplier supplier = (Supplier) contents.get(0); String name = supplier.getName(); assertEquals("Stepper", name); }
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()); } }
public void testBugzilla() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); { CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOResource resource = transaction.createResource(getResourcePath("/res1")); transaction.createResource(getResourcePath("/res2")); transaction.createResource(getResourcePath("/res3")); 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 < 5; i++) { Bz380987_Person person = HibernateTestFactory.eINSTANCE.createBz380987_Person(); person.setName(i + ""); persons.add(person); Bz380987_Place place = HibernateTestFactory.eINSTANCE.createBz380987_Place(); place.setName(i + ""); places.add(place); Bz380987_Group group = HibernateTestFactory.eINSTANCE.createBz380987_Group(); groups.add(group); } for (int i = 0; i < 5; i++) { persons.get(i).getPlaces().addAll(places); places.get(i).getPeople().addAll(persons); groups.get(i).getPeople().addAll(persons); } resource.getContents().addAll(persons); resource.getContents().addAll(places); resource.getContents().addAll(groups); transaction.commit(); session.close(); CDOServerExporter.XML exporter = new CDOServerExporter.XML(getRepository()); exporter.exportRepository(baos); System.out.println(baos.toString()); } // clear the repo { CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOResource resource = transaction.getResource(getResourcePath("/res1")); resource.getContents().clear(); transaction.commit(); transaction.close(); session.close(); } // repo is cleared { CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOResource resource = transaction.getResource(getResourcePath("/res1")); assertEquals(0, resource.getContents().size()); transaction.commit(); transaction.close(); session.close(); } { InternalRepository repo3 = getRepository("repo3", false); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); CDOServerImporter.XML importer = new CDOServerImporter.XML(repo3); importer.importRepository(bais); } testRepo("repo3"); }