Skip to content

Package: CDOProjectData

CDOProjectData

nameinstructionbranchcomplexitylinemethod
CDOProjectData(InternalProject)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkoutWorkspace()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createWorkspaceConfiguration()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 25 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getProject()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRootResource()
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getTransaction()
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getWorkspace()
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011 Eike Stepper (Berlin, Germany) and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eike Stepper - initial API and implementation
13: *******************************************************************************/
14: package org.eclipse.emf.ecp.cdo.internal.core;
15:
16: import org.eclipse.emf.cdo.eresource.CDOResource;
17: import org.eclipse.emf.cdo.transaction.CDOTransaction;
18: import org.eclipse.emf.cdo.workspace.CDOWorkspace;
19: import org.eclipse.emf.cdo.workspace.CDOWorkspaceConfiguration;
20: import org.eclipse.emf.ecore.resource.ResourceSet;
21: import org.eclipse.emf.ecp.core.util.ECPUtil;
22: import org.eclipse.emf.ecp.spi.core.InternalProject;
23:
24: /**
25: * Represents the data of an ECP project.
26: *
27: * @author Eike Stepper
28: */
29: public final class CDOProjectData {
30:         private final InternalProject project;
31:
32:         private CDOWorkspace workspace;
33:
34:         private CDOTransaction transaction;
35:
36:         private CDOResource rootResource;
37:
38:         /**
39:          * Default constructor.
40:          *
41:          * @param project the project
42:          */
43:         public CDOProjectData(InternalProject project) {
44:                 this.project = project;
45:         }
46:
47:         /**
48:          * Returns the project.
49:          *
50:          * @return the project
51:          */
52:         public InternalProject getProject() {
53:                 return project;
54:         }
55:
56:         /**
57:          * Returns the {@link CDOWorkspace} of the project.
58:          *
59:          * @return the {@link CDOWorkspace}
60:          */
61:         public synchronized CDOWorkspace getWorkspace() {
62:•                if (workspace == null) {
63:                         final CDOWorkspaceConfiguration config = createWorkspaceConfiguration();
64:                         workspace = config.open();
65:                 }
66:
67:                 return workspace;
68:         }
69:
70:         /**
71:          * Check out the {@link CDOWorkspace} of the project.
72:          *
73:          * @return the {@link CDOWorkspace}
74:          */
75:         public synchronized CDOWorkspace checkoutWorkspace() {
76:                 final CDOWorkspaceConfiguration config = createWorkspaceConfiguration();
77:                 workspace = config.checkout();
78:                 return workspace;
79:         }
80:
81:         /**
82:          * Get the a transaction fot the project.
83:          *
84:          * @return the {@link CDOTransaction}
85:          */
86:         public synchronized CDOTransaction getTransaction() {
87:•                if (transaction == null) {
88:                         final ResourceSet resourceSet = project.getEditingDomain().getResourceSet();
89:                         transaction = getWorkspace().openTransaction(resourceSet);
90:                 }
91:
92:                 return transaction;
93:         }
94:
95:         /**
96:          * Get the root resource of the {@link CDOTransaction}, @see {@link CDOTransaction#getRootResource()}.
97:          *
98:          * @return the {@link CDOResource}
99:          */
100:         public synchronized CDOResource getRootResource() {
101:•                if (rootResource == null) {
102:                         rootResource = getTransaction().getRootResource();
103:                 }
104:
105:                 return rootResource;
106:         }
107:
108:         /**
109:          * Dispose all resources of the project data.
110:          */
111:         public void dispose() {
112:•                if (rootResource != null) {
113:                         rootResource = null;
114:                 }
115:
116:•                if (transaction != null) {
117:                         transaction.close();
118:                         transaction = null;
119:                 }
120:
121:•                if (workspace != null) {
122:                         workspace.close();
123:                         workspace = null;
124:                 }
125:         }
126:
127:         private CDOWorkspaceConfiguration createWorkspaceConfiguration() {
128:                 final CDOProvider provider = (CDOProvider) ECPUtil.getResolvedElement(project.getProvider());
129:                 return provider.createWorkspaceConfiguration(project);
130:         }
131: }