41
41
import software .xdev .spring .data .eclipse .store .repository .support .concurrency .ReadWriteLock ;
42
42
import software .xdev .spring .data .eclipse .store .repository .support .concurrency .ReentrantJavaReadWriteLock ;
43
43
import software .xdev .spring .data .eclipse .store .repository .support .copier .id .IdManager ;
44
+ import software .xdev .spring .data .eclipse .store .repository .support .copier .id .IdManagerProvider ;
44
45
import software .xdev .spring .data .eclipse .store .repository .support .copier .id .IdSetter ;
46
+ import software .xdev .spring .data .eclipse .store .repository .support .copier .version .EntityVersionIncrementer ;
47
+ import software .xdev .spring .data .eclipse .store .repository .support .copier .version .VersionManager ;
48
+ import software .xdev .spring .data .eclipse .store .repository .support .copier .version .VersionManagerProvider ;
45
49
import software .xdev .spring .data .eclipse .store .repository .support .reposyncer .RepositorySynchronizer ;
46
50
import software .xdev .spring .data .eclipse .store .repository .support .reposyncer .SimpleRepositorySynchronizer ;
47
51
48
52
49
53
public class EclipseStoreStorage
50
- implements EntityListProvider , IdManagerProvider , PersistableChecker , ObjectSwizzling
54
+ implements EntityListProvider , IdManagerProvider , VersionManagerProvider , PersistableChecker , ObjectSwizzling
51
55
{
52
56
private static final Logger LOG = LoggerFactory .getLogger (EclipseStoreStorage .class );
53
57
private final Map <Class <?>, SimpleEclipseStoreRepository <?, ?>> entityClassToRepository = new HashMap <>();
58
+ /**
59
+ * "Why are the IdManagers seperated from the repositories?" - Because there might be entities for which there are
60
+ * no repositories, but they still have IDs.
61
+ */
54
62
private final Map <Class <?>, IdManager <?, ?>> idManagers = new ConcurrentHashMap <>();
63
+ /**
64
+ * "Why are the VersionManagers seperated from the repositories?" - Because there might be entities for which there
65
+ * are no repositories, but they still have Versions.
66
+ */
67
+ private final Map <Class <?>, VersionManager <?>> versionManagers = new ConcurrentHashMap <>();
55
68
private final EclipseStoreStorageFoundationProvider foundationProvider ;
56
69
private EntitySetCollector entitySetCollector ;
57
70
private PersistableChecker persistenceChecker ;
@@ -311,6 +324,7 @@ public synchronized void stop()
311
324
this .root = null ;
312
325
this .registry .reset ();
313
326
this .idManagers .clear ();
327
+ this .versionManagers .clear ();
314
328
LOG .info ("Stopped storage." );
315
329
}
316
330
else
@@ -323,23 +337,37 @@ public synchronized void stop()
323
337
324
338
@ Override
325
339
@ SuppressWarnings ("unchecked" )
326
- public <T , ID > IdManager <T , ID > ensureIdManager (final Class <T > domainClass )
340
+ public <T , ID > IdManager <T , ID > ensureIdManager (final Class <T > classPossiblyWithId )
327
341
{
328
342
return (IdManager <T , ID >)this .idManagers .computeIfAbsent (
329
- domainClass ,
343
+ classPossiblyWithId ,
330
344
clazz ->
331
345
new IdManager <>(
332
- domainClass ,
346
+ classPossiblyWithId ,
333
347
(IdSetter <T >)IdSetter .createIdSetter (
334
348
clazz ,
335
- id -> this .setLastId (clazz , id ),
336
- () -> this .getLastId (clazz )
349
+ id -> this .setLastId (classPossiblyWithId , id ),
350
+ () -> this .getLastId (classPossiblyWithId )
337
351
),
338
352
this
339
353
)
340
354
);
341
355
}
342
356
357
+ @ Override
358
+ @ SuppressWarnings ("unchecked" )
359
+ public <T > VersionManager <T > ensureVersionManager (final Class <T > possiblyVersionedClass )
360
+ {
361
+ return (VersionManager <T >)this .versionManagers .computeIfAbsent (
362
+ possiblyVersionedClass ,
363
+ clazz ->
364
+ new VersionManager <>(
365
+ possiblyVersionedClass ,
366
+ EntityVersionIncrementer .createVersionSetter (possiblyVersionedClass )
367
+ )
368
+ );
369
+ }
370
+
343
371
public Object getLastId (final Class <?> entityClass )
344
372
{
345
373
return this .readWriteLock .read (() -> this .root .getLastId (entityClass ));
0 commit comments