Skip to content

v2.0.1 #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ hs_err_pid*
storage
storage-person
storage-invoice
storage-jpa
storage-complex
storage-eclipsestore
spring-data-eclipse-store-jpa/storage-h2.mv.db
spring-data-eclipse-store-jpa/storage-h2.trace.db

# == IntelliJ ==
*.iml
Expand All @@ -86,4 +89,3 @@ storage-jpa
.idea/codeStyles/*
!.idea/codeStyles/codeStyleConfig.xml
!.idea/codeStyles/Project.xml
/spring-data-eclipse-store-demo/storage-complex
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.0.1

* Fix for Issue [#131](https://github.com/xdev-software/spring-data-eclipse-store/issues/131)

# 2.0.0

* Restructured root to improve performance with IDs in entities
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
</dependency>
</dependencies>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
@EnableEclipseStoreRepositories
public class ComplexConfiguration extends EclipseStoreClientConfiguration
{

public static final String STORAGE_PATH = "storage-complex";

@Autowired
public ComplexConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
Expand All @@ -42,7 +45,7 @@ public ComplexConfiguration(
@Override
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
{
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of("storage-complex"))));
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
public class PersistenceInvoiceConfiguration extends EclipseStoreClientConfiguration
{

public static final String STORAGE_PATH = "storage-invoice";

@Autowired
protected PersistenceInvoiceConfiguration(
final EclipseStoreProperties defaultEclipseStoreProperties,
Expand All @@ -43,6 +45,6 @@ protected PersistenceInvoiceConfiguration(
@Override
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
{
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of("storage-invoice"))));
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@EnableEclipseStoreRepositories
public class PersistencePersonConfiguration extends EclipseStoreClientConfiguration
{
public static final String STORAGE_PATH = "storage-person";

private final EmbeddedStorageFoundationFactory foundation;
private final EclipseStoreProperties properties;

Expand Down Expand Up @@ -49,7 +51,7 @@ public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
{
final ConfigurationPair additionalProperties = new ConfigurationPair(
EmbeddedStorageConfigurationPropertyNames.STORAGE_DIRECTORY,
"storage-person");
STORAGE_PATH);
return this.foundation.createStorageFoundation(this.properties, additionalProperties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright © 2024 XDEV Software (https://xdev.software)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package software.xdev.spring.data.eclipse.store.demo;

import java.io.File;

import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;


public final class TestUtil
{
public static boolean deleteDirectory(final File directoryToDelete)
{
final File[] allContents = directoryToDelete.listFiles();
if(allContents != null)
{
for(final File file : allContents)
{
deleteDirectory(file);
}
}
return directoryToDelete.delete();
}

public static void restartDatastore(final EclipseStoreClientConfiguration configuration)
{
configuration.getStorageInstance().stop();
// Storage starts automatically again, if the repo is accessed
}

private TestUtil()
{
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
package software.xdev.spring.data.eclipse.store.demo.complex;

import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import software.xdev.spring.data.eclipse.store.demo.TestUtil;
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;


@SpringBootTest(classes = ComplexDemoApplication.class)
class ComplexDemoApplicationTest
{
private final EclipseStoreClientConfiguration configuration;

@Autowired
public ComplexDemoApplicationTest(final ComplexConfiguration configuration)
{
this.configuration = configuration;
}

@BeforeAll
static void clearPreviousData()
{
TestUtil.deleteDirectory(new File("./" + ComplexConfiguration.STORAGE_PATH));
}

@Test
void checkPossibilityToSimplyStartApplication()
void checkPossibilityToSimplyStartAndRestartApplication()
{
assertTrue(true);
this.configuration.getStorageInstance().stop();
ComplexDemoApplication.main(new String[]{});
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
package software.xdev.spring.data.eclipse.store.demo.simple;

import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import software.xdev.spring.data.eclipse.store.demo.TestUtil;
import software.xdev.spring.data.eclipse.store.repository.config.DefaultEclipseStoreClientConfiguration;
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;


@SpringBootTest(classes = SimpleDemoApplication.class)
class SimpleDemoApplicationTest
{
public static final String STORAGE_PATH = "storage";
private final EclipseStoreClientConfiguration configuration;

@Autowired
public SimpleDemoApplicationTest(final DefaultEclipseStoreClientConfiguration configuration)
{
this.configuration = configuration;
}

@BeforeAll
static void clearPreviousData()
{
TestUtil.deleteDirectory(new File("./" + STORAGE_PATH));
}

@Test
void checkPossibilityToSimplyStartApplication()
void checkPossibilityToSimplyStartAndRestartApplication()
{
assertTrue(true);
this.configuration.getStorageInstance().stop();
SimpleDemoApplication.main(new String[]{});
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
org.eclipse.store.storage-directory=./storage-jpa
org.eclipse.store.storage-directory=./storage-eclipsestore
spring.datasource.url=jdbc:h2:file:./storage-h2;
spring.jpa.hibernate.ddl-auto=update
4 changes: 2 additions & 2 deletions spring-data-eclipse-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
</dependency>
</dependencies>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ private void initRoot()
{
if(this.root.getCurrentRootData().getEntityData(entityClass) == null)
{
this.createNewEntityList(entityClass);
this.createNewEntityData(entityClass, this.root);
entityListMustGetStored = true;
}
else
{
this.setIdManagerForEntityData(entityClass, this.root);
}
}
if(entityListMustGetStored)
{
Expand All @@ -183,10 +187,17 @@ private void initRoot()
}
}

private <T, ID> void createNewEntityList(final Class<T> entityClass)
private <T, ID> void createNewEntityData(final Class<T> entityClass, final VersionedRoot root)
{
final IdManager<T, ID> idManager = this.ensureIdManager(entityClass);
root.getCurrentRootData().createNewEntityData(entityClass, idManager::getId);
}

private <T, ID> void setIdManagerForEntityData(final Class<T> entityClass, final VersionedRoot root)
{
final IdManager<T, ID> idManager = this.ensureIdManager(entityClass);
this.root.getCurrentRootData().createNewEntityList(entityClass, idManager::getId);
final EntityData<T, Object> entityData = root.getCurrentRootData().getEntityData(entityClass);
entityData.setIdGetter(idManager::getId);
}

public synchronized <T> void registerEntity(
Expand Down Expand Up @@ -356,7 +367,7 @@ public synchronized void stop()
LOG.info("Stopping storage...");
if(this.storageManager != null)
{
this.storageManager.shutdown();
this.storageManager.close();
this.storageManager = null;
this.root = null;
this.registry.reset();
Expand Down Expand Up @@ -407,20 +418,26 @@ public <T> VersionManager<T> ensureVersionManager(final Class<T> possiblyVersion

public Object getLastId(final Class<?> entityClass)
{
this.ensureEntitiesInRoot();
return this.readWriteLock.read(() -> this.root.getCurrentRootData().getLastId(entityClass));
}

public void setLastId(final Class<?> entityClass, final Object lastId)
{
this.ensureEntitiesInRoot();
this.readWriteLock.write(
() ->
{
final EntityData<?, Object> entityData = this.root.getCurrentRootData().getEntityData(entityClass);
if(entityData == null)
{
this.createNewEntityList(entityClass);
this.createNewEntityData(entityClass, this.root);
this.storageManager.store(this.root.getCurrentRootData().getEntityListsToStore());
}
else
{
this.setIdManagerForEntityData(entityClass, this.root);
}
this.root.getCurrentRootData().setLastId(entityClass, lastId);
this.storageManager.store(this.root.getCurrentRootData().getObjectsToStoreAfterNewLastId(entityClass));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,59 @@
@NoRepositoryBean
public interface EclipseStoreCrudRepository<T, ID> extends CrudRepository<T, ID>
{
/**
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
* another object, the behavior of this function may differ from what you are used to!
* <p>
* JPA would throw a {@code JdbcSQLIntegrityConstraintViolationException} but it would be very expensive to search
* the referencedObject in the complete object tree and throw the exception.
* <p>
* That is why this library simply removes the element from the repository, but if it is still referenced by
* another
* object, this <b>reference is still working and pointing to the object</b>. That means that in fact this the
* object to remove could very well stay in the storage if it is referenced.
* </p>
*/
@Override
void deleteById(ID id);

/**
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
* another object, the behavior of this function may differ from what you are used to!
* <p>
* For more information see {@link #deleteById(Object)}
* </p>
*/
@Override
void delete(T entity);

/**
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
* another object, the behavior of this function may differ from what you are used to!
* <p>
* For more information see {@link #deleteById(Object)}
* </p>
*/
@Override
void deleteAllById(Iterable<? extends ID> ids);

/**
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
* another object, the behavior of this function may differ from what you are used to!
* <p>
* For more information see {@link #deleteById(Object)}
* </p>
*/
@Override
void deleteAll(Iterable<? extends T> entities);

/**
* @inheritDoc <b>Caution with referenced objects!</b><br/> If you are deleting an object that is referenced by
* another object, the behavior of this function may differ from what you are used to!
* <p>
* For more information see {@link #deleteById(Object)}
* </p>
*/
@Override
void deleteAll();
}
Loading