Skip to content

Commit f0f2e61

Browse files
authored
Merge pull request #3 from mihaicostin/hibernate-5.2
Hibernate 5.2.1.Final
2 parents d561943 + d98e73f commit f0f2e61

26 files changed

+737
-334
lines changed

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,8 @@ A library for using Memcached as a second level distributed cache in Hibernate.
88
* https://github.com/raykrueger/hibernate-memcached
99
* https://github.com/kcarlson/hibernate-memcached
1010

11-
#Versions
1211

13-
## 1.1.0
14-
15-
Memcached client now respects the region timeout property
16-
- [Issue #1](https://github.com/mihaicostin/hibernate-l2-memcached/issues/1)
17-
```xml
18-
<property name="hibernate.memcached.REGION.cacheTimeSeconds">10</property>
19-
```
20-
21-
22-
## 1.0.0
23-
* Compatible with hibernate 4.3.x
24-
* Example config:
12+
#Example config:
2513

2614
```xml
2715
<property name="hibernate.cache.region.factory_class">com.mc.hibernate.memcached.MemcachedRegionFactory</property>
@@ -43,3 +31,27 @@ In order to use this library as a maven dependency, just add the following depen
4331
</dependency>
4432
```
4533

34+
35+
#Versions
36+
37+
## 5.2.1.0
38+
39+
- Switched to a new versioning schema, that goes hand in had with [hibernate](http://hibernate.org/orm/).
40+
- Version 5.2.1.x is developed for (and compatible with) hibernate 5.2.1.Final
41+
- Update [spymemcached](https://github.com/couchbase/spymemcached) to the latest version: 2.12.1
42+
43+
44+
### Known issues
45+
- SecondLevelCacheStatistics won't work with this adapter since it tries to get the cache content as a Map (and that's not easily done with memcached)
46+
47+
## 1.1.0
48+
49+
Memcached client now respects the region timeout property
50+
- [Issue #1](https://github.com/mihaicostin/hibernate-l2-memcached/issues/1)
51+
```xml
52+
<property name="hibernate.memcached.REGION.cacheTimeSeconds">10</property>
53+
```
54+
55+
## 1.0.0
56+
* Compatible with hibernate 4.3.x
57+

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.github.mihaicostin</groupId>
66
<artifactId>hibernate-l2-memcached</artifactId>
7-
<version>1.1.0</version>
7+
<version>5.2.1.0-SNAPSHOT</version>
88
<name>hibernate-l2-memcached</name>
99
<description>A library for using Memcached as a second level distributed cache in Hibernate.</description>
1010
<url>https://github.com/mihaicostin/hibernate-l2-memcached</url>
@@ -39,8 +39,8 @@
3939
</distributionManagement>
4040

4141
<properties>
42-
<hibernate-core.version>4.3.11.Final</hibernate-core.version>
43-
<spymemcached.version>2.11.6</spymemcached.version>
42+
<hibernate-core.version>5.2.1.Final</hibernate-core.version>
43+
<spymemcached.version>2.12.1</spymemcached.version>
4444
<slf4j-api.version>1.5.6</slf4j-api.version>
4545

4646
<junit.version>4.12</junit.version>

src/main/java/com/mc/hibernate/memcached/MemcachedRegionFactory.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.mc.hibernate.memcached;
1717

1818
import com.mc.hibernate.memcached.region.*;
19+
import org.hibernate.boot.spi.SessionFactoryOptions;
1920
import org.hibernate.cache.CacheException;
2021
import org.hibernate.cache.spi.*;
2122
import org.hibernate.cache.spi.access.AccessType;
@@ -37,7 +38,7 @@ public class MemcachedRegionFactory implements RegionFactory {
3738

3839
private Properties properties;
3940
private Memcache client;
40-
private Settings settings;
41+
private SessionFactoryOptions settings;
4142

4243
public MemcachedRegionFactory(Properties properties) {
4344
this.properties = properties;
@@ -46,7 +47,9 @@ public MemcachedRegionFactory(Properties properties) {
4647
public MemcachedRegionFactory() {
4748
}
4849

49-
public void start(Settings settings, Properties properties) throws CacheException {
50+
@Override
51+
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
52+
5053
this.settings = settings;
5154
this.properties = properties;
5255
log.info("Starting MemcachedClient...");
@@ -57,6 +60,8 @@ public void start(Settings settings, Properties properties) throws CacheExceptio
5760
}
5861
}
5962

63+
64+
6065
public void stop() {
6166
if (client != null) {
6267
log.debug("Shutting down Memcache client");
@@ -78,8 +83,7 @@ public long nextTimestamp() {
7883
}
7984

8085
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {
81-
return new MemcachedEntityRegion(getCache(regionName), settings,
82-
metadata, properties, client);
86+
return new MemcachedEntityRegion(getCache(regionName), settings, metadata, properties, client);
8387
}
8488

8589
public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {

src/main/java/com/mc/hibernate/memcached/keystrategy/AbstractKeyStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public abstract class AbstractKeyStrategy implements KeyStrategy {
3131

32-
public static final int MAX_KEY_LENGTH = 250;
32+
private static final int MAX_KEY_LENGTH = 250;
3333

3434
protected final Logger log = LoggerFactory.getLogger(getClass());
3535

src/main/java/com/mc/hibernate/memcached/region/AbstractMemcachedRegion.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515

1616
package com.mc.hibernate.memcached.region;
1717

18-
import java.util.Map;
19-
18+
import com.mc.hibernate.memcached.MemcachedCache;
2019
import org.hibernate.cache.CacheException;
2120
import org.hibernate.cache.spi.Region;
2221

23-
import com.mc.hibernate.memcached.MemcachedCache;
22+
import java.util.Map;
2423

2524
public abstract class AbstractMemcachedRegion implements Region {
2625

@@ -54,8 +53,9 @@ public long getElementCountOnDisk() {
5453
return cache.getElementCountOnDisk();
5554
}
5655

56+
@Override
5757
public Map toMap() {
58-
return null;
58+
return cache.toMap();
5959
}
6060

6161
public long nextTimestamp() {

src/main/java/com/mc/hibernate/memcached/region/MemcachedCollectionRegion.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,30 @@
1515

1616
package com.mc.hibernate.memcached.region;
1717

18-
import java.util.Properties;
19-
18+
import com.mc.hibernate.memcached.Memcache;
19+
import com.mc.hibernate.memcached.MemcachedCache;
20+
import com.mc.hibernate.memcached.strategy.NonStrictReadWriteMemcachedCollectionRegionAccessStrategy;
21+
import com.mc.hibernate.memcached.strategy.ReadOnlyMemcachedCollectionRegionAccessStrategy;
22+
import com.mc.hibernate.memcached.strategy.ReadWriteMemcachedCollectionRegionAccessStrategy;
23+
import com.mc.hibernate.memcached.strategy.TransactionalMemcachedCollectionRegionAccessStrategy;
24+
import org.hibernate.boot.spi.SessionFactoryOptions;
2025
import org.hibernate.cache.CacheException;
2126
import org.hibernate.cache.spi.CacheDataDescription;
2227
import org.hibernate.cache.spi.CollectionRegion;
2328
import org.hibernate.cache.spi.access.AccessType;
2429
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
25-
import org.hibernate.cfg.Settings;
2630
import org.slf4j.Logger;
2731
import org.slf4j.LoggerFactory;
2832

29-
import com.mc.hibernate.memcached.Memcache;
30-
import com.mc.hibernate.memcached.MemcachedCache;
31-
import com.mc.hibernate.memcached.strategy.NonStrictReadWriteMemcachedCollectionRegionAccessStrategy;
32-
import com.mc.hibernate.memcached.strategy.ReadOnlyMemcachedCollectionRegionAccessStrategy;
33-
import com.mc.hibernate.memcached.strategy.ReadWriteMemcachedCollectionRegionAccessStrategy;
34-
import com.mc.hibernate.memcached.strategy.TransactionalMemcachedCollectionRegionAccessStrategy;
33+
import java.util.Properties;
3534

3635
public class MemcachedCollectionRegion extends AbstractMemcachedRegion implements CollectionRegion {
3736

3837
private final Logger log = LoggerFactory.getLogger(MemcachedCollectionRegion.class);
3938
private final CacheDataDescription metadata;
40-
private final Settings settings;
39+
private final SessionFactoryOptions settings;
4140

42-
public MemcachedCollectionRegion(MemcachedCache cache, Settings settings, CacheDataDescription metadata, Properties properties, Memcache client) {
41+
public MemcachedCollectionRegion(MemcachedCache cache, SessionFactoryOptions settings, CacheDataDescription metadata, Properties properties, Memcache client) {
4342
super(cache);
4443
this.metadata = metadata;
4544
this.settings = settings;

src/main/java/com/mc/hibernate/memcached/region/MemcachedEntityRegion.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,32 @@
1616
package com.mc.hibernate.memcached.region;
1717

1818

19-
import java.util.Properties;
20-
19+
import com.mc.hibernate.memcached.Memcache;
20+
import com.mc.hibernate.memcached.MemcachedCache;
21+
import com.mc.hibernate.memcached.strategy.NonStrictReadWriteMemcachedEntityRegionAccessStrategy;
22+
import com.mc.hibernate.memcached.strategy.ReadOnlyMemcachedEntityRegionAccessStrategy;
23+
import com.mc.hibernate.memcached.strategy.ReadWriteMemcachedEntityRegionAccessStrategy;
24+
import com.mc.hibernate.memcached.strategy.TransactionalMemcachedEntityRegionAccessStrategy;
25+
import org.hibernate.boot.spi.SessionFactoryOptions;
2126
import org.hibernate.cache.CacheException;
2227
import org.hibernate.cache.spi.CacheDataDescription;
2328
import org.hibernate.cache.spi.EntityRegion;
2429
import org.hibernate.cache.spi.access.AccessType;
2530
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
26-
import org.hibernate.cfg.Settings;
2731
import org.slf4j.Logger;
2832
import org.slf4j.LoggerFactory;
2933

30-
import com.mc.hibernate.memcached.Memcache;
31-
import com.mc.hibernate.memcached.MemcachedCache;
32-
import com.mc.hibernate.memcached.strategy.NonStrictReadWriteMemcachedEntityRegionAccessStrategy;
33-
import com.mc.hibernate.memcached.strategy.ReadOnlyMemcachedEntityRegionAccessStrategy;
34-
import com.mc.hibernate.memcached.strategy.ReadWriteMemcachedEntityRegionAccessStrategy;
35-
import com.mc.hibernate.memcached.strategy.TransactionalMemcachedEntityRegionAccessStrategy;
34+
import java.util.Properties;
3635

3736

3837
public class MemcachedEntityRegion extends AbstractMemcachedRegion implements EntityRegion {
3938

4039
private final Logger log = LoggerFactory.getLogger(MemcachedEntityRegion.class);
4140

4241
private final CacheDataDescription metadata;
43-
private final Settings settings;
42+
private final SessionFactoryOptions settings;
4443

45-
public MemcachedEntityRegion(MemcachedCache cache, Settings settings, CacheDataDescription metadata, Properties properties, Memcache client) {
44+
public MemcachedEntityRegion(MemcachedCache cache, SessionFactoryOptions settings, CacheDataDescription metadata, Properties properties, Memcache client) {
4645
super(cache);
4746
this.metadata = metadata;
4847
this.settings = settings;

src/main/java/com/mc/hibernate/memcached/region/MemcachedNaturalIdRegion.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,31 @@
1515

1616
package com.mc.hibernate.memcached.region;
1717

18-
import java.util.Properties;
19-
18+
import com.mc.hibernate.memcached.Memcache;
19+
import com.mc.hibernate.memcached.MemcachedCache;
20+
import com.mc.hibernate.memcached.strategy.NonStrictReadWriteMemcachedNaturalIdRegionAccessStrategy;
21+
import com.mc.hibernate.memcached.strategy.ReadOnlyMemcachedNaturalIdRegionAccessStrategy;
22+
import com.mc.hibernate.memcached.strategy.ReadWriteMemcachedNaturalIdRegionAccessStrategy;
23+
import com.mc.hibernate.memcached.strategy.TransactionalMemcachedNaturalIdRegionAccessStrategy;
24+
import org.hibernate.boot.spi.SessionFactoryOptions;
2025
import org.hibernate.cache.CacheException;
2126
import org.hibernate.cache.spi.CacheDataDescription;
2227
import org.hibernate.cache.spi.NaturalIdRegion;
2328
import org.hibernate.cache.spi.access.AccessType;
2429
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
25-
import org.hibernate.cfg.Settings;
2630
import org.slf4j.Logger;
2731
import org.slf4j.LoggerFactory;
2832

29-
import com.mc.hibernate.memcached.Memcache;
30-
import com.mc.hibernate.memcached.MemcachedCache;
31-
import com.mc.hibernate.memcached.strategy.NonStrictReadWriteMemcachedNaturalIdRegionAccessStrategy;
32-
import com.mc.hibernate.memcached.strategy.ReadOnlyMemcachedNaturalIdRegionAccessStrategy;
33-
import com.mc.hibernate.memcached.strategy.ReadWriteMemcachedNaturalIdRegionAccessStrategy;
34-
import com.mc.hibernate.memcached.strategy.TransactionalMemcachedNaturalIdRegionAccessStrategy;
33+
import java.util.Properties;
3534

3635
public class MemcachedNaturalIdRegion extends AbstractMemcachedRegion implements NaturalIdRegion {
3736

3837
private final Logger log = LoggerFactory.getLogger(MemcachedNaturalIdRegion.class);
3938

4039
private final CacheDataDescription metadata;
41-
private final Settings settings;
40+
private final SessionFactoryOptions settings;
4241

43-
public MemcachedNaturalIdRegion(MemcachedCache cache, Settings settings, CacheDataDescription metadata, Properties properties, Memcache client) {
42+
public MemcachedNaturalIdRegion(MemcachedCache cache, SessionFactoryOptions settings, CacheDataDescription metadata, Properties properties, Memcache client) {
4443
super(cache);
4544
this.metadata = metadata;
4645
this.settings = settings;

src/main/java/com/mc/hibernate/memcached/region/MemcachedQueryResultsRegion.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
package com.mc.hibernate.memcached.region;
1717

18+
import com.mc.hibernate.memcached.MemcachedCache;
1819
import org.hibernate.cache.CacheException;
1920
import org.hibernate.cache.spi.QueryResultsRegion;
21+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2022
import org.slf4j.Logger;
2123
import org.slf4j.LoggerFactory;
2224

23-
import com.mc.hibernate.memcached.MemcachedCache;
24-
2525
public class MemcachedQueryResultsRegion extends AbstractMemcachedRegion implements QueryResultsRegion {
2626

2727
private final Logger log = LoggerFactory.getLogger(MemcachedQueryResultsRegion.class);
@@ -30,11 +30,13 @@ public MemcachedQueryResultsRegion(MemcachedCache cache) {
3030
super(cache);
3131
}
3232

33-
public Object get(Object key) throws CacheException {
33+
@Override
34+
public Object get(SharedSessionContractImplementor session, Object key) throws CacheException {
3435
return cache.get(key);
3536
}
3637

37-
public void put(Object key, Object value) throws CacheException {
38+
@Override
39+
public void put(SharedSessionContractImplementor session, Object key, Object value) throws CacheException {
3840
cache.put(key, value);
3941
}
4042

src/main/java/com/mc/hibernate/memcached/region/MemcachedTimestampsRegion.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
package com.mc.hibernate.memcached.region;
1717

18+
import com.mc.hibernate.memcached.MemcachedCache;
1819
import org.hibernate.cache.CacheException;
1920
import org.hibernate.cache.spi.TimestampsRegion;
21+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2022
import org.slf4j.Logger;
2123
import org.slf4j.LoggerFactory;
2224

23-
import com.mc.hibernate.memcached.MemcachedCache;
24-
2525
public class MemcachedTimestampsRegion extends AbstractMemcachedRegion implements TimestampsRegion {
2626

2727
private final Logger log = LoggerFactory.getLogger(MemcachedTimestampsRegion.class);
@@ -30,11 +30,13 @@ public MemcachedTimestampsRegion(MemcachedCache cache) {
3030
super(cache);
3131
}
3232

33-
public Object get(Object key) throws CacheException {
33+
@Override
34+
public Object get(SharedSessionContractImplementor session, Object key) throws CacheException {
3435
return cache.get(key);
3536
}
3637

37-
public void put(Object key, Object value) throws CacheException {
38+
@Override
39+
public void put(SharedSessionContractImplementor session, Object key, Object value) throws CacheException {
3840
cache.put(key, value);
3941
}
4042

0 commit comments

Comments
 (0)