Skip to content

Commit fec86dc

Browse files
Fix for restarting bug
1 parent 68a7265 commit fec86dc

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

spring-data-eclipse-store-demo/src/test/java/software/xdev/spring/data/eclipse/store/demo/complex/ComplexDemoApplicationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.springframework.boot.test.context.SpringBootTest;
99

1010
import software.xdev.spring.data.eclipse.store.demo.TestUtil;
11-
import software.xdev.spring.data.eclipse.store.demo.simple.SimpleDemoApplication;
1211
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
1312

1413

@@ -34,6 +33,6 @@ void checkPossibilityToSimplyStartAndRestartApplication()
3433
{
3534
this.configuration.getStorageInstance().clearData();
3635
this.configuration.getStorageInstance().stop();
37-
SimpleDemoApplication.main(new String[]{});
36+
ComplexDemoApplication.main(new String[]{});
3837
}
3938
}

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ private void initRoot()
165165
{
166166
if(this.root.getCurrentRootData().getEntityData(entityClass) == null)
167167
{
168-
this.createNewEntityList(entityClass);
168+
this.root.getCurrentRootData().createNewEntityData(entityClass);
169169
entityListMustGetStored = true;
170170
}
171+
this.setIdManagerForEntityData(entityClass, this.root);
171172
}
172173
if(entityListMustGetStored)
173174
{
@@ -183,10 +184,11 @@ private void initRoot()
183184
}
184185
}
185186

186-
private <T, ID> void createNewEntityList(final Class<T> entityClass)
187+
private <T, ID> void setIdManagerForEntityData(final Class<T> entityClass, final VersionedRoot root)
187188
{
188189
final IdManager<T, ID> idManager = this.ensureIdManager(entityClass);
189-
this.root.getCurrentRootData().createNewEntityList(entityClass, idManager::getId);
190+
final EntityData<T, Object> entityData = root.getCurrentRootData().getEntityData(entityClass);
191+
entityData.setIdGetter(idManager::getId);
190192
}
191193

192194
public synchronized <T> void registerEntity(
@@ -356,7 +358,7 @@ public synchronized void stop()
356358
LOG.info("Stopping storage...");
357359
if(this.storageManager != null)
358360
{
359-
this.storageManager.shutdown();
361+
this.storageManager.close();
360362
this.storageManager = null;
361363
this.root = null;
362364
this.registry.reset();
@@ -418,7 +420,8 @@ public void setLastId(final Class<?> entityClass, final Object lastId)
418420
final EntityData<?, Object> entityData = this.root.getCurrentRootData().getEntityData(entityClass);
419421
if(entityData == null)
420422
{
421-
this.createNewEntityList(entityClass);
423+
this.root.getCurrentRootData().createNewEntityData(entityClass);
424+
this.setIdManagerForEntityData(entityClass, this.root);
422425
this.storageManager.store(this.root.getCurrentRootData().getEntityListsToStore());
423426
}
424427
this.root.getCurrentRootData().setLastId(entityClass, lastId);

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/EntityData.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ public class EntityData<T, ID>
4040
*/
4141
private final HashMap<ID, T> entitiesById;
4242

43-
private final transient Function<T, ID> idGetter;
43+
private transient Function<T, ID> idGetter;
4444

45-
public EntityData(final Function<T, ID> idGetter)
45+
public EntityData()
4646
{
47-
this.idGetter = idGetter;
4847
this.entities = new IdentitySet<>();
4948
this.entitiesById = new HashMap<>();
5049
}
5150

51+
public void setIdGetter(final Function<T, ID> idGetter)
52+
{
53+
this.idGetter = idGetter;
54+
}
55+
5256
public IdentitySet<T> getEntities()
5357
{
5458
return this.entities;

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/root/RootDataV2.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.util.HashMap;
1919
import java.util.Map;
20-
import java.util.function.Function;
2120

2221

2322
/**
@@ -58,11 +57,9 @@ public <T, ID> EntityData<T, ID> getEntityData(final String entityClassName)
5857
return (EntityData<T, ID>)this.entityLists.get(entityClassName);
5958
}
6059

61-
public <T, ID> void createNewEntityList(
62-
final Class<T> entityClass,
63-
final Function<T, ID> idGetter)
60+
public <T, ID> void createNewEntityData(final Class<T> entityClass)
6461
{
65-
this.entityLists.put(this.getEntityName(entityClass), new EntityData<>(idGetter));
62+
this.entityLists.put(this.getEntityName(entityClass), new EntityData<>());
6663
}
6764

6865
private <T> String getEntityName(final Class<T> classToRegister)

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/helper/DummyEntityProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class DummyEntityProvider<T> extends EntityProvider<T, Void>
2727
public DummyEntityProvider(final Collection<T> collection)
2828
{
2929
super();
30-
final EntityData<T, Void> objects = new EntityData<>(t -> null);
30+
final EntityData<T, Void> objects = new EntityData<>();
31+
objects.setIdGetter(i -> null);
3132
objects.getEntities().addAll(collection);
3233
this.addEntityData(objects);
3334
}

0 commit comments

Comments
 (0)