org.apache.maven.plugins
maven-source-plugin
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/aot/EclipseStoreRuntimeHints.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/aot/EclipseStoreRuntimeHints.java
new file mode 100644
index 00000000..20352c97
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/aot/EclipseStoreRuntimeHints.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2023 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.aot;
+
+import org.springframework.aot.hint.RuntimeHints;
+import org.springframework.aot.hint.RuntimeHintsRegistrar;
+import org.springframework.lang.Nullable;
+
+import jakarta.annotation.Nonnull;
+
+
+/**
+ * Makes registration of types for reflection ({@link org.springframework.aot.hint.RuntimeHints} or proxies possible.
+ *
+ * Is not needed right now, but is left here for future use.
+ *
+ * @see https://docs.spring
+ * .io/spring-framework/reference/core/aot.html#aot.hints
+ */
+class EclipseStoreRuntimeHints implements RuntimeHintsRegistrar
+{
+ public EclipseStoreRuntimeHints()
+ {
+ // Is not needed right now, but is left here for future use.
+ }
+
+ @Override
+ @Nonnull
+ public void registerHints(@Nonnull final RuntimeHints hints, @Nullable final ClassLoader classLoader)
+ {
+ // Is not needed right now, but is left here for future use.
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/IdentitySet.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/IdentitySet.java
new file mode 100644
index 00000000..d5af7575
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/core/IdentitySet.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright © 2023 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.core;
+
+import java.util.Collection;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import jakarta.annotation.Nonnull;
+
+import org.eclipse.serializer.meta.NotImplementedYetError;
+import org.springframework.lang.NonNull;
+
+
+/**
+ * A hash map implementation depending on object identity (==) rather than equality (.equals) to identify elements.
+ **/
+public class IdentitySet implements Set
+{
+ private final IdentityHashMap internalMap;
+
+ public IdentitySet()
+ {
+ this.internalMap = new IdentityHashMap<>();
+ }
+
+ @Override
+ public int size()
+ {
+ return this.internalMap.size();
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return this.internalMap.isEmpty();
+ }
+
+ @SuppressWarnings("SuspiciousMethodCalls")
+ @Override
+ public boolean contains(final Object o)
+ {
+ return this.internalMap.containsKey(o);
+ }
+
+ @Override
+ @Nonnull
+ public Iterator iterator()
+ {
+ return this.internalMap.keySet().iterator();
+ }
+
+ @Override
+ @Nonnull
+ public Object[] toArray()
+ {
+ return this.internalMap.keySet().toArray();
+ }
+
+ @Override
+ @NonNull
+ public T[] toArray(@Nonnull final T[] a)
+ {
+ return this.internalMap.keySet().toArray(a);
+ }
+
+ @Override
+ public boolean add(final E e)
+ {
+ return this.internalMap.put(e, null) == null;
+ }
+
+ @Override
+ public boolean remove(final Object o)
+ {
+ return this.internalMap.remove(o) != null;
+ }
+
+ @Override
+ public boolean containsAll(@Nonnull final Collection> c)
+ {
+ return this.internalMap.keySet().containsAll(c);
+ }
+
+ @Override
+ public boolean addAll(@Nonnull final Collection extends E> c)
+ {
+ throw new NotImplementedYetError();
+ }
+
+ @Override
+ public boolean retainAll(@Nonnull final Collection> c)
+ {
+ throw new NotImplementedYetError();
+ }
+
+ @Override
+ public boolean removeAll(final Collection> c)
+ {
+ // "Why toList?" - So that if you input your own reference (this) into this function, it does not break.
+ return c.stream().toList().stream().map(this.internalMap::remove).anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void clear()
+ {
+ this.internalMap.clear();
+ }
+
+ @SuppressWarnings("com.haulmont.jpb.EqualsDoesntCheckParameterClass")
+ @Override
+ public boolean equals(final Object o)
+ {
+ return this.internalMap.equals(o);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return this.internalMap.hashCode();
+ }
+
+ public Map getInternalMap()
+ {
+ return this.internalMap;
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/AlreadyRegisteredException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/AlreadyRegisteredException.java
new file mode 100644
index 00000000..a0ba3bf7
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/AlreadyRegisteredException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class AlreadyRegisteredException extends RuntimeException
+{
+ public AlreadyRegisteredException(final String entityName)
+ {
+ super(String.format("Entity %s already registered.", entityName));
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/DifferentClassesException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/DifferentClassesException.java
new file mode 100644
index 00000000..9eee8d81
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/DifferentClassesException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class DifferentClassesException extends RuntimeException
+{
+ public DifferentClassesException(final String message)
+ {
+ super(message);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/FieldAccessReflectionException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/FieldAccessReflectionException.java
new file mode 100644
index 00000000..a5c854c7
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/FieldAccessReflectionException.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+import java.lang.reflect.Field;
+
+
+public class FieldAccessReflectionException extends RuntimeException
+{
+ public static final String COULD_NOT_READ_FIELD = "Could not read field %s";
+
+ public FieldAccessReflectionException(final String message, final Exception e)
+ {
+ super(message, e);
+ }
+
+ public FieldAccessReflectionException(final Field field, final Exception e)
+ {
+ this(String.format(FieldAccessReflectionException.COULD_NOT_READ_FIELD, field.getName()), e);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdFieldFinalException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdFieldFinalException.java
new file mode 100644
index 00000000..2abfa3e2
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdFieldFinalException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class IdFieldFinalException extends RuntimeException
+{
+ public IdFieldFinalException(final String message)
+ {
+ super(message);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdGeneratorNotSupportedException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdGeneratorNotSupportedException.java
new file mode 100644
index 00000000..808049b7
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/IdGeneratorNotSupportedException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class IdGeneratorNotSupportedException extends RuntimeException
+{
+ public IdGeneratorNotSupportedException(final String message)
+ {
+ super(message);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/MergeFailedException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/MergeFailedException.java
new file mode 100644
index 00000000..0ce35b02
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/MergeFailedException.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class MergeFailedException extends RuntimeException
+{
+ public MergeFailedException(final Object sourceObject, final Object targetObject, final Exception e)
+ {
+ super(
+ String.format(
+ "Could not merge values of object %s with object %s",
+ sourceObject.getClass().getName(),
+ targetObject.getClass().getName()
+ ),
+ e
+ );
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoIdFieldFoundException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoIdFieldFoundException.java
new file mode 100644
index 00000000..cd9c6f7f
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoIdFieldFoundException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class NoIdFieldFoundException extends RuntimeException
+{
+ public NoIdFieldFoundException(final String message)
+ {
+ super(message);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoPageableObjectFoundException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoPageableObjectFoundException.java
new file mode 100644
index 00000000..c49733a4
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NoPageableObjectFoundException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class NoPageableObjectFoundException extends RuntimeException
+{
+ public NoPageableObjectFoundException(final String message)
+ {
+ super(message);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NotComparableException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NotComparableException.java
new file mode 100644
index 00000000..115e2b8f
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/NotComparableException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class NotComparableException extends RuntimeException
+{
+ public NotComparableException(final String message)
+ {
+ super(message);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/StringBlankException.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/StringBlankException.java
new file mode 100644
index 00000000..78d203f2
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/exceptions/StringBlankException.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2023 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.exceptions;
+
+public class StringBlankException extends RuntimeException
+{
+ public StringBlankException()
+ {
+ this("String is empty or blank.");
+ }
+
+ public StringBlankException(final String message)
+ {
+ super(message);
+ }
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreRepository.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreRepository.java
new file mode 100644
index 00000000..e311af0c
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreRepository.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright © 2023 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.repository;
+
+import org.springframework.data.repository.ListCrudRepository;
+import org.springframework.data.repository.ListPagingAndSortingRepository;
+import org.springframework.data.repository.NoRepositoryBean;
+
+
+@NoRepositoryBean
+public interface EclipseStoreRepository
+ extends ListCrudRepository, ListPagingAndSortingRepository
+{
+}
diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java
new file mode 100644
index 00000000..d9c5de5b
--- /dev/null
+++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java
@@ -0,0 +1,297 @@
+/*
+ * Copyright © 2023 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.repository;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import org.eclipse.serializer.persistence.binary.jdk17.java.util.BinaryHandlerImmutableCollectionsList12;
+import org.eclipse.serializer.persistence.binary.jdk17.java.util.BinaryHandlerImmutableCollectionsSet12;
+import org.eclipse.serializer.persistence.types.Storer;
+import org.eclipse.store.integrations.spring.boot.types.EclipseStoreProvider;
+import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
+import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
+import org.eclipse.store.storage.types.StorageManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import software.xdev.spring.data.eclipse.store.core.IdentitySet;
+import software.xdev.spring.data.eclipse.store.exceptions.AlreadyRegisteredException;
+import software.xdev.spring.data.eclipse.store.repository.support.copier.id.IdSetter;
+import software.xdev.spring.data.eclipse.store.repository.support.reposyncer.RepositorySynchronizer;
+import software.xdev.spring.data.eclipse.store.repository.support.reposyncer.SimpleRepositorySynchronizer;
+
+
+@Component
+public class EclipseStoreStorage
+ implements EntityListProvider, IdSetterProvider, PersistableChecker
+{
+ private static final Logger LOG = LoggerFactory.getLogger(EclipseStoreStorage.class);
+ private final Map, String> entityClassToRepositoryName = new HashMap<>();
+ private final Map, IdSetter>> entityClassToIdSetter = new HashMap<>();
+ private EntitySetCollector entitySetCollector;
+ private PersistableChecker persistenceChecker;
+ private final EclipseStoreProperties storeConfiguration;
+ private final EclipseStoreProvider storeProvider;
+
+ private StorageManager storageManager;
+ private Root root;
+
+ private final WorkingCopyRegistry registry = new WorkingCopyRegistry();
+ private RepositorySynchronizer repositorySynchronizer;
+
+ @Autowired
+ public EclipseStoreStorage(
+ final EclipseStoreProperties storeConfiguration,
+ final EclipseStoreProvider storeProvider)
+ {
+ this.storeConfiguration = storeConfiguration;
+ this.storeProvider = storeProvider;
+ }
+
+ private synchronized StorageManager getInstanceOfStorageManager()
+ {
+ this.ensureEntitiesInRoot();
+ return this.storageManager;
+ }
+
+ public WorkingCopyRegistry getRegistry()
+ {
+ return this.registry;
+ }
+
+ private synchronized void ensureEntitiesInRoot()
+ {
+ if(this.storageManager == null)
+ {
+ LOG.info("Starting storage...");
+ this.root = new Root();
+ final EmbeddedStorageFoundation> embeddedStorageFoundation =
+ this.storeProvider.createStorageFoundation(this.storeConfiguration);
+ embeddedStorageFoundation.registerTypeHandler(BinaryHandlerImmutableCollectionsSet12.New());
+ embeddedStorageFoundation.registerTypeHandler(BinaryHandlerImmutableCollectionsList12.New());
+ this.storageManager = embeddedStorageFoundation.start(this.root);
+ this.persistenceChecker = new RelayedPersistenceChecker(embeddedStorageFoundation);
+ this.initRoot();
+ final Integer entitySum =
+ this.root.getEntityLists().values().stream().map(IdentitySet::size).reduce(0, Integer::sum);
+ LOG.info(
+ "Storage started with {} entity lists and {} entities.",
+ this.root.getEntityLists().size(),
+ entitySum);
+ }
+ }
+
+ private void initRoot()
+ {
+ if(LOG.isDebugEnabled())
+ {
+ LOG.debug("Initializing entity lists...");
+ }
+ this.repositorySynchronizer =
+ new SimpleRepositorySynchronizer(this.entityClassToRepositoryName, this.root);
+ boolean entityListMustGetStored = false;
+ for(final String entityName : this.entityClassToRepositoryName.values())
+ {
+ if(!this.root.getEntityLists().containsKey(entityName))
+ {
+ this.root.getEntityLists().put(entityName, new IdentitySet<>());
+ entityListMustGetStored = true;
+ }
+ }
+ if(entityListMustGetStored)
+ {
+ this.storageManager.store(this.root.getEntityLists());
+ }
+ this.entitySetCollector = new EntitySetCollector(this.root.getEntityLists(), this.entityClassToRepositoryName);
+ if(LOG.isDebugEnabled())
+ {
+ LOG.debug("Done initializing entity lists.");
+ }
+ }
+
+ public synchronized void registerEntity(final Class classToRegister)
+ {
+ final String entityName = this.getEntityName(classToRegister);
+ if(this.entityClassToRepositoryName.containsKey(classToRegister))
+ {
+ throw new AlreadyRegisteredException(entityName);
+ }
+ this.entityClassToRepositoryName.put(classToRegister, entityName);
+ }
+
+ private String getEntityName(final Class classToRegister)
+ {
+ return classToRegister.getName();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized IdentitySet getEntityList(final Class clazz)
+ {
+ this.ensureEntitiesInRoot();
+ return (IdentitySet)this.root.getEntityLists().get(this.getEntityName(clazz));
+ }
+
+ public synchronized void store(
+ final Collection