diff options
author | Eike Stepper | 2015-02-15 10:37:00 +0000 |
---|---|---|
committer | Eike Stepper | 2015-02-15 11:46:30 +0000 |
commit | 13c44096eb22fff760f912ef50c92ab55b0c74c1 (patch) | |
tree | 3a68253f5f6ff5eb08e01110943aebf3e777104d | |
parent | 4752bd84dd94e1efba9429dc898cfa44ecb1caee (diff) | |
download | cdo-13c44096eb22fff760f912ef50c92ab55b0c74c1.tar.gz cdo-13c44096eb22fff760f912ef50c92ab55b0c74c1.tar.xz cdo-13c44096eb22fff760f912ef50c92ab55b0c74c1.zip |
[458349] Consolidate UI
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349
27 files changed, 620 insertions, 152 deletions
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml index 6f8daa066d..6b6e1d4cca 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml @@ -352,9 +352,13 @@ name="Disconnect Repository" defaultHandler="org.eclipse.emf.cdo.explorer.ui.handlers.RepositoryDisconnectHandler"/> <command - id="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckout" - name="Checkout Repository" - defaultHandler="org.eclipse.emf.cdo.explorer.ui.handlers.RepositoryCheckoutHandler"/> + id="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckoutOnline" + name="Checkout Repository Online" + defaultHandler="org.eclipse.emf.cdo.explorer.ui.handlers.RepositoryCheckoutHandler$Online"/> + <command + id="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckoutOffline" + name="Checkout Repository Offline" + defaultHandler="org.eclipse.emf.cdo.explorer.ui.handlers.RepositoryCheckoutHandler$Offline"/> <command id="org.eclipse.emf.cdo.explorer.ui.CreateBranch" name="Create Branch" @@ -489,11 +493,27 @@ allPopups="false" locationURI="popup:org.eclipse.ui.popup.any?group=group.checkout"> <command - commandId="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckout" + commandId="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckoutOnline" icon="icons/checkout.gif" label="Checkout" style="push" - tooltip="Check the repository out"> + tooltip="Check the repository out as an online connection"> + <visibleWhen + checkEnabled="false"> + <with + variable="activeMenuSelection"> + <iterate> + <adapt type="org.eclipse.emf.cdo.explorer.repositories.CDORepositoryElement"/> + </iterate> + </with> + </visibleWhen> + </command> + <command + commandId="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckoutOffline" + icon="icons/checkout.gif" + label="Checkout Offline" + style="push" + tooltip="Check the repository out as an offline connection"> <visibleWhen checkEnabled="false"> <with diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/DeleteDialog.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/DeleteDialog.java index 7f89af1d64..abda5eae09 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/DeleteDialog.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/DeleteDialog.java @@ -65,25 +65,6 @@ public class DeleteDialog extends TitleAreaDialog int size = elements.length; if (size != 0) { - List<String> contents = new ArrayList<String>(); - for (AbstractElement element : elements) - { - collectContents(contents, element.getFolder()); - } - - Collections.sort(contents); - StringBuilder builder = new StringBuilder(); - - for (String path : contents) - { - if (builder.length() != 0) - { - builder.append('\n'); - } - - builder.append(path); - } - String type = elements[0] instanceof CDORepository ? "Repository" : "Checkout"; String types = elements[0] instanceof CDORepository ? "Repositories" : "Checkouts"; @@ -118,7 +99,36 @@ public class DeleteDialog extends TitleAreaDialog text = new Text(container, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.MULTI); text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - text.setText(builder.toString()); + + List<String> contents = new ArrayList<String>(); + for (AbstractElement element : elements) + { + collectContents(contents, element.getFolder()); + } + + if (contents.isEmpty()) + { + deleteContentsButton.setSelection(false); + deleteContentsButton.setEnabled(false); + text.setEnabled(false); + } + else + { + Collections.sort(contents); + + StringBuilder builder = new StringBuilder(); + for (String path : contents) + { + if (builder.length() != 0) + { + builder.append('\n'); + } + + builder.append(path); + } + + text.setText(builder.toString()); + } deleteContentsButton.setFocus(); } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutDropAdapterAssistant.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutDropAdapterAssistant.java index 557484a582..bef81a495a 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutDropAdapterAssistant.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutDropAdapterAssistant.java @@ -10,6 +10,7 @@ */ package org.eclipse.emf.cdo.explorer.ui.checkouts; +import org.eclipse.emf.cdo.CDOState; import org.eclipse.emf.cdo.eresource.CDOResource; import org.eclipse.emf.cdo.eresource.CDOResourceFolder; import org.eclipse.emf.cdo.eresource.CDOResourceNode; @@ -22,6 +23,8 @@ import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.net4j.util.ObjectUtil; + import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; @@ -373,25 +376,40 @@ public class CDOCheckoutDropAdapterAssistant extends CommonDropAdapterAssistant private static void setUniqueName(CDOResourceNode resourceNode, EList<? extends EObject> contents) { + boolean nameConflict = false; + String resourceName = resourceNode.getName(); Set<String> names = new HashSet<String>(); + for (Object object : contents) { - names.add(((CDOResourceNode)object).getName()); + if (object != resourceNode) + { + String name = ((CDOResourceNode)object).getName(); + if (ObjectUtil.equals(name, resourceName)) + { + nameConflict = true; + } + + names.add(name); + } } - String copyName = resourceNode.getName() + "-copy"; - for (int i = 0; i < Integer.MAX_VALUE; i++) + if (nameConflict) { - String name = copyName; - if (i != 0) + String copyName = resourceName + "-copy"; + for (int i = 0; i < Integer.MAX_VALUE; i++) { - name += i; - } + String name = copyName; + if (i != 0) + { + name += i; + } - if (!names.contains(name)) - { - resourceNode.setName(name); - return; + if (!names.contains(name)) + { + resourceNode.setName(name); + return; + } } } } @@ -544,19 +562,27 @@ public class CDOCheckoutDropAdapterAssistant extends CommonDropAdapterAssistant super(objects, target); } + /** + * TODO Consolidate with {@link ResourceNodeToFolder#insert(List, CDOResourceFolder, IProgressMonitor)}. + */ @Override protected void insert(List<? extends EObject> objects, CDOResource target, IProgressMonitor monitor) { EList<EObject> contents = target.getContents(); for (EObject object : objects) { - contents.add(object); + CDOResourceNode resourceNode = (CDOResourceNode)object; + boolean copy = resourceNode.cdoState() == CDOState.TRANSIENT; + contents.add(resourceNode); + // resourceNode.setFolder(null); - // The object must be attached before getParent() is called! - if (CDOExplorerUtil.getParent(object) == target) + if (copy) { - CDOResourceNode resourceNode = (CDOResourceNode)object; - setUniqueName(resourceNode, contents); + // The object must be attached before getParent() is called! + if (CDOExplorerUtil.getParent(object) == target) + { + setUniqueName(resourceNode, contents); + } } } } @@ -579,12 +605,17 @@ public class CDOCheckoutDropAdapterAssistant extends CommonDropAdapterAssistant for (EObject object : objects) { CDOResourceNode resourceNode = (CDOResourceNode)object; + boolean copy = resourceNode.cdoState() == CDOState.TRANSIENT; nodes.add(resourceNode); + // ((InternalCDOObject)resourceNode).eSetResource(null, null); - // The resourceNode must be attached before getParent() is called! - if (CDOExplorerUtil.getParent(resourceNode) == target) + if (copy) { - setUniqueName(resourceNode, nodes); + // The resourceNode must be attached before getParent() is called! + if (CDOExplorerUtil.getParent(resourceNode) == target) + { + setUniqueName(resourceNode, nodes); + } } } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java index 882d8c44fb..638c6d52b8 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java @@ -26,9 +26,12 @@ import java.util.Properties; */ public class RepositoryCheckoutHandler extends AbstractBaseHandler<CDORepositoryElement> { - public RepositoryCheckoutHandler() + private final String type; + + protected RepositoryCheckoutHandler(String type) { super(CDORepositoryElement.class, null); + this.type = type; } @Override @@ -39,7 +42,7 @@ public class RepositoryCheckoutHandler extends AbstractBaseHandler<CDORepository CDORepository repository = repositoryElement.getRepository(); Properties properties = new Properties(); - properties.put("type", "online"); + properties.put("type", type); properties.put("label", repository.getLabel()); properties.put("repository", repository.getID()); properties.put("branchID", Integer.toString(repositoryElement.getBranchID())); @@ -51,4 +54,26 @@ public class RepositoryCheckoutHandler extends AbstractBaseHandler<CDORepository checkout.open(); } } + + /** + * @author Eike Stepper + */ + public static final class Online extends RepositoryCheckoutHandler + { + public Online() + { + super("online"); + } + } + + /** + * @author Eike Stepper + */ + public static final class Offline extends RepositoryCheckoutHandler + { + public Offline() + { + super("offline"); + } + } } diff --git a/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF index 47ebe7afc3..a803f5d5a9 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)", org.eclipse.emf.cdo.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport, + org.eclipse.emf.cdo.workspace;bundle-version="[4.0.0,5.0.0)", org.eclipse.emf.cdo.server;bundle-version="[4.0.0,5.0.0)", org.eclipse.emf.cdo.server.db;bundle-version="[4.0.0,5.0.0)", org.eclipse.net4j.db.h2;bundle-version="[4.0.0,5.0.0)" diff --git a/plugins/org.eclipse.emf.cdo.explorer/plugin.xml b/plugins/org.eclipse.emf.cdo.explorer/plugin.xml index 40c47c4e92..afe66fe67d 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.explorer/plugin.xml @@ -27,13 +27,13 @@ id="org.eclipse.emf.cdo.explorer.repository.properties" type="org.eclipse.emf.cdo.explorer.repositories.CDORepository" namespace="org.eclipse.emf.cdo.explorer.repository" - properties="state,connected,id,folder,uri" + properties="state,connected,type,id,folder,uri" class="org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryProperties$Tester"/> <propertyTester id="org.eclipse.emf.cdo.explorer.checkout.properties" type="org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout" namespace="org.eclipse.emf.cdo.explorer.checkout" - properties="state,open,id,folder,rootType,canContainResources,branchID,branch,timeStamp,readOnly,rootID,repositoryID,repositoryFolder,repositoryURI" + properties="state,open,type,id,folder,rootType,canContainResources,branchID,branch,timeStamp,readOnly,rootID,repositoryID,repositoryFolder,repositoryURI" class="org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutProperties$Tester"/> </extension> diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java index 1a7f2ab5fa..fb1be35412 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java @@ -22,6 +22,8 @@ import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.container.IPluginContainer; import org.eclipse.net4j.util.event.IEvent; import org.eclipse.net4j.util.event.IListener; import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; @@ -208,10 +210,15 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec { state = State.Closing; - rootObject.eAdapters().remove(this); - view.close(); - - ((CDORepositoryImpl)repository).closeCheckout(this); + try + { + rootObject.eAdapters().remove(this); + closeView(); + } + finally + { + ((CDORepositoryImpl)repository).closeCheckout(this); + } } finally { @@ -374,6 +381,11 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec properties.put(PROP_ROOT_ID, string); } + protected IManagedContainer getContainer() + { + return IPluginContainer.INSTANCE; + } + protected EObject loadRootObject() { return view.getObject(rootID); @@ -381,6 +393,11 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec protected abstract CDOView openView(CDOSession session); + protected void closeView() + { + view.close(); + } + public static String getCDOIDString(CDOID id) { StringBuilder builder = new StringBuilder(); diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java index b27c2db045..524d35c1ec 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java @@ -58,9 +58,25 @@ public class CDOCheckoutManagerImpl extends AbstractManager<CDOCheckout> impleme return new OnlineCDOCheckout(); } + if ("offline".equals(type)) + { + return new OfflineCDOCheckout(); + } + throw new IllegalArgumentException("Unknown type: " + type); } + @Override + protected void doDeactivate() throws Exception + { + for (CDOCheckout checkout : getCheckouts()) + { + checkout.close(); + } + + super.doDeactivate(); + } + static { // Make sure all object types are registered. diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutProperties.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutProperties.java index f171c1d5d5..da14c8f8b7 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutProperties.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutProperties.java @@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.internal.explorer.checkouts; import org.eclipse.emf.cdo.common.util.CDOCommonUtil; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout.ObjectType; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository; import org.eclipse.emf.cdo.internal.explorer.AbstractElement; import org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryProperties; import org.eclipse.emf.cdo.view.CDOView; @@ -52,6 +53,14 @@ public class CDOCheckoutProperties extends Properties<CDOCheckout> return checkout.isOpen(); } }); + add(new Property<CDOCheckout>("type", "Type", "The type of this checkout", CATEGORY_CHECKOUT) + { + @Override + protected Object eval(CDOCheckout checkout) + { + return checkout.getType(); + } + }); add(new Property<CDOCheckout>("id", "ID", "The ID of this checkout", CATEGORY_CHECKOUT) { @@ -157,7 +166,13 @@ public class CDOCheckoutProperties extends Properties<CDOCheckout> @Override protected Object eval(CDOCheckout checkout) { - return checkout.getRepository().getID(); + CDORepository repository = checkout.getRepository(); + if (repository != null) + { + return repository.getID(); + } + + return null; } }); @@ -167,7 +182,13 @@ public class CDOCheckoutProperties extends Properties<CDOCheckout> @Override protected Object eval(CDOCheckout checkout) { - return ((AbstractElement)checkout.getRepository()).getFolder(); + AbstractElement repository = (AbstractElement)checkout.getRepository(); + if (repository != null) + { + return repository.getFolder(); + } + + return null; } }); @@ -177,7 +198,13 @@ public class CDOCheckoutProperties extends Properties<CDOCheckout> @Override protected Object eval(CDOCheckout checkout) { - return checkout.getRepository().getURI(); + CDORepository repository = checkout.getRepository(); + if (repository != null) + { + return repository.getURI(); + } + + return null; } }); } diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java new file mode 100644 index 0000000000..f9758a5c57 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2004-2014 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.internal.explorer.checkouts; + +import org.eclipse.emf.cdo.common.revision.CDORevisionCache; +import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository; +import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration; +import org.eclipse.emf.cdo.net4j.CDONet4jUtil; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.db.CDODBUtil; +import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.session.CDOSessionConfiguration; +import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.workspace.CDOWorkspace; +import org.eclipse.emf.cdo.workspace.CDOWorkspaceBase; +import org.eclipse.emf.cdo.workspace.CDOWorkspaceConfiguration; +import org.eclipse.emf.cdo.workspace.CDOWorkspaceUtil; + +import org.eclipse.net4j.Net4jUtil; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.db.DBUtil; +import org.eclipse.net4j.db.IDBAdapter; +import org.eclipse.net4j.db.IDBConnectionProvider; +import org.eclipse.net4j.util.container.IManagedContainer; + +import org.h2.jdbcx.JdbcDataSource; + +import java.io.File; + +/** + * @author Eike Stepper + */ +public class OfflineCDOCheckout extends CDOCheckoutImpl +{ + private CDOWorkspace workspace; + + public OfflineCDOCheckout() + { + } + + @Override + protected CDOView openView(CDOSession session) + { + final IManagedContainer container = getContainer(); + final CDORepository repository = getRepository(); + + final String connectorType = repository.getConnectorType(); + final String connectorDescription = repository.getConnectorDescription(); + final String repositoryName = repository.getName(); + + CDOSessionConfigurationFactory remote = new CDOSessionConfigurationFactory() + { + public CDOSessionConfiguration createSessionConfiguration() + { + IConnector connector = Net4jUtil.getConnector(container, connectorType, connectorDescription); + + CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration(); + config.setConnector(connector); + config.setRepositoryName(repositoryName); + config.setRevisionManager(CDORevisionUtil.createRevisionManager(CDORevisionCache.NOOP)); + + return config; + } + }; + + File folder = getFolder(); + File storeFolder = new File(folder, "store"); + File dbPrefix = new File(storeFolder, "db"); + + JdbcDataSource dataSource = new JdbcDataSource(); + dataSource.setURL("jdbc:h2:" + dbPrefix); + + IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(true, true, false); + IDBAdapter dbAdapter = DBUtil.getDBAdapter("h2"); + IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource); + IStore store = CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider); + + File baseFolder = new File(folder, "base"); + CDOWorkspaceBase base = CDOWorkspaceUtil.createFolderWorkspaceBase(baseFolder); + + String localRepositoryName = repositoryName + "-workspace" + getID(); + int branchID = getBranchID(); + long timeStamp = getTimeStamp(); + + CDOWorkspaceConfiguration configuration = CDOWorkspaceUtil.createWorkspaceConfiguration(); + configuration.setLocalRepositoryName(localRepositoryName); + configuration.setRemote(remote); + configuration.setStore(store); + configuration.setBase(base); + + if (storeFolder.isDirectory()) + { + workspace = configuration.open(); + } + else + { + configuration.setBranchID(branchID); + configuration.setTimeStamp(timeStamp); + + workspace = configuration.checkout(); + } + + if (isReadOnly()) + { + return workspace.openView(); + } + + return workspace.openTransaction(); + } + + @Override + protected void closeView() + { + super.closeView(); + + if (workspace != null) + { + workspace.close(); + workspace = null; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java index d1bb3cae3b..c3034f0514 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java @@ -97,6 +97,17 @@ public class CDORepositoryManagerImpl extends AbstractManager<CDORepository> imp throw new IllegalArgumentException("Unknown type: " + type); } + @Override + protected void doDeactivate() throws Exception + { + for (CDORepository repository : getRepositories()) + { + repository.disconnect(); + } + + super.doDeactivate(); + } + /** * @author Eike Stepper */ diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryProperties.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryProperties.java index 1fa2e2de1c..09ae93b351 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryProperties.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryProperties.java @@ -50,6 +50,15 @@ public class CDORepositoryProperties extends Properties<CDORepository> } }); + add(new Property<CDORepository>("type", "Type", "The type of this repository", CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDORepository repository) + { + return repository.getType(); + } + }); + add(new Property<CDORepository>("id", "ID", "The ID of this repository", CATEGORY_REPOSITORY) { @Override diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/BranchNotificationIndication.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/BranchNotificationIndication.java index a36ae27011..fa3dd85cc0 100644 --- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/BranchNotificationIndication.java +++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/BranchNotificationIndication.java @@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchChangedEvent.ChangeKind; import org.eclipse.emf.cdo.common.protocol.CDODataInput; import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; import java.io.IOException; @@ -40,5 +41,10 @@ public class BranchNotificationIndication extends CDOClientIndication String name = in.readString(); ((InternalCDOBranch)branch).basicSetName(name); } + else + { + InternalCDOBranchManager branchManager = getSession().getBranchManager(); + branchManager.handleBranchChanged((InternalCDOBranch)branch, changeKind); + } } } diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java index 6cdc28c9e0..33a63d0b79 100644 --- a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java +++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java @@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader.BranchInfo; +import org.eclipse.emf.cdo.spi.server.InternalSession; import org.eclipse.emf.cdo.spi.server.InternalSessionManager; import java.io.IOException; @@ -50,8 +51,9 @@ public class CreateBranchIndication extends CDOServerWriteIndication InternalCDOBranch branch = branchManager.createBranch(branchID, branchInfo.getName(), baseBranch, branchInfo.getBaseTimeStamp()); + InternalSession session = getSession(); InternalSessionManager sessionManager = getRepository().getSessionManager(); - sessionManager.sendBranchNotification(getSession(), branch, ChangeKind.CREATED); + sessionManager.sendBranchNotification(session, branch, ChangeKind.CREATED); out.writeInt(branch.getID()); out.writeLong(branch.getBase().getTimeStamp()); diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RenameBranchIndication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RenameBranchIndication.java index 987d312665..f863a40396 100644 --- a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RenameBranchIndication.java +++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RenameBranchIndication.java @@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.protocol.CDODataOutput; import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; +import org.eclipse.emf.cdo.spi.server.InternalSession; import org.eclipse.emf.cdo.spi.server.InternalSessionManager; import org.eclipse.net4j.util.ObjectUtil; @@ -58,8 +59,9 @@ public class RenameBranchIndication extends CDOServerWriteIndication branch.setName(newName); + InternalSession session = getSession(); InternalSessionManager sessionManager = getRepository().getSessionManager(); - sessionManager.sendBranchNotification(getSession(), branch, ChangeKind.RENAMED); + sessionManager.sendBranchNotification(session, branch, ChangeKind.RENAMED); out.writeBoolean(true); } diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java index ab6fa6c775..9f8d4b626f 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java @@ -15,9 +15,11 @@ package org.eclipse.emf.cdo.tests; import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.CDOState; import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; import org.eclipse.emf.cdo.common.lob.CDOBlob; import org.eclipse.emf.cdo.common.lob.CDOClob; import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionData; import org.eclipse.emf.cdo.eresource.CDOBinaryResource; import org.eclipse.emf.cdo.eresource.CDOResource; import org.eclipse.emf.cdo.eresource.CDOResourceFolder; @@ -546,6 +548,52 @@ public class ResourceTest extends AbstractCDOTest session.close(); } + @CleanRepositoriesBefore(reason = "Root resource access") + @CleanRepositoriesAfter(reason = "Root resource access") + public void testMoveToRoot() throws Exception + { + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource rootResource = transaction.getRootResource(); + CDOResourceFolder resourceFolder = transaction.createResourceFolder("folder1"); + CDOResource resource = transaction.createResource("/folder1/resource"); + transaction.commit(); + + CDORevisionData data = resource.cdoRevision().data(); + assertEquals(resourceFolder.cdoID(), data.getContainerID()); + assertEquals(true, CDOIDUtil.isNull(data.getResourceID())); + + EList<EObject> contents = rootResource.getContents(); + contents.add(resource); + + data = resource.cdoRevision().data(); + assertEquals(true, CDOIDUtil.isNull((CDOID)data.getContainerID())); + assertEquals(rootResource.cdoID(), data.getResourceID()); + } + + @CleanRepositoriesBefore(reason = "Root resource access") + @CleanRepositoriesAfter(reason = "Root resource access") + public void testMoveFromRoot() throws Exception + { + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource rootResource = transaction.getRootResource(); + CDOResourceFolder resourceFolder = transaction.createResourceFolder("folder1"); + CDOResource resource = transaction.createResource("resource"); + transaction.commit(); + + CDORevisionData data = resource.cdoRevision().data(); + assertEquals(true, CDOIDUtil.isNull((CDOID)data.getContainerID())); + assertEquals(rootResource.cdoID(), data.getResourceID()); + + EList<CDOResourceNode> nodes = resourceFolder.getNodes(); + nodes.add(resource); + + data = resource.cdoRevision().data(); + assertEquals(resourceFolder.cdoID(), data.getContainerID()); + assertEquals(true, CDOIDUtil.isNull(data.getResourceID())); + } + public void testDuplicatePath() throws Exception { CDOSession session = openSession(); diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java index 463dab7236..cda42910f5 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java @@ -70,12 +70,11 @@ public class Bugzilla_441136_Test extends AbstractCDOTest Company company = getModel1Factory().createCompany(); resource.getContents().add(company); transaction.commit(useMonitor ? new NullProgressMonitor() : null); - String assertMessage = " differents kinds of requests should be sent, QueryRequest, QueryCancel, LoadRevisionsRequest and CommitTransactionRequest"; + String assertMessage = " differents kinds of requests should have been sent, QueryRequest, QueryCancel, LoadRevisionsRequest and CommitTransactionRequest"; int nbExpectedCalls; Map<Short, Integer> nbRequestsCalls = nbRequestsCallsCounter.getNBRequestsCalls(); if (!useMonitor) { - // QueryRequest, QueryCancel are used to get the resourcePath nbExpectedCalls = 4; assertEquals(nbExpectedCalls + assertMessage, nbExpectedCalls, nbRequestsCalls.size()); @@ -87,7 +86,8 @@ public class Bugzilla_441136_Test extends AbstractCDOTest else { nbExpectedCalls = 5; - assertMessage += " and MonitorProgressIndications should be received"; + assertMessage += " and MonitorProgressIndications should have been received"; + // QueryRequest, QueryCancel are used to get the resourcePath assertEquals(nbExpectedCalls + assertMessage, nbExpectedCalls, nbRequestsCalls.size()); assertEquals(true, nbRequestsCalls.containsKey(CDOProtocolConstants.SIGNAL_QUERY)); @@ -98,9 +98,11 @@ public class Bugzilla_441136_Test extends AbstractCDOTest } } - class CommitTransactionIndicationWaiting implements CDOCommitInfoHandler + /** + * @author Esteban Dugueperoux + */ + private static final class CommitTransactionIndicationWaiting implements CDOCommitInfoHandler { - public void handleCommitInfo(CDOCommitInfo commitInfo) { try @@ -112,6 +114,5 @@ public class Bugzilla_441136_Test extends AbstractCDOTest ex.printStackTrace(); } } - } } diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java index f1341c87de..23538e27d4 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java @@ -23,18 +23,18 @@ import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.event.IEvent; import org.eclipse.net4j.util.event.IListener; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + /** * Test that when another client creates a branch, and we call {@link CDOBranch#getBranches()} for the first time, it calls all existing branches. * * @author Esteban Dugueperoux */ @Requires(IRepositoryConfig.CAPABILITY_BRANCHING) -@CleanRepositoriesBefore(reason = "to have assert works") +@CleanRepositoriesBefore(reason = "Branching") public class Bugzilla_447912_Test extends AbstractCDOTest { - - private NewBranchNotificationListener newBranchNotificationListener; - public void testCDOBranch_getBranches() throws Exception { CDOSession session1 = openSession(); @@ -48,12 +48,11 @@ public class Bugzilla_447912_Test extends AbstractCDOTest CDOView view2 = session2.openView(); CDOBranch mainBranchFromView2 = view2.getBranch(); - newBranchNotificationListener = new NewBranchNotificationListener(session2); - synchronized (newBranchNotificationListener) - { - mainBranchFromView1.createBranch(branchB2Name); - newBranchNotificationListener.wait(); - } + NewBranchNotificationListener listener = new NewBranchNotificationListener(session2); + mainBranchFromView1.createBranch(branchB2Name); + + assertEquals("Timeout - No CDOBranchChangedEvent received.", true, + listener.getLatch().await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)); assertEquals(mainBranchFromView1.getBranches().length, mainBranchFromView2.getBranches().length); assertEquals(session1.getBranchManager().getMainBranch().getBranches().length, session2.getBranchManager() @@ -67,24 +66,33 @@ public class Bugzilla_447912_Test extends AbstractCDOTest assertEquals(branchB2Name, mainBranchFromView2.getBranches()[1].getName()); } - class NewBranchNotificationListener implements IListener + /** + * @author Esteban Dugueperoux + */ + private static final class NewBranchNotificationListener implements IListener { + private final CountDownLatch latch = new CountDownLatch(1); + public NewBranchNotificationListener(CDOSession session) { session.getBranchManager().addListener(this); } - public synchronized void notifyEvent(IEvent event) + public final CountDownLatch getLatch() + { + return latch; + } + + public void notifyEvent(IEvent event) { if (event instanceof CDOBranchChangedEvent) { CDOBranchChangedEvent branchChangedEvent = (CDOBranchChangedEvent)event; if (branchChangedEvent.getChangeKind() == ChangeKind.CREATED) { - notify(); + latch.countDown(); } } } } - } diff --git a/plugins/org.eclipse.emf.cdo.workspace/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.workspace/META-INF/MANIFEST.MF index 1b28fbab90..8336012886 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.workspace/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.emf.cdo.workspace;singleton:=true -Bundle-Version: 4.1.300.qualifier +Bundle-Version: 4.2.0.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin @@ -13,7 +13,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)";resoluti org.eclipse.emf.cdo.server.net4j;bundle-version="[4.0.0,5.0.0)", org.eclipse.emf.cdo.net4j;bundle-version="[4.0.0,5.0.0)", org.eclipse.net4j.jvm;bundle-version="[4.0.0,5.0.0)" -Export-Package: org.eclipse.emf.cdo.internal.workspace;version="4.1.300";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.tests.db,org.eclipse.emf.cdo.ui.workspace", - org.eclipse.emf.cdo.internal.workspace.bundle;version="4.1.300";x-internal:=true, - org.eclipse.emf.cdo.spi.workspace;version="4.1.300", - org.eclipse.emf.cdo.workspace;version="4.1.300" +Export-Package: org.eclipse.emf.cdo.internal.workspace;version="4.2.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.tests.db,org.eclipse.emf.cdo.ui.workspace", + org.eclipse.emf.cdo.internal.workspace.bundle;version="4.2.0";x-internal:=true, + org.eclipse.emf.cdo.spi.workspace;version="4.2.0", + org.eclipse.emf.cdo.workspace;version="4.2.0" diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceConfigurationImpl.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceConfigurationImpl.java index abfdb7b8e5..9b3c4e89c3 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceConfigurationImpl.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceConfigurationImpl.java @@ -4,7 +4,7 @@ * 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 */ @@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.id.CDOIDGenerator; import org.eclipse.emf.cdo.server.IStore; import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory; +import org.eclipse.emf.cdo.spi.workspace.InternalCDOWorkspace; import org.eclipse.emf.cdo.spi.workspace.InternalCDOWorkspaceBase; import org.eclipse.emf.cdo.workspace.CDOWorkspace; import org.eclipse.emf.cdo.workspace.CDOWorkspaceBase; @@ -34,6 +35,8 @@ public class CDOWorkspaceConfigurationImpl implements CDOWorkspaceConfiguration private CDOSessionConfigurationFactory remote; + private int branchID = InternalCDOWorkspace.NO_BRANCH_ID; + private String branchPath; private long timeStamp = CDOBranchPoint.UNSPECIFIED_DATE; @@ -86,6 +89,16 @@ public class CDOWorkspaceConfigurationImpl implements CDOWorkspaceConfiguration this.remote = remote; } + public int getBranchID() + { + return branchID; + } + + public void setBranchID(int branchID) + { + this.branchID = branchID; + } + public String getBranchPath() { return branchPath; @@ -135,6 +148,6 @@ public class CDOWorkspaceConfigurationImpl implements CDOWorkspaceConfiguration public CDOWorkspace checkout() { return new CDOWorkspaceImpl(localRepositoryName, store, idGenerationLocation, idGenerator, - (InternalCDOWorkspaceBase)base, remote, branchPath, timeStamp); + (InternalCDOWorkspaceBase)base, remote, branchID, branchPath, timeStamp); } } diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java index 94c9874f69..cee8d3f934 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java @@ -72,6 +72,7 @@ import org.eclipse.net4j.jvm.IJVMAcceptor; import org.eclipse.net4j.jvm.IJVMConnector; import org.eclipse.net4j.jvm.JVMUtil; import org.eclipse.net4j.signal.ISignalProtocol; +import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.container.ContainerUtil; import org.eclipse.net4j.util.container.IManagedContainer; @@ -107,6 +108,8 @@ import java.util.Set; */ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace { + private static final String PROP_BRANCH_ID = "org.eclipse.emf.cdo.workspace.branchID"; //$NON-NLS-1$ + private static final String PROP_BRANCH_PATH = "org.eclipse.emf.cdo.workspace.branchPath"; //$NON-NLS-1$ private static final String PROP_TIME_STAMP = "org.eclipse.emf.cdo.workspace.timeStamp"; //$NON-NLS-1$ @@ -127,6 +130,8 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace private CDOBranchPoint head; + private int branchID = NO_BRANCH_ID; + private String branchPath; private long timeStamp; @@ -139,13 +144,17 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace private Set<InternalCDOView> views = new HashSet<InternalCDOView>(); + /** + * Checkout. + */ public CDOWorkspaceImpl(String localRepositoryName, IStore local, IDGenerationLocation idGenerationLocation, - CDOIDGenerator idGenerator, InternalCDOWorkspaceBase base, CDOSessionConfigurationFactory remote, + CDOIDGenerator idGenerator, InternalCDOWorkspaceBase base, CDOSessionConfigurationFactory remote, int branchID, String branchPath, long timeStamp) { init(localRepositoryName, local, idGenerationLocation, idGenerator, base, remote); - this.branchPath = StringUtil.isEmpty(branchPath) ? CDOBranch.MAIN_BRANCH_NAME : branchPath; + this.branchID = branchID; + this.branchPath = branchPath; this.timeStamp = timeStamp; fixed = timeStamp != CDOBranchPoint.UNSPECIFIED_DATE; @@ -153,6 +162,9 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace saveProperties(); } + /** + * Open. + */ public CDOWorkspaceImpl(String localRepositoryName, IStore local, IDGenerationLocation idGenerationLocation, CDOIDGenerator idGenerator, InternalCDOWorkspaceBase base, CDOSessionConfigurationFactory remote) { @@ -160,27 +172,6 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace loadProperties(); } - protected void init(String localRepositoryName, IStore local, IDGenerationLocation idGenerationLocation, - CDOIDGenerator idGenerator, InternalCDOWorkspaceBase base, CDOSessionConfigurationFactory remote) - { - this.idGenerationLocation = idGenerationLocation; - this.idGenerator = idGenerator; - - container = createContainer(local); - remoteSessionConfigurationFactory = remote; - - localRepository = createLocalRepository(localRepositoryName, local); - - this.base = base; - this.base.init(this); - setDirtyFromBase(); - } - - private void setDirtyFromBase() - { - setDirty(!base.isEmpty()); - } - protected void checkout() { final OMMonitor monitor = new Monitor(); @@ -201,6 +192,7 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace { packageRegistry.putPackageUnit(packageUnit); } + accessor.rawStore(packageUnits, monitor); CDORevisionHandler handler = new CDORevisionHandler() @@ -221,7 +213,24 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace } }; - CDOBranch branch = remoteSession.getBranchManager().getBranch(branchPath); + InternalCDOBranchManager branchManager = remoteSession.getBranchManager(); + CDOBranch branch; + if (branchID == NO_BRANCH_ID) + { + if (StringUtil.isEmpty(branchPath)) + { + branchPath = CDOBranch.MAIN_BRANCH_NAME; + } + + branch = branchManager.getBranch(branchPath); + branchID = branch.getID(); + } + else + { + branch = branchManager.getBranch(branchID); + branchPath = branch.getPathName(); + } + remoteSession.getSessionProtocol().handleRevisions(null, branch, false, timeStamp, false, handler); } finally @@ -239,6 +248,45 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace } } + protected void init(String localRepositoryName, IStore local, IDGenerationLocation idGenerationLocation, + CDOIDGenerator idGenerator, InternalCDOWorkspaceBase base, CDOSessionConfigurationFactory remote) + { + this.idGenerationLocation = idGenerationLocation; + this.idGenerator = idGenerator; + + container = createContainer(local); + remoteSessionConfigurationFactory = remote; + + try + { + localRepository = createLocalRepository(localRepositoryName, local); + + this.base = base; + this.base.init(this); + setDirtyFromBase(); + } + catch (RuntimeException ex) + { + close(); + throw ex; + } + catch (Error ex) + { + close(); + throw ex; + } + } + + private void setDirtyFromBase() + { + setDirty(!base.isEmpty()); + } + + public int getBranchID() + { + return branchID; + } + public String getBranchPath() { return branchPath; @@ -940,6 +988,14 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace throw new IllegalStateException("Remote repository uses different ID generation location: " + remoteLocation); } + InternalCDOBranch branch = session.getBranchManager().getBranch(branchID); + String pathName = branch.getPathName(); + if (!ObjectUtil.equals(pathName, branchPath)) + { + branchPath = pathName; + saveProperties(); + } + return session; } @@ -955,6 +1011,7 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace protected void saveProperties() { Map<String, String> props = new HashMap<String, String>(); + props.put(PROP_BRANCH_ID, String.valueOf(branchID)); props.put(PROP_BRANCH_PATH, branchPath); props.put(PROP_TIME_STAMP, String.valueOf(timeStamp)); props.put(PROP_FIXED, String.valueOf(fixed)); @@ -963,8 +1020,11 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace protected void loadProperties() { - Set<String> names = new HashSet<String>(Arrays.asList(PROP_BRANCH_PATH, PROP_TIME_STAMP, PROP_FIXED)); + Set<String> names = new HashSet<String>( + Arrays.asList(PROP_BRANCH_ID, PROP_BRANCH_PATH, PROP_TIME_STAMP, PROP_FIXED)); Map<String, String> props = localRepository.getStore().getPersistentProperties(names); + String prop = props.get(PROP_BRANCH_ID); + branchID = prop == null ? InternalCDOWorkspace.NO_BRANCH_ID : Integer.parseInt(prop); branchPath = props.get(PROP_BRANCH_PATH); timeStamp = Long.parseLong(props.get(PROP_TIME_STAMP)); fixed = Boolean.parseBoolean(props.get(PROP_FIXED)); diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java index 44fe9cefd8..1fdb8b06d5 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java @@ -104,10 +104,15 @@ public class FolderCDOWorkspaceBase extends AbstractCDOWorkspaceBase protected Set<CDOID> doGetIDs() { Set<CDOID> ids = new HashSet<CDOID>(); - for (String key : folder.list()) + + String[] keys = folder.list(); + if (keys != null) { - CDOID id = getCDOID(key); - ids.add(id); + for (String key : keys) + { + CDOID id = getCDOID(key); + ids.add(id); + } } return ids; diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/spi/workspace/InternalCDOWorkspace.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/spi/workspace/InternalCDOWorkspace.java index a85edba751..afca59b487 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/spi/workspace/InternalCDOWorkspace.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/spi/workspace/InternalCDOWorkspace.java @@ -27,6 +27,11 @@ import org.eclipse.emf.spi.cdo.InternalCDOSession; public interface InternalCDOWorkspace extends CDOWorkspace { /** + * @since 4.2 + */ + public static final int NO_BRANCH_ID = -1; + + /** * @since 4.1 */ public IDGenerationLocation getIDGenerationLocation(); diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspace.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspace.java index 41ab92dffc..c010e86c66 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspace.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspace.java @@ -33,6 +33,11 @@ import org.eclipse.emf.ecore.resource.ResourceSet; */ public interface CDOWorkspace extends CDORevisionProvider, Closeable, INotifier { + /** + * @since 4.2 + */ + public int getBranchID(); + public String getBranchPath(); public long getTimeStamp(); diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspaceConfiguration.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspaceConfiguration.java index 70b15e231e..1f2020e80f 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspaceConfiguration.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/workspace/CDOWorkspaceConfiguration.java @@ -4,7 +4,7 @@ * 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 */ @@ -17,7 +17,7 @@ import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory; /** * Checks out new {@link CDOWorkspace workspace} or opens existing ones. - * + * * @author Eike Stepper * @since 4.1 * @noextend This interface is not intended to be extended by clients. @@ -43,6 +43,16 @@ public interface CDOWorkspaceConfiguration public void setRemote(CDOSessionConfigurationFactory remote); + /** + * @since 4.2 + */ + public int getBranchID(); + + /** + * @since 4.2 + */ + public void setBranchID(int branchPath); + public String getBranchPath(); public void setBranchPath(String branchPath); diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java index 6145e41011..501c5f125c 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java @@ -569,7 +569,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, if (errors == null) { errors = new NotifyingListImpl<Diagnostic>() - { + { private static final long serialVersionUID = 1L; @Override @@ -589,7 +589,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, { return EresourcePackage.CDO_RESOURCE__ERRORS; } - }; + }; } return errors; @@ -605,7 +605,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, if (warnings == null) { warnings = new NotifyingListImpl<Diagnostic>() - { + { private static final long serialVersionUID = 1L; @Override @@ -625,7 +625,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, { return EresourcePackage.CDO_RESOURCE__WARNINGS; } - }; + }; } return warnings; @@ -656,7 +656,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, public TreeIterator<EObject> getAllContents() { return new AbstractTreeIterator<EObject>(this, false) - { + { private static final long serialVersionUID = 1L; @Override @@ -665,7 +665,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, return object == CDOResourceImpl.this ? CDOResourceImpl.this.getContents().iterator() : ((EObject)object) .eContents().iterator(); } - }; + }; } /** @@ -881,7 +881,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, protected TreeIterator<EObject> getAllProperContents(List<EObject> contents) { return new ContentTreeIterator<EObject>(contents, false) - { + { private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") @@ -891,7 +891,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, return object == this.object ? ((List<EObject>)object).iterator() : new ProperContentIterator<EObject>( (EObject)object); } - }; + }; } /** @@ -1210,16 +1210,16 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, IProgressMonitor progressMonitor = options != null ? (IProgressMonitor)options .get(CDOResource.OPTION_SAVE_PROGRESS_MONITOR) : null; - try - { - transaction.commit(progressMonitor); - } - catch (CommitException ex) - { - throw new TransactionException(ex); - } + try + { + transaction.commit(progressMonitor); + } + catch (CommitException ex) + { + throw new TransactionException(ex); + } - setModified(false); + setModified(false); } /** @@ -1230,20 +1230,20 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, CDOTransaction transaction = options != null ? (CDOTransaction)options .get(CDOResource.OPTION_SAVE_OVERRIDE_TRANSACTION) : null; - if (transaction == null) - { - CDOView view = cdoView(); - if (view instanceof CDOTransaction) - { - transaction = (CDOTransaction)view; - } - else - { - throw new IllegalStateException("No transaction available"); - } - } + if (transaction == null) + { + CDOView view = cdoView(); + if (view instanceof CDOTransaction) + { + transaction = (CDOTransaction)view; + } + else + { + throw new IllegalStateException("No transaction available"); + } + } - return transaction; + return transaction; } /** @@ -1455,13 +1455,13 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, { InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(resourceSet); viewSet.executeWithoutNotificationHandling(new Callable<Boolean>() - { + { public Boolean call() throws Exception { resourceSet.getResources().remove(CDOResourceImpl.this); return true; } - }); + }); } } @@ -1526,12 +1526,12 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(oldResourceSet); notifications = viewSet.executeWithoutNotificationHandling(new Callable<NotificationChain>() - { + { public NotificationChain call() throws Exception { return ((InternalEList<Resource>)oldResourceSet.getResources()).basicRemove(this, finalNotifications); } - }); + }); } setResourceSet(resourceSet); @@ -1747,7 +1747,13 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction); notifications = cdoObject.eSetResource(CDOResourceImpl.this, notifications); - // Attach here instead of in CDOObjectImpl.eSetResource because EMF does it also here + if (isRoot()) + { + // The root resource must not create containment proxies for its CDOResourceNodes. + ((CDOResourceNodeImpl)cdoObject).basicSetFolder(null, false); + } + + // Attach here instead of in CDOObjectImpl.eSetResource because EMF does it also here. if (FSMUtil.isTransient(cdoObject)) { attached(cdoObject, transaction); diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java index d3b33e8801..fbedc8134f 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java @@ -80,14 +80,11 @@ public class SetContainer<E> extends Container<E> implements IContainer.Modifiab @Override public synchronized boolean isEmpty() { - checkActive(); return set.isEmpty(); } public E[] getElements() { - checkActive(); - E[] array; synchronized (this) { |