├── .gitignore
├── LICENSE
├── README.md
├── checkstyle
├── ClassHeader.txt
├── checkstyle.xml
└── suppressions.xml
├── findbugs
└── findbugs-exclude.xml
├── hazelcast-hibernate3
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── hazelcast
│ │ │ └── hibernate
│ │ │ ├── AbstractHazelcastCacheRegionFactory.java
│ │ │ ├── CacheEnvironment.java
│ │ │ ├── HazelcastCacheRegionFactory.java
│ │ │ ├── HazelcastLocalCacheRegionFactory.java
│ │ │ ├── HazelcastTimestamper.java
│ │ │ ├── RegionCache.java
│ │ │ ├── VersionAwareMapMergePolicy.java
│ │ │ ├── access
│ │ │ ├── AbstractAccessDelegate.java
│ │ │ ├── AccessDelegate.java
│ │ │ ├── NonStrictReadWriteAccessDelegate.java
│ │ │ ├── ReadOnlyAccessDelegate.java
│ │ │ ├── ReadWriteAccessDelegate.java
│ │ │ └── package-info.java
│ │ │ ├── distributed
│ │ │ ├── AbstractRegionCacheEntryProcessor.java
│ │ │ ├── IMapRegionCache.java
│ │ │ ├── LockEntryProcessor.java
│ │ │ ├── UnlockEntryProcessor.java
│ │ │ ├── UpdateEntryProcessor.java
│ │ │ └── package-info.java
│ │ │ ├── instance
│ │ │ ├── HazelcastAccessor.java
│ │ │ ├── HazelcastClientLoader.java
│ │ │ ├── HazelcastInstanceFactory.java
│ │ │ ├── HazelcastInstanceLoader.java
│ │ │ ├── IHazelcastInstanceLoader.java
│ │ │ └── package-info.java
│ │ │ ├── local
│ │ │ ├── CleanupService.java
│ │ │ ├── Invalidation.java
│ │ │ ├── LocalRegionCache.java
│ │ │ ├── Timestamp.java
│ │ │ ├── TimestampsRegionCache.java
│ │ │ └── package-info.java
│ │ │ ├── package-info.java
│ │ │ ├── region
│ │ │ ├── AbstractGeneralRegion.java
│ │ │ ├── AbstractHazelcastRegion.java
│ │ │ ├── AbstractTransactionalDataRegion.java
│ │ │ ├── CollectionRegionAccessStrategyAdapter.java
│ │ │ ├── EntityRegionAccessStrategyAdapter.java
│ │ │ ├── HazelcastCollectionRegion.java
│ │ │ ├── HazelcastEntityRegion.java
│ │ │ ├── HazelcastQueryResultsRegion.java
│ │ │ ├── HazelcastRegion.java
│ │ │ ├── HazelcastTimestampsRegion.java
│ │ │ └── package-info.java
│ │ │ └── serialization
│ │ │ ├── Expirable.java
│ │ │ ├── ExpiryMarker.java
│ │ │ ├── Hibernate3CacheEntrySerializer.java
│ │ │ ├── Hibernate3CacheEntrySerializerHook.java
│ │ │ ├── Hibernate3CacheKeySerializer.java
│ │ │ ├── Hibernate3CacheKeySerializerHook.java
│ │ │ ├── HibernateDataSerializerHook.java
│ │ │ ├── MarkerWrapper.java
│ │ │ ├── Value.java
│ │ │ └── package-info.java
│ └── resources
│ │ ├── META-INF
│ │ └── services
│ │ │ ├── com.hazelcast.DataSerializerHook
│ │ │ └── com.hazelcast.SerializerHook
│ │ └── hazelcast-community-license.txt
│ └── test
│ ├── java
│ └── com
│ │ └── hazelcast
│ │ └── hibernate
│ │ ├── CacheHitMissNonStrictTest.java
│ │ ├── CacheHitMissReadOnlyTest.java
│ │ ├── CacheHitMissReadWriteTest.java
│ │ ├── CollectionCacheTest.java
│ │ ├── CustomPropertiesTest.java
│ │ ├── HibernateSlowTestSupport.java
│ │ ├── HibernateStatisticsTestSupport.java
│ │ ├── HibernateTestSupport.java
│ │ ├── LocalRegionFactoryDefaultTest.java
│ │ ├── LocalRegionFactorySlowTest.java
│ │ ├── NativeClientTest.java
│ │ ├── RegionFactoryDefaultSlowTest.java
│ │ ├── RegionFactoryDefaultTest.java
│ │ ├── RegionFactoryQueryTest.java
│ │ ├── VersionAwareMapMergePolicyTest.java
│ │ ├── access
│ │ └── ReadWriteAccessDelegateTest.java
│ │ ├── distributed
│ │ ├── LockEntryProcessorTest.java
│ │ ├── UnlockEntryProcessorTest.java
│ │ └── UpdateEntryProcessorTest.java
│ │ ├── entity
│ │ ├── DummyEntity.java
│ │ └── DummyProperty.java
│ │ ├── instance
│ │ └── HazelcastMockInstanceLoader.java
│ │ ├── local
│ │ ├── LocalRegionCacheTest.java
│ │ └── TimestampsRegionCacheTest.java
│ │ ├── region
│ │ ├── HazelcastQueryResultsRegionTest.java
│ │ └── HazelcastTimestampsRegionTest.java
│ │ └── serialization
│ │ ├── ExpiryMarkerTest.java
│ │ ├── HibernateSerializationHookAvailableTest.java
│ │ ├── HibernateSerializationHookNonAvailableTest.java
│ │ └── ValueTest.java
│ └── resources
│ ├── com
│ └── hazelcast
│ │ └── hibernate
│ │ └── entity
│ │ ├── DummyEntity.hbm.xml
│ │ └── DummyProperty.hbm.xml
│ ├── hazelcast-client-custom.xml
│ ├── hazelcast-custom.xml
│ ├── logging.properties
│ ├── test-hibernate-client.cfg.xml
│ └── test-hibernate.cfg.xml
├── hazelcast-hibernate4
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── hazelcast
│ │ │ └── hibernate
│ │ │ ├── AbstractHazelcastCacheRegionFactory.java
│ │ │ ├── CacheEnvironment.java
│ │ │ ├── HazelcastCacheRegionFactory.java
│ │ │ ├── HazelcastLocalCacheRegionFactory.java
│ │ │ ├── HazelcastTimestamper.java
│ │ │ ├── RegionCache.java
│ │ │ ├── VersionAwareMapMergePolicy.java
│ │ │ ├── access
│ │ │ ├── AbstractAccessDelegate.java
│ │ │ ├── AccessDelegate.java
│ │ │ ├── NonStrictReadWriteAccessDelegate.java
│ │ │ ├── ReadOnlyAccessDelegate.java
│ │ │ ├── ReadWriteAccessDelegate.java
│ │ │ └── package-info.java
│ │ │ ├── distributed
│ │ │ ├── AbstractRegionCacheEntryProcessor.java
│ │ │ ├── IMapRegionCache.java
│ │ │ ├── LockEntryProcessor.java
│ │ │ ├── UnlockEntryProcessor.java
│ │ │ ├── UpdateEntryProcessor.java
│ │ │ └── package-info.java
│ │ │ ├── instance
│ │ │ ├── HazelcastAccessor.java
│ │ │ ├── HazelcastClientLoader.java
│ │ │ ├── HazelcastInstanceFactory.java
│ │ │ ├── HazelcastInstanceLoader.java
│ │ │ ├── IHazelcastInstanceLoader.java
│ │ │ └── package-info.java
│ │ │ ├── local
│ │ │ ├── CleanupService.java
│ │ │ ├── Invalidation.java
│ │ │ ├── LocalRegionCache.java
│ │ │ ├── Timestamp.java
│ │ │ ├── TimestampsRegionCache.java
│ │ │ └── package-info.java
│ │ │ ├── package-info.java
│ │ │ ├── region
│ │ │ ├── AbstractGeneralRegion.java
│ │ │ ├── AbstractHazelcastRegion.java
│ │ │ ├── AbstractTransactionalDataRegion.java
│ │ │ ├── CollectionRegionAccessStrategyAdapter.java
│ │ │ ├── EntityRegionAccessStrategyAdapter.java
│ │ │ ├── HazelcastCollectionRegion.java
│ │ │ ├── HazelcastEntityRegion.java
│ │ │ ├── HazelcastNaturalIdRegion.java
│ │ │ ├── HazelcastQueryResultsRegion.java
│ │ │ ├── HazelcastRegion.java
│ │ │ ├── HazelcastTimestampsRegion.java
│ │ │ ├── NaturalIdRegionAccessStrategyAdapter.java
│ │ │ └── package-info.java
│ │ │ └── serialization
│ │ │ ├── Expirable.java
│ │ │ ├── ExpiryMarker.java
│ │ │ ├── Hibernate41CacheEntrySerializer.java
│ │ │ ├── Hibernate42CacheEntrySerializer.java
│ │ │ ├── Hibernate4CacheEntrySerializerHook.java
│ │ │ ├── Hibernate4CacheKeySerializer.java
│ │ │ ├── Hibernate4CacheKeySerializerHook.java
│ │ │ ├── HibernateDataSerializerHook.java
│ │ │ ├── MarkerWrapper.java
│ │ │ ├── Value.java
│ │ │ └── package-info.java
│ └── resources
│ │ ├── META-INF
│ │ └── services
│ │ │ ├── com.hazelcast.DataSerializerHook
│ │ │ └── com.hazelcast.SerializerHook
│ │ └── hazelcast-community-license.txt
│ └── test
│ ├── java
│ └── com
│ │ └── hazelcast
│ │ └── hibernate
│ │ ├── CacheHitMissNonStrictTest.java
│ │ ├── CacheHitMissReadOnlyTest.java
│ │ ├── CacheHitMissReadWriteTest.java
│ │ ├── CollectionCacheTest.java
│ │ ├── CustomPropertiesTest.java
│ │ ├── HibernateSlowTestSupport.java
│ │ ├── HibernateStatisticsTestSupport.java
│ │ ├── HibernateTestSupport.java
│ │ ├── LocalRegionFactoryDefaultTest.java
│ │ ├── LocalRegionFactorySlowTest.java
│ │ ├── NativeClientTest.java
│ │ ├── NaturalIdTest.java
│ │ ├── RegionFactoryDefaultSlowTest.java
│ │ ├── RegionFactoryDefaultTest.java
│ │ ├── RegionFactoryQueryTest.java
│ │ ├── VersionAwareMapMergePolicyTest.java
│ │ ├── access
│ │ └── ReadWriteAccessDelegateTest.java
│ │ ├── distributed
│ │ ├── LockEntryProcessorTest.java
│ │ ├── UnlockEntryProcessorTest.java
│ │ └── UpdateEntryProcessorTest.java
│ │ ├── entity
│ │ ├── AnnotatedEntity.java
│ │ ├── DummyEntity.java
│ │ └── DummyProperty.java
│ │ ├── instance
│ │ └── HazelcastMockInstanceLoader.java
│ │ ├── local
│ │ ├── LocalRegionCacheTest.java
│ │ └── TimestampsRegionCacheTest.java
│ │ ├── region
│ │ ├── HazelcastQueryResultsRegionTest.java
│ │ └── HazelcastTimestampsRegionTest.java
│ │ └── serialization
│ │ ├── ExpiryMarkerTest.java
│ │ ├── HibernateSerializationHookAvailableTest.java
│ │ ├── HibernateSerializationHookNonAvailableTest.java
│ │ └── ValueTest.java
│ └── resources
│ ├── com
│ └── hazelcast
│ │ └── hibernate
│ │ └── entity
│ │ ├── DummyEntity.hbm.xml
│ │ └── DummyProperty.hbm.xml
│ ├── hazelcast-client-custom.xml
│ ├── hazelcast-custom.xml
│ ├── test-hibernate-client.cfg.xml
│ └── test-hibernate.cfg.xml
├── images
├── HZLocalCacheRgnFactory.jpg
└── NoteSmall.jpg
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | over/
2 | target/
3 | .project
4 | .classpath
5 | .settings/
6 | .idea/
7 | .patch
8 | .surefire-*
9 | *.iml
10 | *.ipr
11 | *.iws
12 | .DS_Store
13 | reports/
14 | .directory
15 | atlassian-ide-plugin.xml
16 | performance*.log
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### please refer to [hazelcast-hibernate-3-and-4 branch](https://github.com/hazelcast/hazelcast-hibernate/tree/hazelcast-hibernate3-and-4) for hibernate 3 and 4 support
2 |
3 |
4 |
--------------------------------------------------------------------------------
/checkstyle/ClassHeader.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 |
--------------------------------------------------------------------------------
/checkstyle/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/findbugs/findbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/pom.xml:
--------------------------------------------------------------------------------
1 |
15 | 4.0.0
16 |
17 | hazelcast-hibernate3
18 | hazelcast-hibernate3
19 | jar
20 |
21 |
22 | com.hazelcast
23 | hazelcast-hibernate
24 | 3.8.5-SNAPSHOT
25 | ../pom.xml
26 |
27 |
28 |
29 |
30 | ${project.parent.basedir}
31 |
32 | 3.6.10.Final
33 |
34 |
35 |
36 |
37 | org.hibernate
38 | hibernate-core
39 | ${hibernate.core.version}
40 | provided
41 |
42 |
43 | slf4j-api
44 | org.slf4j
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/src/main/java/com/hazelcast/hibernate/HazelcastCacheRegionFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.hazelcast.hibernate;
17 |
18 | import com.hazelcast.core.HazelcastInstance;
19 | import com.hazelcast.hibernate.distributed.IMapRegionCache;
20 | import com.hazelcast.hibernate.region.HazelcastCollectionRegion;
21 | import com.hazelcast.hibernate.region.HazelcastEntityRegion;
22 | import com.hazelcast.hibernate.region.HazelcastTimestampsRegion;
23 | import org.hibernate.cache.CacheDataDescription;
24 | import org.hibernate.cache.CacheException;
25 | import org.hibernate.cache.CollectionRegion;
26 | import org.hibernate.cache.EntityRegion;
27 | import org.hibernate.cache.RegionFactory;
28 | import org.hibernate.cache.TimestampsRegion;
29 |
30 | import java.util.Properties;
31 |
32 | /**
33 | * Simple RegionFactory implementation to return Hazelcast based Region implementations
34 | */
35 | public class HazelcastCacheRegionFactory extends AbstractHazelcastCacheRegionFactory implements RegionFactory {
36 |
37 | @SuppressWarnings("unused")
38 | public HazelcastCacheRegionFactory() {
39 | }
40 |
41 | @SuppressWarnings("unused")
42 | public HazelcastCacheRegionFactory(final HazelcastInstance instance) {
43 | super(instance);
44 | }
45 |
46 | @SuppressWarnings("unused")
47 | public HazelcastCacheRegionFactory(final Properties properties) {
48 | super(properties);
49 | }
50 |
51 | @Override
52 | public CollectionRegion buildCollectionRegion(final String regionName, final Properties properties,
53 | final CacheDataDescription metadata) throws CacheException {
54 | return new HazelcastCollectionRegion(instance, regionName, properties, metadata,
55 | new IMapRegionCache(regionName, instance, properties, metadata));
56 | }
57 |
58 | @Override
59 | public EntityRegion buildEntityRegion(final String regionName, final Properties properties,
60 | final CacheDataDescription metadata) throws CacheException {
61 | return new HazelcastEntityRegion(instance, regionName, properties, metadata,
62 | new IMapRegionCache(regionName, instance, properties, metadata));
63 | }
64 |
65 | @Override
66 | public TimestampsRegion buildTimestampsRegion(final String regionName, final Properties properties)
67 | throws CacheException {
68 | return new HazelcastTimestampsRegion(instance, regionName, properties,
69 | new IMapRegionCache(regionName, instance, properties, null));
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/src/main/java/com/hazelcast/hibernate/HazelcastLocalCacheRegionFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.hazelcast.hibernate;
17 |
18 | import com.hazelcast.core.HazelcastInstance;
19 | import com.hazelcast.hibernate.local.LocalRegionCache;
20 | import com.hazelcast.hibernate.local.TimestampsRegionCache;
21 | import com.hazelcast.hibernate.region.HazelcastCollectionRegion;
22 | import com.hazelcast.hibernate.region.HazelcastEntityRegion;
23 | import com.hazelcast.hibernate.region.HazelcastTimestampsRegion;
24 | import org.hibernate.cache.CacheDataDescription;
25 | import org.hibernate.cache.CacheException;
26 | import org.hibernate.cache.CollectionRegion;
27 | import org.hibernate.cache.EntityRegion;
28 | import org.hibernate.cache.RegionFactory;
29 | import org.hibernate.cache.TimestampsRegion;
30 |
31 | import java.util.Properties;
32 |
33 | /**
34 | * Simple RegionFactory implementation to return Hazelcast based local Region implementations
35 | */
36 | public class HazelcastLocalCacheRegionFactory extends AbstractHazelcastCacheRegionFactory implements RegionFactory {
37 |
38 | @SuppressWarnings("unused")
39 | public HazelcastLocalCacheRegionFactory() {
40 | }
41 |
42 | @SuppressWarnings("unused")
43 | public HazelcastLocalCacheRegionFactory(final HazelcastInstance instance) {
44 | super(instance);
45 | }
46 |
47 | @SuppressWarnings("unused")
48 | public HazelcastLocalCacheRegionFactory(final Properties properties) {
49 | super(properties);
50 | }
51 |
52 | @Override
53 | public CollectionRegion buildCollectionRegion(final String regionName, final Properties properties,
54 | final CacheDataDescription metadata) throws CacheException {
55 | final HazelcastCollectionRegion region = new HazelcastCollectionRegion(instance,
56 | regionName, properties, metadata, new LocalRegionCache(regionName, instance, metadata));
57 | cleanupService.registerCache(region.getCache());
58 | return region;
59 | }
60 |
61 | @Override
62 | public EntityRegion buildEntityRegion(final String regionName, final Properties properties,
63 | final CacheDataDescription metadata) throws CacheException {
64 | final HazelcastEntityRegion region = new HazelcastEntityRegion(instance,
65 | regionName, properties, metadata, new LocalRegionCache(regionName, instance, metadata));
66 | cleanupService.registerCache(region.getCache());
67 | return region;
68 | }
69 |
70 | @Override
71 | public TimestampsRegion buildTimestampsRegion(final String regionName, final Properties properties)
72 | throws CacheException {
73 | return new HazelcastTimestampsRegion(instance, regionName, properties,
74 | new TimestampsRegionCache(regionName, instance));
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/src/main/java/com/hazelcast/hibernate/HazelcastTimestamper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.hazelcast.hibernate;
17 |
18 | import com.hazelcast.config.Config;
19 | import com.hazelcast.config.MapConfig;
20 | import com.hazelcast.core.HazelcastInstance;
21 | import com.hazelcast.logging.Logger;
22 |
23 | /**
24 | * Helper class to create timestamps and calculate timeouts based on either Hazelcast
25 | * configuration of by requesting values on the cluster.
26 | */
27 | public final class HazelcastTimestamper {
28 |
29 | private static final int SEC_TO_MS = 1000;
30 |
31 | private HazelcastTimestamper() {
32 | }
33 |
34 | public static long nextTimestamp(HazelcastInstance instance) {
35 | if (instance == null) {
36 | throw new RuntimeException("No Hazelcast instance!");
37 | } else if (instance.getCluster() == null) {
38 | throw new RuntimeException("Hazelcast instance has no cluster!");
39 | }
40 |
41 | // System time in ms.
42 | return instance.getCluster().getClusterTime();
43 | }
44 |
45 | public static int getTimeout(HazelcastInstance instance, String regionName) {
46 | try {
47 | final MapConfig cfg = instance.getConfig().findMapConfig(regionName);
48 | if (cfg.getTimeToLiveSeconds() > 0) {
49 | // TTL in ms.
50 | return cfg.getTimeToLiveSeconds() * SEC_TO_MS;
51 | }
52 | } catch (UnsupportedOperationException e) {
53 | // HazelcastInstance is instance of HazelcastClient.
54 | Logger.getLogger(HazelcastTimestamper.class).finest(e);
55 | }
56 | return CacheEnvironment.getDefaultCacheTimeoutInMillis();
57 | }
58 |
59 | public static long getMaxOperationTimeout(HazelcastInstance instance) {
60 | String maxOpTimeoutProp = null;
61 | try {
62 | Config config = instance.getConfig();
63 | maxOpTimeoutProp = config.getProperty(CacheEnvironment.HAZELCAST_OPERATION_TIMEOUT);
64 | } catch (UnsupportedOperationException e) {
65 | // HazelcastInstance is instance of HazelcastClient.
66 | Logger.getLogger(HazelcastTimestamper.class).finest(e);
67 | }
68 | if (maxOpTimeoutProp != null) {
69 | return Long.parseLong(maxOpTimeoutProp);
70 | }
71 | return Long.MAX_VALUE;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/src/main/java/com/hazelcast/hibernate/RegionCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.hazelcast.hibernate;
17 |
18 | import org.hibernate.cache.access.SoftLock;
19 |
20 | import java.util.Map;
21 |
22 | /**
23 | * This interface defines an internal cached region implementation as well as a mechanism
24 | * to unmap the cache to an underlying Map data-structure
25 | */
26 | public interface RegionCache {
27 |
28 | Object get(final Object key, final long txTimestamp);
29 |
30 | boolean insert(final Object key, final Object value, final Object currentVersion);
31 |
32 | boolean put(final Object key, final Object value, final long txTimestamp, final Object version);
33 |
34 | boolean update(final Object key, final Object newValue, final Object newVersion, final SoftLock lock);
35 |
36 | boolean remove(final Object key);
37 |
38 | SoftLock tryLock(final Object key, final Object version);
39 |
40 | void unlock(final Object key, final SoftLock lock);
41 |
42 | boolean contains(final Object key);
43 |
44 | void clear();
45 |
46 | long size();
47 |
48 | long getSizeInMemory();
49 |
50 | Map asMap();
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/src/main/java/com/hazelcast/hibernate/VersionAwareMapMergePolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.hazelcast.hibernate;
17 |
18 | import com.hazelcast.core.EntryView;
19 | import com.hazelcast.map.merge.MapMergePolicy;
20 | import com.hazelcast.nio.ObjectDataInput;
21 | import com.hazelcast.nio.ObjectDataOutput;
22 | import org.hibernate.cache.entry.CacheEntry;
23 |
24 | import java.io.IOException;
25 |
26 | /**
27 | * A merge policy implementation to handle split brain remerges based on the timestamps stored in
28 | * the values.
29 | */
30 | public class VersionAwareMapMergePolicy implements MapMergePolicy {
31 |
32 | public Object merge(String mapName, EntryView mergingEntry, EntryView existingEntry) {
33 | final Object existingValue = existingEntry != null ? existingEntry.getValue() : null;
34 | final Object mergingValue = mergingEntry.getValue();
35 | if (existingValue != null && existingValue instanceof CacheEntry
36 | && mergingValue != null && mergingValue instanceof CacheEntry) {
37 |
38 | final CacheEntry existingCacheEntry = (CacheEntry) existingValue;
39 | final CacheEntry mergingCacheEntry = (CacheEntry) mergingValue;
40 | final Object mergingVersionObject = mergingCacheEntry.getVersion();
41 | final Object existingVersionObject = existingCacheEntry.getVersion();
42 | if (mergingVersionObject != null && existingVersionObject != null
43 | && mergingVersionObject instanceof Comparable && existingVersionObject instanceof Comparable) {
44 |
45 | final Comparable mergingVersion = (Comparable) mergingVersionObject;
46 | final Comparable existingVersion = (Comparable) existingVersionObject;
47 |
48 | if (mergingVersion.compareTo(existingVersion) > 0) {
49 | return mergingValue;
50 | } else {
51 | return existingValue;
52 | }
53 | }
54 | }
55 | return mergingValue;
56 | }
57 |
58 | @Override
59 | public void writeData(ObjectDataOutput out) throws IOException {
60 | }
61 |
62 | @Override
63 | public void readData(ObjectDataInput in) throws IOException {
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/src/main/java/com/hazelcast/hibernate/access/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 | /**
17 | * Provides access interfaces/classes for Hibernate.
18 | * such as AccessDelegate, ReadWriteAccessDelegate.
19 | */
20 | package com.hazelcast.hibernate.access;
21 |
--------------------------------------------------------------------------------
/hazelcast-hibernate3/src/main/java/com/hazelcast/hibernate/distributed/AbstractRegionCacheEntryProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Hazelcast Inc.
3 | *
4 | * Licensed under the Hazelcast Community License (the "License"); you may not use
5 | * this file except in compliance with the License. You may obtain a copy of the
6 | * License at
7 | *
8 | * http://hazelcast.com/hazelcast-community-license
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, WITHOUT
12 | * WARRANTIES OF ANY KIND, either express or implied. See the License for the
13 | * specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.hazelcast.hibernate.distributed;
17 |
18 |
19 | import com.hazelcast.hibernate.serialization.Expirable;
20 | import com.hazelcast.hibernate.serialization.HibernateDataSerializerHook;
21 |
22 | import com.hazelcast.map.EntryBackupProcessor;
23 | import com.hazelcast.map.EntryProcessor;
24 | import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
25 |
26 | import java.util.Map;
27 |
28 | /**
29 | * An abstract implementation of {@link EntryProcessor} which acts on a hibernate region cache
30 | * {@link com.hazelcast.core.IMap}
31 | */
32 |
33 | public abstract class AbstractRegionCacheEntryProcessor implements EntryProcessor