| /* |
| * Copyright (c) 2012, 2013 Eike Stepper (Berlin, Germany) and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Eike Stepper - initial API and implementation |
| */ |
| package org.eclipse.emf.cdo.tests.hibernate; |
| |
| import org.eclipse.emf.cdo.eresource.CDOResource; |
| import org.eclipse.emf.cdo.server.CDOServerExporter; |
| import org.eclipse.emf.cdo.server.CDOServerImporter; |
| import org.eclipse.emf.cdo.session.CDOSession; |
| import org.eclipse.emf.cdo.spi.server.InternalRepository; |
| import org.eclipse.emf.cdo.tests.AbstractCDOTest; |
| import org.eclipse.emf.cdo.transaction.CDOTransaction; |
| import org.eclipse.emf.cdo.util.CommitException; |
| |
| import org.eclipse.emf.common.util.TreeIterator; |
| import org.eclipse.emf.ecore.EObject; |
| |
| import java.io.ByteArrayInputStream; |
| import java.io.ByteArrayOutputStream; |
| |
| /** |
| * @author Martin Taal |
| */ |
| public class Hibernate_Failure_Test extends AbstractCDOTest |
| { |
| @Override |
| protected void doSetUp() throws Exception |
| { |
| disableConsole(); |
| super.doSetUp(); |
| skipStoreWithoutRawAccess(); |
| } |
| |
| @Override |
| protected void doTearDown() throws Exception |
| { |
| disableConsole(); |
| super.doTearDown(); |
| } |
| |
| /** |
| * TODO |
| * {@link org.eclipse.emf.cdo.server.IStoreAccessor.Raw#rawStore(org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision, org.eclipse.net4j.util.om.monitor.OMMonitor) |
| * rawStore()} is not adequate with range-based list mappings because they need deltas! |
| */ |
| @Skips("DB.ranges") |
| public void testImport() throws Exception |
| { |
| CDOSession session = openSession(); |
| CDOTransaction transaction = session.openTransaction(); |
| // CDOResource resource = transaction.createResource(getResourcePath("/res1")); |
| transaction.commit(); |
| // Customer eike = createCustomer("Eike"); |
| // resource.getContents().add(eike); |
| // SalesOrder salesOrder = createSalesOrder(eike); |
| // salesOrder.getOrderDetails().add(getModel1Factory().createOrderDetail()); |
| // resource.getContents().add(salesOrder); |
| // transaction.commit(); |
| session.close(); |
| |
| InternalRepository repo1 = getRepository(); |
| |
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| CDOServerExporter.XML exporter = new CDOServerExporter.XML(repo1); |
| exporter.exportRepository(baos); |
| System.out.println(baos.toString()); |
| |
| InternalRepository repo2 = getRepository("repo2", false); |
| |
| ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); |
| CDOServerImporter.XML importer = new CDOServerImporter.XML(repo2); |
| importer.importRepository(bais); |
| |
| useAfterImport("repo2"); |
| } |
| |
| private void useAfterImport(String repoName) throws CommitException |
| { |
| CDOSession session2 = openSession(repoName); |
| CDOTransaction transaction2 = session2.openTransaction(); |
| |
| // Read all repo contents |
| TreeIterator<EObject> iter = transaction2.getRootResource().getAllContents(); |
| while (iter.hasNext()) |
| { |
| iter.next(); |
| } |
| |
| // Add content from a new package |
| CDOResource resource = transaction2.createResource(getResourcePath("/r1")); |
| resource.getContents().add(getModel3Factory().createPolygon()); |
| transaction2.commit(); |
| |
| session2.close(); |
| } |
| } |