Skip to content

Commit 4b094b9

Browse files
Implemented Auto migration from older SDES versions
1 parent c7cef27 commit 4b094b9

20 files changed

Lines changed: 660 additions & 61 deletions

File tree

docs/antora.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: ROOT
22
title: Spring-Data-Eclipse-Store
33
version: master
4-
display_version: '1.1.0'
4+
display_version: '2.0.0'
55
start_page: index.adoc
66
nav:
77
- modules/ROOT/nav.adoc
88
asciidoc:
99
attributes:
1010
product-name: 'Spring-Data-Eclipse-Store'
11-
display-version: '1.1.0'
12-
maven-version: '1.1.0'
11+
display-version: '2.0.0'
12+
maven-version: '2.0.0'
1313
page-editable: false
1414
page-out-of-support: false

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>spring-data-eclipse-store-root</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<organization>

spring-data-eclipse-store-benchmark/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<parent>
66
<groupId>software.xdev</groupId>
77
<artifactId>spring-data-eclipse-store-root</artifactId>
8-
<version>1.1.0-SNAPSHOT</version>
8+
<version>2.0.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>spring-data-eclipse-store-benchmark</artifactId>
12-
<version>1.1.0-SNAPSHOT</version>
12+
<version>2.0.0-SNAPSHOT</version>
1313
<packaging>jar</packaging>
1414

1515
<inceptionYear>2023</inceptionYear>

spring-data-eclipse-store-demo/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>software.xdev</groupId>
99
<artifactId>spring-data-eclipse-store-root</artifactId>
10-
<version>1.1.0-SNAPSHOT</version>
10+
<version>2.0.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>spring-data-eclipse-store-demo</artifactId>
14-
<version>1.1.0-SNAPSHOT</version>
14+
<version>2.0.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

1717
<organization>

spring-data-eclipse-store-jpa/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>software.xdev</groupId>
99
<artifactId>spring-data-eclipse-store-root</artifactId>
10-
<version>1.1.0-SNAPSHOT</version>
10+
<version>2.0.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>spring-data-eclipse-store-jpa</artifactId>
14-
<version>1.1.0-SNAPSHOT</version>
14+
<version>2.0.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

1717
<inceptionYear>2023</inceptionYear>

