Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0f34a85e962427b8e032cbe9d571cc770ab3ff73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 * Copyright (c) 2004 - 2012 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
 *    Stefan Winkler - 271444: [DB] Multiple refactorings bug 271444
 */
package org.eclipse.emf.cdo.server.db.mapping;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryResourcesContext;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;

import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.util.collection.CloseableIterator;
import org.eclipse.net4j.util.om.monitor.OMMonitor;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;

import java.io.IOException;
import java.sql.Connection;
import java.util.Map;
import java.util.Set;

/**
 * The mapping strategy acts as a connection between the DBStore and the database management (and OR-mapping) classes.
 * The {@link DBStore} uses methods of this interface to create and lookup mappings (or mappers, as they could also be
 * named as such) and to get properties and informations about the mappings used. The mapping classes (e.g., instances
 * of IClassMapping and IListMapping) also use this class as a central point of information and as a resource of common
 * functionalities.
 * 
 * @author Eike Stepper
 * @author Stefan Winkler
 * @since 2.0
 */
public interface IMappingStrategy
{
  /**
   * Name of the integer property that configures the maximum length for table names. A value of zero indicates the
   * value of the {@link IDBAdapter#getMaxTableNameLength() db adapter} to be used.
   */
  public static final String PROP_MAX_TABLE_NAME_LENGTH = "maxTableNameLength"; //$NON-NLS-1$

  /**
   * Name of the integer property that configures the maximum length for column names. A value of zero indicates the
   * value of the {@link IDBAdapter#getMaxFieldNameLength() db adapter} to be used.
   */
  public static final String PROP_MAX_FIELD_NAME_LENGTH = "maxFieldNameLength"; //$NON-NLS-1$

  /**
   * Name of the String property that specifies a common prefix for table names.
   */
  public static final String PROP_TABLE_NAME_PREFIX = "tableNamePrefix"; //$NON-NLS-1$

  /**
   * Name of the boolean property that configures whether the table names are made of simple class names or of qualified
   * class names.
   */
  public static final String PROP_QUALIFIED_NAMES = "qualifiedNames"; //$NON-NLS-1$

  /**
   * Name of the boolean property that configures whether table names and column names are always suffixed with the
   * internal DBID or only in cases where generated names violate the naming constraints of the underlying backend.
   */
  public static final String PROP_FORCE_NAMES_WITH_ID = "forceNamesWithID"; //$NON-NLS-1$

  /**
   * Name of the integer property that configures the size of the object type in-memory cache. Possible configuration
   * values are:
   * <ul>
   * <li>0 (zero). Don't use memory caching.
   * <li>&gt;0. Use memory caching with the cache size given.
   * </ul>
   * Default is a memory cache size of 10,000,000.
   * <p>
   * 
   * @since 4.0
   */
  public static final String PROP_OBJECT_TYPE_CACHE_SIZE = "objectTypeCacheSize"; //$NON-NLS-1$

  /**
   * @return the store, this MappingStrategy instance belongs to.
   */
  public IDBStore getStore();

  /**
   * Set the store to which this MappingStrategy instance belongs. Should only be called by the {@link DBStore}, and
   * only once to initialize the connection between {@link DBStore} and mapping strategy.
   * 
   * @param dbStore
   *          the DBStore instance to which this MappingStrategy instance belongs.
   */
  public void setStore(IDBStore dbStore);

  /**
   * Factory for value mappings of single-valued attributes.
   * 
   * @param feature
   *          the feature for which a mapping should be created. It must hold <code>feature.isMany() == false</code>.
   * @return the mapping created.
   */
  public ITypeMapping createValueMapping(EStructuralFeature feature);

  /**
   * Factory for value mappings of multi-valued-attributes.
   * 
   * @param containingClass
   *          the class containing the feature.
   * @param feature
   *          the feature for which a mapping should be created. It must hold <code>feature.isMany() == true</code>.
   */
  public IListMapping createListMapping(EClass containingClass, EStructuralFeature feature);

  /**
   * Create a suitable table name which can be used to map the given element. Should only be called by mapping classes.
   * 
   * @param element
   *          the element for which the name should be created. It must hold:
   *          <code>element instanceof EClass || element instanceof EPackage</code>.
   * @return the created table name. It is guaranteed that the table name is compatible with the chosen database.
   */
  public String getTableName(ENamedElement element);

  /**
   * Create a suitable table name which can be used to map the given element. Should only be called by mapping classes.
   * Should only be called by mapping classes.
   * 
   * @param containingClass
   *          the class containeng the feature.
   * @param feature
   *          the feature for which the table name should be created.
   * @return the created table name. It is guaranteed that the table name is compatible with the chosen database.
   */
  public String getTableName(EClass containingClass, EStructuralFeature feature);

  /**
   * Create a suitable column name which can be used to map the given element. Should only be called by mapping classes.
   * 
   * @param feature
   *          the feature for which the column name should be created.
   * @return the created column name. It is guaranteed that the name is compatible with the chosen database.
   */
  public String getFieldName(EStructuralFeature feature);

  /**
   * Create and initialize the mapping infrastructure for the given packages. Should be called from the DBStore or the
   * DBStoreAccessor.
   * 
   * @param connection
   *          the connection to use.
   * @param packageUnits
   *          the packages whose elements should be mapped.
   * @param monitor
   *          the monitor to report progress.
   */
  public void createMapping(Connection connection, InternalCDOPackageUnit[] packageUnits, OMMonitor monitor);

