Skip to content

Commit e229a80

Browse files
Merge pull request #132 from xdev-software/develop
v2.0.1
2 parents 0090099 + dd3bc41 commit e229a80

File tree

19 files changed

+294
-36
lines changed

19 files changed

+294
-36
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ hs_err_pid*
6565
storage
6666
storage-person
6767
storage-invoice
68-
storage-jpa
68+
storage-complex
69+
storage-eclipsestore
70+
spring-data-eclipse-store-jpa/storage-h2.mv.db
71+
spring-data-eclipse-store-jpa/storage-h2.trace.db
6972

7073
# == IntelliJ ==
7174
*.iml
@@ -86,4 +89,3 @@ storage-jpa
8689
.idea/codeStyles/*
8790
!.idea/codeStyles/codeStyleConfig.xml
8891
!.idea/codeStyles/Project.xml
89-
/spring-data-eclipse-store-demo/storage-complex

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.1
2+
3+
* Fix for Issue [#131](https://github.com/xdev-software/spring-data-eclipse-store/issues/131)
4+
15
# 2.0.0
26

37
* Restructured root to improve performance with IDs in entities

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@
9393
<dependency>
9494
<groupId>net.sourceforge.pmd</groupId>
9595
<artifactId>pmd-core</artifactId>
96-
<version>7.3.0</version>
96+
<version>7.4.0</version>
9797
</dependency>
9898
<dependency>
9999
<groupId>net.sourceforge.pmd</groupId>
100100
<artifactId>pmd-java</artifactId>
101-
<version>7.3.0</version>
101+
<version>7.4.0</version>
102102
</dependency>
103103
</dependencies>
104104
</plugin>

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/ComplexConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
@EnableEclipseStoreRepositories
2323
public class ComplexConfiguration extends EclipseStoreClientConfiguration
2424
{
25+
26+
public static final String STORAGE_PATH = "storage-complex";
27+
2528
@Autowired
2629
public ComplexConfiguration(
2730
final EclipseStoreProperties defaultEclipseStoreProperties,
@@ -42,7 +45,7 @@ public ComplexConfiguration(
4245
@Override
4346
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
4447
{
45-
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of("storage-complex"))));
48+
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
4649
}
4750

4851
/**

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/dual/storage/invoice/PersistenceInvoiceConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
public class PersistenceInvoiceConfiguration extends EclipseStoreClientConfiguration
2525
{
2626

27+
public static final String STORAGE_PATH = "storage-invoice";
28+
2729
@Autowired
2830
protected PersistenceInvoiceConfiguration(
2931
final EclipseStoreProperties defaultEclipseStoreProperties,
@@ -43,6 +45,6 @@ protected PersistenceInvoiceConfiguration(
4345
@Override
4446
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
4547
{
46-
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of("storage-invoice"))));
48+
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
4749
}
4850
}

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/dual/storage/person/PersistencePersonConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
@EnableEclipseStoreRepositories
2323
public class PersistencePersonConfiguration extends EclipseStoreClientConfiguration
2424
{
25+
public static final String STORAGE_PATH = "storage-person";
26+
2527
private final EmbeddedStorageFoundationFactory foundation;
2628
private final EclipseStoreProperties properties;
2729

@@ -49,7 +51,7 @@ public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
4951
{
5052
final ConfigurationPair additionalProperties = new ConfigurationPair(
5153
EmbeddedStorageConfigurationPropertyNames.STORAGE_DIRECTORY,
52-
"storage-person");
54+
STORAGE_PATH);
5355
return this.foundation.createStorageFoundation(this.properties, additionalProperties);
5456
}
5557
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.demo;
17+
18+
import java.io.File;
19+
20+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
21+
22+
23+
public final class TestUtil
24+
{
25+
public static boolean deleteDirectory(final File directoryToDelete)
26+
{
27+
final File[] allContents = directoryToDelete.listFiles();
28+
if(allContents != null)
29+
{
30+
for(final File file : allContents)
31+
{
32+
deleteDirectory(file);
33+
}
34+
}
35+
return directoryToDelete.delete();
36+
}
37+
38+
public static void restartDatastore(final EclipseStoreClientConfiguration configuration)
39+
{
40+
configuration.getStorageInstance().stop();
41+
// Storage starts automatically again, if the repo is accessed
42+
}
43+
44+
private TestUtil()
45+
{
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
package software.xdev.spring.data.eclipse.store.demo.complex;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import java.io.File;
44

5+
import org.junit.jupiter.api.BeforeAll;
56
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
68
import org.springframework.boot.test.context.SpringBootTest;
79

10+
import software.xdev.spring.data.eclipse.store.demo.TestUtil;
11+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
12+
813

914
@SpringBootTest(classes = ComplexDemoApplication.class)
1015
class ComplexDemoApplicationTest
1116
{
17+
private final EclipseStoreClientConfiguration configuration;
18+
19+
@Autowired
20+
public ComplexDemoApplicationTest(final ComplexConfiguration configuration)
21+
{
22+
this.configuration = configuration;
23+
}
24+
25+
@BeforeAll
26+
static void clearPreviousData()
27+
{
28+
TestUtil.deleteDirectory(new File("./" + ComplexConfiguration.STORAGE_PATH));
29+
}
30+
1231
@Test
13-
void checkPossibilityToSimplyStartApplication()
32+
void checkPossibilityToSimplyStartAndRestartApplication()
1433
{
15-
assertTrue(true);
34+
this.configuration.getStorageInstance().stop();
35+
ComplexDemoApplication.main(new String[]{});
1636
}
1737
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
package software.xdev.spring.data.eclipse.store.demo.simple;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import java.io.File;
44

5+
import org.junit.jupiter.api.BeforeAll;
56
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
68
import org.springframework.boot.test.context.SpringBootTest;
79

10+
import software.xdev.spring.data.eclipse.store.demo.TestUtil;
11+
import software.xdev.spring.data.eclipse.store.repository.config.DefaultEclipseStoreClientConfiguration;
12+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
13+
814

915
@SpringBootTest(classes = SimpleDemoApplication.class)
1016
class SimpleDemoApplicationTest
1117
{
18+
public static final String STORAGE_PATH = "storage";
19+
private final EclipseStoreClientConfiguration configuration;
20+
21+
@Autowired
22+
public SimpleDemoApplicationTest(final DefaultEclipseStoreClientConfiguration configuration)
23+
{
24+
this.configuration = configuration;
25+
}
26+
27+
@BeforeAll
28+
static void clearPreviousData()
29+
{
30+
TestUtil.deleteDirectory(new File("./" + STORAGE_PATH));
31+
}
32+
1233
@Test
13-
void checkPossibilityToSimplyStartApplication()
34+
void checkPossibilityToSimplyStartAndRestartApplication()
1435
{
15-
assertTrue(true);
36+
this.configuration.getStorageInstance().stop();
37+
SimpleDemoApplication.main(new String[]{});
1638
}
1739
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
org.eclipse.store.storage-directory=./storage-jpa
1+
org.eclipse.store.storage-directory=./storage-eclipsestore
2+
spring.datasource.url=jdbc:h2:file:./storage-h2;
3+
spring.jpa.hibernate.ddl-auto=update

spring-data-eclipse-store/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,12 @@
426426
<dependency>
427427
<groupId>net.sourceforge.pmd</groupId>
428428
<artifactId>pmd-core</artifactId>
429-
<version>7.3.0</version>
429+
<version>7.4.0</version>
430430
</dependency>
431431
<dependency>
432432
<groupId>net.sourceforge.pmd</groupId>
433433
<artifactId>pmd-java</artifactId>
434-
<version>7.3.0</version>
434+
<version>7.4.0</version>
435435
</dependency>
436436
</dependencies>
437437
</plugin>

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,13 @@ private void initRoot()
165165
{
166166
if(this.root.getCurrentRootData().getEntityData(entityClass) == null)
167167
{
168-
this.createNewEntityList(entityClass);
168+
this.createNewEntityData(entityClass, this.root);
169169
entityListMustGetStored = true;
170170
}
171+
else
172+
{
173+
this.setIdManagerForEntityData(entityClass, this.root);
174+
}
171175
}
172176
if(entityListMustGetStored)
173177
{
@@ -183,10 +187,17 @@ private void initRoot()
183187
}
184188
}
185189

186-
private <T, ID> void createNewEntityList(final Class<T> entityClass)
190+
private <T, ID> void createNewEntityData(final Class<T> entityClass, final VersionedRoot root)
191+
{
192+
final IdManager<T, ID> idManager = this.ensureIdManager(entityClass);
193+
root.getCurrentRootData().createNewEntityData(entityClass, idManager::getId);
194+
}
195+
196+
private <T, ID> void setIdManagerForEntityData(final Class<T> entityClass, final VersionedRoot root)
187197
{
188198
final IdManager<T, ID> idManager = this.ensureIdManager(entityClass);
189-
this.root.getCurrentRootData().createNewEntityList(entityClass, idManager::getId);
199+
final EntityData<T, Object> entityData = root.getCurrentRootData().getEntityData(entityClass);
200+
entityData.setIdGetter(idManager::getId);
190201
}
191202

192203
public synchronized <T> void registerEntity(
@@ -356,7 +367,7 @@ public synchronized void stop()
356367
LOG.info("Stopping storage...");
357368
if(this.storageManager != null)
358369
{
359-
this.storageManager.shutdown();
370+
this.storageManager.close();
360371
this.storageManager = null;
361372
this.root = null;
362373
this.registry.reset();
@@ -407,20 +418,26 @@ public <T> VersionManager<T> ensureVersionManager(final Class<T> possiblyVersion
407418

408419
public Object getLastId(final Class<?> entityClass)
409420
{
421+
this.ensureEntitiesInRoot();
410422
return this.readWriteLock.read(() -> this.root.getCurrentRootData().getLastId(entityClass));
411423
}
412424

413425
public void setLastId(final Class<?> entityClass, final Object lastId)
414426
{
427+
this.ensureEntitiesInRoot();
415428
this.readWriteLock.write(
416429
() ->
417430
{
418431
final EntityData<?, Object> entityData = this.root.getCurrentRootData().getEntityData(entityClass);
419432
if(entityData == null)
420433
{
421-
this.createNewEntityList(entityClass);
434+
this.createNewEntityData(entityClass, this.root);
422435
this.storageManager.store(this.root.getCurrentRootData().getEntityListsToStore());
423436
}
437+
else
438+
{
439+
this.setIdManagerForEntityData(entityClass, this.root);
440+
}
424441
this.root.getCurrentRootData().setLastId(entityClass, lastId);
425442
this.storageManager.store(this.root.getCurrentRootData().getObjectsToStoreAfterNewLastId(entityClass));
426443
}

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,59 @@
2323
@NoRepositoryBean
2424
public interface EclipseStoreCrudRepository<T, ID> extends CrudRepository<T, ID>
2525
{
26+
/**
27+
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
28+
* another object, the behavior of this function may differ from what you are used to!
29+
* <p>
30+
* JPA would throw a {@code JdbcSQLIntegrityConstraintViolationException} but it would be very expensive to search
31+
* the referencedObject in the complete object tree and throw the exception.
32+
* <p>
33+
* That is why this library simply removes the element from the repository, but if it is still referenced by
34+
* another
35+
* object, this <b>reference is still working and pointing to the object</b>. That means that in fact this the
36+
* object to remove could very well stay in the storage if it is referenced.
37+
* </p>
38+
*/
39+
@Override
40+
void deleteById(ID id);
41+
42+
/**
43+
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
44+
* another object, the behavior of this function may differ from what you are used to!
45+
* <p>
46+
* For more information see {@link #deleteById(Object)}
47+
* </p>
48+
*/
49+
@Override
50+
void delete(T entity);
51+
52+
/**
53+
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
54+
* another object, the behavior of this function may differ from what you are used to!
55+
* <p>
56+
* For more information see {@link #deleteById(Object)}
57+
* </p>
58+
*/
59+
@Override
60+
void deleteAllById(Iterable<? extends ID> ids);
61+
62+
/**
63+
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
64+
* another object, the behavior of this function may differ from what you are used to!
65+
* <p>
66+
* For more information see {@link #deleteById(Object)}
67+
* </p>
68+
*/
69+
@Override
70+
void deleteAll(Iterable<? extends T> entities);
71+
72+
/**
73+
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
74+
* another object, the behavior of this function may differ from what you are used to!
75+
* <p>
76+
* For more information see {@link #deleteById(Object)}
77+
* </p>
78+
*/
79+
@Override
80+
void deleteAll();
2681
}

0 commit comments

Comments
 (0)