spring-data-eclipse-store/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>spring-data-eclipse-store</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>spring-data-eclipse-store</name>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.exceptions;
17+
18+
public class InvalidRootException extends RuntimeException
19+
{
20+
public InvalidRootException(final String message)
21+
{
22+
super(message);
23+
}
24+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.repository;
17+
18+
import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
19+
20+
import software.xdev.micromigration.eclipsestore.MigrationManager;
21+
import software.xdev.micromigration.migrater.reflection.ReflectiveMigrater;
22+
import software.xdev.micromigration.version.MigrationVersion;
23+
import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot;
24+
import software.xdev.spring.data.eclipse.store.repository.root.update.scripts.v2_0_0_InitalizeVersioning;
25+
26+
27+
public class EclipseStoreMigrator
28+
{
29+
public static final Class<?> FIRST_UPDATE_SCRIPT = v2_0_0_InitalizeVersioning.class;
30+
31+
private EclipseStoreMigrator()
32+
{
33+
}
34+
35+
public static void migrate(final VersionedRoot versionedRoot, final EmbeddedStorageManager storageManager)
36+
{
37+
final ReflectiveMigrater migrater =
38+
new ReflectiveMigrater(FIRST_UPDATE_SCRIPT.getPackageName());
39+
new MigrationManager(versionedRoot, migrater, storageManager)
40+
.migrate(versionedRoot);
41+
}
42+
43+
public static MigrationVersion getLatestVersion()
44+
{
45+
final ReflectiveMigrater migrater =
46+
new ReflectiveMigrater(FIRST_UPDATE_SCRIPT.getPackageName());
47+
return migrater.getSortedScripts().last().getTargetVersion();
48+
}
49+
}

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

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@
2626
import org.eclipse.serializer.persistence.types.Storer;
2727
import org.eclipse.serializer.reference.ObjectSwizzling;
2828
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
29+
import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
2930
import org.eclipse.store.storage.types.StorageManager;
3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
3233

3334
import software.xdev.spring.data.eclipse.store.core.EntityListProvider;
3435
import software.xdev.spring.data.eclipse.store.core.EntityProvider;
3536
import software.xdev.spring.data.eclipse.store.exceptions.AlreadyRegisteredException;
37+
import software.xdev.spring.data.eclipse.store.exceptions.InvalidRootException;
3638
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
3739
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreStorageFoundationProvider;
3840
import software.xdev.spring.data.eclipse.store.repository.root.EntityData;
39-
import software.xdev.spring.data.eclipse.store.repository.root.Root;
41+
import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot;
4042
import software.xdev.spring.data.eclipse.store.repository.support.SimpleEclipseStoreRepository;
4143
import software.xdev.spring.data.eclipse.store.repository.support.concurrency.ReadWriteLock;
4244
import software.xdev.spring.data.eclipse.store.repository.support.concurrency.ReentrantJavaReadWriteLock;
@@ -68,8 +70,8 @@ public class EclipseStoreStorage
6870
private final EclipseStoreStorageFoundationProvider foundationProvider;
6971
private EntitySetCollector entitySetCollector;
7072
private PersistableChecker persistenceChecker;
71-
private StorageManager storageManager;
72-
private Root root;
73+
private EmbeddedStorageManager storageManager;
74+
private VersionedRoot root;
7375

7476
private final WorkingCopyRegistry registry = new WorkingCopyRegistry();
7577
private final ReadWriteLock readWriteLock = new ReentrantJavaReadWriteLock();
@@ -95,23 +97,55 @@ private synchronized void ensureEntitiesInRoot()
9597
{
9698
if(this.storageManager == null)
9799
{
98-
LOG.info("Starting storage...");
99-
this.root = new Root();
100100
final EmbeddedStorageFoundation<?> embeddedStorageFoundation =
101-
this.foundationProvider.createEmbeddedStorageFoundation();
102-
embeddedStorageFoundation.registerTypeHandler(BinaryHandlerImmutableCollectionsSet12.New());
103-
embeddedStorageFoundation.registerTypeHandler(BinaryHandlerImmutableCollectionsList12.New());
104-
this.storageManager = embeddedStorageFoundation.start(this.root);
101+
this.startStorageManager();
105102
this.persistenceChecker = new RelayedPersistenceChecker(embeddedStorageFoundation);
106103
this.initRoot();
107104
LOG.info(
108105
"Storage started with {} entity lists and {} entities.",
109-
this.root.getEntityTypesCount(),
110-
this.root.getEntityCount()
106+
this.root.getCurrentRootData().getEntityTypesCount(),
107+
this.root.getCurrentRootData().getEntityCount()
111108
);
109+
EclipseStoreMigrator.migrate(this.root, this.storageManager);
112110
}
113111
}
114112

113+
private EmbeddedStorageFoundation<?> startStorageManager()
114+
{
115+
LOG.info("Starting storage...");
116+
final EmbeddedStorageFoundation<?> embeddedStorageFoundation =
117+
this.foundationProvider.createEmbeddedStorageFoundation();
118+
embeddedStorageFoundation.registerTypeHandler(BinaryHandlerImmutableCollectionsSet12.New());
119+
embeddedStorageFoundation.registerTypeHandler(BinaryHandlerImmutableCollectionsList12.New());
120+
final EmbeddedStorageManager embeddedStorageManager = embeddedStorageFoundation.start();
121+
if(embeddedStorageManager.root() != null)
122+
{
123+
if(embeddedStorageManager.root() instanceof final Root oldRoot)
124+
{
125+
embeddedStorageManager.setRoot(new VersionedRoot(oldRoot));
126+
embeddedStorageManager.storeRoot();
127+
}
128+
else if(!(embeddedStorageManager.root() instanceof VersionedRoot))
129+
{
130+
throw new InvalidRootException(
131+
"Root object of type %s is invalid."
132+
.formatted(embeddedStorageManager.root()
133+
.getClass()
134+
.getName()
135+
)
136+
);
137+
}
138+
}
139+
else
140+
{
141+
embeddedStorageManager.setRoot(new VersionedRoot());
142+
embeddedStorageManager.storeRoot();
143+
}
144+
this.root = (VersionedRoot)embeddedStorageManager.root();
145+
this.storageManager = embeddedStorageManager;
146+
return embeddedStorageFoundation;
147+
}
148+
115149
public <T> SimpleEclipseStoreRepository<T, ?> getRepository(final Class<T> entityClass)
116150
{
117151
return (SimpleEclipseStoreRepository<T, ?>)this.entityClassToRepository.get(entityClass);
@@ -124,22 +158,24 @@ private void initRoot()
124158
LOG.debug("Initializing entity lists...");
125159
}
126160
this.repositorySynchronizer =
127-
new SimpleRepositorySynchronizer(this.root);
161+
new SimpleRepositorySynchronizer(this.root.getCurrentRootData());
128162
boolean entityListMustGetStored = false;
129163
for(final Class<?> entityClass : this.entityClassToRepository.keySet())
130164
{
131-
if(this.root.getEntityData(entityClass) == null)
165+
if(this.root.getCurrentRootData().getEntityData(entityClass) == null)
132166
{
133167
this.createNewEntityList(entityClass);
134168
entityListMustGetStored = true;
135169
}
136170
}
137171
if(entityListMustGetStored)
138172
{
139-
this.storageManager.store(this.root.getEntityLists());
173+
this.storageManager.store(this.root.getCurrentRootData().getEntityLists());
140174
}
141175
this.entitySetCollector =
142-
new EntitySetCollector(this.root::getEntityData, this.entityClassToRepository.keySet());
176+
new EntitySetCollector(
177+
this.root.getCurrentRootData()::getEntityData,
178+
this.entityClassToRepository.keySet());
143179
if(LOG.isDebugEnabled())
144180
{
145181
LOG.debug("Done initializing entity lists.");
@@ -149,7 +185,7 @@ private void initRoot()
149185
private <T, ID> void createNewEntityList(final Class<T> entityClass)
150186
{
151187
final IdManager<T, ID> idManager = this.ensureIdManager(entityClass);
152-
this.root.createNewEntityList(entityClass, e -> idManager.getId(e));
188+
this.root.getCurrentRootData().createNewEntityList(entityClass, e -> idManager.getId(e));
153189
}
154190

155191
public synchronized <T> void registerEntity(
@@ -174,7 +210,7 @@ private <T, ID> EntityData<T, ID> getEntityData(final Class<T> clazz)
174210
{
175211
this.ensureEntitiesInRoot();
176212
return this.readWriteLock.read(
177-
() -> this.root.getEntityData(clazz)
213+
() -> this.root.getCurrentRootData().getEntityData(clazz)
178214
);
179215
}
180216

@@ -193,7 +229,7 @@ public <T> long getEntityCount(final Class<T> clazz)
193229
return this.readWriteLock.read(
194230
() ->
195231
{
196-
final EntityData<T, Object> entityData = this.root.getEntityData(clazz);
232+
final EntityData<T, Object> entityData = this.root.getCurrentRootData().getEntityData(clazz);
197233
return entityData == null ? 0 : entityData.getEntityCount();
198234
}
199235
);
@@ -286,7 +322,7 @@ public void clearData()
286322
this.readWriteLock.write(
287323
() ->
288324
{
289-
this.root = new Root();
325+
this.root = new VersionedRoot();
290326
final StorageManager instanceOfstorageManager = this.getInstanceOfStorageManager();
291327
this.initRoot();
292328

@@ -370,22 +406,22 @@ public <T> VersionManager<T> ensureVersionManager(final Class<T> possiblyVersion
370406

371407
public Object getLastId(final Class<?> entityClass)
372408
{
373-
return this.readWriteLock.read(() -> this.root.getLastId(entityClass));
409+
return this.readWriteLock.read(() -> this.root.getCurrentRootData().getLastId(entityClass));
374410
}
375411

376412
public void setLastId(final Class<?> entityClass, final Object lastId)
377413
{
378414
this.readWriteLock.write(
379415
() ->
380416
{
381-
final EntityData<?, Object> entityData = this.root.getEntityData(entityClass);
417+
final EntityData<?, Object> entityData = this.root.getCurrentRootData().getEntityData(entityClass);
382418
if(entityData == null)
383419
{
384420
this.createNewEntityList(entityClass);
385-
this.storageManager.store(this.root.getEntityLists());
421+
this.storageManager.store(this.root.getCurrentRootData().getEntityLists());
386422
}
387-
this.root.setLastId(entityClass, lastId);
388-
this.storageManager.store(this.root.getObjectsToStoreAfterNewLastId(entityClass));
423+
this.root.getCurrentRootData().setLastId(entityClass, lastId);
424+
this.storageManager.store(this.root.getCurrentRootData().getObjectsToStoreAfterNewLastId(entityClass));
389425
}
390426
);
391427
}

0 commit comments

Comments
 (0)