  /**
   * Remove the mapping infrastructure for the given packages. Should be called from the DBStore or the DBStoreAccessor.
   * 
   * @param connection
   *          the connection to use.
   * @param packageUnits
   *          the packages for which the mappings should be removed
   * @since 4.0
   */
  // Bugzilla 298632
  public void removeMapping(Connection connection, InternalCDOPackageUnit[] packageUnits);

  /**
   * Look up an existing class mapping for the given class. Before this method is called, the class mapping must have
   * been initialized by calling {@link #createMapping(Connection, InternalCDOPackageUnit[], OMMonitor)} on its
   * containing package.
   * 
   * @param eClass
   *          the class to look up.
   * @return the class mapping.
   */
  public IClassMapping getClassMapping(EClass eClass);

  /**
   * Returns all class mappings of this strategy.
   * 
   * @since 4.0
   */
  public Map<EClass, IClassMapping> getClassMappings();

  /**
   * Returns all class mappings of this strategy.
   * 
   * @since 4.0
   */
  public Map<EClass, IClassMapping> getClassMappings(boolean createOnDemand);

  /**
   * Query if this mapping supports revision deltas. <br>
   * If this method returns <code>true</code>, it is guaranteed that all class mappings returned by
   * {@link #getClassMapping(EClass)} implement {@link IClassMappingDeltaSupport}.
   * 
   * @return <code>true</code> if revision deltas are supported, <code>false</code> else.
   */
  public boolean hasDeltaSupport();

  /**
   * Query if this mapping supports audits. <br>
   * If this method returns <code>true</code>, it is guaranteed that all class mappings returned by
   * {@link #getClassMapping(EClass)} implement {@link IClassMappingAuditSupport}.
   * 
   * @return <code>true</code> if audits are supported, <code>false</code> else.
   */
  public boolean hasAuditSupport();

  /**
   * Query if this mapping supports branches. <br>
   * 
   * @return <code>true</code> if branches are supported, <code>false</code> else.
   * @since 3.0
   */
  public boolean hasBranchingSupport();

  /**
   * Executes a resource query.
   * 
   * @param accessor
   *          the accessor to use.
   * @param context
   *          the context from which the query parameters are read and to which the result is written.
   */
  public void queryResources(IDBStoreAccessor accessor, QueryResourcesContext context);

  /**
   * Executes a cross reference query.
   * 
   * @param accessor
   *          the accessor to use.
   * @param context
   *          the context from which the query parameters are read and to which the result is written.
   * @since 3.0
   */
  public void queryXRefs(IDBStoreAccessor accessor, QueryXRefsContext context);

  /**
   * Read the type (i.e. class) of the object referred to by a given ID.
   * 
   * @param accessor
   *          the accessor to use to look up the type.
   * @param id
   *          the ID of the object for which the type is to be determined.
   * @return the type of the object.
   */
  public CDOClassifierRef readObjectType(IDBStoreAccessor accessor, CDOID id);

  /**
   * Get an iterator over all instances of objects in the store.
   * 
   * @param accessor
   *          the accessor to use.
   * @return the iterator.
   */
  public CloseableIterator<CDOID> readObjectIDs(IDBStoreAccessor accessor);

  /**
   * Return the maximum object id used in the store. This is used by the DBStore if a previous crash is discovered
   * during the startup process. Should only be called by the DBStore and only during startup.
   * 
   * @param dbAdapter
   *          the dbAdapter to use to access the database
   * @param connection
   *          the connection to use to access the database
   * @since 4.0
   */
  public void repairAfterCrash(IDBAdapter dbAdapter, Connection connection);

  /**
   * Returns the configuration properties of this mapping strategy.
   * 
   * @since 4.0
   */
  public Map<String, String> getProperties();

  /**
   * Set configuration properties for this mapping strategy. Should only be called by the factory creating the mapping
   * strategy instance.
   * 
   * @param properties
   *          the configuration properties to set.
   */
  public void setProperties(Map<String, String> properties);

  /**
   * Passes all revisions of the store to the {@link CDORevisionHandler handler} if <b>all</b> of the following
   * conditions are met:
   * <ul>
   * <li>The <code>eClass</code> parameter is <code>null</code> or equal to <code>revision.getEClass()</code>.
   * <li>The <code>branch</code> parameter is <code>null</code> or equal to <code>revision.getBranch()</code>.
   * <li>The <code>timeStamp</code> parameter is {@link CDOBranchPoint#UNSPECIFIED_DATE} or equal to
   * <code>revision.getTimeStamp()</code>.
   * </ul>
   * 
   * @since 4.0
   */
  public void handleRevisions(IDBStoreAccessor accessor, EClass eClass, CDOBranch branch, long timeStamp,
      boolean exactTime, CDORevisionHandler handler);

  /**
   * Returns a set of CDOIDs that have at least one revision in any of the passed branches and time ranges.
   * DetachedCDORevisions must also be considered!
   * 
   * @see IStoreAccessor#readChangeSet(OMMonitor, CDOChangeSetSegment...)
   * @since 4.0
   */
  public Set<CDOID> readChangeSet(IDBStoreAccessor accessor, OMMonitor monitor, CDOChangeSetSegment[] segments);

  /**
   * @since 3.0
   */
  public void rawExport(IDBStoreAccessor accessor, CDODataOutput out, int lastReplicatedBranchID, int lastBranchID,
      long lastReplicatedCommitTime, long lastCommitTime) throws IOException;

  /**
   * @since 4.0
   */
  public void rawImport(IDBStoreAccessor accessor, CDODataInput in, long fromCommitTime, long toCommitTime,
      OMMonitor monitor) throws IOException;

  /**
   * @since 4.0
   */
  public String getListJoin(String attrTable, String listTable);
}

Back to the top