Skip to content

Commit fe8bfb4

Browse files
Implemented a definitive list that includes unsupported data types
1 parent cd80f3a commit fe8bfb4

11 files changed

Lines changed: 163 additions & 16 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright © 2023 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+
import software.xdev.spring.data.eclipse.store.util.StringUtil;
19+
20+
21+
public class DataTypeNotSupportedException extends RuntimeException
22+
{
23+
public DataTypeNotSupportedException(final String message)
24+
{
25+
super(message);
26+
}
27+
28+
public DataTypeNotSupportedException(final Class<?> clazz)
29+
{
30+
this(
31+
String.format(
32+
"Datatype %s is not supported right now. Please open a ticket at %s if you feel that this type should "
33+
+ "be supported.",
34+
clazz.getSimpleName(),
35+
StringUtil.REPOSITORY_URL
36+
)
37+
);
38+
}
39+
}

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/importer/EclipseStoreDataImporter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.slf4j.LoggerFactory;
3131

3232
import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage;
33+
import software.xdev.spring.data.eclipse.store.repository.SupportedChecker;
3334
import software.xdev.spring.data.eclipse.store.repository.support.SimpleEclipseStoreRepository;
3435
import software.xdev.spring.data.eclipse.store.repository.support.copier.working.RecursiveWorkingCopier;
3536

@@ -201,7 +202,8 @@ private <T> void createRepositoryForType(
201202
domainClass,
202203
this.eclipseStoreStorage.getRegistry(),
203204
this.eclipseStoreStorage,
204-
this.eclipseStoreStorage),
205+
this.eclipseStoreStorage,
206+
new SupportedChecker.Implementation()),
205207
domainClass);
206208
}
207209

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@
1515
*/
1616
package software.xdev.spring.data.eclipse.store.repository;
1717

