3939import software .xdev .spring .data .eclipse .store .repository .config .EclipseStoreClientConfiguration ;
4040import software .xdev .spring .data .eclipse .store .repository .config .EclipseStoreStorageFoundationProvider ;
4141import software .xdev .spring .data .eclipse .store .repository .interfaces .EclipseStoreRepository ;
42- import software .xdev .spring .data .eclipse .store .repository .root .EntityData ;
4342import software .xdev .spring .data .eclipse .store .repository .root .VersionedRoot ;
43+ import software .xdev .spring .data .eclipse .store .repository .root .v2_4 .EntityData ;
44+ import software .xdev .spring .data .eclipse .store .repository .support .SimpleEclipseStoreRepository ;
4445import software .xdev .spring .data .eclipse .store .repository .support .concurrency .ReadWriteLock ;
4546import software .xdev .spring .data .eclipse .store .repository .support .concurrency .ReentrantJavaReadWriteLock ;
4647import software .xdev .spring .data .eclipse .store .repository .support .copier .version .EntityVersionIncrementer ;
5556
5657@ SuppressWarnings ("java:S119" )
5758public class EclipseStoreStorage
58- implements EntityListProvider , IdManagerProvider , VersionManagerProvider , PersistableChecker , ObjectSwizzling
59+ implements EntityListProvider ,
60+ IdManagerProvider ,
61+ VersionManagerProvider ,
62+ PersistableChecker ,
63+ ObjectSwizzling ,
64+ StorageCommunicator
5965{
6066 private static final Logger LOG = LoggerFactory .getLogger (EclipseStoreStorage .class );
61- private final Map <Class <?>, EclipseStoreRepository <?, ?>> entityClassToRepository = new HashMap <>();
62- private final Map <Class <?>, EclipseStoreRepository <?, ?>> lazyEntityClassToRepository = new HashMap <>();
67+ private final Map <Class <?>, SimpleEclipseStoreRepository <?, ?>> entityClassToRepository = new HashMap <>();
6368 /**
6469 * "Why are the IdManagers seperated from the repositories?" - Because there might be entities for which there are
6570 * no repositories, but they still have IDs.
@@ -107,8 +112,7 @@ private synchronized void ensureEntitiesInRoot()
107112 {
108113 if (this .storageManager == null )
109114 {
110- final EmbeddedStorageFoundation <?> embeddedStorageFoundation =
111- this .startStorageManager ();
115+ final EmbeddedStorageFoundation <?> embeddedStorageFoundation = this .startStorageManager ();
112116 this .persistenceChecker = new RelayedPersistenceChecker (embeddedStorageFoundation );
113117 this .initRoot ();
114118 LOG .info (
@@ -120,6 +124,7 @@ private synchronized void ensureEntitiesInRoot()
120124 }
121125 }
122126
127+ @ SuppressWarnings ("deprecation" )
123128 private EmbeddedStorageFoundation <?> startStorageManager ()
124129 {
125130 LOG .info ("Starting storage..." );
@@ -161,11 +166,6 @@ else if(!(embeddedStorageManager.root() instanceof VersionedRoot))
161166 return this .entityClassToRepository .get (entityClass );
162167 }
163168
164- public <T > EclipseStoreRepository <?, ?> getLazyRepository (final Class <T > entityClass )
165- {
166- return this .lazyEntityClassToRepository .get (entityClass );
167- }
168-
169169 private void initRoot ()
170170 {
171171 if (LOG .isDebugEnabled ())
@@ -175,7 +175,6 @@ private void initRoot()
175175 this .repositorySynchronizer =
176176 new SimpleRepositorySynchronizer (this .root .getCurrentRootData ());
177177 this .ensureEntityData ();
178- this .ensureLazyEntityData ();
179178 this .entitySetCollector =
180179 new EntitySetCollector (
181180 this .root .getCurrentRootData ()::getEntityData ,
@@ -207,39 +206,19 @@ private void ensureEntityData()
207206 }
208207 }
209208
210- private void ensureLazyEntityData ( )
209+ public < T , ID > void createNewEntityData ( final Class < T > entityClass , final VersionedRoot root )
211210 {
212- boolean entityListMustGetStored = false ;
213- for ( final Class <?> entityClass : this .lazyEntityClassToRepository . keySet ())
211+ final IdManager < T , ID > idManager = this . ensureIdManager ( entityClass ) ;
212+ if ( this .entityClassToRepository . get ( entityClass ). isLazy ())
214213 {
215- if (this .root .getCurrentRootData ().getLazyEntityData (entityClass ) == null )
216- {
217- this .createNewLazyEntityData (entityClass , this .root );
218- entityListMustGetStored = true ;
219- }
220- else
221- {
222- this .setIdManagerForEntityData (entityClass , this .root );
223- }
214+ root .getCurrentRootData ().createNewLazyEntityData (entityClass , idManager ::getId );
224215 }
225- if ( entityListMustGetStored )
216+ else
226217 {
227- this . storageManager . store ( this . root .getCurrentRootData ().getLazyEntityListsToStore () );
218+ root .getCurrentRootData ().createNewEntityData ( entityClass , idManager :: getId );
228219 }
229220 }
230221
231- private <T , ID > void createNewEntityData (final Class <T > entityClass , final VersionedRoot root )
232- {
233- final IdManager <T , ID > idManager = this .ensureIdManager (entityClass );
234- root .getCurrentRootData ().createNewEntityData (entityClass , idManager ::getId );
235- }
236-
237- private <T , ID > void createNewLazyEntityData (final Class <T > entityClass , final VersionedRoot root )
238- {
239- final IdManager <T , ID > idManager = this .ensureIdManager (entityClass );
240- root .getCurrentRootData ().createNewLazyEntityData (entityClass , idManager ::getId );
241- }
242-
243222 private <T , ID > void setIdManagerForEntityData (final Class <T > entityClass , final VersionedRoot root )
244223 {
245224 final IdManager <T , ID > idManager = this .ensureIdManager (entityClass );
@@ -254,9 +233,10 @@ private <T, ID> void setIdManagerForEntityData(final Class<T> entityClass, final
254233 }
255234 }
256235
257- public synchronized <T > void registerEntity (
236+ @ Override
237+ public synchronized <T , ID > void registerEntity (
258238 final Class <T > classToRegister ,
259- final EclipseStoreRepository <?, ? > repository )
239+ final SimpleEclipseStoreRepository < T , ID > repository )
260240 {
261241 if (this .entityClassToRepository .containsKey (classToRegister ))
262242 {
@@ -278,33 +258,24 @@ private <T, ID> EntityData<T, ID> getEntityData(final Class<T> clazz)
278258 return this .readWriteLock .read (() -> this .root .getCurrentRootData ().getEntityData (clazz ));
279259 }
280260
281- private <T , ID > EntityData <T , ID > getLazyEntityData (final Class <T > clazz )
282- {
283- this .ensureEntitiesInRoot ();
284- return this .readWriteLock .read (() -> this .root .getCurrentRootData ().getLazyEntityData (clazz ));
285- }
286-
287261 @ Override
288262 public <T , ID > EntityProvider <T , ID > getEntityProvider (final Class <T > clazz )
289263 {
290264 this .ensureEntitiesInRoot ();
291265 return this .entitySetCollector .getRelatedIdentitySets (clazz );
292266 }
293267
294- @ SuppressWarnings ("unchecked" )
295268 @ Override
296269 public <T > long getEntityCount (final Class <T > clazz )
297270 {
298271 this .ensureEntitiesInRoot ();
299- return this .readWriteLock .read (
300- () ->
301- {
302- final EntityData <T , Object > entityData = this .root .getCurrentRootData ().getEntityData (clazz );
303- return entityData == null ? 0 : entityData .getEntityCount ();
304- }
305- );
272+ return this .readWriteLock .read (() -> {
273+ final EntityData <T , Object > entityData = this .getEntityData (clazz );
274+ return entityData == null ? 0 : entityData .getEntityCount ();
275+ });
306276 }
307277
278+ @ Override
308279 public <T > void store (
309280 final Collection <Object > nonEntitiesToStore ,
310281 final Class <T > clazz ,
@@ -315,7 +286,10 @@ public <T> void store(
315286 () ->
316287 {
317288 final Collection <Object > entitiesAndPossiblyNonEntitiesToStore =
318- this .collectRootEntitiesToStore (clazz , entitiesToStore );
289+ this .collectRootEntitiesToStore (
290+ this .getEntityData (clazz ),
291+ clazz ,
292+ entitiesToStore );
319293 entitiesAndPossiblyNonEntitiesToStore .addAll (nonEntitiesToStore );
320294 if (LOG .isDebugEnabled ())
321295 {
@@ -336,16 +310,14 @@ public <T> void store(
336310 * Also collects the object-list to store, if necessary.
337311 */
338312 private <T , ID > Collection <Object > collectRootEntitiesToStore (
313+ final EntityData <T , ID > entityData ,
339314 final Class <T > clazz ,
340315 final Iterable <T > entitiesToStore )
341316 {
342- final EntityData <T , ID > entityData = this .getEntityData (clazz );
343- final EntityData <T , ID > lazyEntityData = this .getLazyEntityData (clazz );
344317 final Collection <Object > objectsToStore = new ArrayList <>();
345318 for (final T entityToStore : entitiesToStore )
346319 {
347320 objectsToStore .addAll (entityData .ensureEntityAndReturnObjectsToStore (entityToStore ));
348- objectsToStore .addAll (lazyEntityData .ensureEntityAndReturnObjectsToStore (entityToStore ));
349321 objectsToStore .add (entityToStore );
350322 // Add the separate lists of entities to store.
351323 this .repositorySynchronizer .syncAndReturnChangedObjectLists (entityToStore ).forEach (
@@ -355,13 +327,14 @@ private <T, ID> Collection<Object> collectRootEntitiesToStore(
355327 return objectsToStore ;
356328 }
357329
358- public <T , ID > void delete (final Class <T > clazz , final T entityToRemove )
330+ @ Override
331+ public <T > void delete (final Class <T > clazz , final T entityToRemove )
359332 {
360333 this .ensureEntitiesInRoot ();
361334 this .readWriteLock .write (
362335 () ->
363336 {
364- final EntityData <T , ID > entityData = this .getEntityData (clazz );
337+ final EntityData <T , ? > entityData = this .getEntityData (clazz );
365338 this .storageManager .storeAll (entityData .removeEntityAndReturnObjectsToStore (entityToRemove ));
366339 if (LOG .isDebugEnabled ())
367340 {
@@ -371,13 +344,14 @@ public <T, ID> void delete(final Class<T> clazz, final T entityToRemove)
371344 );
372345 }
373346
374- public <T , ID > void deleteAll (final Class <T > clazz )
347+ @ Override
348+ public <T > void deleteAll (final Class <T > clazz )
375349 {
376350 this .ensureEntitiesInRoot ();
377351 this .readWriteLock .write (
378352 () ->
379353 {
380- final EntityData <T , ID > entityData = this .getEntityData (clazz );
354+ final EntityData <T , ? > entityData = this .getEntityData (clazz );
381355 final long oldSize = entityData .getEntityCount ();
382356 this .storageManager .storeAll (entityData .removeAllEntitiesAndReturnObjectsToStore ());
383357 if (LOG .isDebugEnabled ())
@@ -518,6 +492,7 @@ public Object getObject(final long objectId)
518492 return this .storageManager .getObject (objectId );
519493 }
520494
495+ @ Override
521496 public ReadWriteLock getReadWriteLock ()
522497 {
523498 return this .readWriteLock ;
0 commit comments