18+
/**
19+
* Checks if a class is persistable by EclipseStore through the
20+
* {@link org.eclipse.store.storage.embedded.types.EmbeddedStorage}.
21+
*/
1822
@FunctionalInterface
1923
public interface PersistableChecker
2024
{
25+
/**
26+
* Checks if a class is persistable by EclipseStore through the
27+
* {@link org.eclipse.store.storage.embedded.types.EmbeddedStorage}.
28+
*/
2129
boolean isPersistable(Class<?> clazz);
2230
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright © 2023 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 java.util.Calendar;
19+
import java.util.EnumMap;
20+
import java.util.List;
21+
import java.util.WeakHashMap;
22+
23+
import org.eclipse.serializer.reference.Lazy;
24+
25+
26+
/**
27+
* Checks if a class is supported by the Spring-Data-Eclipse-Store library.
28+
* <p>
29+
* Some classes are not supported, because Eclipse Store doesn't support them.
30+
* </p>
31+
* <p>
32+
* {@link Lazy} is not supported, because a lot of hidden stuff must be done to keep Lazy-References really Lazy when
33+
* creating a working copy.
34+
* </p>
35+
*/
36+
@FunctionalInterface
37+
public interface SupportedChecker
38+
{
39+
/**
40+
* Checks if a class is supported by the Spring-Data-Eclipse-Store library.
41+
* <p>
42+
* Some classes are not supported, because Eclipse Store doesn't support them.
43+
* </p>
44+
* <p>
45+
* {@link Lazy} is not supported, because a lot of hidden stuff must be done to keep Lazy-References really Lazy
46+
* when creating a working copy.
47+
* </p>
48+
*/
49+
boolean isSupported(Class<?> clazz);
50+
51+
class Implementation implements SupportedChecker
52+
{
53+
private static final List<Class<?>> UNSUPPORTED_DATA_TYPES = List.of(
54+
// Is difficult to handle when creating working copies
55+
Lazy.class,
56+
// Here EclipseStore has problems: https://github.com/microstream-one/microstream/issues/173
57+
Calendar.class,
58+
WeakHashMap.class,
59+
// Here EclipseStore has problems too: https://github.com/microstream-one/microstream/issues/204
60+
EnumMap.class
61+
);
62+
63+
@Override
64+
public boolean isSupported(final Class<?> clazz)
65+
{
66+
return !UNSUPPORTED_DATA_TYPES.stream().anyMatch(
67+
unsupportedClazz -> unsupportedClazz.isAssignableFrom(clazz)
68+
);
69+
}
70+
}
71+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.lang.Nullable;
3333

3434
import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage;
35+
import software.xdev.spring.data.eclipse.store.repository.SupportedChecker;
3536
import software.xdev.spring.data.eclipse.store.repository.support.copier.working.RecursiveWorkingCopier;
3637
import software.xdev.spring.data.eclipse.store.repository.support.copier.working.WorkingCopier;
3738

@@ -80,7 +81,13 @@ private <T> WorkingCopier<T> createWorkingCopier(
8081
final Class<T> domainType,
8182
final EclipseStoreStorage storage)
8283
{
83-
return new RecursiveWorkingCopier<>(domainType, storage.getRegistry(), storage, storage);
84+
return new RecursiveWorkingCopier<>(
85+
domainType,
86+
storage.getRegistry(),
87+
storage,
88+
storage,
89+
new SupportedChecker.Implementation()
90+
);
8491
}
8592

8693
@Override

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/object/EclipseSerializerRegisteringCopier.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434

35+
import software.xdev.spring.data.eclipse.store.exceptions.DataTypeNotSupportedException;
36+
import software.xdev.spring.data.eclipse.store.repository.SupportedChecker;
3537
import software.xdev.spring.data.eclipse.store.repository.WorkingCopyRegistry;
3638
import software.xdev.spring.data.eclipse.store.repository.support.copier.DataTypeUtil;
3739

@@ -45,16 +47,20 @@ public class EclipseSerializerRegisteringCopier implements RegisteringObjectCopi
4547
private static final Logger LOG = LoggerFactory.getLogger(EclipseSerializerRegisteringCopier.class);
4648
private final SerializerFoundation<?> foundation;
4749
private PersistenceManager<Binary> persistenceManager;
50+
private final SupportedChecker supportedChecker;
4851

4952
private final WorkingCopyRegistry registry;
5053

51-
public EclipseSerializerRegisteringCopier(final WorkingCopyRegistry registry)
54+
public EclipseSerializerRegisteringCopier(
55+
final WorkingCopyRegistry registry,
56+
final SupportedChecker supportedChecker)
5257
{
5358
final SerializerFoundation<?> newFoundation = SerializerFoundation.New();
5459
newFoundation.registerCustomTypeHandler(BinaryHandlerImmutableCollectionsSet12.New());
5560
newFoundation.registerCustomTypeHandler(BinaryHandlerImmutableCollectionsList12.New());
5661
this.foundation = newFoundation;
5762
this.registry = registry;
63+
this.supportedChecker = supportedChecker;
5864
}
5965

6066
@Override
@@ -134,6 +140,10 @@ public synchronized <T> T copy(final T source, final boolean invertRegistering)
134140
loader.iterateEntries(
135141
(id, copiedObject) ->
136142
{
143+
if(copiedObject != null && !this.supportedChecker.isSupported(copiedObject.getClass()))
144+
{
145+
throw new DataTypeNotSupportedException(copiedObject.getClass());
146+
}
137147
summarizer.incrementCopiedObjectsCount();
138148
if(DataTypeUtil.isPrimitiveType(copiedObject.getClass()))
139149
{

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/working/RecursiveWorkingCopier.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import software.xdev.spring.data.eclipse.store.exceptions.MergeFailedException;
3434
import software.xdev.spring.data.eclipse.store.repository.IdSetterProvider;
3535
import software.xdev.spring.data.eclipse.store.repository.PersistableChecker;
36+
import software.xdev.spring.data.eclipse.store.repository.SupportedChecker;
3637
import software.xdev.spring.data.eclipse.store.repository.WorkingCopyRegistry;
3738
import software.xdev.spring.data.eclipse.store.repository.access.AccessHelper;
3839
import software.xdev.spring.data.eclipse.store.repository.access.modifier.FieldAccessModifier;
@@ -57,11 +58,12 @@ public RecursiveWorkingCopier(
5758
final Class<T> domainClass,
5859
final WorkingCopyRegistry registry,
5960
final IdSetterProvider idSetterProvider,
60-
final PersistableChecker persistableChecker)
61+
final PersistableChecker persistableChecker,
62+
final SupportedChecker supportedChecker)
6163
{
6264
this.domainClass = domainClass;
6365
this.registry = registry;
64-
this.objectCopier = new EclipseSerializerRegisteringCopier(registry);
66+
this.objectCopier = new EclipseSerializerRegisteringCopier(registry, supportedChecker);
6567
this.idSetterProvider = idSetterProvider;
6668
this.persistableChecker = persistableChecker;
6769
}

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/util/StringUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
public final class StringUtil
2424
{
25+
public static final String REPOSITORY_URL = "https://github.com/xdev-software/spring-data-eclipse-store";
26+
2527
private StringUtil()
2628
{
2729
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/TypesData.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.function.Function;
4545
import java.util.stream.Stream;
4646

47+
import org.eclipse.serializer.reference.Lazy;
4748
import org.junit.jupiter.params.provider.Arguments;
4849

4950
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository;
@@ -382,21 +383,25 @@ public static Stream<Arguments> generateData()
382383
).toArguments();
383384
}
384385

386+
/**
387+
* Should be identical to
388+
* {@link
389+
* software.xdev.spring.data.eclipse.store.repository.SupportedChecker.Implementation#UNSUPPORTED_DATA_TYPES}
390+
*/
385391
public static Stream<Arguments> generateNotWorkingData()
386392
{
387393
return new ListOfTestArguments(
388394
List.of(
389395
new TestArguments<>(
390396
LazyRepository.class,
391-
id -> new LazyDaoObject(id, org.eclipse.serializer.reference.Lazy.Reference("1")),
392-
object -> object.setValue(org.eclipse.serializer.reference.Lazy.Reference("2"))
397+
id -> new LazyDaoObject(id, Lazy.Reference("1")),
398+
object -> object.setValue(Lazy.Reference("2"))
393399
),
394400
new TestArguments<>(
395401
LazyRepository.class,
396-
id -> new LazyDaoObject(id, org.eclipse.serializer.reference.Lazy.Reference("1")),
402+
id -> new LazyDaoObject(id, Lazy.Reference("1")),
397403
object -> object.getValue().clear()
398404
),
399-
// Here EclipseStore has problems too: https://github.com/microstream-one/microstream/issues/204
400405
new TestArguments<>(
401406
EnumMapRepository.class,
402407
id -> new EnumMapDaoObject(id, new EnumMap<>(EnumMapDaoObject.Album.class)),
@@ -427,7 +432,6 @@ public static Stream<Arguments> generateNotWorkingData()
427432
id -> new MapDaoObject(id, new WeakHashMap<>(Map.of("1", "1", "2", "2"))),
428433
set -> set.getValue().put("3", "3")
429434
),
430-
// Here EclipseStore has problems: https://github.com/microstream-one/microstream/issues/173
431435
new TestArguments<>(
432436
CalendarRepository.class,
433437
id -> new CalendarDaoObject(id, Calendar.getInstance()),

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/TypesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.context.ApplicationContext;
2929
import org.springframework.test.context.TestPropertySource;
3030

31+
import software.xdev.spring.data.eclipse.store.exceptions.DataTypeNotSupportedException;
3132
import software.xdev.spring.data.eclipse.store.helper.TestUtil;
3233
import software.xdev.spring.data.eclipse.store.integration.isolated.tests.IsolatedTestAnnotations;
3334
import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage;
@@ -78,7 +79,7 @@ <T extends ComplexObject<?>> void simpleStoreAndReadForNotWorkingTypes(
7879
@Autowired final ApplicationContext context)
7980
{
8081
Assertions.assertThrows(
81-
Exception.class,
82+
DataTypeNotSupportedException.class,
8283
() -> this.simpleChangeAfterStore(repositoryClass, objectCreator, ignoredObjectChanger, context));
8384
}
8485

0 commit comments

Comments
 (0)