From 2db12047b443574724b8f0353edc78ee409539e0 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Thu, 27 Sep 2018 15:05:57 +0800 Subject: [PATCH 001/131] fixed #IN6S0 --- .../oschina/j2cache/hibernate4/J2CacheCacheRegion.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/hibernate4/src/net/oschina/j2cache/hibernate4/J2CacheCacheRegion.java b/modules/hibernate4/src/net/oschina/j2cache/hibernate4/J2CacheCacheRegion.java index 5afa750..3e0d480 100644 --- a/modules/hibernate4/src/net/oschina/j2cache/hibernate4/J2CacheCacheRegion.java +++ b/modules/hibernate4/src/net/oschina/j2cache/hibernate4/J2CacheCacheRegion.java @@ -17,10 +17,6 @@ package net.oschina.j2cache.hibernate4; import net.oschina.j2cache.CacheChannel; import net.oschina.j2cache.CacheObject; -import org.hibernate.HibernateException; - -import java.io.IOException; -import java.io.Serializable; public class J2CacheCacheRegion implements CacheRegion { @@ -44,17 +40,17 @@ public class J2CacheCacheRegion implements CacheRegion { @Override public CacheObject get(Object key) { - return this.cacheChannel.get(this.region, (String) key); + return this.cacheChannel.get(this.region, key.toString()); } @Override public void put(Object key, Object value) { - this.cacheChannel.set(this.region, (String) key, value); + this.cacheChannel.set(this.region, key.toString(), value); } @Override public void evict(Object key) { - this.cacheChannel.evict(this.region, (String)key); + this.cacheChannel.evict(this.region, key.toString()); } public Iterable keys() { -- Gitee From 70e23abdc552f1e9ec07766ae0487269d66e243f Mon Sep 17 00:00:00 2001 From: tandy <879620309@qq.com> Date: Thu, 27 Sep 2018 19:34:56 +0800 Subject: [PATCH 002/131] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hibernate5/hibernate5_2_17/pom.xml | 107 + .../AbstractJ2CacheRegionFactory.java | 97 + .../j2cache/hibernate5/CacheRegion.java | 18 + .../hibernate5/J2CacheCacheRegion.java | 44 + .../hibernate5/J2CacheRegionFactory.java | 39 + .../hibernate5/log/J2CacheMessageLogger.java | 115 + .../log/J2CacheMessageLogger_$logger.java | 3522 +++++++++++++++++ ...HibernateNonstopCacheExceptionHandler.java | 32 + .../nonstop/NonStopCacheException.java | 18 + ...opAwareCollectionRegionAccessStrategy.java | 142 + ...onstopAwareEntityRegionAccessStrategy.java | 180 + ...topAwareNaturalIdRegionAccessStrategy.java | 181 + .../regions/J2CacheCollectionRegion.java | 25 + .../hibernate5/regions/J2CacheDataRegion.java | 105 + .../regions/J2CacheEntityRegion.java | 25 + .../regions/J2CacheGeneralDataRegion.java | 69 + .../regions/J2CacheNaturalIdRegion.java | 25 + .../regions/J2CacheQueryResultsRegion.java | 15 + .../regions/J2CacheTimestampsRegion.java | 15 + .../J2CacheTransactionalDataRegion.java | 94 + .../AbstractJ2CacheAccessStrategy.java | 59 + ...bstractReadWriteJ2CacheAccessStrategy.java | 268 ++ .../J2CacheAccessStrategyFactory.java | 18 + .../J2CacheAccessStrategyFactoryImpl.java | 75 + ...J2CacheCollectionRegionAccessStrategy.java | 67 + ...riteJ2CacheEntityRegionAccessStrategy.java | 87 + ...eJ2CacheNaturalIdRegionAccessStrategy.java | 88 + .../NonstopAccessStrategyFactory.java | 38 + ...J2CacheCollectionRegionAccessStrategy.java | 60 + ...OnlyJ2CacheEntityRegionAccessStrategy.java | 81 + ...yJ2CacheNaturalIdRegionAccessStrategy.java | 80 + ...J2CacheCollectionRegionAccessStrategy.java | 32 + ...riteJ2CacheEntityRegionAccessStrategy.java | 95 + ...eJ2CacheNaturalIdRegionAccessStrategy.java | 82 + ...J2CacheCollectionRegionAccessStrategy.java | 70 + ...onalJ2CacheEntityRegionAccessStrategy.java | 95 + ...lJ2CacheNaturalIdRegionAccessStrategy.java | 89 + .../j2cache/hibernate5/util/SlewClock.class | Bin 0 -> 4020 bytes .../j2cache/hibernate5/util/SlewClock.java | 105 + .../hibernate5/util/TimeProviderLoader.java | 23 + .../j2cache/hibernate5/util/Timestamper.java | 62 + .../util/lang/VicariousThreadLocal.java | 118 + .../test/config/commons-logging.properties | 3 + .../hibernate5_2_17/test/config/ehcache.xml | 59 + .../hibernate5_2_17/test/config/ehcache3.xml | 19 + .../test/config/j2cache.properties | 169 + .../hibernate5_2_17/test/config/log4j.xml | 65 + .../hibernate5_2_17/test/config/network.xml | 66 + .../test/config/props/jdbc.properties | 24 + .../test/config/redis.properties | 9 + .../test/config/spring/applicationContext.xml | 65 + .../hibernate5/J2CacheRegionFactoryTest.java | 152 + .../j2cache/hibernate5/bean/Article.java | 133 + .../hibernate5/service/ArticleService.java | 54 + .../hibernate5/service/IArticleService.java | 29 + 55 files changed, 7407 insertions(+) create mode 100644 modules/hibernate5/hibernate5_2_17/pom.xml create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/CacheRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.class create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/Timestamper.java create mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/commons-logging.properties create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/ehcache.xml create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/ehcache3.xml create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/j2cache.properties create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/log4j.xml create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/network.xml create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/props/jdbc.properties create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/redis.properties create mode 100644 modules/hibernate5/hibernate5_2_17/test/config/spring/applicationContext.xml create mode 100644 modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java create mode 100644 modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/bean/Article.java create mode 100644 modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java create mode 100644 modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java diff --git a/modules/hibernate5/hibernate5_2_17/pom.xml b/modules/hibernate5/hibernate5_2_17/pom.xml new file mode 100644 index 0000000..26260b7 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/pom.xml @@ -0,0 +1,107 @@ + + + + + j2cache + net.oschina.j2cache + 2.7.0-release + + 4.0.0 + + j2cache-hibernate5 + jar + J2Cache - hibernate5 + + + 5.2.17.Final + 5.0.8.RELEASE + + + + + net.oschina.j2cache + j2cache-core + ${j2cache-version} + compile + + + org.hibernate + hibernate-ehcache + ${hibernate.version} + compile + + + + org.springframework + spring-test + ${spring.version} + test + + + org.springframework + spring-web + ${spring.version} + test + + + org.springframework + spring-context-support + ${spring.version} + test + + + org.springframework + spring-orm + ${spring.version} + test + + + org.springframework + spring-aop + ${spring.version} + test + + + org.springframework + spring-aspects + ${spring.version} + test + + + com.cloudhopper.proxool + proxool + 0.9.1 + test + + + log4j + log4j + 1.2.17 + test + + + mysql + mysql-connector-java + 5.1.46 + test + + + + org.ehcache + ehcache + 3.4.0 + test + + + + + src + test/src + + diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java new file mode 100644 index 0000000..e2a3e48 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2014-Now http://j2eplus.com All rights reserved. + */ +package net.oschina.j2cache.hibernate5; + +import net.oschina.j2cache.CacheChannel; +import net.oschina.j2cache.hibernate5.strategy.NonstopAccessStrategyFactory; +import net.oschina.j2cache.hibernate5.regions.*; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactoryImpl; +import net.oschina.j2cache.hibernate5.util.Timestamper; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.*; +import org.hibernate.cache.spi.access.AccessType; + +import java.util.Properties; + +/** + * This guy is lazy, nothing left. + * + * @author Tandy 2018/9/16 17:37 + */ +public abstract class AbstractJ2CacheRegionFactory implements RegionFactory { + + protected SessionFactoryOptions settings; + + protected CacheChannel channel; + + protected final J2CacheAccessStrategyFactory accessStrategyFactory = new NonstopAccessStrategyFactory(new J2CacheAccessStrategyFactoryImpl()); + + @Override + public boolean isMinimalPutsEnabledByDefault() { + return true; + } + + @Override + public long nextTimestamp() { + return Timestamper.next(); + } + + @Override + public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) + throws CacheException { + return new J2CacheEntityRegion(accessStrategyFactory, getCache( regionName ), settings, metadata, properties ); + } + + @Override + public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata) + throws CacheException { + return new J2CacheNaturalIdRegion( + accessStrategyFactory, + getCache( regionName ), + settings, + metadata, + properties + ); + } + + @Override + public CollectionRegion buildCollectionRegion( + String regionName, + Properties properties, + CacheDataDescription metadata) + throws CacheException { + return new J2CacheCollectionRegion( + accessStrategyFactory, + getCache( regionName ), + settings, + metadata, + properties + ); + } + + @Override + public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException { + return new J2CacheQueryResultsRegion( accessStrategyFactory, getCache( regionName ), properties ); + } + + @Override + public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException { + return new J2CacheTimestampsRegion( accessStrategyFactory, getCache( regionName ), properties ); + } + + @Override + public AccessType getDefaultAccessType() { + return AccessType.READ_WRITE; + } + + public void setChannel(CacheChannel channel) { + this.channel = channel; + } + + private CacheRegion getCache(String name) throws CacheException { + return new J2CacheCacheRegion(channel,name); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/CacheRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/CacheRegion.java new file mode 100644 index 0000000..d93ef2f --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/CacheRegion.java @@ -0,0 +1,18 @@ +package net.oschina.j2cache.hibernate5; + +import net.oschina.j2cache.CacheObject; + +public interface CacheRegion { + + String getName(); + + void clear(); + + CacheObject get(Object key); + + void put(Object key, Object value); + + void evict(Object key); + + Iterable keys(); +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java new file mode 100644 index 0000000..917bc86 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java @@ -0,0 +1,44 @@ +package net.oschina.j2cache.hibernate5; + +import net.oschina.j2cache.CacheChannel; +import net.oschina.j2cache.CacheObject; + +public class J2CacheCacheRegion implements CacheRegion { + + private CacheChannel cacheChannel; + private String region; + + public J2CacheCacheRegion(CacheChannel channel, String region) { + this.cacheChannel = channel; + this.region = region; + } + + @Override + public String getName() { + return this.region; + } + + @Override + public void clear() { + this.cacheChannel.clear(this.region); + } + + @Override + public CacheObject get(Object key) { + return this.cacheChannel.get(this.region, key.toString()); + } + + @Override + public void put(Object key, Object value) { + this.cacheChannel.set(this.region, key.toString(), value); + } + + @Override + public void evict(Object key) { + this.cacheChannel.evict(this.region, key.toString()); + } + + public Iterable keys() { + return this.cacheChannel.keys(this.region); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java new file mode 100644 index 0000000..ffd5222 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java @@ -0,0 +1,39 @@ +package net.oschina.j2cache.hibernate5; + +import net.oschina.j2cache.J2Cache; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; + +import java.util.Map; +import java.util.Properties; + +public class J2CacheRegionFactory extends AbstractJ2CacheRegionFactory { + + private static final String SPRING_CACHEMANAGER = "hibernate.cache.spring.cache_manager"; + + private static final String DEFAULT_SPRING_CACHEMANAGER = "cacheManager"; + + @SuppressWarnings("UnusedDeclaration") + public J2CacheRegionFactory() { + } + + @SuppressWarnings("UnusedDeclaration") + public J2CacheRegionFactory(Properties prop) { + super(); + } + + @Override + public void start(SessionFactoryOptions settings, Properties properties) throws CacheException { + this.settings = settings; + if (this.channel == null) { + this.channel = J2Cache.getChannel(); + } + } + + @Override + public void stop() { + if (channel != null) { + channel.close(); + } + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java new file mode 100644 index 0000000..28f3744 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2015-2017. + *

+ * 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 net.oschina.j2cache.hibernate5.log; + +import org.hibernate.internal.CoreMessageLogger; +import org.jboss.logging.LogMessage; +import org.jboss.logging.Logger.Level; +import org.jboss.logging.Message; +import org.jboss.logging.MessageLogger; + +@MessageLogger(projectCode = "HHH") +public interface J2CacheMessageLogger extends CoreMessageLogger { + + + @LogMessage(level = Level.WARN) + @Message( + value = "Attempt to restart an already started J2CacheRegionFactory. Use sessionFactory.close() between " + + "repeated calls to buildSessionFactory. Using previously created J2CacheRegionFactory. If this " + + "behaviour is required, consider using org.hibernate.cache.j2cache.SingletonJ2CacheRegionFactory.", + id = 20001 + ) + void attemptToRestartAlreadyStartedJ2CacheProvider(); + + /** + * Log a message (WARN) about inability to find configuration file + * + * @param name The name of the configuration file + */ + @LogMessage(level = Level.WARN) + @Message(value = "Could not find configuration [%s]; using defaults.", id = 20002) + void unableToFindConfiguration(String name); + + /** + * Log a message (WARN) about inability to find named cache configuration + * + * @param name The name of the cache configuration + */ + @LogMessage(level = Level.WARN) + @Message(value = "Could not find a specific J2Cache configuration for cache named [%s]; using defaults.", id = 20003) + void unableToFindJ2CacheConfiguration(String name); + + /** + * Logs a message about not being able to resolve the configuration by resource name. + * + * @param configurationResourceName The resource name we attempted to resolve + */ + @LogMessage(level = Level.WARN) + @Message( + value = "A configurationResourceName was set to %s but the resource could not be loaded from the classpath. " + + "J2Cache will configure itself using defaults.", + id = 20004 + ) + void unableToLoadConfiguration(String configurationResourceName); + + /** + * Logs a message (WARN) about attempt to use an incompatible + */ + @LogMessage(level = Level.WARN) + @Message( + value = "The default cache value mode for this J2Cache configuration is \"identity\". " + + "This is incompatible with clustered Hibernate caching - the value mode has therefore been " + + "switched to \"serialization\"", + id = 20005 + ) + void incompatibleCacheValueMode(); + + /** + * Logs a message (WARN) about attempt to use an incompatible + * + * @param cacheName The name of the cache whose config attempted to specify value mode. + */ + @LogMessage(level = Level.WARN) + @Message(value = "The value mode for the cache[%s] is \"identity\". This is incompatible with clustered Hibernate caching - " + + "the value mode has therefore been switched to \"serialization\"", id = 20006) + void incompatibleCacheValueModePerCache(String cacheName); + + /** + * Log a message (WARN) about an attempt to specify read-only caching for a mutable entity + * + * @param entityName The name of the entity + */ + @LogMessage(level = Level.WARN) + @Message(value = "read-only cache configured for mutable entity [%s]", id = 20007) + void readOnlyCacheConfiguredForMutableEntity(String entityName); + + /** + * Log a message (WARN) about expiry of soft-locked region. + * + * @param regionName The region name + * @param key The cache key + * @param lock The lock + */ + @LogMessage(level = Level.WARN) + @Message( + value = "Cache[%s] Key[%s] Lockable[%s]\n" + + "A soft-locked cache entry was expired by the underlying J2Cache. If this happens regularly you " + + "should consider increasing the cache timeouts and/or capacity limits", + id = 20008 + ) + void softLockedCacheExpired(String regionName, Object key, String lock); + +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java new file mode 100644 index 0000000..9d62271 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java @@ -0,0 +1,3522 @@ +/** + * Copyright (c) 2015-2017. + *

+ * 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 net.oschina.j2cache.hibernate5.log; + +import org.hibernate.HibernateException; +import org.hibernate.LockMode; +import org.hibernate.cache.CacheException; +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; +import org.hibernate.engine.jndi.JndiException; +import org.hibernate.engine.jndi.JndiNameException; +import org.hibernate.engine.loading.internal.CollectionLoadContext; +import org.hibernate.engine.loading.internal.EntityLoadContext; +import org.hibernate.engine.spi.CollectionKey; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.id.IntegralDataTypeHolder; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.type.BasicType; +import org.hibernate.type.SerializationException; +import org.hibernate.type.Type; +import org.jboss.logging.BasicLogger; +import org.jboss.logging.DelegatingBasicLogger; +import org.jboss.logging.Logger; + +import javax.annotation.Generated; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; +import javax.transaction.Synchronization; +import javax.transaction.SystemException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.net.URL; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.util.*; + +@Generated(value = "org.jboss.logging.processor.generator.model.MessageLoggerImplementor", date = "2015-01-06T12:13:01-0800") +public class J2CacheMessageLogger_$logger extends DelegatingBasicLogger implements Serializable, J2CacheMessageLogger, CoreMessageLogger, BasicLogger { + + private static final long serialVersionUID = 1L; + private static final String FQCN = J2CacheMessageLogger_$logger.class.getName(); + private static final Locale LOCALE; + private static final String attemptToRestartAlreadyStartedJ2CacheProvider = "HHH020001: Attempt to restart an already started J2CacheRegionFactory. Use sessionFactory.close() between repeated calls to buildSessionFactory. Using previously created J2CacheRegionFactory. If this behaviour is required, consider using org.hibernate.cache.ehcache.SingletonJ2CacheRegionFactory."; + private static final String unableToFindConfiguration = "HHH020002: Could not find configuration [%s]; using defaults."; + private static final String unableToFindJ2CacheConfiguration = "HHH020003: Could not find a specific ehcache configuration for cache named [%s]; using defaults."; + private static final String unableToLoadConfiguration = "HHH020004: A configurationResourceName was set to %s but the resource could not be loaded from the classpath. Ehcache will configure itself using defaults."; + private static final String incompatibleCacheValueMode = "HHH020005: The default cache value mode for this Ehcache configuration is \"identity\". This is incompatible with clustered Hibernate caching - the value mode has therefore been switched to \"serialization\""; + private static final String incompatibleCacheValueModePerCache = "HHH020006: The value mode for the cache[%s] is \"identity\". This is incompatible with clustered Hibernate caching - the value mode has therefore been switched to \"serialization\""; + private static final String readOnlyCacheConfiguredForMutableEntity = "HHH020007: read-only cache configured for mutable entity [%s]"; + private static final String softLockedCacheExpired = "HHH020008: Cache[%s] Key[%s] Lockable[%s]\nA soft-locked cache entry was expired by the underlying Ehcache. If this happens regularly you should consider increasing the cache timeouts and/or capacity limits"; + private static final String alreadySessionBound = "HHH000002: Already session bound on call to bind(); make sure you clean up your sessions!"; + private static final String autoCommitMode = "HHH000006: Autocommit mode: %s"; + private static final String autoFlushWillNotWork = "HHH000008: JTASessionContext being used with JDBC transactions; auto-flush will not operate correctly with getCurrentSession()"; + private static final String batchContainedStatementsOnRelease = "HHH000010: On release of batch it still contained JDBC statements"; + private static final String bytecodeProvider = "HHH000021: Bytecode provider name : %s"; + private static final String c3p0ProviderClassNotFound = "HHH000022: c3p0 properties were encountered, but the %s provider class was not found on the classpath; these properties are going to be ignored."; + private static final String cachedFileNotFound = "HHH000023: I/O reported cached file could not be found : %s : %s"; + private static final String cacheProvider = "HHH000024: Cache provider: %s"; + private static final String callingJoinTransactionOnNonJtaEntityManager = "HHH000027: Calling joinTransaction() on a non JTA EntityManager"; + private static final String closing = "HHH000031: Closing"; + private static final String collectionsFetched = "HHH000032: Collections fetched (minimize this): %s"; + private static final String collectionsLoaded = "HHH000033: Collections loaded: %s"; + private static final String collectionsRecreated = "HHH000034: Collections recreated: %s"; + private static final String collectionsRemoved = "HHH000035: Collections removed: %s"; + private static final String collectionsUpdated = "HHH000036: Collections updated: %s"; + private static final String columns = "HHH000037: Columns: %s"; + private static final String compositeIdClassDoesNotOverrideEquals = "HHH000038: Composite-id class does not override equals(): %s"; + private static final String compositeIdClassDoesNotOverrideHashCode = "HHH000039: Composite-id class does not override hashCode(): %s"; + private static final String configurationResource = "HHH000040: Configuration resource: %s"; + private static final String configuredSessionFactory = "HHH000041: Configured SessionFactory: %s"; + private static final String configuringFromFile = "HHH000042: Configuring from file: %s"; + private static final String configuringFromResource = "HHH000043: Configuring from resource: %s"; + private static final String configuringFromUrl = "HHH000044: Configuring from URL: %s"; + private static final String configuringFromXmlDocument = "HHH000045: Configuring from XML document"; + private static final String connectionsObtained = "HHH000048: Connections obtained: %s"; + private static final String containerProvidingNullPersistenceUnitRootUrl = "HHH000050: Container is providing a null PersistenceUnitRootUrl: discovery impossible"; + private static final String containsJoinFetchedCollection = "HHH000051: Ignoring bag join fetch [%s] due to prior collection join fetch"; + private static final String creatingSubcontextInfo = "HHH000053: Creating subcontext: %s"; + private static final String definingFlushBeforeCompletionIgnoredInHem = "HHH000059: Defining %s=true ignored in HEM"; + private static final String deprecatedForceDescriminatorAnnotation = "HHH000062: @ForceDiscriminator is deprecated use @DiscriminatorOptions instead."; + private static final String deprecatedOracle9Dialect = "HHH000063: The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead"; + private static final String deprecatedOracleDialect = "HHH000064: The OracleDialect dialect has been deprecated; use Oracle8iDialect instead"; + private static final String deprecatedUuidGenerator = "HHH000065: DEPRECATED : use [%s] instead with custom [%s] implementation"; + private static final String disallowingInsertStatementComment = "HHH000067: Disallowing insert statement comment for select-identity due to Oracle driver bug"; + private static final String duplicateGeneratorName = "HHH000069: Duplicate generator name %s"; + private static final String duplicateGeneratorTable = "HHH000070: Duplicate generator table: %s"; + private static final String duplicateImport = "HHH000071: Duplicate import: %s -> %s"; + private static final String duplicateJoins = "HHH000072: Duplicate joins for class: %s"; + private static final String duplicateListener = "HHH000073: entity-listener duplication, first event definition will be used: %s"; + private static final String duplicateMetadata = "HHH000074: Found more than one , subsequent ignored"; + private static final String entitiesDeleted = "HHH000076: Entities deleted: %s"; + private static final String entitiesFetched = "HHH000077: Entities fetched (minimize this): %s"; + private static final String entitiesInserted = "HHH000078: Entities inserted: %s"; + private static final String entitiesLoaded = "HHH000079: Entities loaded: %s"; + private static final String entitiesUpdated = "HHH000080: Entities updated: %s"; + private static final String entityAnnotationOnNonRoot = "HHH000081: @org.hibernate.annotations.Entity used on a non root entity: ignored for %s"; + private static final String entityManagerClosedBySomeoneElse = "HHH000082: Entity Manager closed by someone else (%s must not be used)"; + private static final String entityMappedAsNonAbstract = "HHH000084: Entity [%s] is abstract-class/interface explicitly mapped as non-abstract; be sure to supply entity-names"; + private static final String exceptionHeaderFound = "HHH000085: %s %s found"; + private static final String exceptionHeaderNotFound = "HHH000086: %s No %s found"; + private static final String exceptionInAfterTransactionCompletionInterceptor = "HHH000087: Exception in interceptor afterTransactionCompletion()"; + private static final String exceptionInBeforeTransactionCompletionInterceptor = "HHH000088: Exception in interceptor beforeTransactionCompletion()"; + private static final String exceptionInSubResolver = "HHH000089: Sub-resolver threw unexpected exception, continuing to next : %s"; + private static final String expectedType = "HHH000091: Expected type: %s, actual value: %s"; + private static final String expired = "HHH000092: An item was expired by the cache while it was locked (increase your cache timeout): %s"; + private static final String factoryBoundToJndiName = "HHH000094: Bound factory to JNDI name: %s"; + private static final String factoryJndiRename = "HHH000096: A factory was renamed from [%s] to [%s] in JNDI"; + private static final String factoryUnboundFromJndiName = "HHH000097: Unbound factory from JNDI name: %s"; + private static final String factoryUnboundFromName = "HHH000098: A factory was unbound from name: %s"; + private static final String failed = "HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): %s"; + private static final String failSafeCollectionsCleanup = "HHH000100: Fail-safe cleanup (collections) : %s"; + private static final String failSafeEntitiesCleanup = "HHH000101: Fail-safe cleanup (entities) : %s"; + private static final String fetchingDatabaseMetadata = "HHH000102: Fetching database metadata"; + private static final String firstOrMaxResultsSpecifiedWithCollectionFetch = "HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!"; + private static final String flushes = "HHH000105: Flushes: %s"; + private static final String forcingContainerResourceCleanup = "HHH000106: Forcing container resource cleanup on transaction completion"; + private static final String forcingTableUse = "HHH000107: Forcing table use for sequence-style generator due to pooled optimizer selection where db does not support pooled sequences"; + private static final String foreignKeys = "HHH000108: Foreign keys: %s"; + private static final String foundMappingDocument = "HHH000109: Found mapping document in jar: %s"; + private static final String gettersOfLazyClassesCannotBeFinal = "HHH000112: Getters of lazy classes cannot be final: %s.%s"; + private static final String guidGenerated = "HHH000113: GUID identifier generated: %s"; + private static final String handlingTransientEntity = "HHH000114: Handling transient entity in delete processing"; + private static final String hibernateConnectionPoolSize = "HHH000115: Hibernate connection pool size: %s (min=%s)"; + private static final String honoringOptimizerSetting = "HHH000116: Config specified explicit optimizer of [%s], but [%s=%s]; using optimizer [%s] increment default of [%s]."; + private static final String hql = "HHH000117: HQL: %s, time: %sms, rows: %s"; + private static final String hsqldbSupportsOnlyReadCommittedIsolation = "HHH000118: HSQLDB supports only READ_UNCOMMITTED isolation"; + private static final String hydratingEntitiesCount = "HHH000119: On EntityLoadContext#clear, hydratingEntities contained [%s] entries"; + private static final String ignoringTableGeneratorConstraints = "HHH000120: Ignoring unique constraints specified on table generator [%s]"; + private static final String ignoringUnrecognizedQueryHint = "HHH000121: Ignoring unrecognized query hint [%s]"; + private static final String illegalPropertyGetterArgument = "HHH000122: IllegalArgumentException in class: %s, getter method of property: %s"; + private static final String illegalPropertySetterArgument = "HHH000123: IllegalArgumentException in class: %s, setter method of property: %s"; + private static final String immutableAnnotationOnNonRoot = "HHH000124: @Immutable used on a non root entity: ignored for %s"; + private static final String incompleteMappingMetadataCacheProcessing = "HHH000125: Mapping metadata cache was not completely processed"; + private static final String indexes = "HHH000126: Indexes: %s"; + private static final String couldNotBindJndiListener = "HHH000127: Could not bind JNDI listener"; + private static final String instantiatingExplicitConnectionProvider = "HHH000130: Instantiating explicit connection provider: %s"; + private static final String invalidArrayElementType = "HHH000132: Array element type error\n%s"; + private static final String invalidDiscriminatorAnnotation = "HHH000133: Discriminator column has to be defined in the root entity, it will be ignored in subclass: %s"; + private static final String invalidEditOfReadOnlyItem = "HHH000134: Application attempted to edit read only item: %s"; + private static final String invalidJndiName = "HHH000135: Invalid JNDI name: %s"; + private static final String invalidOnDeleteAnnotation = "HHH000136: Inapropriate use of @OnDelete on entity, annotation ignored: %s"; + private static final String invalidPrimaryKeyJoinColumnAnnotation = "HHH000137: Root entity should not hold a PrimaryKeyJoinColum(s), will be ignored: %s"; + private static final String invalidSubStrategy = "HHH000138: Mixing inheritance strategy in a entity hierarchy is not allowed, ignoring sub strategy in: %s"; + private static final String invalidTableAnnotation = "HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: %s"; + private static final String jaccContextId = "HHH000140: JACC contextID: %s"; + private static final String JavaSqlTypesMappedSameCodeMultipleTimes = "HHH000141: java.sql.Types mapped the same code [%s] multiple times; was [%s]; now [%s]"; + private static final String bytecodeEnhancementFailed = "HHH000142: Bytecode enhancement failed: %s"; + private static final String jdbcAutoCommitFalseBreaksEjb3Spec = "HHH000144: %s = false breaks the EJB3 specification"; + private static final String jdbcRollbackFailed = "HHH000151: JDBC rollback failed"; + private static final String jndiInitialContextProperties = "HHH000154: JNDI InitialContext properties:%s"; + private static final String jndiNameDoesNotHandleSessionFactoryReference = "HHH000155: JNDI name %s does not handle a session factory reference"; + private static final String lazyPropertyFetchingAvailable = "HHH000157: Lazy property fetching available for: %s"; + private static final String loadingCollectionKeyNotFound = "HHH000159: In CollectionLoadContext#endLoadingCollections, localLoadingCollectionKeys contained [%s], but no LoadingCollectionEntry was found in loadContexts"; + private static final String localLoadingCollectionKeysCount = "HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [%s] entries"; + private static final String loggingStatistics = "HHH000161: Logging statistics...."; + private static final String logicalConnectionClosed = "HHH000162: *** Logical connection closed ***"; + private static final String logicalConnectionReleasingPhysicalConnection = "HHH000163: Logical connection releasing its physical connection"; + private static final String maxQueryTime = "HHH000173: Max query time: %sms"; + private static final String missingArguments = "HHH000174: Function template anticipated %s arguments, but %s arguments encountered"; + private static final String missingEntityAnnotation = "HHH000175: Class annotated @org.hibernate.annotations.Entity but not javax.persistence.Entity (most likely a user error): %s"; + private static final String namedQueryError = "HHH000177: Error in named query: %s"; + private static final String namingExceptionAccessingFactory = "HHH000178: Naming exception occurred accessing factory: %s"; + private static final String narrowingProxy = "HHH000179: Narrowing proxy to %s - this operation breaks =="; + private static final String needsLimit = "HHH000180: FirstResult/maxResults specified on polymorphic query; applying in memory!"; + private static final String noAppropriateConnectionProvider = "HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections"; + private static final String noDefaultConstructor = "HHH000182: No default (no-argument) constructor for class: %s (class must be instantiated by Interceptor)"; + private static final String noPersistentClassesFound = "HHH000183: no persistent classes found for query class: %s"; + private static final String noSessionFactoryWithJndiName = "HHH000184: No session factory with JNDI name %s"; + private static final String optimisticLockFailures = "HHH000187: Optimistic lock failures: %s"; + private static final String orderByAnnotationIndexedCollection = "HHH000189: @OrderBy not allowed for an indexed collection, annotation ignored."; + private static final String overridingTransactionStrategyDangerous = "HHH000193: Overriding %s is dangerous, this might break the EJB3 specification implementation"; + private static final String packageNotFound = "HHH000194: Package not found or wo package-info.java: %s"; + private static final String parsingXmlError = "HHH000196: Error parsing XML (%s) : %s"; + private static final String parsingXmlErrorForFile = "HHH000197: Error parsing XML: %s(%s) %s"; + private static final String parsingXmlWarning = "HHH000198: Warning parsing XML (%s) : %s"; + private static final String parsingXmlWarningForFile = "HHH000199: Warning parsing XML: %s(%s) %s"; + private static final String persistenceProviderCallerDoesNotImplementEjb3SpecCorrectly = "HHH000200: Persistence provider caller does not implement the EJB3 spec correctly.PersistenceUnitInfo.getNewTempClassLoader() is null."; + private static final String pooledOptimizerReportedInitialValue = "HHH000201: Pooled optimizer source reported [%s] as the initial value; use of 1 or greater highly recommended"; + private static final String preparedStatementAlreadyInBatch = "HHH000202: PreparedStatement was already in the batch, [%s]."; + private static final String processEqualityExpression = "HHH000203: processEqualityExpression() : No expression to process!"; + private static final String processingPersistenceUnitInfoName = "HHH000204: Processing PersistenceUnitInfo [\n\tname: %s\n\t...]"; + private static final String propertiesLoaded = "HHH000205: Loaded properties from resource hibernate.properties: %s"; + private static final String propertiesNotFound = "HHH000206: hibernate.properties not found"; + private static final String propertyNotFound = "HHH000207: Property %s not found in class but described in (possible typo error)"; + private static final String proxoolProviderClassNotFound = "HHH000209: proxool properties were encountered, but the %s provider class was not found on the classpath; these properties are going to be ignored."; + private static final String queriesExecuted = "HHH000210: Queries executed to database: %s"; + private static final String queryCacheHits = "HHH000213: Query cache hits: %s"; + private static final String queryCacheMisses = "HHH000214: Query cache misses: %s"; + private static final String queryCachePuts = "HHH000215: Query cache puts: %s"; + private static final String rdmsOs2200Dialect = "HHH000218: RDMSOS2200Dialect version: 1.0"; + private static final String readingCachedMappings = "HHH000219: Reading mappings from cache file: %s"; + private static final String readingMappingsFromFile = "HHH000220: Reading mappings from file: %s"; + private static final String readingMappingsFromResource = "HHH000221: Reading mappings from resource: %s"; + private static final String readOnlyCacheConfiguredForMutableCollection = "HHH000222: read-only cache configured for mutable collection [%s]"; + private static final String recognizedObsoleteHibernateNamespace = "HHH000223: Recognized obsolete hibernate namespace %s. Use namespace %s instead. Refer to Hibernate 3.6 Migration Guide!"; + private static final String renamedProperty = "HHH000225: Property [%s] has been renamed to [%s]; update your properties appropriately"; + private static final String requiredDifferentProvider = "HHH000226: Required a different provider: %s"; + private static final String runningHbm2ddlSchemaExport = "HHH000227: Running hbm2ddl schema export"; + private static final String runningHbm2ddlSchemaUpdate = "HHH000228: Running hbm2ddl schema update"; + private static final String runningSchemaValidator = "HHH000229: Running schema validator"; + private static final String schemaExportComplete = "HHH000230: Schema export complete"; + private static final String schemaExportUnsuccessful = "HHH000231: Schema export unsuccessful"; + private static final String schemaUpdateComplete = "HHH000232: Schema update complete"; + private static final String scopingTypesToSessionFactoryAfterAlreadyScoped = "HHH000233: Scoping types to session factory %s after already scoped %s"; + private static final String searchingForMappingDocuments = "HHH000235: Searching for mapping documents in jar: %s"; + private static final String secondLevelCacheHits = "HHH000237: Second level cache hits: %s"; + private static final String secondLevelCacheMisses = "HHH000238: Second level cache misses: %s"; + private static final String secondLevelCachePuts = "HHH000239: Second level cache puts: %s"; + private static final String serviceProperties = "HHH000240: Service properties: %s"; + private static final String sessionsClosed = "HHH000241: Sessions closed: %s"; + private static final String sessionsOpened = "HHH000242: Sessions opened: %s"; + private static final String settersOfLazyClassesCannotBeFinal = "HHH000243: Setters of lazy classes cannot be final: %s.%s"; + private static final String sortAnnotationIndexedCollection = "HHH000244: @Sort not allowed for an indexed collection, annotation ignored."; + private static final String splitQueries = "HHH000245: Manipulation query [%s] resulted in [%s] split queries"; + private static final String sqlWarning = "HHH000247: SQL Error: %s, SQLState: %s"; + private static final String startingQueryCache = "HHH000248: Starting query cache at region: %s"; + private static final String startingServiceAtJndiName = "HHH000249: Starting service at JNDI name: %s"; + private static final String startingUpdateTimestampsCache = "HHH000250: Starting update timestamps cache at region: %s"; + private static final String startTime = "HHH000251: Start time: %s"; + private static final String statementsClosed = "HHH000252: Statements closed: %s"; + private static final String statementsPrepared = "HHH000253: Statements prepared: %s"; + private static final String stoppingService = "HHH000255: Stopping service"; + private static final String subResolverException = "HHH000257: sub-resolver threw unexpected exception, continuing to next : %s"; + private static final String successfulTransactions = "HHH000258: Successful transactions: %s"; + private static final String synchronizationAlreadyRegistered = "HHH000259: Synchronization [%s] was already registered"; + private static final String synchronizationFailed = "HHH000260: Exception calling user Synchronization [%s] : %s"; + private static final String tableFound = "HHH000261: Table found: %s"; + private static final String tableNotFound = "HHH000262: Table not found: %s"; + private static final String multipleTablesFound = "HHH000263: More than one table found: %s"; + private static final String transactions = "HHH000266: Transactions: %s"; + private static final String transactionStartedOnNonRootSession = "HHH000267: Transaction started on non-root session"; + private static final String transactionStrategy = "HHH000268: Transaction strategy: %s"; + private static final String typeDefinedNoRegistrationKeys = "HHH000269: Type [%s] defined no registration keys; ignoring"; + private static final String typeRegistrationOverridesPrevious = "HHH000270: Type registration [%s] overrides previous : %s"; + private static final String unableToAccessEjb3Configuration = "HHH000271: Naming exception occurred accessing Ejb3Configuration"; + private static final String unableToAccessSessionFactory = "HHH000272: Error while accessing session factory with JNDI name %s"; + private static final String unableToAccessTypeInfoResultSet = "HHH000273: Error accessing type info result set : %s"; + private static final String unableToApplyConstraints = "HHH000274: Unable to apply constraints on DDL for %s"; + private static final String unableToBindEjb3ConfigurationToJndi = "HHH000276: Could not bind Ejb3Configuration to JNDI"; + private static final String unableToBindFactoryToJndi = "HHH000277: Could not bind factory to JNDI"; + private static final String unableToBindValueToParameter = "HHH000278: Could not bind value '%s' to parameter: %s; %s"; + private static final String unableToBuildEnhancementMetamodel = "HHH000279: Unable to build enhancement metamodel for %s"; + private static final String unableToBuildSessionFactoryUsingMBeanClasspath = "HHH000280: Could not build SessionFactory using the MBean classpath - will try again using client classpath: %s"; + private static final String unableToCleanUpCallableStatement = "HHH000281: Unable to clean up callable statement"; + private static final String unableToCleanUpPreparedStatement = "HHH000282: Unable to clean up prepared statement"; + private static final String unableToCleanupTemporaryIdTable = "HHH000283: Unable to cleanup temporary id table after use [%s]"; + private static final String unableToCloseConnection = "HHH000284: Error closing connection"; + private static final String unableToCloseInitialContext = "HHH000285: Error closing InitialContext [%s]"; + private static final String unableToCloseInputFiles = "HHH000286: Error closing input files: %s"; + private static final String unableToCloseInputStream = "HHH000287: Could not close input stream"; + private static final String unableToCloseInputStreamForResource = "HHH000288: Could not close input stream for %s"; + private static final String unableToCloseIterator = "HHH000289: Unable to close iterator"; + private static final String unableToCloseJar = "HHH000290: Could not close jar: %s"; + private static final String unableToCloseOutputFile = "HHH000291: Error closing output file: %s"; + private static final String unableToCloseOutputStream = "HHH000292: IOException occurred closing output stream"; + private static final String unableToCloseSession = "HHH000294: Could not close session"; + private static final String unableToCloseSessionDuringRollback = "HHH000295: Could not close session during rollback"; + private static final String unableToCloseStream = "HHH000296: IOException occurred closing stream"; + private static final String unableToCloseStreamError = "HHH000297: Could not close stream on hibernate.properties: %s"; + private static final String unableToCommitJta = "HHH000298: JTA commit failed"; + private static final String unableToCompleteSchemaUpdate = "HHH000299: Could not complete schema update"; + private static final String unableToCompleteSchemaValidation = "HHH000300: Could not complete schema validation"; + private static final String unableToConfigureSqlExceptionConverter = "HHH000301: Unable to configure SQLExceptionConverter : %s"; + private static final String unableToConstructCurrentSessionContext = "HHH000302: Unable to construct current session context [%s]"; + private static final String unableToConstructSqlExceptionConverter = "HHH000303: Unable to construct instance of specified SQLExceptionConverter : %s"; + private static final String unableToCopySystemProperties = "HHH000304: Could not copy system properties, system properties will be ignored"; + private static final String unableToCreateProxyFactory = "HHH000305: Could not create proxy factory for:%s"; + private static final String unableToCreateSchema = "HHH000306: Error creating schema "; + private static final String unableToDeserializeCache = "HHH000307: Could not deserialize cache file: %s : %s"; + private static final String unableToDestroyCache = "HHH000308: Unable to destroy cache: %s"; + private static final String unableToDestroyQueryCache = "HHH000309: Unable to destroy query cache: %s: %s"; + private static final String unableToDestroyUpdateTimestampsCache = "HHH000310: Unable to destroy update timestamps cache: %s: %s"; + private static final String unableToDetermineLockModeValue = "HHH000311: Unable to determine lock mode value : %s -> %s"; + private static final String unableToDetermineTransactionStatus = "HHH000312: Could not determine transaction status"; + private static final String unableToDetermineTransactionStatusAfterCommit = "HHH000313: Could not determine transaction status after commit"; + private static final String unableToDropTemporaryIdTable = "HHH000314: Unable to drop temporary id table after use [%s]"; + private static final String unableToExecuteBatch = "HHH000315: Exception executing batch [%s], SQL: %s"; + private static final String unableToExecuteResolver = "HHH000316: Error executing resolver [%s] : %s"; + private static final String unableToFindPersistenceXmlInClasspath = "HHH000318: Could not find any META-INF/persistence.xml file in the classpath"; + private static final String unableToGetDatabaseMetadata = "HHH000319: Could not get database metadata"; + private static final String unableToInstantiateConfiguredSchemaNameResolver = "HHH000320: Unable to instantiate configured schema name resolver [%s] %s"; + private static final String unableToLocateCustomOptimizerClass = "HHH000321: Unable to interpret specified optimizer [%s], falling back to noop"; + private static final String unableToInstantiateOptimizer = "HHH000322: Unable to instantiate specified optimizer [%s], falling back to noop"; + private static final String unableToInstantiateUuidGenerationStrategy = "HHH000325: Unable to instantiate UUID generation strategy class : %s"; + private static final String unableToJoinTransaction = "HHH000326: Cannot join transaction: do not override %s"; + private static final String unableToLoadCommand = "HHH000327: Error performing load command : %s"; + private static final String unableToLoadDerbyDriver = "HHH000328: Unable to load/access derby driver class sysinfo to check versions : %s"; + private static final String unableToLoadProperties = "HHH000329: Problem loading properties from hibernate.properties"; + private static final String unableToLocateConfigFile = "HHH000330: Unable to locate config file: %s"; + private static final String unableToLocateConfiguredSchemaNameResolver = "HHH000331: Unable to locate configured schema name resolver class [%s] %s"; + private static final String unableToLocateMBeanServer = "HHH000332: Unable to locate MBeanServer on JMX service shutdown"; + private static final String unableToLocateUuidGenerationStrategy = "HHH000334: Unable to locate requested UUID generation strategy class : %s"; + private static final String unableToLogSqlWarnings = "HHH000335: Unable to log SQLWarnings : %s"; + private static final String unableToLogWarnings = "HHH000336: Could not log warnings"; + private static final String unableToMarkForRollbackOnPersistenceException = "HHH000337: Unable to mark for rollback on PersistenceException: "; + private static final String unableToMarkForRollbackOnTransientObjectException = "HHH000338: Unable to mark for rollback on TransientObjectException: "; + private static final String unableToObjectConnectionMetadata = "HHH000339: Could not obtain connection metadata: %s"; + private static final String unableToObjectConnectionToQueryMetadata = "HHH000340: Could not obtain connection to query metadata: %s"; + private static final String unableToObtainConnectionMetadata = "HHH000341: Could not obtain connection metadata : %s"; + private static final String unableToObtainConnectionToQueryMetadata = "HHH000342: Could not obtain connection to query metadata : %s"; + private static final String unableToObtainInitialContext = "HHH000343: Could not obtain initial context"; + private static final String unableToParseMetadata = "HHH000344: Could not parse the package-level metadata [%s]"; + private static final String unableToPerformJdbcCommit = "HHH000345: JDBC commit failed"; + private static final String unableToPerformManagedFlush = "HHH000346: Error during managed flush [%s]"; + private static final String unableToQueryDatabaseMetadata = "HHH000347: Unable to query java.sql.DatabaseMetaData"; + private static final String unableToReadClass = "HHH000348: Unable to read class: %s"; + private static final String unableToReadColumnValueFromResultSet = "HHH000349: Could not read column value from result set: %s; %s"; + private static final String unableToReadHiValue = "HHH000350: Could not read a hi value - you need to populate the table: %s"; + private static final String unableToReadOrInitHiValue = "HHH000351: Could not read or init a hi value"; + private static final String unableToReleaseBatchStatement = "HHH000352: Unable to release batch statement..."; + private static final String unableToReleaseCacheLock = "HHH000353: Could not release a cache lock : %s"; + private static final String unableToReleaseContext = "HHH000354: Unable to release initial context: %s"; + private static final String unableToReleaseCreatedMBeanServer = "HHH000355: Unable to release created MBeanServer : %s"; + private static final String unableToReleaseIsolatedConnection = "HHH000356: Unable to release isolated connection [%s]"; + private static final String unableToReleaseTypeInfoResultSet = "HHH000357: Unable to release type info result set"; + private static final String unableToRemoveBagJoinFetch = "HHH000358: Unable to erase previously added bag join fetch"; + private static final String unableToResolveAggregateFunction = "HHH000359: Could not resolve aggregate function [%s]; using standard definition"; + private static final String unableToResolveMappingFile = "HHH000360: Unable to resolve mapping file [%s]"; + private static final String unableToRetrieveCache = "HHH000361: Unable to retrieve cache from JNDI [%s]: %s"; + private static final String unableToRetrieveTypeInfoResultSet = "HHH000362: Unable to retrieve type info result set : %s"; + private static final String unableToRollbackConnection = "HHH000363: Unable to rollback connection on exception [%s]"; + private static final String unableToRollbackIsolatedTransaction = "HHH000364: Unable to rollback isolated transaction on error [%s] : [%s]"; + private static final String unableToRollbackJta = "HHH000365: JTA rollback failed"; + private static final String unableToRunSchemaUpdate = "HHH000366: Error running schema update"; + private static final String unableToSetTransactionToRollbackOnly = "HHH000367: Could not set transaction to rollback only"; + private static final String unableToStopHibernateService = "HHH000368: Exception while stopping service"; + private static final String unableToStopService = "HHH000369: Error stopping service [%s] : %s"; + private static final String unableToSwitchToMethodUsingColumnIndex = "HHH000370: Exception switching from method: [%s] to a method using the column index. Reverting to using: [%, , , , or , which will only initialize entities (not as a proxy) as needed."; + private static final String deprecatedManyToManyFetch = "HHH000455: The fetch attribute on has been deprecated. Instead of fetch=\"select\", use lazy=\"extra\" with , , , , or , which will only initialize entities (not as a proxy) as needed."; + private static final String unsupportedNamedParameters = "HHH000456: Named parameters are used for a callable statement, but database metadata indicates named parameters are not supported."; + private static final String applyingExplicitDiscriminatorColumnForJoined = "HHH000457: Joined inheritance hierarchy [%1$s] defined explicit @DiscriminatorColumn. Legacy Hibernate behavior was to ignore the @DiscriminatorColumn. However, as part of issue HHH-6911 we now apply the explicit @DiscriminatorColumn. If you would prefer the legacy behavior, enable the `%2$s` setting (%2$s=true)"; + private static final String creatingPooledLoOptimizer = "HHH000467: Creating pooled optimizer (lo) with [incrementSize=%s; returnClass=%s]"; + private static final String logBadHbmAttributeConverterType = "HHH000468: Unable to interpret type [%s] as an AttributeConverter due to an exception : %s"; + private static final String usingStoppedClassLoaderService = "HHH000469: The ClassLoaderService can not be reused. This instance was stopped already."; + private static final String logUnexpectedSessionInCollectionNotConnected = "HHH000470: An unexpected session is defined for a collection, but the collection is not connected to that session. A persistent collection may only be associated with one session at a time. Overwriting session. %s"; + private static final String logCannotUnsetUnexpectedSessionInCollection = "HHH000471: Cannot unset session in a collection because an unexpected session is defined. A persistent collection may only be associated with one session at a time. %s"; + private static final String hikariProviderClassNotFound = "HHH000472: Hikari properties were encountered, but the Hikari ConnectionProvider was not found on the classpath; these properties are going to be ignored."; + private static final String cachedFileObsolete = "HHH000473: Omitting cached file [%s] as the mapping file is newer"; + private static final String ambiguousPropertyMethods = "HHH000474: Ambiguous persistent property methods detected on %s; mark one as @Transient : [%s] and [%s]"; + private static final String logCannotLocateIndexColumnInformation = "HHH000475: Cannot locate column information using identifier [%s]; ignoring index [%s]"; + private static final String executingImportScript = "HHH000476: Executing import script '%s'"; + private static final String startingDelayedSchemaDrop = "HHH000477: Starting delayed drop of schema as part of SessionFactory shut-down'"; + private static final String unsuccessfulSchemaManagementCommand = "HHH000478: Unsuccessful: %s"; + private static final String collectionNotProcessedByFlush = "HHH000479: Collection [%s] was not processed by flush(). This is likely due to unsafe use of the session (e.g. used in multiple threads concurrently, updates during entity lifecycle hooks)."; + private static final String stalePersistenceContextInEntityEntry = "HHH000480: A ManagedEntity was associated with a stale PersistenceContext. A ManagedEntity may only be associated with one PersistenceContext at a time; %s"; + private static final String unknownJavaTypeNoEqualsHashCode = "HHH000481: Encountered Java type [%s] for which we could not locate a JavaTypeDescriptor and which does not appear to implement equals and/or hashCode. This can lead to significant performance problems when performing equality/dirty checking involving this Java type. Consider registering a custom JavaTypeDescriptor or at least implementing equals/hashCode."; + private static final String cacheOrCacheableAnnotationOnNonRoot = "HHH000482: @javax.persistence.Cacheable or @org.hibernate.annotations.Cache used on a non-root entity: ignored for %s"; + private static final String emptyCompositesEnabled = "HHH000483: An experimental feature has been enabled (hibernate.create_empty_composites.enabled=true) that instantiates empty composite/embedded objects when all of its attribute values are null. This feature has known issues and should not be used in production until it is stabilized. See Hibernate Jira issue HHH-11936 for details."; + private static final String immutableEntityUpdateQuery = "HHH000487: The query: [%s] attempts to update an immutable entity: %s"; + + public J2CacheMessageLogger_$logger(Logger log) { + super(log); + } + + protected Locale getLoggingLocale() { + return LOCALE; + } + + public final void attemptToRestartAlreadyStartedJ2CacheProvider() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.attemptToRestartAlreadyStartedJ2CacheProvider$str(), new Object[0]); + } + + protected String attemptToRestartAlreadyStartedJ2CacheProvider$str() { + return "HHH020001: Attempt to restart an already started J2CacheRegionFactory. Use sessionFactory.close() between repeated calls to buildSessionFactory. Using previously created J2CacheRegionFactory. If this behaviour is required, consider using org.hibernate.cache.ehcache.SingletonJ2CacheRegionFactory."; + } + + public final void unableToFindConfiguration(String name) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToFindConfiguration$str(), name); + } + + protected String unableToFindConfiguration$str() { + return "HHH020002: Could not find configuration [%s]; using defaults."; + } + + public final void unableToFindJ2CacheConfiguration(String name) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToFindJ2CacheConfiguration$str(), name); + } + + protected String unableToFindJ2CacheConfiguration$str() { + return "HHH020003: Could not find a specific ehcache configuration for cache named [%s]; using defaults."; + } + + public final void unableToLoadConfiguration(String configurationResourceName) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToLoadConfiguration$str(), configurationResourceName); + } + + protected String unableToLoadConfiguration$str() { + return "HHH020004: A configurationResourceName was set to %s but the resource could not be loaded from the classpath. Ehcache will configure itself using defaults."; + } + + public final void incompatibleCacheValueMode() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.incompatibleCacheValueMode$str(), new Object[0]); + } + + protected String incompatibleCacheValueMode$str() { + return "HHH020005: The default cache value mode for this Ehcache configuration is \"identity\". This is incompatible with clustered Hibernate caching - the value mode has therefore been switched to \"serialization\""; + } + + public final void incompatibleCacheValueModePerCache(String cacheName) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.incompatibleCacheValueModePerCache$str(), cacheName); + } + + protected String incompatibleCacheValueModePerCache$str() { + return "HHH020006: The value mode for the cache[%s] is \"identity\". This is incompatible with clustered Hibernate caching - the value mode has therefore been switched to \"serialization\""; + } + + public final void readOnlyCacheConfiguredForMutableEntity(String entityName) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.readOnlyCacheConfiguredForMutableEntity$str(), entityName); + } + + protected String readOnlyCacheConfiguredForMutableEntity$str() { + return "HHH020007: read-only cache configured for mutable entity [%s]"; + } + + public final void softLockedCacheExpired(String regionName, Object key, String lock) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.softLockedCacheExpired$str(), regionName, key, lock); + } + + protected String softLockedCacheExpired$str() { + return "HHH020008: Cache[%s] Key[%s] Lockable[%s]\nA soft-locked cache entry was expired by the underlying Ehcache. If this happens regularly you should consider increasing the cache timeouts and/or capacity limits"; + } + + public final void alreadySessionBound() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.alreadySessionBound$str(), new Object[0]); + } + + protected String alreadySessionBound$str() { + return "HHH000002: Already session bound on call to bind(); make sure you clean up your sessions!"; + } + + public final void autoCommitMode(boolean arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.autoCommitMode$str(), arg0); + } + + protected String autoCommitMode$str() { + return "HHH000006: Autocommit mode: %s"; + } + + public final void autoFlushWillNotWork() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.autoFlushWillNotWork$str(), new Object[0]); + } + + protected String autoFlushWillNotWork$str() { + return "HHH000008: JTASessionContext being used with JDBC transactions; auto-flush will not operate correctly with getCurrentSession()"; + } + + public final void batchContainedStatementsOnRelease() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.batchContainedStatementsOnRelease$str(), new Object[0]); + } + + protected String batchContainedStatementsOnRelease$str() { + return "HHH000010: On release of batch it still contained JDBC statements"; + } + + public final void bytecodeProvider(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.bytecodeProvider$str(), arg0); + } + + protected String bytecodeProvider$str() { + return "HHH000021: Bytecode provider name : %s"; + } + + public final void c3p0ProviderClassNotFound(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.c3p0ProviderClassNotFound$str(), arg0); + } + + protected String c3p0ProviderClassNotFound$str() { + return "HHH000022: c3p0 properties were encountered, but the %s provider class was not found on the classpath; these properties are going to be ignored."; + } + + public final void cachedFileNotFound(String arg0, FileNotFoundException arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.cachedFileNotFound$str(), arg0, arg1); + } + + protected String cachedFileNotFound$str() { + return "HHH000023: I/O reported cached file could not be found : %s : %s"; + } + + public final void cacheProvider(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.cacheProvider$str(), arg0); + } + + protected String cacheProvider$str() { + return "HHH000024: Cache provider: %s"; + } + + public final void callingJoinTransactionOnNonJtaEntityManager() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.callingJoinTransactionOnNonJtaEntityManager$str(), new Object[0]); + } + + protected String callingJoinTransactionOnNonJtaEntityManager$str() { + return "HHH000027: Calling joinTransaction() on a non JTA EntityManager"; + } + + public final void closing() { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.closing$str(), new Object[0]); + } + + protected String closing$str() { + return "HHH000031: Closing"; + } + + public final void collectionsFetched(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.collectionsFetched$str(), arg0); + } + + protected String collectionsFetched$str() { + return "HHH000032: Collections fetched (minimize this): %s"; + } + + public final void collectionsLoaded(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.collectionsLoaded$str(), arg0); + } + + protected String collectionsLoaded$str() { + return "HHH000033: Collections loaded: %s"; + } + + public final void collectionsRecreated(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.collectionsRecreated$str(), arg0); + } + + protected String collectionsRecreated$str() { + return "HHH000034: Collections recreated: %s"; + } + + public final void collectionsRemoved(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.collectionsRemoved$str(), arg0); + } + + protected String collectionsRemoved$str() { + return "HHH000035: Collections removed: %s"; + } + + public final void collectionsUpdated(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.collectionsUpdated$str(), arg0); + } + + protected String collectionsUpdated$str() { + return "HHH000036: Collections updated: %s"; + } + + public final void columns(Set arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.columns$str(), arg0); + } + + protected String columns$str() { + return "HHH000037: Columns: %s"; + } + + public final void compositeIdClassDoesNotOverrideEquals(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.compositeIdClassDoesNotOverrideEquals$str(), arg0); + } + + protected String compositeIdClassDoesNotOverrideEquals$str() { + return "HHH000038: Composite-id class does not override equals(): %s"; + } + + public final void compositeIdClassDoesNotOverrideHashCode(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.compositeIdClassDoesNotOverrideHashCode$str(), arg0); + } + + protected String compositeIdClassDoesNotOverrideHashCode$str() { + return "HHH000039: Composite-id class does not override hashCode(): %s"; + } + + public final void configurationResource(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.configurationResource$str(), arg0); + } + + protected String configurationResource$str() { + return "HHH000040: Configuration resource: %s"; + } + + public final void configuredSessionFactory(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.configuredSessionFactory$str(), arg0); + } + + protected String configuredSessionFactory$str() { + return "HHH000041: Configured SessionFactory: %s"; + } + + public final void configuringFromFile(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.configuringFromFile$str(), arg0); + } + + protected String configuringFromFile$str() { + return "HHH000042: Configuring from file: %s"; + } + + public final void configuringFromResource(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.configuringFromResource$str(), arg0); + } + + protected String configuringFromResource$str() { + return "HHH000043: Configuring from resource: %s"; + } + + public final void configuringFromUrl(URL arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.configuringFromUrl$str(), arg0); + } + + protected String configuringFromUrl$str() { + return "HHH000044: Configuring from URL: %s"; + } + + public final void configuringFromXmlDocument() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.configuringFromXmlDocument$str(), new Object[0]); + } + + protected String configuringFromXmlDocument$str() { + return "HHH000045: Configuring from XML document"; + } + + public final void connectionsObtained(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.connectionsObtained$str(), arg0); + } + + protected String connectionsObtained$str() { + return "HHH000048: Connections obtained: %s"; + } + + public final void containerProvidingNullPersistenceUnitRootUrl() { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.containerProvidingNullPersistenceUnitRootUrl$str(), new Object[0]); + } + + protected String containerProvidingNullPersistenceUnitRootUrl$str() { + return "HHH000050: Container is providing a null PersistenceUnitRootUrl: discovery impossible"; + } + + public final void containsJoinFetchedCollection(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.containsJoinFetchedCollection$str(), arg0); + } + + protected String containsJoinFetchedCollection$str() { + return "HHH000051: Ignoring bag join fetch [%s] due to prior collection join fetch"; + } + + public final void creatingSubcontextInfo(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.creatingSubcontextInfo$str(), arg0); + } + + protected String creatingSubcontextInfo$str() { + return "HHH000053: Creating subcontext: %s"; + } + + public final void definingFlushBeforeCompletionIgnoredInHem(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.definingFlushBeforeCompletionIgnoredInHem$str(), arg0); + } + + protected String definingFlushBeforeCompletionIgnoredInHem$str() { + return "HHH000059: Defining %s=true ignored in HEM"; + } + + public final void deprecatedForceDescriminatorAnnotation() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.deprecatedForceDescriminatorAnnotation$str(), new Object[0]); + } + + protected String deprecatedForceDescriminatorAnnotation$str() { + return "HHH000062: @ForceDiscriminator is deprecated use @DiscriminatorOptions instead."; + } + + public final void deprecatedOracle9Dialect() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.deprecatedOracle9Dialect$str(), new Object[0]); + } + + protected String deprecatedOracle9Dialect$str() { + return "HHH000063: The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead"; + } + + public final void deprecatedOracleDialect() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.deprecatedOracleDialect$str(), new Object[0]); + } + + protected String deprecatedOracleDialect$str() { + return "HHH000064: The OracleDialect dialect has been deprecated; use Oracle8iDialect instead"; + } + + public final void deprecatedUuidGenerator(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.deprecatedUuidGenerator$str(), arg0, arg1); + } + + protected String deprecatedUuidGenerator$str() { + return "HHH000065: DEPRECATED : use [%s] instead with custom [%s] implementation"; + } + + public final void disallowingInsertStatementComment() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.disallowingInsertStatementComment$str(), new Object[0]); + } + + protected String disallowingInsertStatementComment$str() { + return "HHH000067: Disallowing insert statement comment for select-identity due to Oracle driver bug"; + } + + public final void duplicateGeneratorName(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.duplicateGeneratorName$str(), arg0); + } + + protected String duplicateGeneratorName$str() { + return "HHH000069: Duplicate generator name %s"; + } + + public final void duplicateGeneratorTable(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.duplicateGeneratorTable$str(), arg0); + } + + protected String duplicateGeneratorTable$str() { + return "HHH000070: Duplicate generator table: %s"; + } + + public final void duplicateImport(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.duplicateImport$str(), arg0, arg1); + } + + protected String duplicateImport$str() { + return "HHH000071: Duplicate import: %s -> %s"; + } + + public final void duplicateJoins(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.duplicateJoins$str(), arg0); + } + + protected String duplicateJoins$str() { + return "HHH000072: Duplicate joins for class: %s"; + } + + public final void duplicateListener(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.duplicateListener$str(), arg0); + } + + protected String duplicateListener$str() { + return "HHH000073: entity-listener duplication, first event definition will be used: %s"; + } + + public final void duplicateMetadata() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.duplicateMetadata$str(), new Object[0]); + } + + protected String duplicateMetadata$str() { + return "HHH000074: Found more than one , subsequent ignored"; + } + + public final void entitiesDeleted(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.entitiesDeleted$str(), arg0); + } + + protected String entitiesDeleted$str() { + return "HHH000076: Entities deleted: %s"; + } + + public final void entitiesFetched(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.entitiesFetched$str(), arg0); + } + + protected String entitiesFetched$str() { + return "HHH000077: Entities fetched (minimize this): %s"; + } + + public final void entitiesInserted(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.entitiesInserted$str(), arg0); + } + + protected String entitiesInserted$str() { + return "HHH000078: Entities inserted: %s"; + } + + public final void entitiesLoaded(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.entitiesLoaded$str(), arg0); + } + + protected String entitiesLoaded$str() { + return "HHH000079: Entities loaded: %s"; + } + + public final void entitiesUpdated(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.entitiesUpdated$str(), arg0); + } + + protected String entitiesUpdated$str() { + return "HHH000080: Entities updated: %s"; + } + + public final void entityAnnotationOnNonRoot(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.entityAnnotationOnNonRoot$str(), arg0); + } + + protected String entityAnnotationOnNonRoot$str() { + return "HHH000081: @org.hibernate.annotations.Entity used on a non root entity: ignored for %s"; + } + + public final void entityManagerClosedBySomeoneElse(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.entityManagerClosedBySomeoneElse$str(), arg0); + } + + protected String entityManagerClosedBySomeoneElse$str() { + return "HHH000082: Entity Manager closed by someone else (%s must not be used)"; + } + + public final void entityMappedAsNonAbstract(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.entityMappedAsNonAbstract$str(), arg0); + } + + protected String entityMappedAsNonAbstract$str() { + return "HHH000084: Entity [%s] is abstract-class/interface explicitly mapped as non-abstract; be sure to supply entity-names"; + } + + public final void exceptionHeaderFound(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.exceptionHeaderFound$str(), arg0, arg1); + } + + protected String exceptionHeaderFound$str() { + return "HHH000085: %s %s found"; + } + + public final void exceptionHeaderNotFound(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.exceptionHeaderNotFound$str(), arg0, arg1); + } + + protected String exceptionHeaderNotFound$str() { + return "HHH000086: %s No %s found"; + } + + public final void exceptionInAfterTransactionCompletionInterceptor(Throwable arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.exceptionInAfterTransactionCompletionInterceptor$str(), new Object[0]); + } + + protected String exceptionInAfterTransactionCompletionInterceptor$str() { + return "HHH000087: Exception in interceptor afterTransactionCompletion()"; + } + + public final void exceptionInBeforeTransactionCompletionInterceptor(Throwable arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.exceptionInBeforeTransactionCompletionInterceptor$str(), new Object[0]); + } + + protected String exceptionInBeforeTransactionCompletionInterceptor$str() { + return "HHH000088: Exception in interceptor beforeTransactionCompletion()"; + } + + public final void exceptionInSubResolver(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.exceptionInSubResolver$str(), arg0); + } + + protected String exceptionInSubResolver$str() { + return "HHH000089: Sub-resolver threw unexpected exception, continuing to next : %s"; + } + + public final void expectedType(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.expectedType$str(), arg0, arg1); + } + + protected String expectedType$str() { + return "HHH000091: Expected type: %s, actual value: %s"; + } + + public final void expired(Object arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.expired$str(), arg0); + } + + protected String expired$str() { + return "HHH000092: An item was expired by the cache while it was locked (increase your cache timeout): %s"; + } + + public final void factoryBoundToJndiName(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.factoryBoundToJndiName$str(), arg0); + } + + protected String factoryBoundToJndiName$str() { + return "HHH000094: Bound factory to JNDI name: %s"; + } + + public final void factoryJndiRename(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.factoryJndiRename$str(), arg0, arg1); + } + + protected String factoryJndiRename$str() { + return "HHH000096: A factory was renamed from [%s] to [%s] in JNDI"; + } + + public final void factoryUnboundFromJndiName(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.factoryUnboundFromJndiName$str(), arg0); + } + + protected String factoryUnboundFromJndiName$str() { + return "HHH000097: Unbound factory from JNDI name: %s"; + } + + public final void factoryUnboundFromName(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.factoryUnboundFromName$str(), arg0); + } + + protected String factoryUnboundFromName$str() { + return "HHH000098: A factory was unbound from name: %s"; + } + + public final void failed(Throwable arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.failed$str(), arg0); + } + + protected String failed$str() { + return "HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): %s"; + } + + public final void failSafeCollectionsCleanup(CollectionLoadContext arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.failSafeCollectionsCleanup$str(), arg0); + } + + protected String failSafeCollectionsCleanup$str() { + return "HHH000100: Fail-safe cleanup (collections) : %s"; + } + + public final void failSafeEntitiesCleanup(EntityLoadContext arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.failSafeEntitiesCleanup$str(), arg0); + } + + protected String failSafeEntitiesCleanup$str() { + return "HHH000101: Fail-safe cleanup (entities) : %s"; + } + + public final void fetchingDatabaseMetadata() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.fetchingDatabaseMetadata$str(), new Object[0]); + } + + protected String fetchingDatabaseMetadata$str() { + return "HHH000102: Fetching database metadata"; + } + + public final void firstOrMaxResultsSpecifiedWithCollectionFetch() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.firstOrMaxResultsSpecifiedWithCollectionFetch$str(), new Object[0]); + } + + protected String firstOrMaxResultsSpecifiedWithCollectionFetch$str() { + return "HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!"; + } + + public final void flushes(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.flushes$str(), arg0); + } + + protected String flushes$str() { + return "HHH000105: Flushes: %s"; + } + + public final void forcingContainerResourceCleanup() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.forcingContainerResourceCleanup$str(), new Object[0]); + } + + protected String forcingContainerResourceCleanup$str() { + return "HHH000106: Forcing container resource cleanup on transaction completion"; + } + + public final void forcingTableUse() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.forcingTableUse$str(), new Object[0]); + } + + protected String forcingTableUse$str() { + return "HHH000107: Forcing table use for sequence-style generator due to pooled optimizer selection where db does not support pooled sequences"; + } + + public final void foreignKeys(Set arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.foreignKeys$str(), arg0); + } + + protected String foreignKeys$str() { + return "HHH000108: Foreign keys: %s"; + } + + public final void foundMappingDocument(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.foundMappingDocument$str(), arg0); + } + + protected String foundMappingDocument$str() { + return "HHH000109: Found mapping document in jar: %s"; + } + + public final void gettersOfLazyClassesCannotBeFinal(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.gettersOfLazyClassesCannotBeFinal$str(), arg0, arg1); + } + + protected String gettersOfLazyClassesCannotBeFinal$str() { + return "HHH000112: Getters of lazy classes cannot be final: %s.%s"; + } + + public final void guidGenerated(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.guidGenerated$str(), arg0); + } + + protected String guidGenerated$str() { + return "HHH000113: GUID identifier generated: %s"; + } + + public final void handlingTransientEntity() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.handlingTransientEntity$str(), new Object[0]); + } + + protected String handlingTransientEntity$str() { + return "HHH000114: Handling transient entity in delete processing"; + } + + public final void hibernateConnectionPoolSize(int arg0, int arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.hibernateConnectionPoolSize$str(), arg0, arg1); + } + + protected String hibernateConnectionPoolSize$str() { + return "HHH000115: Hibernate connection pool size: %s (min=%s)"; + } + + public final void honoringOptimizerSetting(String arg0, String arg1, int arg2, String arg3, int arg4) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.honoringOptimizerSetting$str(), new Object[]{arg0, arg1, arg2, arg3, arg4}); + } + + protected String honoringOptimizerSetting$str() { + return "HHH000116: Config specified explicit optimizer of [%s], but [%s=%s]; using optimizer [%s] increment default of [%s]."; + } + + public final void hql(String arg0, Long arg1, Long arg2) { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.hql$str(), arg0, arg1, arg2); + } + + protected String hql$str() { + return "HHH000117: HQL: %s, time: %sms, rows: %s"; + } + + public final void hsqldbSupportsOnlyReadCommittedIsolation() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.hsqldbSupportsOnlyReadCommittedIsolation$str(), new Object[0]); + } + + protected String hsqldbSupportsOnlyReadCommittedIsolation$str() { + return "HHH000118: HSQLDB supports only READ_UNCOMMITTED isolation"; + } + + public final void hydratingEntitiesCount(int arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.hydratingEntitiesCount$str(), arg0); + } + + protected String hydratingEntitiesCount$str() { + return "HHH000119: On EntityLoadContext#clear, hydratingEntities contained [%s] entries"; + } + + public final void ignoringTableGeneratorConstraints(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.ignoringTableGeneratorConstraints$str(), arg0); + } + + protected String ignoringTableGeneratorConstraints$str() { + return "HHH000120: Ignoring unique constraints specified on table generator [%s]"; + } + + public final void ignoringUnrecognizedQueryHint(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.ignoringUnrecognizedQueryHint$str(), arg0); + } + + protected String ignoringUnrecognizedQueryHint$str() { + return "HHH000121: Ignoring unrecognized query hint [%s]"; + } + + public final void illegalPropertyGetterArgument(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.illegalPropertyGetterArgument$str(), arg0, arg1); + } + + protected String illegalPropertyGetterArgument$str() { + return "HHH000122: IllegalArgumentException in class: %s, getter method of property: %s"; + } + + public final void illegalPropertySetterArgument(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.illegalPropertySetterArgument$str(), arg0, arg1); + } + + protected String illegalPropertySetterArgument$str() { + return "HHH000123: IllegalArgumentException in class: %s, setter method of property: %s"; + } + + public final void immutableAnnotationOnNonRoot(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.immutableAnnotationOnNonRoot$str(), arg0); + } + + protected String immutableAnnotationOnNonRoot$str() { + return "HHH000124: @Immutable used on a non root entity: ignored for %s"; + } + + public final void incompleteMappingMetadataCacheProcessing() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.incompleteMappingMetadataCacheProcessing$str(), new Object[0]); + } + + protected String incompleteMappingMetadataCacheProcessing$str() { + return "HHH000125: Mapping metadata cache was not completely processed"; + } + + public final void indexes(Set arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.indexes$str(), arg0); + } + + protected String indexes$str() { + return "HHH000126: Indexes: %s"; + } + + public final void couldNotBindJndiListener() { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.couldNotBindJndiListener$str(), new Object[0]); + } + + protected String couldNotBindJndiListener$str() { + return "HHH000127: Could not bind JNDI listener"; + } + + public final void instantiatingExplicitConnectionProvider(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.instantiatingExplicitConnectionProvider$str(), arg0); + } + + protected String instantiatingExplicitConnectionProvider$str() { + return "HHH000130: Instantiating explicit connection provider: %s"; + } + + public final void invalidArrayElementType(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.invalidArrayElementType$str(), arg0); + } + + protected String invalidArrayElementType$str() { + return "HHH000132: Array element type error\n%s"; + } + + public final void invalidDiscriminatorAnnotation(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.invalidDiscriminatorAnnotation$str(), arg0); + } + + protected String invalidDiscriminatorAnnotation$str() { + return "HHH000133: Discriminator column has to be defined in the root entity, it will be ignored in subclass: %s"; + } + + public final void invalidEditOfReadOnlyItem(Object arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.invalidEditOfReadOnlyItem$str(), arg0); + } + + protected String invalidEditOfReadOnlyItem$str() { + return "HHH000134: Application attempted to edit read only item: %s"; + } + + public final void invalidJndiName(String arg0, JndiNameException arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.invalidJndiName$str(), arg0); + } + + protected String invalidJndiName$str() { + return "HHH000135: Invalid JNDI name: %s"; + } + + public final void invalidOnDeleteAnnotation(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.invalidOnDeleteAnnotation$str(), arg0); + } + + protected String invalidOnDeleteAnnotation$str() { + return "HHH000136: Inapropriate use of @OnDelete on entity, annotation ignored: %s"; + } + + public final void invalidPrimaryKeyJoinColumnAnnotation(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.invalidPrimaryKeyJoinColumnAnnotation$str(), arg0); + } + + protected String invalidPrimaryKeyJoinColumnAnnotation$str() { + return "HHH000137: Root entity should not hold a PrimaryKeyJoinColum(s), will be ignored: %s"; + } + + public final void invalidSubStrategy(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.invalidSubStrategy$str(), arg0); + } + + protected String invalidSubStrategy$str() { + return "HHH000138: Mixing inheritance strategy in a entity hierarchy is not allowed, ignoring sub strategy in: %s"; + } + + public final void invalidTableAnnotation(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.invalidTableAnnotation$str(), arg0); + } + + protected String invalidTableAnnotation$str() { + return "HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: %s"; + } + + public final void jaccContextId(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.jaccContextId$str(), arg0); + } + + protected String jaccContextId$str() { + return "HHH000140: JACC contextID: %s"; + } + + public final void JavaSqlTypesMappedSameCodeMultipleTimes(int arg0, String arg1, String arg2) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.JavaSqlTypesMappedSameCodeMultipleTimes$str(), arg0, arg1, arg2); + } + + protected String JavaSqlTypesMappedSameCodeMultipleTimes$str() { + return "HHH000141: java.sql.Types mapped the same code [%s] multiple times; was [%s]; now [%s]"; + } + + protected String bytecodeEnhancementFailed$str() { + return "HHH000142: Bytecode enhancement failed: %s"; + } + + public final String bytecodeEnhancementFailed(String arg0) { + return String.format(this.getLoggingLocale(), this.bytecodeEnhancementFailed$str(), arg0); + } + + public final void jdbcAutoCommitFalseBreaksEjb3Spec(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.jdbcAutoCommitFalseBreaksEjb3Spec$str(), arg0); + } + + protected String jdbcAutoCommitFalseBreaksEjb3Spec$str() { + return "HHH000144: %s = false breaks the EJB3 specification"; + } + + protected String jdbcRollbackFailed$str() { + return "HHH000151: JDBC rollback failed"; + } + + public final String jdbcRollbackFailed() { + return String.format(this.getLoggingLocale(), this.jdbcRollbackFailed$str()); + } + + public final void jndiInitialContextProperties(Hashtable arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.jndiInitialContextProperties$str(), arg0); + } + + protected String jndiInitialContextProperties$str() { + return "HHH000154: JNDI InitialContext properties:%s"; + } + + public final void jndiNameDoesNotHandleSessionFactoryReference(String arg0, ClassCastException arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.jndiNameDoesNotHandleSessionFactoryReference$str(), arg0); + } + + protected String jndiNameDoesNotHandleSessionFactoryReference$str() { + return "HHH000155: JNDI name %s does not handle a session factory reference"; + } + + public final void lazyPropertyFetchingAvailable(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.lazyPropertyFetchingAvailable$str(), arg0); + } + + protected String lazyPropertyFetchingAvailable$str() { + return "HHH000157: Lazy property fetching available for: %s"; + } + + public final void loadingCollectionKeyNotFound(CollectionKey arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.loadingCollectionKeyNotFound$str(), arg0); + } + + protected String loadingCollectionKeyNotFound$str() { + return "HHH000159: In CollectionLoadContext#endLoadingCollections, localLoadingCollectionKeys contained [%s], but no LoadingCollectionEntry was found in loadContexts"; + } + + public final void localLoadingCollectionKeysCount(int arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.localLoadingCollectionKeysCount$str(), arg0); + } + + protected String localLoadingCollectionKeysCount$str() { + return "HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [%s] entries"; + } + + public final void loggingStatistics() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.loggingStatistics$str(), new Object[0]); + } + + protected String loggingStatistics$str() { + return "HHH000161: Logging statistics...."; + } + + public final void logicalConnectionClosed() { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.logicalConnectionClosed$str(), new Object[0]); + } + + protected String logicalConnectionClosed$str() { + return "HHH000162: *** Logical connection closed ***"; + } + + public final void logicalConnectionReleasingPhysicalConnection() { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.logicalConnectionReleasingPhysicalConnection$str(), new Object[0]); + } + + protected String logicalConnectionReleasingPhysicalConnection$str() { + return "HHH000163: Logical connection releasing its physical connection"; + } + + public final void maxQueryTime(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.maxQueryTime$str(), arg0); + } + + protected String maxQueryTime$str() { + return "HHH000173: Max query time: %sms"; + } + + public final void missingArguments(int arg0, int arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.missingArguments$str(), arg0, arg1); + } + + protected String missingArguments$str() { + return "HHH000174: Function template anticipated %s arguments, but %s arguments encountered"; + } + + public final void missingEntityAnnotation(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.missingEntityAnnotation$str(), arg0); + } + + protected String missingEntityAnnotation$str() { + return "HHH000175: Class annotated @org.hibernate.annotations.Entity but not javax.persistence.Entity (most likely a user error): %s"; + } + + public final void namedQueryError(String arg0, HibernateException arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.namedQueryError$str(), arg0); + } + + protected String namedQueryError$str() { + return "HHH000177: Error in named query: %s"; + } + + public final void namingExceptionAccessingFactory(NamingException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.namingExceptionAccessingFactory$str(), arg0); + } + + protected String namingExceptionAccessingFactory$str() { + return "HHH000178: Naming exception occurred accessing factory: %s"; + } + + public final void narrowingProxy(Class arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.narrowingProxy$str(), arg0); + } + + protected String narrowingProxy$str() { + return "HHH000179: Narrowing proxy to %s - this operation breaks =="; + } + + public final void needsLimit() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.needsLimit$str(), new Object[0]); + } + + protected String needsLimit$str() { + return "HHH000180: FirstResult/maxResults specified on polymorphic query; applying in memory!"; + } + + public final void noAppropriateConnectionProvider() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.noAppropriateConnectionProvider$str(), new Object[0]); + } + + protected String noAppropriateConnectionProvider$str() { + return "HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections"; + } + + public final void noDefaultConstructor(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.noDefaultConstructor$str(), arg0); + } + + protected String noDefaultConstructor$str() { + return "HHH000182: No default (no-argument) constructor for class: %s (class must be instantiated by Interceptor)"; + } + + public final void noPersistentClassesFound(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.noPersistentClassesFound$str(), arg0); + } + + protected String noPersistentClassesFound$str() { + return "HHH000183: no persistent classes found for query class: %s"; + } + + public final void noSessionFactoryWithJndiName(String arg0, NameNotFoundException arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.noSessionFactoryWithJndiName$str(), arg0); + } + + protected String noSessionFactoryWithJndiName$str() { + return "HHH000184: No session factory with JNDI name %s"; + } + + public final void optimisticLockFailures(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.optimisticLockFailures$str(), arg0); + } + + protected String optimisticLockFailures$str() { + return "HHH000187: Optimistic lock failures: %s"; + } + + public final void orderByAnnotationIndexedCollection() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.orderByAnnotationIndexedCollection$str(), new Object[0]); + } + + protected String orderByAnnotationIndexedCollection$str() { + return "HHH000189: @OrderBy not allowed for an indexed collection, annotation ignored."; + } + + public final void overridingTransactionStrategyDangerous(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.overridingTransactionStrategyDangerous$str(), arg0); + } + + protected String overridingTransactionStrategyDangerous$str() { + return "HHH000193: Overriding %s is dangerous, this might break the EJB3 specification implementation"; + } + + public final void packageNotFound(String arg0) { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.packageNotFound$str(), arg0); + } + + protected String packageNotFound$str() { + return "HHH000194: Package not found or wo package-info.java: %s"; + } + + public final void parsingXmlError(int arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.parsingXmlError$str(), arg0, arg1); + } + + protected String parsingXmlError$str() { + return "HHH000196: Error parsing XML (%s) : %s"; + } + + public final void parsingXmlErrorForFile(String arg0, int arg1, String arg2) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.parsingXmlErrorForFile$str(), arg0, arg1, arg2); + } + + protected String parsingXmlErrorForFile$str() { + return "HHH000197: Error parsing XML: %s(%s) %s"; + } + + public final void parsingXmlWarning(int arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.parsingXmlWarning$str(), arg0, arg1); + } + + protected String parsingXmlWarning$str() { + return "HHH000198: Warning parsing XML (%s) : %s"; + } + + public final void parsingXmlWarningForFile(String arg0, int arg1, String arg2) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.parsingXmlWarningForFile$str(), arg0, arg1, arg2); + } + + protected String parsingXmlWarningForFile$str() { + return "HHH000199: Warning parsing XML: %s(%s) %s"; + } + + public final void persistenceProviderCallerDoesNotImplementEjb3SpecCorrectly() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.persistenceProviderCallerDoesNotImplementEjb3SpecCorrectly$str(), new Object[0]); + } + + protected String persistenceProviderCallerDoesNotImplementEjb3SpecCorrectly$str() { + return "HHH000200: Persistence provider caller does not implement the EJB3 spec correctly.PersistenceUnitInfo.getNewTempClassLoader() is null."; + } + + public final void pooledOptimizerReportedInitialValue(IntegralDataTypeHolder arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.pooledOptimizerReportedInitialValue$str(), arg0); + } + + protected String pooledOptimizerReportedInitialValue$str() { + return "HHH000201: Pooled optimizer source reported [%s] as the initial value; use of 1 or greater highly recommended"; + } + + public final void preparedStatementAlreadyInBatch(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.preparedStatementAlreadyInBatch$str(), arg0); + } + + protected String preparedStatementAlreadyInBatch$str() { + return "HHH000202: PreparedStatement was already in the batch, [%s]."; + } + + public final void processEqualityExpression() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.processEqualityExpression$str(), new Object[0]); + } + + protected String processEqualityExpression$str() { + return "HHH000203: processEqualityExpression() : No expression to process!"; + } + + public final void processingPersistenceUnitInfoName(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.processingPersistenceUnitInfoName$str(), arg0); + } + + protected String processingPersistenceUnitInfoName$str() { + return "HHH000204: Processing PersistenceUnitInfo [\n\tname: %s\n\t...]"; + } + + public final void propertiesLoaded(Properties arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.propertiesLoaded$str(), arg0); + } + + protected String propertiesLoaded$str() { + return "HHH000205: Loaded properties from resource hibernate.properties: %s"; + } + + public final void propertiesNotFound() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.propertiesNotFound$str(), new Object[0]); + } + + protected String propertiesNotFound$str() { + return "HHH000206: hibernate.properties not found"; + } + + public final void propertyNotFound(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.propertyNotFound$str(), arg0); + } + + protected String propertyNotFound$str() { + return "HHH000207: Property %s not found in class but described in (possible typo error)"; + } + + public final void proxoolProviderClassNotFound(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.proxoolProviderClassNotFound$str(), arg0); + } + + protected String proxoolProviderClassNotFound$str() { + return "HHH000209: proxool properties were encountered, but the %s provider class was not found on the classpath; these properties are going to be ignored."; + } + + public final void queriesExecuted(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.queriesExecuted$str(), arg0); + } + + protected String queriesExecuted$str() { + return "HHH000210: Queries executed to database: %s"; + } + + public final void queryCacheHits(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.queryCacheHits$str(), arg0); + } + + protected String queryCacheHits$str() { + return "HHH000213: Query cache hits: %s"; + } + + public final void queryCacheMisses(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.queryCacheMisses$str(), arg0); + } + + protected String queryCacheMisses$str() { + return "HHH000214: Query cache misses: %s"; + } + + public final void queryCachePuts(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.queryCachePuts$str(), arg0); + } + + protected String queryCachePuts$str() { + return "HHH000215: Query cache puts: %s"; + } + + public final void rdmsOs2200Dialect() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.rdmsOs2200Dialect$str(), new Object[0]); + } + + protected String rdmsOs2200Dialect$str() { + return "HHH000218: RDMSOS2200Dialect version: 1.0"; + } + + public final void readingCachedMappings(File arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.readingCachedMappings$str(), arg0); + } + + protected String readingCachedMappings$str() { + return "HHH000219: Reading mappings from cache file: %s"; + } + + public final void readingMappingsFromFile(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.readingMappingsFromFile$str(), arg0); + } + + protected String readingMappingsFromFile$str() { + return "HHH000220: Reading mappings from file: %s"; + } + + public final void readingMappingsFromResource(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.readingMappingsFromResource$str(), arg0); + } + + protected String readingMappingsFromResource$str() { + return "HHH000221: Reading mappings from resource: %s"; + } + + public final void readOnlyCacheConfiguredForMutableCollection(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.readOnlyCacheConfiguredForMutableCollection$str(), arg0); + } + + protected String readOnlyCacheConfiguredForMutableCollection$str() { + return "HHH000222: read-only cache configured for mutable collection [%s]"; + } + + public final void recognizedObsoleteHibernateNamespace(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.recognizedObsoleteHibernateNamespace$str(), arg0, arg1); + } + + protected String recognizedObsoleteHibernateNamespace$str() { + return "HHH000223: Recognized obsolete hibernate namespace %s. Use namespace %s instead. Refer to Hibernate 3.6 Migration Guide!"; + } + + public final void renamedProperty(Object arg0, Object arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.renamedProperty$str(), arg0, arg1); + } + + protected String renamedProperty$str() { + return "HHH000225: Property [%s] has been renamed to [%s]; update your properties appropriately"; + } + + public final void requiredDifferentProvider(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.requiredDifferentProvider$str(), arg0); + } + + protected String requiredDifferentProvider$str() { + return "HHH000226: Required a different provider: %s"; + } + + public final void runningHbm2ddlSchemaExport() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.runningHbm2ddlSchemaExport$str(), new Object[0]); + } + + protected String runningHbm2ddlSchemaExport$str() { + return "HHH000227: Running hbm2ddl schema export"; + } + + public final void runningHbm2ddlSchemaUpdate() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.runningHbm2ddlSchemaUpdate$str(), new Object[0]); + } + + protected String runningHbm2ddlSchemaUpdate$str() { + return "HHH000228: Running hbm2ddl schema update"; + } + + public final void runningSchemaValidator() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.runningSchemaValidator$str(), new Object[0]); + } + + protected String runningSchemaValidator$str() { + return "HHH000229: Running schema validator"; + } + + public final void schemaExportComplete() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.schemaExportComplete$str(), new Object[0]); + } + + protected String schemaExportComplete$str() { + return "HHH000230: Schema export complete"; + } + + public final void schemaExportUnsuccessful(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.schemaExportUnsuccessful$str(), new Object[0]); + } + + protected String schemaExportUnsuccessful$str() { + return "HHH000231: Schema export unsuccessful"; + } + + public final void schemaUpdateComplete() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.schemaUpdateComplete$str(), new Object[0]); + } + + protected String schemaUpdateComplete$str() { + return "HHH000232: Schema update complete"; + } + + public final void scopingTypesToSessionFactoryAfterAlreadyScoped(SessionFactoryImplementor arg0, SessionFactoryImplementor arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.scopingTypesToSessionFactoryAfterAlreadyScoped$str(), arg0, arg1); + } + + protected String scopingTypesToSessionFactoryAfterAlreadyScoped$str() { + return "HHH000233: Scoping types to session factory %s after already scoped %s"; + } + + public final void searchingForMappingDocuments(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.searchingForMappingDocuments$str(), arg0); + } + + protected String searchingForMappingDocuments$str() { + return "HHH000235: Searching for mapping documents in jar: %s"; + } + + public final void secondLevelCacheHits(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.secondLevelCacheHits$str(), arg0); + } + + protected String secondLevelCacheHits$str() { + return "HHH000237: Second level cache hits: %s"; + } + + public final void secondLevelCacheMisses(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.secondLevelCacheMisses$str(), arg0); + } + + protected String secondLevelCacheMisses$str() { + return "HHH000238: Second level cache misses: %s"; + } + + public final void secondLevelCachePuts(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.secondLevelCachePuts$str(), arg0); + } + + protected String secondLevelCachePuts$str() { + return "HHH000239: Second level cache puts: %s"; + } + + public final void serviceProperties(Properties arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.serviceProperties$str(), arg0); + } + + protected String serviceProperties$str() { + return "HHH000240: Service properties: %s"; + } + + public final void sessionsClosed(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.sessionsClosed$str(), arg0); + } + + protected String sessionsClosed$str() { + return "HHH000241: Sessions closed: %s"; + } + + public final void sessionsOpened(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.sessionsOpened$str(), arg0); + } + + protected String sessionsOpened$str() { + return "HHH000242: Sessions opened: %s"; + } + + public final void settersOfLazyClassesCannotBeFinal(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.settersOfLazyClassesCannotBeFinal$str(), arg0, arg1); + } + + protected String settersOfLazyClassesCannotBeFinal$str() { + return "HHH000243: Setters of lazy classes cannot be final: %s.%s"; + } + + public final void sortAnnotationIndexedCollection() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.sortAnnotationIndexedCollection$str(), new Object[0]); + } + + protected String sortAnnotationIndexedCollection$str() { + return "HHH000244: @Sort not allowed for an indexed collection, annotation ignored."; + } + + public final void splitQueries(String arg0, int arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.splitQueries$str(), arg0, arg1); + } + + protected String splitQueries$str() { + return "HHH000245: Manipulation query [%s] resulted in [%s] split queries"; + } + + public final void sqlWarning(int arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.sqlWarning$str(), arg0, arg1); + } + + protected String sqlWarning$str() { + return "HHH000247: SQL Error: %s, SQLState: %s"; + } + + public final void startingQueryCache(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.startingQueryCache$str(), arg0); + } + + protected String startingQueryCache$str() { + return "HHH000248: Starting query cache at region: %s"; + } + + public final void startingServiceAtJndiName(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.startingServiceAtJndiName$str(), arg0); + } + + protected String startingServiceAtJndiName$str() { + return "HHH000249: Starting service at JNDI name: %s"; + } + + public final void startingUpdateTimestampsCache(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.startingUpdateTimestampsCache$str(), arg0); + } + + protected String startingUpdateTimestampsCache$str() { + return "HHH000250: Starting update timestamps cache at region: %s"; + } + + public final void startTime(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.startTime$str(), arg0); + } + + protected String startTime$str() { + return "HHH000251: Start time: %s"; + } + + public final void statementsClosed(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.statementsClosed$str(), arg0); + } + + protected String statementsClosed$str() { + return "HHH000252: Statements closed: %s"; + } + + public final void statementsPrepared(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.statementsPrepared$str(), arg0); + } + + protected String statementsPrepared$str() { + return "HHH000253: Statements prepared: %s"; + } + + public final void stoppingService() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.stoppingService$str(), new Object[0]); + } + + protected String stoppingService$str() { + return "HHH000255: Stopping service"; + } + + public final void subResolverException(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.subResolverException$str(), arg0); + } + + protected String subResolverException$str() { + return "HHH000257: sub-resolver threw unexpected exception, continuing to next : %s"; + } + + public final void successfulTransactions(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.successfulTransactions$str(), arg0); + } + + protected String successfulTransactions$str() { + return "HHH000258: Successful transactions: %s"; + } + + public final void synchronizationAlreadyRegistered(Synchronization arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.synchronizationAlreadyRegistered$str(), arg0); + } + + protected String synchronizationAlreadyRegistered$str() { + return "HHH000259: Synchronization [%s] was already registered"; + } + + public final void synchronizationFailed(Synchronization arg0, Throwable arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.synchronizationFailed$str(), arg0, arg1); + } + + protected String synchronizationFailed$str() { + return "HHH000260: Exception calling user Synchronization [%s] : %s"; + } + + public final void tableFound(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.tableFound$str(), arg0); + } + + protected String tableFound$str() { + return "HHH000261: Table found: %s"; + } + + public final void tableNotFound(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.tableNotFound$str(), arg0); + } + + protected String tableNotFound$str() { + return "HHH000262: Table not found: %s"; + } + + public final void multipleTablesFound(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.multipleTablesFound$str(), arg0); + } + + protected String multipleTablesFound$str() { + return "HHH000263: More than one table found: %s"; + } + + public final void transactions(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.transactions$str(), arg0); + } + + protected String transactions$str() { + return "HHH000266: Transactions: %s"; + } + + public final void transactionStartedOnNonRootSession() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.transactionStartedOnNonRootSession$str(), new Object[0]); + } + + protected String transactionStartedOnNonRootSession$str() { + return "HHH000267: Transaction started on non-root session"; + } + + public final void transactionStrategy(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.transactionStrategy$str(), arg0); + } + + protected String transactionStrategy$str() { + return "HHH000268: Transaction strategy: %s"; + } + + public final void typeDefinedNoRegistrationKeys(BasicType arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.typeDefinedNoRegistrationKeys$str(), arg0); + } + + protected String typeDefinedNoRegistrationKeys$str() { + return "HHH000269: Type [%s] defined no registration keys; ignoring"; + } + + public final void typeRegistrationOverridesPrevious(String arg0, Type arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.typeRegistrationOverridesPrevious$str(), arg0, arg1); + } + + protected String typeRegistrationOverridesPrevious$str() { + return "HHH000270: Type registration [%s] overrides previous : %s"; + } + + public final void unableToAccessEjb3Configuration(NamingException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToAccessEjb3Configuration$str(), new Object[0]); + } + + protected String unableToAccessEjb3Configuration$str() { + return "HHH000271: Naming exception occurred accessing Ejb3Configuration"; + } + + public final void unableToAccessSessionFactory(String arg0, NamingException arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.unableToAccessSessionFactory$str(), arg0); + } + + protected String unableToAccessSessionFactory$str() { + return "HHH000272: Error while accessing session factory with JNDI name %s"; + } + + public final void unableToAccessTypeInfoResultSet(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToAccessTypeInfoResultSet$str(), arg0); + } + + protected String unableToAccessTypeInfoResultSet$str() { + return "HHH000273: Error accessing type info result set : %s"; + } + + public final void unableToApplyConstraints(String arg0, Exception arg1) { + super.log.logf(FQCN, Logger.Level.WARN, arg1, this.unableToApplyConstraints$str(), arg0); + } + + protected String unableToApplyConstraints$str() { + return "HHH000274: Unable to apply constraints on DDL for %s"; + } + + public final void unableToBindEjb3ConfigurationToJndi(JndiException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToBindEjb3ConfigurationToJndi$str(), new Object[0]); + } + + protected String unableToBindEjb3ConfigurationToJndi$str() { + return "HHH000276: Could not bind Ejb3Configuration to JNDI"; + } + + public final void unableToBindFactoryToJndi(JndiException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToBindFactoryToJndi$str(), new Object[0]); + } + + protected String unableToBindFactoryToJndi$str() { + return "HHH000277: Could not bind factory to JNDI"; + } + + public final void unableToBindValueToParameter(String arg0, int arg1, String arg2) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToBindValueToParameter$str(), arg0, arg1, arg2); + } + + protected String unableToBindValueToParameter$str() { + return "HHH000278: Could not bind value '%s' to parameter: %s; %s"; + } + + public final void unableToBuildEnhancementMetamodel(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToBuildEnhancementMetamodel$str(), arg0); + } + + protected String unableToBuildEnhancementMetamodel$str() { + return "HHH000279: Unable to build enhancement metamodel for %s"; + } + + public final void unableToBuildSessionFactoryUsingMBeanClasspath(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToBuildSessionFactoryUsingMBeanClasspath$str(), arg0); + } + + protected String unableToBuildSessionFactoryUsingMBeanClasspath$str() { + return "HHH000280: Could not build SessionFactory using the MBean classpath - will try again using client classpath: %s"; + } + + public final void unableToCleanUpCallableStatement(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToCleanUpCallableStatement$str(), new Object[0]); + } + + protected String unableToCleanUpCallableStatement$str() { + return "HHH000281: Unable to clean up callable statement"; + } + + public final void unableToCleanUpPreparedStatement(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToCleanUpPreparedStatement$str(), new Object[0]); + } + + protected String unableToCleanUpPreparedStatement$str() { + return "HHH000282: Unable to clean up prepared statement"; + } + + public final void unableToCleanupTemporaryIdTable(Throwable arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToCleanupTemporaryIdTable$str(), arg0); + } + + protected String unableToCleanupTemporaryIdTable$str() { + return "HHH000283: Unable to cleanup temporary id table after use [%s]"; + } + + public final void unableToCloseConnection(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToCloseConnection$str(), new Object[0]); + } + + protected String unableToCloseConnection$str() { + return "HHH000284: Error closing connection"; + } + + public final void unableToCloseInitialContext(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToCloseInitialContext$str(), arg0); + } + + protected String unableToCloseInitialContext$str() { + return "HHH000285: Error closing InitialContext [%s]"; + } + + public final void unableToCloseInputFiles(String arg0, IOException arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.unableToCloseInputFiles$str(), arg0); + } + + protected String unableToCloseInputFiles$str() { + return "HHH000286: Error closing input files: %s"; + } + + public final void unableToCloseInputStream(IOException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToCloseInputStream$str(), new Object[0]); + } + + protected String unableToCloseInputStream$str() { + return "HHH000287: Could not close input stream"; + } + + public final void unableToCloseInputStreamForResource(String arg0, IOException arg1) { + super.log.logf(FQCN, Logger.Level.WARN, arg1, this.unableToCloseInputStreamForResource$str(), arg0); + } + + protected String unableToCloseInputStreamForResource$str() { + return "HHH000288: Could not close input stream for %s"; + } + + public final void unableToCloseIterator(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.INFO, arg0, this.unableToCloseIterator$str(), new Object[0]); + } + + protected String unableToCloseIterator$str() { + return "HHH000289: Unable to close iterator"; + } + + public final void unableToCloseJar(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToCloseJar$str(), arg0); + } + + protected String unableToCloseJar$str() { + return "HHH000290: Could not close jar: %s"; + } + + public final void unableToCloseOutputFile(String arg0, IOException arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.unableToCloseOutputFile$str(), arg0); + } + + protected String unableToCloseOutputFile$str() { + return "HHH000291: Error closing output file: %s"; + } + + public final void unableToCloseOutputStream(IOException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToCloseOutputStream$str(), new Object[0]); + } + + protected String unableToCloseOutputStream$str() { + return "HHH000292: IOException occurred closing output stream"; + } + + public final void unableToCloseSession(HibernateException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToCloseSession$str(), new Object[0]); + } + + protected String unableToCloseSession$str() { + return "HHH000294: Could not close session"; + } + + public final void unableToCloseSessionDuringRollback(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToCloseSessionDuringRollback$str(), new Object[0]); + } + + protected String unableToCloseSessionDuringRollback$str() { + return "HHH000295: Could not close session during rollback"; + } + + public final void unableToCloseStream(IOException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToCloseStream$str(), new Object[0]); + } + + protected String unableToCloseStream$str() { + return "HHH000296: IOException occurred closing stream"; + } + + public final void unableToCloseStreamError(IOException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToCloseStreamError$str(), arg0); + } + + protected String unableToCloseStreamError$str() { + return "HHH000297: Could not close stream on hibernate.properties: %s"; + } + + protected String unableToCommitJta$str() { + return "HHH000298: JTA commit failed"; + } + + public final String unableToCommitJta() { + return String.format(this.getLoggingLocale(), this.unableToCommitJta$str()); + } + + public final void unableToCompleteSchemaUpdate(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToCompleteSchemaUpdate$str(), new Object[0]); + } + + protected String unableToCompleteSchemaUpdate$str() { + return "HHH000299: Could not complete schema update"; + } + + public final void unableToCompleteSchemaValidation(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToCompleteSchemaValidation$str(), new Object[0]); + } + + protected String unableToCompleteSchemaValidation$str() { + return "HHH000300: Could not complete schema validation"; + } + + public final void unableToConfigureSqlExceptionConverter(HibernateException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToConfigureSqlExceptionConverter$str(), arg0); + } + + protected String unableToConfigureSqlExceptionConverter$str() { + return "HHH000301: Unable to configure SQLExceptionConverter : %s"; + } + + public final void unableToConstructCurrentSessionContext(String arg0, Throwable arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, arg1, this.unableToConstructCurrentSessionContext$str(), arg0); + } + + protected String unableToConstructCurrentSessionContext$str() { + return "HHH000302: Unable to construct current session context [%s]"; + } + + public final void unableToConstructSqlExceptionConverter(Throwable arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToConstructSqlExceptionConverter$str(), arg0); + } + + protected String unableToConstructSqlExceptionConverter$str() { + return "HHH000303: Unable to construct instance of specified SQLExceptionConverter : %s"; + } + + public final void unableToCopySystemProperties() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToCopySystemProperties$str(), new Object[0]); + } + + protected String unableToCopySystemProperties$str() { + return "HHH000304: Could not copy system properties, system properties will be ignored"; + } + + public final void unableToCreateProxyFactory(String arg0, HibernateException arg1) { + super.log.logf(FQCN, Logger.Level.WARN, arg1, this.unableToCreateProxyFactory$str(), arg0); + } + + protected String unableToCreateProxyFactory$str() { + return "HHH000305: Could not create proxy factory for:%s"; + } + + public final void unableToCreateSchema(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToCreateSchema$str(), new Object[0]); + } + + protected String unableToCreateSchema$str() { + return "HHH000306: Error creating schema "; + } + + public final void unableToDeserializeCache(String arg0, SerializationException arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToDeserializeCache$str(), arg0, arg1); + } + + protected String unableToDeserializeCache$str() { + return "HHH000307: Could not deserialize cache file: %s : %s"; + } + + public final void unableToDestroyCache(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToDestroyCache$str(), arg0); + } + + protected String unableToDestroyCache$str() { + return "HHH000308: Unable to destroy cache: %s"; + } + + public final void unableToDestroyQueryCache(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToDestroyQueryCache$str(), arg0, arg1); + } + + protected String unableToDestroyQueryCache$str() { + return "HHH000309: Unable to destroy query cache: %s: %s"; + } + + public final void unableToDestroyUpdateTimestampsCache(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToDestroyUpdateTimestampsCache$str(), arg0, arg1); + } + + protected String unableToDestroyUpdateTimestampsCache$str() { + return "HHH000310: Unable to destroy update timestamps cache: %s: %s"; + } + + public final void unableToDetermineLockModeValue(String arg0, Object arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToDetermineLockModeValue$str(), arg0, arg1); + } + + protected String unableToDetermineLockModeValue$str() { + return "HHH000311: Unable to determine lock mode value : %s -> %s"; + } + + protected String unableToDetermineTransactionStatus$str() { + return "HHH000312: Could not determine transaction status"; + } + + public final String unableToDetermineTransactionStatus() { + return String.format(this.getLoggingLocale(), this.unableToDetermineTransactionStatus$str()); + } + + protected String unableToDetermineTransactionStatusAfterCommit$str() { + return "HHH000313: Could not determine transaction status after commit"; + } + + public final String unableToDetermineTransactionStatusAfterCommit() { + return String.format(this.getLoggingLocale(), this.unableToDetermineTransactionStatusAfterCommit$str()); + } + + public final void unableToDropTemporaryIdTable(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToDropTemporaryIdTable$str(), arg0); + } + + protected String unableToDropTemporaryIdTable$str() { + return "HHH000314: Unable to drop temporary id table after use [%s]"; + } + + public final void unableToExecuteBatch(Exception arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToExecuteBatch$str(), arg0, arg1); + } + + protected String unableToExecuteBatch$str() { + return "HHH000315: Exception executing batch [%s], SQL: %s"; + } + + public final void unableToExecuteResolver(DialectResolver arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToExecuteResolver$str(), arg0, arg1); + } + + protected String unableToExecuteResolver$str() { + return "HHH000316: Error executing resolver [%s] : %s"; + } + + public final void unableToFindPersistenceXmlInClasspath() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToFindPersistenceXmlInClasspath$str(), new Object[0]); + } + + protected String unableToFindPersistenceXmlInClasspath$str() { + return "HHH000318: Could not find any META-INF/persistence.xml file in the classpath"; + } + + public final void unableToGetDatabaseMetadata(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToGetDatabaseMetadata$str(), new Object[0]); + } + + protected String unableToGetDatabaseMetadata$str() { + return "HHH000319: Could not get database metadata"; + } + + public final void unableToInstantiateConfiguredSchemaNameResolver(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToInstantiateConfiguredSchemaNameResolver$str(), arg0, arg1); + } + + protected String unableToInstantiateConfiguredSchemaNameResolver$str() { + return "HHH000320: Unable to instantiate configured schema name resolver [%s] %s"; + } + + public final void unableToLocateCustomOptimizerClass(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToLocateCustomOptimizerClass$str(), arg0); + } + + protected String unableToLocateCustomOptimizerClass$str() { + return "HHH000321: Unable to interpret specified optimizer [%s], falling back to noop"; + } + + public final void unableToInstantiateOptimizer(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToInstantiateOptimizer$str(), arg0); + } + + protected String unableToInstantiateOptimizer$str() { + return "HHH000322: Unable to instantiate specified optimizer [%s], falling back to noop"; + } + + public final void unableToInstantiateUuidGenerationStrategy(Exception arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToInstantiateUuidGenerationStrategy$str(), arg0); + } + + protected String unableToInstantiateUuidGenerationStrategy$str() { + return "HHH000325: Unable to instantiate UUID generation strategy class : %s"; + } + + public final void unableToJoinTransaction(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToJoinTransaction$str(), arg0); + } + + protected String unableToJoinTransaction$str() { + return "HHH000326: Cannot join transaction: do not override %s"; + } + + public final void unableToLoadCommand(HibernateException arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToLoadCommand$str(), arg0); + } + + protected String unableToLoadCommand$str() { + return "HHH000327: Error performing load command : %s"; + } + + public final void unableToLoadDerbyDriver(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToLoadDerbyDriver$str(), arg0); + } + + protected String unableToLoadDerbyDriver$str() { + return "HHH000328: Unable to load/access derby driver class sysinfo to check versions : %s"; + } + + public final void unableToLoadProperties() { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToLoadProperties$str(), new Object[0]); + } + + protected String unableToLoadProperties$str() { + return "HHH000329: Problem loading properties from hibernate.properties"; + } + + protected String unableToLocateConfigFile$str() { + return "HHH000330: Unable to locate config file: %s"; + } + + public final String unableToLocateConfigFile(String arg0) { + return String.format(this.getLoggingLocale(), this.unableToLocateConfigFile$str(), arg0); + } + + public final void unableToLocateConfiguredSchemaNameResolver(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToLocateConfiguredSchemaNameResolver$str(), arg0, arg1); + } + + protected String unableToLocateConfiguredSchemaNameResolver$str() { + return "HHH000331: Unable to locate configured schema name resolver class [%s] %s"; + } + + public final void unableToLocateMBeanServer() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToLocateMBeanServer$str(), new Object[0]); + } + + protected String unableToLocateMBeanServer$str() { + return "HHH000332: Unable to locate MBeanServer on JMX service shutdown"; + } + + public final void unableToLocateUuidGenerationStrategy(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToLocateUuidGenerationStrategy$str(), arg0); + } + + protected String unableToLocateUuidGenerationStrategy$str() { + return "HHH000334: Unable to locate requested UUID generation strategy class : %s"; + } + + public final void unableToLogSqlWarnings(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToLogSqlWarnings$str(), arg0); + } + + protected String unableToLogSqlWarnings$str() { + return "HHH000335: Unable to log SQLWarnings : %s"; + } + + public final void unableToLogWarnings(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToLogWarnings$str(), new Object[0]); + } + + protected String unableToLogWarnings$str() { + return "HHH000336: Could not log warnings"; + } + + public final void unableToMarkForRollbackOnPersistenceException(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToMarkForRollbackOnPersistenceException$str(), new Object[0]); + } + + protected String unableToMarkForRollbackOnPersistenceException$str() { + return "HHH000337: Unable to mark for rollback on PersistenceException: "; + } + + public final void unableToMarkForRollbackOnTransientObjectException(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToMarkForRollbackOnTransientObjectException$str(), new Object[0]); + } + + protected String unableToMarkForRollbackOnTransientObjectException$str() { + return "HHH000338: Unable to mark for rollback on TransientObjectException: "; + } + + public final void unableToObjectConnectionMetadata(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToObjectConnectionMetadata$str(), arg0); + } + + protected String unableToObjectConnectionMetadata$str() { + return "HHH000339: Could not obtain connection metadata: %s"; + } + + public final void unableToObjectConnectionToQueryMetadata(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToObjectConnectionToQueryMetadata$str(), arg0); + } + + protected String unableToObjectConnectionToQueryMetadata$str() { + return "HHH000340: Could not obtain connection to query metadata: %s"; + } + + public final void unableToObtainConnectionMetadata(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToObtainConnectionMetadata$str(), arg0); + } + + protected String unableToObtainConnectionMetadata$str() { + return "HHH000341: Could not obtain connection metadata : %s"; + } + + public final void unableToObtainConnectionToQueryMetadata(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToObtainConnectionToQueryMetadata$str(), arg0); + } + + protected String unableToObtainConnectionToQueryMetadata$str() { + return "HHH000342: Could not obtain connection to query metadata : %s"; + } + + public final void unableToObtainInitialContext(NamingException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToObtainInitialContext$str(), new Object[0]); + } + + protected String unableToObtainInitialContext$str() { + return "HHH000343: Could not obtain initial context"; + } + + public final void unableToParseMetadata(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToParseMetadata$str(), arg0); + } + + protected String unableToParseMetadata$str() { + return "HHH000344: Could not parse the package-level metadata [%s]"; + } + + protected String unableToPerformJdbcCommit$str() { + return "HHH000345: JDBC commit failed"; + } + + public final String unableToPerformJdbcCommit() { + return String.format(this.getLoggingLocale(), this.unableToPerformJdbcCommit$str()); + } + + public final void unableToPerformManagedFlush(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToPerformManagedFlush$str(), arg0); + } + + protected String unableToPerformManagedFlush$str() { + return "HHH000346: Error during managed flush [%s]"; + } + + protected String unableToQueryDatabaseMetadata$str() { + return "HHH000347: Unable to query java.sql.DatabaseMetaData"; + } + + public final String unableToQueryDatabaseMetadata() { + return String.format(this.getLoggingLocale(), this.unableToQueryDatabaseMetadata$str()); + } + + public final void unableToReadClass(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToReadClass$str(), arg0); + } + + protected String unableToReadClass$str() { + return "HHH000348: Unable to read class: %s"; + } + + public final void unableToReadColumnValueFromResultSet(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToReadColumnValueFromResultSet$str(), arg0, arg1); + } + + protected String unableToReadColumnValueFromResultSet$str() { + return "HHH000349: Could not read column value from result set: %s; %s"; + } + + protected String unableToReadHiValue$str() { + return "HHH000350: Could not read a hi value - you need to populate the table: %s"; + } + + public final String unableToReadHiValue(String arg0) { + return String.format(this.getLoggingLocale(), this.unableToReadHiValue$str(), arg0); + } + + public final void unableToReadOrInitHiValue(SQLException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToReadOrInitHiValue$str(), new Object[0]); + } + + protected String unableToReadOrInitHiValue$str() { + return "HHH000351: Could not read or init a hi value"; + } + + public final void unableToReleaseBatchStatement() { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToReleaseBatchStatement$str(), new Object[0]); + } + + protected String unableToReleaseBatchStatement$str() { + return "HHH000352: Unable to release batch statement..."; + } + + public final void unableToReleaseCacheLock(CacheException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unableToReleaseCacheLock$str(), arg0); + } + + protected String unableToReleaseCacheLock$str() { + return "HHH000353: Could not release a cache lock : %s"; + } + + public final void unableToReleaseContext(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToReleaseContext$str(), arg0); + } + + protected String unableToReleaseContext$str() { + return "HHH000354: Unable to release initial context: %s"; + } + + public final void unableToReleaseCreatedMBeanServer(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToReleaseCreatedMBeanServer$str(), arg0); + } + + protected String unableToReleaseCreatedMBeanServer$str() { + return "HHH000355: Unable to release created MBeanServer : %s"; + } + + public final void unableToReleaseIsolatedConnection(Throwable arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToReleaseIsolatedConnection$str(), arg0); + } + + protected String unableToReleaseIsolatedConnection$str() { + return "HHH000356: Unable to release isolated connection [%s]"; + } + + public final void unableToReleaseTypeInfoResultSet() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToReleaseTypeInfoResultSet$str(), new Object[0]); + } + + protected String unableToReleaseTypeInfoResultSet$str() { + return "HHH000357: Unable to release type info result set"; + } + + public final void unableToRemoveBagJoinFetch() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToRemoveBagJoinFetch$str(), new Object[0]); + } + + protected String unableToRemoveBagJoinFetch$str() { + return "HHH000358: Unable to erase previously added bag join fetch"; + } + + public final void unableToResolveAggregateFunction(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToResolveAggregateFunction$str(), arg0); + } + + protected String unableToResolveAggregateFunction$str() { + return "HHH000359: Could not resolve aggregate function [%s]; using standard definition"; + } + + public final void unableToResolveMappingFile(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToResolveMappingFile$str(), arg0); + } + + protected String unableToResolveMappingFile$str() { + return "HHH000360: Unable to resolve mapping file [%s]"; + } + + public final void unableToRetrieveCache(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToRetrieveCache$str(), arg0, arg1); + } + + protected String unableToRetrieveCache$str() { + return "HHH000361: Unable to retrieve cache from JNDI [%s]: %s"; + } + + public final void unableToRetrieveTypeInfoResultSet(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToRetrieveTypeInfoResultSet$str(), arg0); + } + + protected String unableToRetrieveTypeInfoResultSet$str() { + return "HHH000362: Unable to retrieve type info result set : %s"; + } + + public final void unableToRollbackConnection(Exception arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToRollbackConnection$str(), arg0); + } + + protected String unableToRollbackConnection$str() { + return "HHH000363: Unable to rollback connection on exception [%s]"; + } + + public final void unableToRollbackIsolatedTransaction(Exception arg0, Exception arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToRollbackIsolatedTransaction$str(), arg0, arg1); + } + + protected String unableToRollbackIsolatedTransaction$str() { + return "HHH000364: Unable to rollback isolated transaction on error [%s] : [%s]"; + } + + protected String unableToRollbackJta$str() { + return "HHH000365: JTA rollback failed"; + } + + public final String unableToRollbackJta() { + return String.format(this.getLoggingLocale(), this.unableToRollbackJta$str()); + } + + public final void unableToRunSchemaUpdate(Exception arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToRunSchemaUpdate$str(), new Object[0]); + } + + protected String unableToRunSchemaUpdate$str() { + return "HHH000366: Error running schema update"; + } + + public final void unableToSetTransactionToRollbackOnly(SystemException arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, arg0, this.unableToSetTransactionToRollbackOnly$str(), new Object[0]); + } + + protected String unableToSetTransactionToRollbackOnly$str() { + return "HHH000367: Could not set transaction to rollback only"; + } + + public final void unableToStopHibernateService(Exception arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToStopHibernateService$str(), new Object[0]); + } + + protected String unableToStopHibernateService$str() { + return "HHH000368: Exception while stopping service"; + } + + public final void unableToStopService(Class arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToStopService$str(), arg0, arg1); + } + + protected String unableToStopService$str() { + return "HHH000369: Error stopping service [%s] : %s"; + } + + public final void unableToSwitchToMethodUsingColumnIndex(Method arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToSwitchToMethodUsingColumnIndex$str(), arg0); + } + + protected String unableToSwitchToMethodUsingColumnIndex$str() { + return "HHH000370: Exception switching from method: [%s] to a method using the column index. Reverting to using: [% arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unknownSqlServerVersion$str(), arg0, arg1); + } + + protected String unknownSqlServerVersion$str() { + return "HHH000385: Unknown Microsoft SQL Server major version [%s] using [%s] dialect"; + } + + public final void unregisteredResultSetWithoutStatement() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unregisteredResultSetWithoutStatement$str(), new Object[0]); + } + + protected String unregisteredResultSetWithoutStatement$str() { + return "HHH000386: ResultSet had no statement associated with it, but was not yet registered"; + } + + public final void unregisteredStatement() { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.unregisteredStatement$str(), new Object[0]); + } + + protected String unregisteredStatement$str() { + return "HHH000387: ResultSet's statement was not registered"; + } + + public final void unsuccessful(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unsuccessful$str(), arg0); + } + + protected String unsuccessful$str() { + return "HHH000388: Unsuccessful: %s"; + } + + public final void unsuccessfulCreate(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unsuccessfulCreate$str(), arg0); + } + + protected String unsuccessfulCreate$str() { + return "HHH000389: Unsuccessful: %s"; + } + + public final void unsupportedAfterStatement() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unsupportedAfterStatement$str(), new Object[0]); + } + + protected String unsupportedAfterStatement$str() { + return "HHH000390: Overriding release mode as connection provider does not support 'after_statement'"; + } + + public final void unsupportedIngresVersion() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unsupportedIngresVersion$str(), new Object[0]); + } + + protected String unsupportedIngresVersion$str() { + return "HHH000391: Ingres 10 is not yet fully supported; using Ingres 9.3 dialect"; + } + + public final void unsupportedInitialValue(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unsupportedInitialValue$str(), arg0); + } + + protected String unsupportedInitialValue$str() { + return "HHH000392: Hibernate does not support SequenceGenerator.initialValue() unless '%s' set"; + } + + public final void unsupportedMultiTableBulkHqlJpaql(int arg0, int arg1, int arg2) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unsupportedMultiTableBulkHqlJpaql$str(), arg0, arg1, arg2); + } + + protected String unsupportedMultiTableBulkHqlJpaql$str() { + return "HHH000393: The %s.%s.%s version of H2 implements temporary table creation such that it commits current transaction; multi-table, bulk hql/jpaql will not work properly"; + } + + public final void unsupportedOracleVersion() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unsupportedOracleVersion$str(), new Object[0]); + } + + protected String unsupportedOracleVersion$str() { + return "HHH000394: Oracle 11g is not yet fully supported; using Oracle 10g dialect"; + } + + public final void unsupportedProperty(Object arg0, Object arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unsupportedProperty$str(), arg0, arg1); + } + + protected String unsupportedProperty$str() { + return "HHH000395: Usage of obsolete property: %s no longer supported, use: %s"; + } + + public final void updatingSchema() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.updatingSchema$str(), new Object[0]); + } + + protected String updatingSchema$str() { + return "HHH000396: Updating schema"; + } + + public final void usingAstQueryTranslatorFactory() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.usingAstQueryTranslatorFactory$str(), new Object[0]); + } + + protected String usingAstQueryTranslatorFactory$str() { + return "HHH000397: Using ASTQueryTranslatorFactory"; + } + + public final void usingDefaultIdGeneratorSegmentValue(String arg0, String arg1, String arg2) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.usingDefaultIdGeneratorSegmentValue$str(), arg0, arg1, arg2); + } + + protected String usingDefaultIdGeneratorSegmentValue$str() { + return "HHH000398: Explicit segment value for id generator [%s.%s] suggested; using default [%s]"; + } + + public final void usingDefaultTransactionStrategy() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.usingDefaultTransactionStrategy$str(), new Object[0]); + } + + protected String usingDefaultTransactionStrategy$str() { + return "HHH000399: Using default transaction strategy (direct JDBC transactions)"; + } + + public final void usingDialect(Dialect arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.usingDialect$str(), arg0); + } + + protected String usingDialect$str() { + return "HHH000400: Using dialect: %s"; + } + + public final void usingOldDtd() { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.usingOldDtd$str(), new Object[0]); + } + + protected String usingOldDtd$str() { + return "HHH000404: Don't use old DTDs, read the Hibernate 3.x Migration Guide!"; + } + + public final void usingReflectionOptimizer() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.usingReflectionOptimizer$str(), new Object[0]); + } + + protected String usingReflectionOptimizer$str() { + return "HHH000406: Using bytecode reflection optimizer"; + } + + public final void usingStreams() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.usingStreams$str(), new Object[0]); + } + + protected String usingStreams$str() { + return "HHH000407: Using java.io streams to persist binary types"; + } + + public final void usingTimestampWorkaround() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.usingTimestampWorkaround$str(), new Object[0]); + } + + protected String usingTimestampWorkaround$str() { + return "HHH000408: Using workaround for JVM bug in java.sql.Timestamp"; + } + + public final void usingUuidHexGenerator(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.usingUuidHexGenerator$str(), arg0, arg1); + } + + protected String usingUuidHexGenerator$str() { + return "HHH000409: Using %s which does not generate IETF RFC 4122 compliant UUID values; consider using %s instead"; + } + + public final void validatorNotFound() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.validatorNotFound$str(), new Object[0]); + } + + protected String validatorNotFound$str() { + return "HHH000410: Hibernate Validator not found: ignoring"; + } + + public final void version(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.version$str(), arg0); + } + + protected String version$str() { + return "HHH000412: Hibernate Core {%s}"; + } + + public final void warningsCreatingTempTable(SQLWarning arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.warningsCreatingTempTable$str(), arg0); + } + + protected String warningsCreatingTempTable$str() { + return "HHH000413: Warnings creating temp table : %s"; + } + + public final void willNotRegisterListeners() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.willNotRegisterListeners$str(), new Object[0]); + } + + protected String willNotRegisterListeners$str() { + return "HHH000414: Property hibernate.search.autoregister_listeners is set to false. No attempt will be made to register Hibernate Search event listeners."; + } + + public final void writeLocksNotSupported(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.writeLocksNotSupported$str(), arg0); + } + + protected String writeLocksNotSupported$str() { + return "HHH000416: Write locks via update not supported for non-versioned entities [%s]"; + } + + public final void writingGeneratedSchemaToFile(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.writingGeneratedSchemaToFile$str(), arg0); + } + + protected String writingGeneratedSchemaToFile$str() { + return "HHH000417: Writing generated schema to file: %s"; + } + + public final void addingOverrideFor(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.addingOverrideFor$str(), arg0, arg1); + } + + protected String addingOverrideFor$str() { + return "HHH000418: Adding override for %s: %s"; + } + + public final void resolvedSqlTypeDescriptorForDifferentSqlCode(String arg0, String arg1, String arg2, String arg3) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.resolvedSqlTypeDescriptorForDifferentSqlCode$str(), new Object[]{arg0, arg1, arg2, arg3}); + } + + protected String resolvedSqlTypeDescriptorForDifferentSqlCode$str() { + return "HHH000419: Resolved SqlTypeDescriptor is for a different SQL code. %s has sqlCode=%s; type override %s has sqlCode=%s"; + } + + public final void closingUnreleasedBatch() { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.closingUnreleasedBatch$str(), new Object[0]); + } + + protected String closingUnreleasedBatch$str() { + return "HHH000420: Closing un-released batch"; + } + + public final void disablingContextualLOBCreation(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.disablingContextualLOBCreation$str(), arg0); + } + + protected String disablingContextualLOBCreation$str() { + return "HHH000421: Disabling contextual LOB creation as %s is true"; + } + + public final void disablingContextualLOBCreationSinceConnectionNull() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.disablingContextualLOBCreationSinceConnectionNull$str(), new Object[0]); + } + + protected String disablingContextualLOBCreationSinceConnectionNull$str() { + return "HHH000422: Disabling contextual LOB creation as connection was null"; + } + + public final void disablingContextualLOBCreationSinceOldJdbcVersion(int arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.disablingContextualLOBCreationSinceOldJdbcVersion$str(), arg0); + } + + protected String disablingContextualLOBCreationSinceOldJdbcVersion$str() { + return "HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [%s] less than 4"; + } + + public final void disablingContextualLOBCreationSinceCreateClobFailed(Throwable arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.disablingContextualLOBCreationSinceCreateClobFailed$str(), arg0); + } + + protected String disablingContextualLOBCreationSinceCreateClobFailed$str() { + return "HHH000424: Disabling contextual LOB creation as createClob() method threw error : %s"; + } + + public final void unableToCloseSessionButSwallowingError(HibernateException arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.unableToCloseSessionButSwallowingError$str(), arg0); + } + + protected String unableToCloseSessionButSwallowingError$str() { + return "HHH000425: Could not close session; swallowing exception[%s] as transaction completed"; + } + + public final void setManagerLookupClass() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.setManagerLookupClass$str(), new Object[0]); + } + + protected String setManagerLookupClass$str() { + return "HHH000426: You should set hibernate.transaction.jta.platform if cache is enabled"; + } + + public final void legacyTransactionManagerStrategy(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.legacyTransactionManagerStrategy$str(), arg0, arg1); + } + + protected String legacyTransactionManagerStrategy$str() { + return "HHH000428: Encountered legacy TransactionManagerLookup specified; convert to newer %s contract specified via %s setting"; + } + + public final void entityIdentifierValueBindingExists(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.entityIdentifierValueBindingExists$str(), arg0); + } + + protected String entityIdentifierValueBindingExists$str() { + return "HHH000429: Setting entity-identifier value binding where one already existed : %s."; + } + + public final void deprecatedDerbyDialect() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.deprecatedDerbyDialect$str(), new Object[0]); + } + + protected String deprecatedDerbyDialect$str() { + return "HHH000430: The DerbyDialect dialect has been deprecated; use one of the version-specific dialects instead"; + } + + public final void undeterminedH2Version() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.undeterminedH2Version$str(), new Object[0]); + } + + protected String undeterminedH2Version$str() { + return "HHH000431: Unable to determine H2 database version, certain features may not work"; + } + + public final void noColumnsSpecifiedForIndex(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.noColumnsSpecifiedForIndex$str(), arg0, arg1); + } + + protected String noColumnsSpecifiedForIndex$str() { + return "HHH000432: There were not column names specified for index %s on table %s"; + } + + public final void timestampCachePuts(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.timestampCachePuts$str(), arg0); + } + + protected String timestampCachePuts$str() { + return "HHH000433: update timestamps cache puts: %s"; + } + + public final void timestampCacheHits(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.timestampCacheHits$str(), arg0); + } + + protected String timestampCacheHits$str() { + return "HHH000434: update timestamps cache hits: %s"; + } + + public final void timestampCacheMisses(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.timestampCacheMisses$str(), arg0); + } + + protected String timestampCacheMisses$str() { + return "HHH000435: update timestamps cache misses: %s"; + } + + public final void entityManagerFactoryAlreadyRegistered(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.entityManagerFactoryAlreadyRegistered$str(), arg0, arg1); + } + + protected String entityManagerFactoryAlreadyRegistered$str() { + return "HHH000436: Entity manager factory name (%s) is already registered. If entity manager will be clustered or passivated, specify a unique value for property '%s'"; + } + + public final void cannotResolveNonNullableTransientDependencies(String arg0, Set arg1, Set arg2) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.cannotResolveNonNullableTransientDependencies$str(), arg0, arg1, arg2); + } + + protected String cannotResolveNonNullableTransientDependencies$str() { + return "HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity. The unsaved transient entity must be saved in an operation prior to saving these dependent entities.\n\tUnsaved transient entity: (%s)\n\tDependent entities: (%s)\n\tNon-nullable association(s): (%s)"; + } + + public final void naturalIdCachePuts(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.naturalIdCachePuts$str(), arg0); + } + + protected String naturalIdCachePuts$str() { + return "HHH000438: NaturalId cache puts: %s"; + } + + public final void naturalIdCacheHits(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.naturalIdCacheHits$str(), arg0); + } + + protected String naturalIdCacheHits$str() { + return "HHH000439: NaturalId cache hits: %s"; + } + + public final void naturalIdCacheMisses(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.naturalIdCacheMisses$str(), arg0); + } + + protected String naturalIdCacheMisses$str() { + return "HHH000440: NaturalId cache misses: %s"; + } + + public final void naturalIdMaxQueryTime(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.naturalIdMaxQueryTime$str(), arg0); + } + + protected String naturalIdMaxQueryTime$str() { + return "HHH000441: Max NaturalId query time: %sms"; + } + + public final void naturalIdQueriesExecuted(long arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.naturalIdQueriesExecuted$str(), arg0); + } + + protected String naturalIdQueriesExecuted$str() { + return "HHH000442: NaturalId queries executed to database: %s"; + } + + public final void tooManyInExpressions(String arg0, int arg1, String arg2, int arg3) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.tooManyInExpressions$str(), new Object[]{arg0, arg1, arg2, arg3}); + } + + protected String tooManyInExpressions$str() { + return "HHH000443: Dialect [%s] limits the number of elements in an IN predicate to %s entries. However, the given parameter list [%s] contained %s entries, which will likely cause failures to execute the query in the database"; + } + + public final void usingFollowOnLocking() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.usingFollowOnLocking$str(), new Object[0]); + } + + protected String usingFollowOnLocking$str() { + return "HHH000444: Encountered request for locking however dialect reports that database prefers locking be done in a separate select (follow-on locking); results will be locked after initial query executes"; + } + + public final void aliasSpecificLockingWithFollowOnLocking(LockMode arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.aliasSpecificLockingWithFollowOnLocking$str(), arg0); + } + + protected String aliasSpecificLockingWithFollowOnLocking$str() { + return "HHH000445: Alias-specific lock modes requested, which is not currently supported with follow-on locking; all acquired locks will be [%s]"; + } + + public final void embedXmlAttributesNoLongerSupported() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.embedXmlAttributesNoLongerSupported$str(), new Object[0]); + } + + protected String embedXmlAttributesNoLongerSupported$str() { + return "HHH000446: embed-xml attributes were intended to be used for DOM4J entity mode. Since that entity mode has been removed, embed-xml attributes are no longer supported and should be removed from mappings."; + } + + public final void explicitSkipLockedLockCombo() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.explicitSkipLockedLockCombo$str(), new Object[0]); + } + + protected String explicitSkipLockedLockCombo$str() { + return "HHH000447: Explicit use of UPGRADE_SKIPLOCKED in lock() calls is not recommended; use normal UPGRADE locking instead"; + } + + public final void multipleValidationModes(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.multipleValidationModes$str(), arg0); + } + + protected String multipleValidationModes$str() { + return "HHH000448: 'javax.persistence.validation.mode' named multiple values : %s"; + } + + public final void nonCompliantMapConversion(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.nonCompliantMapConversion$str(), arg0); + } + + protected String nonCompliantMapConversion$str() { + return "HHH000449: @Convert annotation applied to Map attribute [%s] did not explicitly specify attributeName using 'key'/'value' as required by spec; attempting to DoTheRightThing"; + } + + public final void alternateServiceRole(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.alternateServiceRole$str(), arg0, arg1); + } + + protected String alternateServiceRole$str() { + return "HHH000450: Encountered request for Service by non-primary service role [%s -> %s]; please update usage"; + } + + public final void rollbackFromBackgroundThread(int arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.rollbackFromBackgroundThread$str(), arg0); + } + + protected String rollbackFromBackgroundThread$str() { + return "HHH000451: Transaction afterCompletion called by a background thread; delaying afterCompletion processing until the original thread can handle it. [status=%s]"; + } + + public final void unableToLoadScannedClassOrResource(Exception arg0) { + super.log.logf(FQCN, Logger.Level.WARN, arg0, this.unableToLoadScannedClassOrResource$str(), new Object[0]); + } + + protected String unableToLoadScannedClassOrResource$str() { + return "HHH000452: Exception while loading a class or resource found during scanning"; + } + + public final void unableToDiscoverOsgiService(String arg0, Exception arg1) { + super.log.logf(FQCN, Logger.Level.WARN, arg1, this.unableToDiscoverOsgiService$str(), arg0); + } + + protected String unableToDiscoverOsgiService$str() { + return "HHH000453: Exception while discovering OSGi service implementations : %s"; + } + + public final void deprecatedManyToManyOuterJoin() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.deprecatedManyToManyOuterJoin$str(), new Object[0]); + } + + protected String deprecatedManyToManyOuterJoin$str() { + return "HHH000454: The outer-join attribute on has been deprecated. Instead of outer-join=\"false\", use lazy=\"extra\" with , , , , or , which will only initialize entities (not as a proxy) as needed."; + } + + public final void deprecatedManyToManyFetch() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.deprecatedManyToManyFetch$str(), new Object[0]); + } + + protected String deprecatedManyToManyFetch$str() { + return "HHH000455: The fetch attribute on has been deprecated. Instead of fetch=\"select\", use lazy=\"extra\" with , , , , or , which will only initialize entities (not as a proxy) as needed."; + } + + public final void unsupportedNamedParameters() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unsupportedNamedParameters$str(), new Object[0]); + } + + protected String unsupportedNamedParameters$str() { + return "HHH000456: Named parameters are used for a callable statement, but database metadata indicates named parameters are not supported."; + } + + public final void applyingExplicitDiscriminatorColumnForJoined(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.applyingExplicitDiscriminatorColumnForJoined$str(), arg0, arg1); + } + + protected String applyingExplicitDiscriminatorColumnForJoined$str() { + return "HHH000457: Joined inheritance hierarchy [%1$s] defined explicit @DiscriminatorColumn. Legacy Hibernate behavior was to ignore the @DiscriminatorColumn. However, as part of issue HHH-6911 we now apply the explicit @DiscriminatorColumn. If you would prefer the legacy behavior, enable the `%2$s` setting (%2$s=true)"; + } + + public final void creatingPooledLoOptimizer(int arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.DEBUG, (Throwable)null, this.creatingPooledLoOptimizer$str(), arg0, arg1); + } + + protected String creatingPooledLoOptimizer$str() { + return "HHH000467: Creating pooled optimizer (lo) with [incrementSize=%s; returnClass=%s]"; + } + + public final void logBadHbmAttributeConverterType(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.logBadHbmAttributeConverterType$str(), arg0, arg1); + } + + protected String logBadHbmAttributeConverterType$str() { + return "HHH000468: Unable to interpret type [%s] as an AttributeConverter due to an exception : %s"; + } + + protected String usingStoppedClassLoaderService$str() { + return "HHH000469: The ClassLoaderService can not be reused. This instance was stopped already."; + } + + public final HibernateException usingStoppedClassLoaderService() { + HibernateException result = new HibernateException(String.format(this.getLoggingLocale(), this.usingStoppedClassLoaderService$str())); + StackTraceElement[] st = result.getStackTrace(); + result.setStackTrace((StackTraceElement[])Arrays.copyOfRange(st, 1, st.length)); + return result; + } + + public final void logUnexpectedSessionInCollectionNotConnected(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.logUnexpectedSessionInCollectionNotConnected$str(), arg0); + } + + protected String logUnexpectedSessionInCollectionNotConnected$str() { + return "HHH000470: An unexpected session is defined for a collection, but the collection is not connected to that session. A persistent collection may only be associated with one session at a time. Overwriting session. %s"; + } + + public final void logCannotUnsetUnexpectedSessionInCollection(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.logCannotUnsetUnexpectedSessionInCollection$str(), arg0); + } + + protected String logCannotUnsetUnexpectedSessionInCollection$str() { + return "HHH000471: Cannot unset session in a collection because an unexpected session is defined. A persistent collection may only be associated with one session at a time. %s"; + } + + public final void hikariProviderClassNotFound() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.hikariProviderClassNotFound$str(), new Object[0]); + } + + protected String hikariProviderClassNotFound$str() { + return "HHH000472: Hikari properties were encountered, but the Hikari ConnectionProvider was not found on the classpath; these properties are going to be ignored."; + } + + public final void cachedFileObsolete(File arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.cachedFileObsolete$str(), arg0); + } + + protected String cachedFileObsolete$str() { + return "HHH000473: Omitting cached file [%s] as the mapping file is newer"; + } + + protected String ambiguousPropertyMethods$str() { + return "HHH000474: Ambiguous persistent property methods detected on %s; mark one as @Transient : [%s] and [%s]"; + } + + public final String ambiguousPropertyMethods(String arg0, String arg1, String arg2) { + return String.format(this.getLoggingLocale(), this.ambiguousPropertyMethods$str(), arg0, arg1, arg2); + } + + public final void logCannotLocateIndexColumnInformation(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.logCannotLocateIndexColumnInformation$str(), arg0, arg1); + } + + protected String logCannotLocateIndexColumnInformation$str() { + return "HHH000475: Cannot locate column information using identifier [%s]; ignoring index [%s]"; + } + + public final void executingImportScript(String arg0) { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.executingImportScript$str(), arg0); + } + + protected String executingImportScript$str() { + return "HHH000476: Executing import script '%s'"; + } + + public final void startingDelayedSchemaDrop() { + super.log.logf(FQCN, Logger.Level.INFO, (Throwable)null, this.startingDelayedSchemaDrop$str(), new Object[0]); + } + + protected String startingDelayedSchemaDrop$str() { + return "HHH000477: Starting delayed drop of schema as part of SessionFactory shut-down'"; + } + + public final void unsuccessfulSchemaManagementCommand(String arg0) { + super.log.logf(FQCN, Logger.Level.ERROR, (Throwable)null, this.unsuccessfulSchemaManagementCommand$str(), arg0); + } + + protected String unsuccessfulSchemaManagementCommand$str() { + return "HHH000478: Unsuccessful: %s"; + } + + protected String collectionNotProcessedByFlush$str() { + return "HHH000479: Collection [%s] was not processed by flush(). This is likely due to unsafe use of the session (e.g. used in multiple threads concurrently, updates during entity lifecycle hooks)."; + } + + public final String collectionNotProcessedByFlush(String arg0) { + return String.format(this.getLoggingLocale(), this.collectionNotProcessedByFlush$str(), arg0); + } + + public final void stalePersistenceContextInEntityEntry(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.stalePersistenceContextInEntityEntry$str(), arg0); + } + + protected String stalePersistenceContextInEntityEntry$str() { + return "HHH000480: A ManagedEntity was associated with a stale PersistenceContext. A ManagedEntity may only be associated with one PersistenceContext at a time; %s"; + } + + public final void unknownJavaTypeNoEqualsHashCode(Class arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unknownJavaTypeNoEqualsHashCode$str(), arg0); + } + + protected String unknownJavaTypeNoEqualsHashCode$str() { + return "HHH000481: Encountered Java type [%s] for which we could not locate a JavaTypeDescriptor and which does not appear to implement equals and/or hashCode. This can lead to significant performance problems when performing equality/dirty checking involving this Java type. Consider registering a custom JavaTypeDescriptor or at least implementing equals/hashCode."; + } + + public final void cacheOrCacheableAnnotationOnNonRoot(String arg0) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.cacheOrCacheableAnnotationOnNonRoot$str(), arg0); + } + + protected String cacheOrCacheableAnnotationOnNonRoot$str() { + return "HHH000482: @javax.persistence.Cacheable or @org.hibernate.annotations.Cache used on a non-root entity: ignored for %s"; + } + + public final void emptyCompositesEnabled() { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.emptyCompositesEnabled$str(), new Object[0]); + } + + protected String emptyCompositesEnabled$str() { + return "HHH000483: An experimental feature has been enabled (hibernate.create_empty_composites.enabled=true) that instantiates empty composite/embedded objects when all of its attribute values are null. This feature has known issues and should not be used in production until it is stabilized. See Hibernate Jira issue HHH-11936 for details."; + } + + public final void immutableEntityUpdateQuery(String arg0, String arg1) { + super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.immutableEntityUpdateQuery$str(), arg0, arg1); + } + + protected String immutableEntityUpdateQuery$str() { + return "HHH000487: The query: [%s] attempts to update an immutable entity: %s"; + } + + static { + LOCALE = Locale.ROOT; + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java new file mode 100644 index 0000000..9e2a682 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java @@ -0,0 +1,32 @@ +package net.oschina.j2cache.hibernate5.nonstop; + +import net.oschina.j2cache.hibernate5.log.J2CacheMessageLogger; +import org.jboss.logging.Logger; + +public final class HibernateNonstopCacheExceptionHandler { + + public static final String HIBERNATE_THROW_EXCEPTION_ON_TIMEOUT_PROPERTY = "J2Cache.hibernate.propagateNonStopCacheException"; + public static final String HIBERNATE_LOG_EXCEPTION_STACK_TRACE_PROPERTY = "J2Cache.hibernate.logNonStopCacheExceptionStackTrace"; + + private static final J2CacheMessageLogger LOG = Logger.getMessageLogger(J2CacheMessageLogger.class, HibernateNonstopCacheExceptionHandler.class.getName()); + private static final HibernateNonstopCacheExceptionHandler INSTANCE = new HibernateNonstopCacheExceptionHandler(); + + private HibernateNonstopCacheExceptionHandler() { + } + + public static HibernateNonstopCacheExceptionHandler getInstance() { + return INSTANCE; + } + + public void handleNonstopCacheException(NonStopCacheException nonStopCacheException) { + if (Boolean.getBoolean(HIBERNATE_THROW_EXCEPTION_ON_TIMEOUT_PROPERTY)) { + throw nonStopCacheException; + } else { + if (Boolean.getBoolean(HIBERNATE_LOG_EXCEPTION_STACK_TRACE_PROPERTY)) { + LOG.debug("Ignoring NonstopCacheException - " + nonStopCacheException.getMessage(), nonStopCacheException); + } else { + LOG.debug("Ignoring NonstopCacheException - " + nonStopCacheException.getMessage()); + } + } + } +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java new file mode 100644 index 0000000..68bb0c2 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java @@ -0,0 +1,18 @@ +package net.oschina.j2cache.hibernate5.nonstop; + +import org.hibernate.cache.CacheException; + +public class NonStopCacheException extends CacheException { + + public NonStopCacheException(final String message, final Throwable cause) { + super(message, cause); + } + + public NonStopCacheException(final String message) { + super(message); + } + + public NonStopCacheException(final Throwable cause) { + super(cause); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java new file mode 100644 index 0000000..c720711 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java @@ -0,0 +1,142 @@ +package net.oschina.j2cache.hibernate5.nonstop; + + +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.collection.CollectionPersister; + +public class NonstopAwareCollectionRegionAccessStrategy implements CollectionRegionAccessStrategy { + + private final CollectionRegionAccessStrategy actualStrategy; + private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler; + + public NonstopAwareCollectionRegionAccessStrategy(CollectionRegionAccessStrategy actualStrategy, HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) { + this.actualStrategy = actualStrategy; + this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler; + } + + @Override + public CollectionRegion getRegion() { + return this.actualStrategy.getRegion(); + } + + @Override + public void evict(Object key) throws CacheException { + try { + this.actualStrategy.evict(key); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void evictAll() throws CacheException { + try { + this.actualStrategy.evictAll(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + try { + return this.actualStrategy.get(session, key, txTimestamp); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + try { + return this.actualStrategy.lockItem(session, key, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public SoftLock lockRegion() throws CacheException { + try { + return this.actualStrategy.lockRegion(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + throws CacheException { + try { + return this.actualStrategy.putFromLoad(session, key, value, txTimestamp, version, minimalPutOverride); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version) throws CacheException { + try { + return this.actualStrategy.putFromLoad(session, key, value, txTimestamp, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + try { + this.actualStrategy.remove(session, key); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void removeAll() throws CacheException { + try { + this.actualStrategy.removeAll(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + try { + this.actualStrategy.unlockItem(session, key, lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void unlockRegion(SoftLock lock) throws CacheException { + try { + this.actualStrategy.unlockRegion(lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetCollectionId(cacheKey); + } +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java new file mode 100644 index 0000000..98db36f --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java @@ -0,0 +1,180 @@ +package net.oschina.j2cache.hibernate5.nonstop; + +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAccessStrategy { + + private final EntityRegionAccessStrategy actualStrategy; + private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler; + + public NonstopAwareEntityRegionAccessStrategy(EntityRegionAccessStrategy actualStrategy, HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) { + this.actualStrategy = actualStrategy; + this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler; + } + + @Override + public EntityRegion getRegion() { + return this.actualStrategy.getRegion(); + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + try { + return this.actualStrategy.afterInsert(session, key, value, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { + try { + return this.actualStrategy.afterUpdate(session, key, value, currentVersion, previousVersion, lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public void evict(Object key) throws CacheException { + try { + this.actualStrategy.evict(key); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void evictAll() throws CacheException { + try { + this.actualStrategy.evictAll(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + try { + return this.actualStrategy.get(session, key, txTimestamp); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + try { + return this.actualStrategy.insert(session, key, value, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + try { + return this.actualStrategy.lockItem(session, key, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public SoftLock lockRegion() throws CacheException { + try { + return this.actualStrategy.lockRegion(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + try { + return this.actualStrategy.putFromLoad(session, key, value, txTimestamp, version, minimalPutOverride); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version) throws CacheException { + try { + return this.actualStrategy.putFromLoad(session, key, value, txTimestamp, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + try { + this.actualStrategy.remove(session, key); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void removeAll() throws CacheException { + try { + this.actualStrategy.removeAll(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + try { + this.actualStrategy.unlockItem(session, key, lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void unlockRegion(SoftLock lock) throws CacheException { + try { + this.actualStrategy.unlockRegion(lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { + try { + return this.actualStrategy.update(session, key, value, currentVersion, previousVersion); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateEntityKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetEntityId(cacheKey); + } +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java new file mode 100644 index 0000000..b11a239 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java @@ -0,0 +1,181 @@ +package net.oschina.j2cache.hibernate5.nonstop; + +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegionAccessStrategy { + + private final NaturalIdRegionAccessStrategy actualStrategy; + private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler; + + public NonstopAwareNaturalIdRegionAccessStrategy(NaturalIdRegionAccessStrategy actualStrategy, HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) { + this.actualStrategy = actualStrategy; + this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler; + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + try { + return this.actualStrategy.insert(session, key, value); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + try { + return this.actualStrategy.afterInsert(session, key, value); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + try { + return this.actualStrategy.update(session, key, value); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock) throws CacheException { + try { + return this.actualStrategy.afterUpdate(session, key, value, lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public NaturalIdRegion getRegion() { + return this.actualStrategy.getRegion(); + } + + @Override + public void evict(Object key) throws CacheException { + try { + this.actualStrategy.evict(key); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void evictAll() throws CacheException { + try { + this.actualStrategy.evictAll(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + try { + return this.actualStrategy.get(session, key, txTimestamp); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + try { + return this.actualStrategy.lockItem(session, key, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public SoftLock lockRegion() throws CacheException { + try { + return this.actualStrategy.lockRegion(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return null; + } + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + throws CacheException { + try { + return this.actualStrategy.putFromLoad(session, key, value, txTimestamp, version, minimalPutOverride); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version) throws CacheException { + try { + return this.actualStrategy.putFromLoad(session, key, value, txTimestamp, version); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + return false; + } + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + try { + this.actualStrategy.remove(session, key); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void removeAll() throws CacheException { + try { + this.actualStrategy.removeAll(); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + try { + this.actualStrategy.unlockItem(session, key, lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public void unlockRegion(SoftLock lock) throws CacheException { + try { + this.actualStrategy.unlockRegion(lock); + } catch (NonStopCacheException nonStopCacheException) { + hibernateNonstopExceptionHandler.handleNonstopCacheException(nonStopCacheException); + } + } + + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { + return DefaultCacheKeysFactory.staticCreateNaturalIdKey( naturalIdValues, persister, session ); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetNaturalIdValues(cacheKey); + } + +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java new file mode 100644 index 0000000..b838803 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java @@ -0,0 +1,25 @@ +package net.oschina.j2cache.hibernate5.regions; + +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; + +import java.util.Properties; + +public class J2CacheCollectionRegion extends J2CacheTransactionalDataRegion implements CollectionRegion { + + public J2CacheCollectionRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, SessionFactoryOptions settings, CacheDataDescription metadata, Properties properties) { + super(accessStrategyFactory, underlyingCache, settings, metadata, properties); + } + + @Override + public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { + return this.getAccessStrategyFactory().createCollectionRegionAccessStrategy(this, accessType); + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java new file mode 100644 index 0000000..0cc76de --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java @@ -0,0 +1,105 @@ +package net.oschina.j2cache.hibernate5.regions; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import net.oschina.j2cache.hibernate5.log.J2CacheMessageLogger; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.Region; + +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import net.oschina.j2cache.hibernate5.util.Timestamper; + +public abstract class J2CacheDataRegion implements Region { + + private static final J2CacheMessageLogger LOG = org.jboss.logging.Logger.getMessageLogger( + J2CacheMessageLogger.class, + J2CacheDataRegion.class.getName() + ); + private static final String CACHE_LOCK_TIMEOUT_PROPERTY = "hibernate.cache_lock_timeout"; + private static final int DEFAULT_CACHE_LOCK_TIMEOUT = 60000; + + private final CacheRegion cache; + private final J2CacheAccessStrategyFactory accessStrategyFactory; + private final int cacheLockTimeout; + + J2CacheDataRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion cache, Properties properties) { + this.accessStrategyFactory = accessStrategyFactory; + this.cache = cache; + String timeout = properties.getProperty(CACHE_LOCK_TIMEOUT_PROPERTY, Integer.toString(DEFAULT_CACHE_LOCK_TIMEOUT)); + this.cacheLockTimeout = Timestamper.ONE_MS * Integer.decode(timeout); + } + + protected CacheRegion getCache() { + return this.cache; + } + + public CacheRegion getJ2Cache() { + return this.getCache(); + } + + protected J2CacheAccessStrategyFactory getAccessStrategyFactory() { + return this.accessStrategyFactory; + } + + public String getName() { + return this.getCache().getName(); + } + + public void destroy() throws CacheException { + try { + this.getCache().clear(); + } catch (IllegalStateException e) { + LOG.debug("This can happen if multiple frameworks both try to shutdown ehcache", e); + } + } + + public long getSizeInMemory() { + return -1; + } + + @Override + public long getElementCountInMemory() { + return -1; + } + + @Override + public long getElementCountOnDisk() { + return -1; + } + + @Override + public Map toMap() { + try { + Map result = new HashMap(); + for (Object key : this.cache.keys()) { + CacheObject e = this.cache.get(key); + if (e != null) { + result.put(key, e.getValue()); + } + } + return result; + } catch (Exception e) { + throw new CacheException(e); + } + } + + @Override + public long nextTimestamp() { + return Timestamper.next(); + } + + @Override + public int getTimeout() { + return this.cacheLockTimeout; + } + + @Override + public boolean contains(Object key) { + return false; + } + +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java new file mode 100644 index 0000000..7ba3e0c --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java @@ -0,0 +1,25 @@ +package net.oschina.j2cache.hibernate5.regions; + +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; + +import java.util.Properties; + +public class J2CacheEntityRegion extends J2CacheTransactionalDataRegion implements EntityRegion { + + public J2CacheEntityRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, SessionFactoryOptions settings, CacheDataDescription metadata, Properties properties) { + super(accessStrategyFactory,underlyingCache, settings, metadata, properties); + } + + @Override + public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { + return this.getAccessStrategyFactory().createEntityRegionAccessStrategy( this, accessType ); + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java new file mode 100644 index 0000000..afd145d --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java @@ -0,0 +1,69 @@ +package net.oschina.j2cache.hibernate5.regions; + +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.log.J2CacheMessageLogger; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.GeneralDataRegion; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.jboss.logging.Logger; + +import java.util.Properties; + +public class J2CacheGeneralDataRegion extends J2CacheDataRegion implements GeneralDataRegion { + + private static final J2CacheMessageLogger LOG = Logger.getMessageLogger(J2CacheMessageLogger.class, J2CacheGeneralDataRegion.class.getName()); + + public J2CacheGeneralDataRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, Properties properties) { + super(accessStrategyFactory, underlyingCache, properties); + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key) throws CacheException { + LOG.debugf("key: %s", key); + if (key == null) { + return null; + } else { + CacheObject value = this.getCache().get(key); + if (value == null) { + LOG.debugf("value for key %s is null", key); + return null; + } else { + return value.getValue(); + } + } + } + + @Override + public void put(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + LOG.debugf("key: %s value: %s", key, value); + try { + this.getCache().put(key, value); + } catch (IllegalArgumentException e) { + throw new CacheException(e); + } catch (IllegalStateException e) { + throw new CacheException(e); + } + } + + @Override + public void evict(Object key) throws CacheException { + try { + this.getCache().evict(key); + } catch (ClassCastException e) { + throw new CacheException(e); + } catch (IllegalStateException e) { + throw new CacheException(e); + } + } + + @Override + public void evictAll() throws CacheException { + try { + this.getCache().clear(); + } catch (IllegalStateException e) { + throw new CacheException(e); + } + } +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java new file mode 100644 index 0000000..87e0538 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java @@ -0,0 +1,25 @@ +package net.oschina.j2cache.hibernate5.regions; + +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cfg.Settings; + +import java.util.Properties; + +public class J2CacheNaturalIdRegion extends J2CacheTransactionalDataRegion implements NaturalIdRegion { + + public J2CacheNaturalIdRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, SessionFactoryOptions settings, CacheDataDescription metadata, Properties properties) { + super(accessStrategyFactory, underlyingCache, settings, metadata, properties); + } + + @Override + public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { + return getAccessStrategyFactory().createNaturalIdRegionAccessStrategy(this, accessType); + } +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java new file mode 100644 index 0000000..bbc455e --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java @@ -0,0 +1,15 @@ +package net.oschina.j2cache.hibernate5.regions; + +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.cache.spi.QueryResultsRegion; + +import java.util.Properties; + +public class J2CacheQueryResultsRegion extends J2CacheGeneralDataRegion implements QueryResultsRegion { + + public J2CacheQueryResultsRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, Properties properties) { + super( accessStrategyFactory, underlyingCache, properties ); + } + +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java new file mode 100644 index 0000000..a87b682 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java @@ -0,0 +1,15 @@ +package net.oschina.j2cache.hibernate5.regions; + +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.cache.spi.TimestampsRegion; + +import java.util.Properties; + +public class J2CacheTimestampsRegion extends J2CacheGeneralDataRegion implements TimestampsRegion { + + public J2CacheTimestampsRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, Properties properties) { + super(accessStrategyFactory, underlyingCache, properties); + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java new file mode 100644 index 0000000..a33edd4 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java @@ -0,0 +1,94 @@ +package net.oschina.j2cache.hibernate5.regions; + +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.TransactionalDataRegion; + +import java.util.Properties; + +public class J2CacheTransactionalDataRegion extends J2CacheDataRegion implements TransactionalDataRegion { + + private static final int LOCAL_LOCK_PROVIDER_CONCURRENCY = 128; + + private final SessionFactoryOptions settings; + + protected final CacheDataDescription metadata; + + J2CacheTransactionalDataRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion cache, SessionFactoryOptions settings, CacheDataDescription metadata, Properties properties) { + super(accessStrategyFactory, cache, properties); + this.settings = settings; + this.metadata = metadata; + } + + public SessionFactoryOptions getSettings() { + return this.settings; + } + + @Override + public boolean isTransactionAware() { + return false; + } + + @Override + public CacheDataDescription getCacheDataDescription() { + return this.metadata; + } + + public final Object get(Object key) { + CacheObject object = this.getCache().get(key); + return object != null ? object.getValue() : null; + } + + public final void put(Object key, Object value) throws CacheException { + try { + this.getCache().put(key, value); + } catch (IllegalArgumentException e) { + throw new CacheException(e); + } catch (IllegalStateException e) { + throw new CacheException(e); + } + } + + public final void remove(Object key) throws CacheException { + try { + this.getCache().evict(key); + } catch (ClassCastException e) { + throw new CacheException(e); + } catch (IllegalStateException e) { + throw new CacheException(e); + } + } + + public final void clear() throws CacheException { + try { + this.getCache().clear(); + } catch (IllegalStateException e) { + throw new CacheException(e); + } + } + + public final void writeLock(Object key) throws CacheException { + + } + + public final void writeUnlock(Object key) throws CacheException { + + } + + public final void readLock(Object key) throws CacheException { + + } + + public final void readUnlock(Object key) throws CacheException { + + } + + public final boolean locksAreIndependentOfCache() { + return false; + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java new file mode 100644 index 0000000..75c4dd7 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java @@ -0,0 +1,59 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.regions.J2CacheTransactionalDataRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.cfg.Settings; +import org.hibernate.engine.spi.SharedSessionContractImplementor; + + +abstract class AbstractJ2CacheAccessStrategy { + + private final T region; + private final SessionFactoryOptions settings; + + AbstractJ2CacheAccessStrategy(T region, SessionFactoryOptions settings) { + this.region = region; + this.settings = settings; + } + + protected T region() { + return this.region; + } + + protected SessionFactoryOptions settings() { + return this.settings; + } + + public final boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version) throws CacheException { + return putFromLoad( session, key, value, txTimestamp, version, settings.isMinimalPutsEnabled() ); + } + + public abstract boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + throws CacheException; + + public final SoftLock lockRegion() { + return null; + } + + public final void unlockRegion(SoftLock lock) throws CacheException { + region.clear(); + } + + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + } + + public final void removeAll() throws CacheException { + region.clear(); + } + + public final void evict(Object key) throws CacheException { + region.remove( key ); + } + + public final void evictAll() throws CacheException { + region.clear(); + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java new file mode 100644 index 0000000..8716a47 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java @@ -0,0 +1,268 @@ +package net.oschina.j2cache.hibernate5.strategy; + + +import net.oschina.j2cache.hibernate5.log.J2CacheMessageLogger; +import net.oschina.j2cache.hibernate5.regions.J2CacheTransactionalDataRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.jboss.logging.Logger; + +import java.io.Serializable; +import java.util.Comparator; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicLong; + +abstract class AbstractReadWriteJ2CacheAccessStrategy extends AbstractJ2CacheAccessStrategy { + + private static final J2CacheMessageLogger LOG = Logger.getMessageLogger(J2CacheMessageLogger.class, AbstractReadWriteJ2CacheAccessStrategy.class.getName()); + + private final UUID uuid = UUID.randomUUID(); + private final AtomicLong nextLockId = new AtomicLong(); + + private final Comparator versionComparator; + + public AbstractReadWriteJ2CacheAccessStrategy(T region, SessionFactoryOptions settings) { + super(region, settings); + this.versionComparator = region.getCacheDataDescription().getVersionComparator(); + } + + public final Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + readLockIfNeeded(key); + try { + final Lockable item = (Lockable) region().get(key); + final boolean readable = item != null && item.isReadable(txTimestamp); + if (readable) { + return item.getValue(); + } else { + return null; + } + } finally { + readUnlockIfNeeded(key); + } + } + + @Override + public final boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + region().writeLock(key); + try { + final Lockable item = (Lockable) region().get(key); + final boolean writeable = item == null || item.isWriteable(txTimestamp, version, versionComparator); + if (writeable) { + region().put(key, new Item(value, version, region().nextTimestamp())); + return true; + } else { + return false; + } + } finally { + region().writeUnlock(key); + } + } + + public final SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + region().writeLock(key); + try { + final Lockable item = (Lockable) region().get(key); + final long timeout = region().nextTimestamp() + region().getTimeout(); + final Lock lock = (item == null) ? new Lock(timeout, uuid, nextLockId(), version) : item.lock(timeout, uuid, nextLockId()); + region().put(key, lock); + return lock; + } finally { + region().writeUnlock(key); + } + } + + public final void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + region().writeLock(key); + try { + final Lockable item = (Lockable) region().get(key); + if ((item != null) && item.isUnlockable(lock)) { + decrementLock(key, (Lock) item); + } else { + handleLockExpiry(key, item); + } + } finally { + region().writeUnlock(key); + } + } + + private long nextLockId() { + return nextLockId.getAndIncrement(); + } + + protected void decrementLock(Object key, Lock lock) { + lock.unlock(region().nextTimestamp()); + region().put(key, lock); + } + + protected void handleLockExpiry(Object key, Lockable lock) { + LOG.softLockedCacheExpired(region().getName(), key, lock == null ? "(null)" : lock.toString()); + final long ts = region().nextTimestamp() + region().getTimeout(); + final Lock newLock = new Lock(ts, uuid, nextLockId.getAndIncrement(), null); + newLock.unlock(ts); + region().put(key, newLock); + } + + private void readLockIfNeeded(Object key) { + if (region().locksAreIndependentOfCache()) { + region().readLock(key); + } + } + + private void readUnlockIfNeeded(Object key) { + if (region().locksAreIndependentOfCache()) { + region().readUnlock(key); + } + } + + protected interface Lockable { + + boolean isReadable(long txTimestamp); + + boolean isWriteable(long txTimestamp, Object version, Comparator versionComparator); + + Object getValue(); + + boolean isUnlockable(SoftLock lock); + + Lock lock(long timeout, UUID uuid, long lockId); + } + + protected static final class Item implements Serializable, Lockable { + private static final long serialVersionUID = 1L; + private final Object value; + private final Object version; + private final long timestamp; + + Item(Object value, Object version, long timestamp) { + this.value = value; + this.version = version; + this.timestamp = timestamp; + } + + @Override + public boolean isReadable(long txTimestamp) { + return txTimestamp > timestamp; + } + + @Override + @SuppressWarnings("unchecked") + public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) { + return version != null && versionComparator.compare(version, newVersion) < 0; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public boolean isUnlockable(SoftLock lock) { + return false; + } + + @Override + public Lock lock(long timeout, UUID uuid, long lockId) { + return new Lock(timeout, uuid, lockId, version); + } + } + + protected static final class Lock implements Serializable, Lockable, SoftLock { + private static final long serialVersionUID = 2L; + + private final UUID sourceUuid; + private final long lockId; + private final Object version; + + private long timeout; + private boolean concurrent; + private int multiplicity = 1; + private long unlockTimestamp; + + Lock(long timeout, UUID sourceUuid, long lockId, Object version) { + this.timeout = timeout; + this.lockId = lockId; + this.version = version; + this.sourceUuid = sourceUuid; + } + + @Override + public boolean isReadable(long txTimestamp) { + return false; + } + + @Override + @SuppressWarnings({"SimplifiableIfStatement", "unchecked"}) + public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) { + if (txTimestamp > timeout) { + return true; + } + if (multiplicity > 0) { + return false; + } + return version == null + ? txTimestamp > unlockTimestamp + : versionComparator.compare(version, newVersion) < 0; + } + + @Override + public Object getValue() { + return null; + } + + @Override + public boolean isUnlockable(SoftLock lock) { + return equals(lock); + } + + @Override + @SuppressWarnings("SimplifiableIfStatement") + public boolean equals(Object o) { + if (o == this) { + return true; + } else if (o instanceof Lock) { + return (lockId == ((Lock) o).lockId) && sourceUuid.equals(((Lock) o).sourceUuid); + } else { + return false; + } + } + + @Override + public int hashCode() { + final int hash = (sourceUuid != null ? sourceUuid.hashCode() : 0); + int temp = (int) lockId; + for (int i = 1; i < Long.SIZE / Integer.SIZE; i++) { + temp ^= (lockId >>> (i * Integer.SIZE)); + } + return hash + temp; + } + + /** + * Returns true if this Lock has been concurrently locked by more than one transaction. + */ + public boolean wasLockedConcurrently() { + return concurrent; + } + + @Override + public Lock lock(long timeout, UUID uuid, long lockId) { + concurrent = true; + multiplicity++; + this.timeout = timeout; + return this; + } + + public void unlock(long timestamp) { + if (--multiplicity == 0) { + unlockTimestamp = timestamp; + } + } + + @Override + public String toString() { + return "Lock Source-UUID:" + sourceUuid + " Lock-ID:" + lockId; + } + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java new file mode 100644 index 0000000..0abfefe --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java @@ -0,0 +1,18 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.regions.J2CacheCollectionRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheEntityRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheNaturalIdRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; + +public interface J2CacheAccessStrategyFactory { + + EntityRegionAccessStrategy createEntityRegionAccessStrategy(J2CacheEntityRegion entityRegion, AccessType accessType); + + CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(J2CacheCollectionRegion collectionRegion, AccessType accessType); + + NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion naturalIdRegion, AccessType accessType); +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java new file mode 100644 index 0000000..36bf05c --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java @@ -0,0 +1,75 @@ +package net.oschina.j2cache.hibernate5.strategy; + + +import net.oschina.j2cache.hibernate5.log.J2CacheMessageLogger; +import net.oschina.j2cache.hibernate5.regions.J2CacheCollectionRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheEntityRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheNaturalIdRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.jboss.logging.Logger; + +public class J2CacheAccessStrategyFactoryImpl implements J2CacheAccessStrategyFactory { + + private static final J2CacheMessageLogger LOG = Logger.getMessageLogger(J2CacheMessageLogger.class, J2CacheAccessStrategyFactoryImpl.class.getName()); + + public EntityRegionAccessStrategy createEntityRegionAccessStrategy(J2CacheEntityRegion entityRegion, AccessType accessType) { + switch (accessType) { + case READ_ONLY: + if (entityRegion.getCacheDataDescription().isMutable()) { + LOG.readOnlyCacheConfiguredForMutableEntity(entityRegion.getName()); + } + return new ReadOnlyJ2CacheEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); + case READ_WRITE: + return new ReadWriteJ2CacheEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); + case NONSTRICT_READ_WRITE: + return new NonStrictReadWriteJ2CacheEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); + case TRANSACTIONAL: + return new TransactionalJ2CacheEntityRegionAccessStrategy(entityRegion, entityRegion.getJ2Cache(), entityRegion.getSettings()); + default: + throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]"); + + } + + } + + public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(J2CacheCollectionRegion collectionRegion, AccessType accessType) { + switch (accessType) { + case READ_ONLY: + if (collectionRegion.getCacheDataDescription().isMutable()) { + LOG.readOnlyCacheConfiguredForMutableEntity(collectionRegion.getName()); + } + return new ReadOnlyJ2CacheCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); + case READ_WRITE: + return new ReadWriteJ2CacheCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); + case NONSTRICT_READ_WRITE: + return new NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); + case TRANSACTIONAL: + return new TransactionalJ2CacheCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getJ2Cache(), collectionRegion.getSettings()); + default: + throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]"); + } + } + + @Override + public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion naturalIdRegion, AccessType accessType) { + switch (accessType) { + case READ_ONLY: + if (naturalIdRegion.getCacheDataDescription().isMutable()) { + LOG.readOnlyCacheConfiguredForMutableEntity(naturalIdRegion.getName()); + } + return new ReadOnlyJ2CacheNaturalIdRegionAccessStrategy(naturalIdRegion, naturalIdRegion.getSettings()); + case READ_WRITE: + return new ReadWriteJ2CacheNaturalIdRegionAccessStrategy(naturalIdRegion, naturalIdRegion.getSettings()); + case NONSTRICT_READ_WRITE: + return new NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy(naturalIdRegion, naturalIdRegion.getSettings()); + case TRANSACTIONAL: + return new TransactionalJ2CacheNaturalIdRegionAccessStrategy(naturalIdRegion, naturalIdRegion.getJ2Cache(), naturalIdRegion.getSettings()); + default: + throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]"); + } + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java new file mode 100644 index 0000000..d8f4a2f --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java @@ -0,0 +1,67 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.regions.J2CacheCollectionRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.cfg.Settings; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.collection.CollectionPersister; + + +public class NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements CollectionRegionAccessStrategy { + + public NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy(J2CacheCollectionRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public CollectionRegion getRegion() { + return region(); + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + return region().get(key); + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + throws CacheException { + if (minimalPutOverride && region().contains(key)) { + return false; + } else { + region().put(key, value); + return true; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + return null; + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + region().remove(key); + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + region().remove(key); + } + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetCollectionId( cacheKey ); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java new file mode 100644 index 0000000..22d1900 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java @@ -0,0 +1,87 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.regions.J2CacheEntityRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.cfg.Settings; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class NonStrictReadWriteJ2CacheEntityRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements EntityRegionAccessStrategy { + + public NonStrictReadWriteJ2CacheEntityRegionAccessStrategy(J2CacheEntityRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public EntityRegion getRegion() { + return super.region(); + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + return region().get(key); + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + if (minimalPutOverride && region().contains(key)) { + return false; + } else { + region().put(key, value); + return true; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + return null; + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + region().remove(key); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + return false; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + return false; + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { + remove(session, key); + return false; + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { + unlockItem(session, key, lock); + return false; + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + region().remove(key); + } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateEntityKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetEntityId( cacheKey ); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java new file mode 100644 index 0000000..92218b4 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java @@ -0,0 +1,88 @@ +package net.oschina.j2cache.hibernate5.strategy; + + +import net.oschina.j2cache.hibernate5.regions.J2CacheNaturalIdRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.cfg.Settings; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements NaturalIdRegionAccessStrategy { + + public NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public NaturalIdRegion getRegion() { + return region(); + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + return region().get(key); + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + if (minimalPutOverride && region().contains(key)) { + return false; + } else { + region().put(key, value); + return true; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + return null; + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + region().remove(key); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + return false; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + return false; + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + remove(session, key); + return false; + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock) throws CacheException { + unlockItem(session, key, lock); + return false; + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + region().remove(key); + } + + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { + return DefaultCacheKeysFactory.staticCreateNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetNaturalIdValues( cacheKey ); + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java new file mode 100644 index 0000000..bfa418b --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java @@ -0,0 +1,38 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.nonstop.HibernateNonstopCacheExceptionHandler; +import net.oschina.j2cache.hibernate5.nonstop.NonstopAwareCollectionRegionAccessStrategy; +import net.oschina.j2cache.hibernate5.nonstop.NonstopAwareEntityRegionAccessStrategy; +import net.oschina.j2cache.hibernate5.nonstop.NonstopAwareNaturalIdRegionAccessStrategy; +import net.oschina.j2cache.hibernate5.regions.J2CacheCollectionRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheEntityRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheNaturalIdRegion; +import net.oschina.j2cache.hibernate5.strategy.J2CacheAccessStrategyFactory; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; + +public class NonstopAccessStrategyFactory implements J2CacheAccessStrategyFactory { + + private final J2CacheAccessStrategyFactory actualFactory; + + public NonstopAccessStrategyFactory(J2CacheAccessStrategyFactory actualFactory) { + this.actualFactory = actualFactory; + } + + @Override + public EntityRegionAccessStrategy createEntityRegionAccessStrategy(J2CacheEntityRegion entityRegion, AccessType accessType) { + return new NonstopAwareEntityRegionAccessStrategy(this.actualFactory.createEntityRegionAccessStrategy(entityRegion, accessType), HibernateNonstopCacheExceptionHandler.getInstance()); + } + + @Override + public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion naturalIdRegion, AccessType accessType) { + return new NonstopAwareNaturalIdRegionAccessStrategy(this.actualFactory.createNaturalIdRegionAccessStrategy(naturalIdRegion, accessType), HibernateNonstopCacheExceptionHandler.getInstance()); + } + + @Override + public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(J2CacheCollectionRegion collectionRegion, AccessType accessType) { + return new NonstopAwareCollectionRegionAccessStrategy(this.actualFactory.createCollectionRegionAccessStrategy(collectionRegion, accessType ), HibernateNonstopCacheExceptionHandler.getInstance()); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java new file mode 100644 index 0000000..9f99e05 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java @@ -0,0 +1,60 @@ +package net.oschina.j2cache.hibernate5.strategy; + + +import net.oschina.j2cache.hibernate5.regions.J2CacheCollectionRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.collection.CollectionPersister; + +public class ReadOnlyJ2CacheCollectionRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements CollectionRegionAccessStrategy { + + public ReadOnlyJ2CacheCollectionRegionAccessStrategy(J2CacheCollectionRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public CollectionRegion getRegion() { + return region(); + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + return region().get(key); + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + if (minimalPutOverride && region().contains(key)) { + return false; + } else { + region().put(key, value); + return true; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws UnsupportedOperationException { + return null; + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + } + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetCollectionId(cacheKey); + } + +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java new file mode 100644 index 0000000..8737ae9 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java @@ -0,0 +1,81 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.regions.J2CacheEntityRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class ReadOnlyJ2CacheEntityRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements EntityRegionAccessStrategy { + + public ReadOnlyJ2CacheEntityRegionAccessStrategy(J2CacheEntityRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public EntityRegion getRegion() { + return region(); + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + return region().get(key); + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + throws CacheException { + if (minimalPutOverride && region().contains(key)) { + return false; + } else { + region().put(key, value); + return true; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws UnsupportedOperationException { + return null; + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + evict(key); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + return false; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + region().put(key, value); + return true; + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Can't write to a readonly object"); + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Can't write to a readonly object"); + } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateEntityKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetEntityId(cacheKey); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java new file mode 100644 index 0000000..9312f03 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java @@ -0,0 +1,80 @@ +package net.oschina.j2cache.hibernate5.strategy; + + +import net.oschina.j2cache.hibernate5.regions.J2CacheNaturalIdRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class ReadOnlyJ2CacheNaturalIdRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements NaturalIdRegionAccessStrategy { + + public ReadOnlyJ2CacheNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public NaturalIdRegion getRegion() { + return region(); + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + return region().get(key); + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + if (minimalPutOverride && region().contains(key)) { + return false; + } else { + region().put(key, value); + return true; + } + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws UnsupportedOperationException { + return null; + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + region().remove(key); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + return false; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + region().put(key, value); + return true; + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Can't write to a readonly object"); + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Can't write to a readonly object"); + } + + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { + return DefaultCacheKeysFactory.staticCreateNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetNaturalIdValues(cacheKey); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java new file mode 100644 index 0000000..60ab758 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java @@ -0,0 +1,32 @@ +package net.oschina.j2cache.hibernate5.strategy; + + +import net.oschina.j2cache.hibernate5.regions.J2CacheCollectionRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.collection.CollectionPersister; + +public class ReadWriteJ2CacheCollectionRegionAccessStrategy extends AbstractReadWriteJ2CacheAccessStrategy implements CollectionRegionAccessStrategy { + + public ReadWriteJ2CacheCollectionRegionAccessStrategy(J2CacheCollectionRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public CollectionRegion getRegion() { + return region(); + } + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetCollectionId(cacheKey); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java new file mode 100644 index 0000000..1bdb29f --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java @@ -0,0 +1,95 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.regions.J2CacheEntityRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.cfg.Settings; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + + +public class ReadWriteJ2CacheEntityRegionAccessStrategy extends AbstractReadWriteJ2CacheAccessStrategy implements EntityRegionAccessStrategy { + + public ReadWriteJ2CacheEntityRegionAccessStrategy(J2CacheEntityRegion region, SessionFactoryOptions settings) { + super( region, settings ); + } + + @Override + public EntityRegion getRegion() { + return region(); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + return false; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + region().writeLock( key ); + try { + final AbstractReadWriteJ2CacheAccessStrategy.Lockable item = (AbstractReadWriteJ2CacheAccessStrategy.Lockable) region().get( key ); + if ( item == null ) { + region().put( key, new AbstractReadWriteJ2CacheAccessStrategy.Item( value, version, region().nextTimestamp() ) ); + return true; + } + else { + return false; + } + } + finally { + region().writeUnlock( key ); + } + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) + throws CacheException { + return false; + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + throws CacheException { + //what should we do with previousVersion here? + region().writeLock( key ); + try { + final AbstractReadWriteJ2CacheAccessStrategy.Lockable item = (AbstractReadWriteJ2CacheAccessStrategy.Lockable) region().get( key ); + + if ( item != null && item.isUnlockable( lock ) ) { + final AbstractReadWriteJ2CacheAccessStrategy.Lock lockItem = (AbstractReadWriteJ2CacheAccessStrategy.Lock) item; + if ( lockItem.wasLockedConcurrently() ) { + decrementLock( key, lockItem ); + return false; + } + else { + region().put( key, new AbstractReadWriteJ2CacheAccessStrategy.Item( value, currentVersion, region().nextTimestamp() ) ); + return true; + } + } + else { + handleLockExpiry( key, item ); + return false; + } + } + finally { + region().writeUnlock( key ); + } + } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateEntityKey(id, persister, factory, tenantIdentifier); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetEntityId(cacheKey); + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java new file mode 100644 index 0000000..9c64df8 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java @@ -0,0 +1,82 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.hibernate5.regions.J2CacheNaturalIdRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class ReadWriteJ2CacheNaturalIdRegionAccessStrategy extends AbstractReadWriteJ2CacheAccessStrategy implements NaturalIdRegionAccessStrategy { + + public ReadWriteJ2CacheNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion region, SessionFactoryOptions settings) { + super(region, settings); + } + + @Override + public NaturalIdRegion getRegion() { + return region(); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + return false; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + region().writeLock(key); + try { + final Lockable item = (Lockable) region().get(key); + if (item == null) { + region().put(key, new Item(value, null, region().nextTimestamp())); + return true; + } else { + return false; + } + } finally { + region().writeUnlock(key); + } + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + return false; + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock) throws CacheException { + region().writeLock(key); + try { + final Lockable item = (Lockable) region().get(key); + if (item != null && item.isUnlockable(lock)) { + final Lock lockItem = (Lock) item; + if (lockItem.wasLockedConcurrently()) { + decrementLock(key, lockItem); + return false; + } else { + region().put(key, new Item(value, null, region().nextTimestamp())); + return true; + } + } else { + handleLockExpiry(key, item); + return false; + } + } finally { + region().writeUnlock(key); + } + } + + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { + return DefaultCacheKeysFactory.staticCreateNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetNaturalIdValues(cacheKey); + } +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java new file mode 100644 index 0000000..ae56ab7 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java @@ -0,0 +1,70 @@ +package net.oschina.j2cache.hibernate5.strategy; + + +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheCollectionRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.collection.CollectionPersister; + +public class TransactionalJ2CacheCollectionRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements CollectionRegionAccessStrategy { + + private final CacheRegion cache; + + public TransactionalJ2CacheCollectionRegionAccessStrategy(J2CacheCollectionRegion region, CacheRegion cache, SessionFactoryOptions settings) { + super(region, settings); + this.cache = cache; + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + CacheObject object = cache.get(key); + return object != null ? object.getValue() : null; + } + + @Override + public CollectionRegion getRegion() { + return region(); + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + return null; + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + if (minimalPutOverride && cache.get(key) != null) { + return false; + } + cache.put(key, value); + return true; + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + cache.evict(key); + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + } + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetCollectionId(cacheKey); + } + +} \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java new file mode 100644 index 0000000..9e04a88 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java @@ -0,0 +1,95 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheEntityRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + + +public class TransactionalJ2CacheEntityRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements EntityRegionAccessStrategy { + + private final CacheRegion cache; + + public TransactionalJ2CacheEntityRegionAccessStrategy( + J2CacheEntityRegion region, + CacheRegion cache, + SessionFactoryOptions settings) { + super(region, settings); + this.cache = cache; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) { + return false; + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) { + return false; + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + final CacheObject element = cache.get(key); + return element == null ? null : element.getValue(); + } + + @Override + public EntityRegion getRegion() { + return region(); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { + cache.put(key, value); + return true; + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + return null; + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + if (minimalPutOverride && cache.get(key) != null) { + return false; + } + cache.put(key, value); + return true; + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + cache.evict(key); + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { + cache.put(key, value); + return true; + } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.staticCreateEntityKey(id, persister, factory, tenantIdentifier); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetEntityId(cacheKey); + } + +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java new file mode 100644 index 0000000..499a0ba --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java @@ -0,0 +1,89 @@ +package net.oschina.j2cache.hibernate5.strategy; + +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.hibernate5.CacheRegion; +import net.oschina.j2cache.hibernate5.regions.J2CacheNaturalIdRegion; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + +public class TransactionalJ2CacheNaturalIdRegionAccessStrategy extends AbstractJ2CacheAccessStrategy implements NaturalIdRegionAccessStrategy { + + private final CacheRegion cache; + + public TransactionalJ2CacheNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion region, CacheRegion cache, SessionFactoryOptions settings) { + super(region, settings); + this.cache = cache; + } + + @Override + public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value) { + return false; + } + + @Override + public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock) { + return false; + } + + @Override + public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { + final CacheObject element = cache.get(key); + return element == null ? null : element.getValue(); + } + + @Override + public NaturalIdRegion getRegion() { + return region(); + } + + @Override + public boolean insert(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + cache.put(key, value); + return true; + } + + @Override + public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException { + return null; + } + + @Override + public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { + if (minimalPutOverride && cache.get(key) != null) { + return false; + } + cache.put(key, value); + return true; + } + + @Override + public void remove(SharedSessionContractImplementor session, Object key) throws CacheException { + cache.evict(key); + } + + @Override + public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) throws CacheException { + } + + @Override + public boolean update(SharedSessionContractImplementor session, Object key, Object value) throws CacheException { + cache.put(key, value); + return true; + } + + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { + return DefaultCacheKeysFactory.staticCreateNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetNaturalIdValues(cacheKey); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.class b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.class new file mode 100644 index 0000000000000000000000000000000000000000..e45fa2069daf9f631767efdc05e3c931c28c513a GIT binary patch literal 4020 zcmbtX`A;0z9skU-yR$nCr!g3Ouq0q(5_ap87#zo#BLOeq04BEE#vLyM4Bp+Lv$NQ# z>%?j6Ug=%;u$`uN>0#UkT8tej?N6yxRh1$|QKkL^{k>9^NW|{vy;<0e>qs;m#JunO ze&6>#=IvkZ-gzCsUfj{p3M-6yOly3d)vyCe@k$9?TEio-HO%0X;^hcJMi5*<$f}st zP=a$B&f_@&eM+D&2tl6~r!I!@d@)|YCBginiq8n-X9H9$9-r8KPVin9(C3R0#TQh3 zQNx$;WeqRkDr-1eo@rqh))G8r?YpeR1{q=L%0?M%ip$%(zwvA8`sX*wMWLdS-O#`?N@h7}x) zr%g9zXA)CZ+K5f>P8f+PGd5+NF`cyGn)_l|*Gk4llIFRtq@6h1Sg4YcO1g*pdPh$W zbe`xN=!`2+`iUEf_w*dg<1}x7q;sT)2l^DKUB`!qdj>}pG{>inS;Nzju+xdGU{2 zMia$8hxEHs7PA*ymtAXlq1GC@n51LRSngC|mK12+=8R(|n9gwpwZqx8%eon}G8VOV zrqi}-xR#x!(&_?l@;sES3623PnG~kcD`q(`ZYEuW>#X7I+Q&7MG|idZevg7kfvmo? zYdTJLh6ePUPna`8oyY@A)$R7glouS&W!#^#(>B9*&PXN|6kB;AETdDR&RipLcEFgC zkz<3h>r{N7akX*@?=oCb*OSL-7p*2w@Qg_W!w|G5CNic=Bc$CTV6?rtzhC&K<_eLW z!oban3L=MVIFo{-ljFB6$924nP8C1U@d|#Z<45A?kMR>7`>9X~@{#m{y80u(-n zUkZ`G((wtg-G$u>_FlLck^V6VkqO(0T)3FZL|i*!j8A7Xu0)COwkAY#N5&m%!i}o< zwT|E5hK?azQ?Mm@fZ&1XcJb>3&ne|SI13o7_|ORqeaDUb^H#ms#wsmh~FzX zK>lcMG(~fxDViTmQ8AjLA_W=ONX?i|)U!WjoLBJ&9ZR^SV;Q$UgdiESC@i+I2 z(N-iIBIuYYdzJ-XV1YMr*`&EvTHRMQ?=0wa4=YB&T6YT;J2hiC98KdRqTgg!vUlIl z>bWSV2tN>GMlvfpE^qRH;ZD&&nL~9}kcTGd6YVb0pPMurbKfBu+?-(HUitmsP8#Dn zMuM6S6taxC4jZhaKyXgTe`93SQldC2RwGj|T5IlC*lQ$Q+j))wVx+zAw}PfZ-ST_i zvGYNn`Tgt3zUZITJ4D zY+XQb32H-IpgPc|)?Gz-8KEVFtJQhZUqLe&>Km4zUB%x%_-K8DDFiH__{z(xBJ11K zYPBs~ATm5JCFp-bNxNFBzJbB&K&`rj(ks`|MN)3JjIw2vFQH;>U)dH~z=p~ynpPbm z?KU?0A)x9xJl3xHJLa%U*jcX`($YpL%o9Rf8@bxF0zv>GA{znGxCf>wb zs9|y-Qevb5ugfFr7 zUSi!{=lA|5tL+YJ?XN7BH!1BcruuDK^moGlU@85R#q=*~c!$NYf&rG{pc2GWN?3X| zpj2|d2~W!coIx>dt)Qm;2#{wLvIz|mr&3cLt=!MDdYhgeBcJ%u@jQkxLh3s_=TXDd zGs<%u!qj@4P!T=4k(2CGYB7dq7_SrjKaG+V_>_ALR6z0b0p5l0J?!xNx!y%1Q3UQ$ zg`}%E2}Q-J;CpEC`|r^Xh1!m&_~<>_UqX28A&zheAER=w6?bzLPnlPPZ$S0W!C!QP zD4)!uXdKXDVOapalEWMmcy_giNT52BYSwD_Xv?3WhUcKRu!QGH^6J5B?vsqqDH&VQ z+~VinX}aP0%@ZrAq&HoDQh3+m2{A3Qtid4HrUh)eye(o@q1H0m{MG(28!=Q(dsRVM zz~*IaxnJS4D5VN9O(Jq;G~o<`FPD2_!8jqmbdiH<1$BOD0`HPJ6B>9h@Dds?FQT}zsbIIc za(j8LM_a_E*RbPc6`F6MWf8vD@W{zqcytlL{EXYi;u7;Q!~mA^Zwt!UNaegNR?yc< WT02R)4^tfBVy-G|s(QqNq5lB+`^yUe literal 0 HcmV?d00001 diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.java new file mode 100644 index 0000000..843898a --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.java @@ -0,0 +1,105 @@ +package net.oschina.j2cache.hibernate5.util; + +import java.util.concurrent.atomic.AtomicLong; + +import net.oschina.j2cache.hibernate5.util.TimeProviderLoader; +import net.oschina.j2cache.hibernate5.util.lang.VicariousThreadLocal; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class SlewClock { + + private static final Logger LOG = LoggerFactory.getLogger(net.oschina.j2cache.hibernate5.util.SlewClock.class); + private static final net.oschina.j2cache.hibernate5.util.SlewClock.TimeProvider PROVIDER = TimeProviderLoader.getTimeProvider(); + private static final long DRIFT_MAXIMAL = (long)Integer.getInteger("net.oschina.j2cache.hibernate5.util.Timestamper.drift.max", 50); + private static final long SLEEP_MAXIMAL = (long)Integer.getInteger("net.oschina.j2cache.hibernate5.util.Timestamper.sleep.max", 50); + private static final int SLEEP_BASE = Integer.getInteger("net.oschina.j2cache.hibernate5.util.Timestamper.sleep.min", 25); + private static final AtomicLong CURRENT = new AtomicLong(-9223372036854775808L); + private static final VicariousThreadLocal OFFSET = new VicariousThreadLocal(); + + private SlewClock() { + } + + /** @deprecated */ + @Deprecated + static void realignWithTimeProvider() { + CURRENT.set(getCurrentTime()); + } + + static long timeMillis() { + boolean interrupted = false; + + try { + while(true) { + long mono = CURRENT.get(); + long wall = getCurrentTime(); + long delta; + if (wall == mono) { + OFFSET.remove(); + delta = wall; + return delta; + } + + if (wall > mono) { + if (CURRENT.compareAndSet(mono, wall)) { + OFFSET.remove(); + delta = wall; + return delta; + } + } else { + delta = mono - wall; + if (delta < DRIFT_MAXIMAL) { + OFFSET.remove(); + long var15 = mono; + return var15; + } + + Long lastDelta = (Long)OFFSET.get(); + long sleep; + if (lastDelta != null && delta >= lastDelta) { + OFFSET.set(Math.max(delta, lastDelta)); + + try { + sleep = sleepTime(delta, lastDelta); + LOG.trace("{} sleeping for {}ms to adjust for wall-clock drift.", Thread.currentThread(), sleep); + Thread.sleep(sleep); + } catch (InterruptedException var13) { + interrupted = true; + } + } else if (CURRENT.compareAndSet(mono, mono + 1L)) { + OFFSET.set(delta); + sleep = mono + 1L; + return sleep; + } + } + } + } finally { + if (interrupted) { + Thread.currentThread().interrupt(); + } + + } + } + + static boolean isThreadCatchingUp() { + return OFFSET.get() != null; + } + + static long behind() { + Long offset = (Long)OFFSET.get(); + return offset == null ? 0L : offset; + } + + private static long sleepTime(long current, long previous) { + long target = (long)SLEEP_BASE + (current - previous) * 2L; + return Math.min(target > 0L ? target : (long)SLEEP_BASE, SLEEP_MAXIMAL); + } + + private static long getCurrentTime() { + return PROVIDER.currentTimeMillis(); + } + + interface TimeProvider { + long currentTimeMillis(); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java new file mode 100644 index 0000000..50b2980 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java @@ -0,0 +1,23 @@ +package net.oschina.j2cache.hibernate5.util; + +import net.oschina.j2cache.hibernate5.util.SlewClock.TimeProvider; + +final class TimeProviderLoader { + + private static TimeProvider timeProvider = new TimeProvider() { + public final long currentTimeMillis() { + return System.currentTimeMillis(); + } + }; + + private TimeProviderLoader() { + } + + public static synchronized TimeProvider getTimeProvider() { + return timeProvider; + } + + public static synchronized void setTimeProvider(TimeProvider timeProvider) { + timeProvider = timeProvider; + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/Timestamper.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/Timestamper.java new file mode 100644 index 0000000..8dca4ac --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/Timestamper.java @@ -0,0 +1,62 @@ +package net.oschina.j2cache.hibernate5.util; + +import java.util.concurrent.atomic.AtomicLong; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class Timestamper { + + public static final int BIN_DIGITS = Integer.getInteger("net.oschina.j2cache.hibernate5.util.shift", 12); + public static final int ONE_MS; + private static final Logger LOG; + private static final int MAX_LOG; + private static final AtomicLong VALUE; + private static final AtomicLong LOGGED; + + private Timestamper() { + } + + public static long next() { + int runs = 0; + + while(true) { + long base = SlewClock.timeMillis() << BIN_DIGITS; + long maxValue = base + (long)ONE_MS - 1L; + long current = VALUE.get(); + + for(long update = Math.max(base, current + 1L); update < maxValue; update = Math.max(base, current + 1L)) { + if (VALUE.compareAndSet(current, update)) { + if (runs > 1) { + log(base, "Thread spin-waits on time to pass. Looped {} times, you might want to increase -Dnet.oschina.j2cache.hibernate5.util.shift", runs); + } + + return update; + } + + current = VALUE.get(); + } + + ++runs; + } + } + + private static void log(long base, String message, Object... params) { + if (LOG.isInfoEnabled()) { + long thisLog = (base >> BIN_DIGITS) / (long)MAX_LOG; + long previousLog = LOGGED.get(); + if (previousLog != thisLog && LOGGED.compareAndSet(previousLog, thisLog)) { + LOG.info(message, params); + } + } + + } + + static { + ONE_MS = 1 << BIN_DIGITS; + LOG = LoggerFactory.getLogger(Timestamper.class); + MAX_LOG = Integer.getInteger("net.oschina.j2cache.hibernate5.util.log.max", 1) * 1000; + VALUE = new AtomicLong(); + LOGGED = new AtomicLong(); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java new file mode 100644 index 0000000..d15eaa8 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java @@ -0,0 +1,118 @@ +package net.oschina.j2cache.hibernate5.util.lang; + +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; + +public class VicariousThreadLocal extends ThreadLocal { + + private static final ThreadLocal> weakThread = new ThreadLocal(); + private static final Object UNINITIALISED = new Object(); + private final ThreadLocal> local = new ThreadLocal(); + private volatile VicariousThreadLocal.Holder strongRefs; + private static final AtomicReferenceFieldUpdater strongRefsUpdater = AtomicReferenceFieldUpdater.newUpdater(VicariousThreadLocal.class, VicariousThreadLocal.Holder.class, "strongRefs"); + private final ReferenceQueue queue = new ReferenceQueue(); + + static WeakReference currentThreadRef() { + WeakReference ref = (WeakReference)weakThread.get(); + if (ref == null) { + ref = new WeakReference(Thread.currentThread()); + weakThread.set(ref); + } + + return ref; + } + + public VicariousThreadLocal() { + } + + public T get() { + WeakReference ref = (WeakReference)this.local.get(); + VicariousThreadLocal.Holder holder; + Object value; + if (ref != null) { + holder = (VicariousThreadLocal.Holder)ref.get(); + value = holder.value; + if (value != UNINITIALISED) { + return (T) value; + } + } else { + holder = this.createHolder(); + } + + value = this.initialValue(); + holder.value = value; + return (T) value; + } + + public void set(T value) { + WeakReference ref = (WeakReference)this.local.get(); + VicariousThreadLocal.Holder holder = ref != null ? (VicariousThreadLocal.Holder)ref.get() : this.createHolder(); + holder.value = value; + } + + private VicariousThreadLocal.Holder createHolder() { + this.poll(); + VicariousThreadLocal.Holder holder = new VicariousThreadLocal.Holder(this.queue); + WeakReference ref = new WeakReference(holder); + + VicariousThreadLocal.Holder old; + do { + old = this.strongRefs; + holder.next = old; + } while(!strongRefsUpdater.compareAndSet(this, old, holder)); + + this.local.set(ref); + return holder; + } + + public void remove() { + WeakReference ref = (WeakReference)this.local.get(); + if (ref != null) { + ((VicariousThreadLocal.Holder)ref.get()).value = UNINITIALISED; + } + + } + + public void poll() { + ReferenceQueue var1 = this.queue; + synchronized(this.queue) { + if (this.queue.poll() != null) { + while(this.queue.poll() != null) { + ; + } + + VicariousThreadLocal.Holder first = this.strongRefs; + if (first != null) { + VicariousThreadLocal.Holder link = first; + VicariousThreadLocal.Holder next = first.next; + + while(next != null) { + if (next.get() == null) { + next = next.next; + link.next = next; + } else { + link = next; + next = next.next; + } + } + + if (first.get() == null && !strongRefsUpdater.weakCompareAndSet(this, first, first.next)) { + first.value = null; + } + + } + } + } + } + + private static class Holder extends WeakReference { + VicariousThreadLocal.Holder next; + Object value; + + Holder(ReferenceQueue queue) { + super(VicariousThreadLocal.currentThreadRef(), queue); + this.value = VicariousThreadLocal.UNINITIALISED; + } + } +} diff --git a/modules/hibernate5/hibernate5_2_17/test/config/commons-logging.properties b/modules/hibernate5/hibernate5_2_17/test/config/commons-logging.properties new file mode 100644 index 0000000..d539d7e --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/commons-logging.properties @@ -0,0 +1,3 @@ +#\u8be5\u6587\u4ef6WAS\u73af\u5883\u5fc5\u987b\u5b58\u5728,\u5426\u5219\u65e5\u5fd7\u4e0d\u4f1a\u8f93\u51fa +org.apache.cmmons.logging.LogFactory = org.apache.commons.logging.impl.LogFactoryImpl +org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/config/ehcache.xml b/modules/hibernate5/hibernate5_2_17/test/config/ehcache.xml new file mode 100644 index 0000000..c9e9f21 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/ehcache.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/config/ehcache3.xml b/modules/hibernate5/hibernate5_2_17/test/config/ehcache3.xml new file mode 100644 index 0000000..4a6a496 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/ehcache3.xml @@ -0,0 +1,19 @@ + + + + + java.lang.String + java.io.Serializable + + 30 + + + 1000 + 100 + + + + \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/config/j2cache.properties b/modules/hibernate5/hibernate5_2_17/test/config/j2cache.properties new file mode 100644 index 0000000..1ecef95 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/j2cache.properties @@ -0,0 +1,169 @@ +#J2Cache configuration + + +######################################### +# Cache Broadcast Method +# values: +# jgroups -> use jgroups's multicast +# redis -> use redis publish/subscribe mechanism (using jedis) +# lettuce -> use redis publish/subscribe mechanism (using lettuce) +# rabbitmq -> use RabbitMQ publisher/consumer mechanism +# rocketmq -> use RocketMQ publisher/consumer mechanism +# none -> don't notify the other nodes in cluster +# xx.xxxx.xxxx.Xxxxx your own cache broadcast policy classname that implement net.oschina.j2cache.cluster.ClusterPolicy +######################################### + +j2cache.broadcast = redis + +# jgroups properties +jgroups.channel.name = j2cache +jgroups.configXml = /network.xml + +# RabbitMQ properties +rabbitmq.exchange = j2cache +rabbitmq.host = localhost +rabbitmq.port = 5672 +rabbitmq.username = guest +rabbitmq.password = guest + +# RocketMQ properties +rocketmq.name = j2cache +rocketmq.topic = j2cache +# use ; to split multi hosts +rocketmq.hosts = 127.0.0.1:9876 + +######################################### +# Level 1&2 provider +# values: +# none -> disable this level cache +# ehcache -> use ehcache2 as level 1 cache +# ehcache3 -> use ehcache3 as level 1 cache +# caffeine -> use caffeine as level 1 cache(only in memory) +# redis -> use redis as level 2 cache (using jedis) +# lettuce -> use redis as level 2 cache (using lettuce) +# readonly-redis -> use redis as level 2 cache ,but never write data to it. if use this provider, you must uncomment `j2cache.L2.config_section` to make the redis configurations available. +# memcached -> use memcached as level 2 cache (xmemcached), +# [classname] -> use custom provider +######################################### + +j2cache.L1.provider_class = ehcache3 +j2cache.L2.provider_class = redis + +# When L2 provider isn't `redis`, using `L2.config_section = redis` to read redis configurations +# j2cache.L2.config_section = redis + +# Enable/Disable ttl in redis cache data (if disabled, the object in redis will never expire, default:true) +# NOTICE: redis hash mode (redis.storage = hash) do not support this feature) +j2cache.sync_ttl_to_redis = true + +# Whether to cache null objects by default (default false) +j2cache.default_cache_null_object = true + +######################################### +# Cache Serialization Provider +# values: +# fst -> using fast-serialization (recommend) +# kyro -> using kyro serialization +# json -> using fst's json serialization (testing) +# fastjson -> using fastjson serialization (embed non-static class not support) +# java -> java standard +# [classname implements Serializer] +######################################### + +j2cache.serialization = json +#json.map.person = net.oschina.j2cache.demo.Person + +######################################### +# Ehcache configuration +######################################### + +# ehcache.configXml = /ehcache.xml + +# ehcache3.configXml = /ehcache3.xml +# ehcache3.defaultHeapSize = 1000 + +######################################### +# Caffeine configuration +# caffeine.region.[name] = size, xxxx[s|m|h|d] +# +######################################### +caffeine.properties = /caffeine.properties + +######################################### +# Redis connection configuration +######################################### + +######################################### +# Redis Cluster Mode +# +# single -> single redis server +# sentinel -> master-slaves servers +# cluster -> cluster servers (ݿЧʹ database = 0 +# sharded -> sharded servers (롢ݿ hosts ָӳЧ ; redis://user:password@127.0.0.1:6379/0 +# +######################################### + +redis.mode = single + +#redis storage mode (generic|hash) +redis.storage = generic + +## redis pub/sub channel name +redis.channel = j2cache +## redis pub/sub server (using redis.hosts when empty) +redis.channel.host = + +#cluster name just for sharded +redis.cluster_name = j2cache + +## redis cache namespace optional, default[empty] +redis.namespace = + +## connection +# Separate multiple redis nodes with commas, such as 192.168.0.10:6379,192.168.0.11:6379,192.168.0.12:6379 + +redis.hosts = 127.0.0.1:6379 +redis.timeout = 2000 +redis.password = +redis.database = 0 + +## redis pool properties +redis.maxTotal = 100 +redis.maxIdle = 10 +redis.maxWaitMillis = 5000 +redis.minEvictableIdleTimeMillis = 60000 +redis.minIdle = 1 +redis.numTestsPerEvictionRun = 10 +redis.lifo = false +redis.softMinEvictableIdleTimeMillis = 10 +redis.testOnBorrow = true +redis.testOnReturn = false +redis.testWhileIdle = true +redis.timeBetweenEvictionRunsMillis = 300000 +redis.blockWhenExhausted = false +redis.jmxEnabled = false + +lettuce.namespace = +lettuce.storage = generic +lettuce.channel = j2cache +lettuce.scheme = redis +lettuce.hosts = 127.0.0.1:6379 +lettuce.password = +lettuce.database = 0 +lettuce.sentinelMasterId = + +######################################### +# memcached server configurations +# refer to https://gitee.com/mirrors/XMemcached +######################################### + +memcached.servers = 127.0.0.1:11211 +memcached.username = +memcached.password = +memcached.connectionPoolSize = 10 +memcached.connectTimeout = 1000 +memcached.failureMode = false +memcached.healSessionInterval = 1000 +memcached.maxQueuedNoReplyOperations = 100 +memcached.opTimeout = 100 +memcached.sanitizeKeys = false \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/config/log4j.xml b/modules/hibernate5/hibernate5_2_17/test/config/log4j.xml new file mode 100644 index 0000000..840473a --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/log4j.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/hibernate5/hibernate5_2_17/test/config/network.xml b/modules/hibernate5/hibernate5_2_17/test/config/network.xml new file mode 100644 index 0000000..fedb76d --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/network.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/config/props/jdbc.properties b/modules/hibernate5/hibernate5_2_17/test/config/props/jdbc.properties new file mode 100644 index 0000000..0556a5d --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/props/jdbc.properties @@ -0,0 +1,24 @@ +# jdbc config +jdbc.driver=com.mysql.jdbc.Driver +#jdbc.driver=oracle.jdbc.driver.OracleDriver +#\u5F00\u53D1\u914D\u7F6E + + +#oracle +#jdbc.driverUrl=jdbc:oracle:thin:@192.168.0.200:1521:ORCL +#jdbc.user=sgp +#jdbc.password=sgp +#jdbc.driverUrl=jdbc:mysql://sp50f83d0575d01.mysql.rds.aliyuncs.com:3306/itsm?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 + +#mysql +#jdbc.driverUrl=jdbc:mysql://192.168.1.200:3306/webapp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 +jdbc.driverUrl=jdbc:mysql://localhost:3306/webapp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 +jdbc.user=root +jdbc.password=123456 + +#\u7EBF\u4E0A\u914D\u7F6E +jdbc.houseKeepingSleepTime=90000 +jdbc.houseKeepingTestSql=select count(1) from sys_sequence +jdbc.prototypeCount=5 +jdbc.maximumConnectionCount=100 +jdbc.minimumConnectionCount=20 \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/config/redis.properties b/modules/hibernate5/hibernate5_2_17/test/config/redis.properties new file mode 100644 index 0000000..39da017 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/redis.properties @@ -0,0 +1,9 @@ +# Redis settings +redis.host=localhost +redis.port=6379 +#redis.pass=java2000_wl + +redis.maxIdle=300 +redis.maxActive=600 +redis.maxWait=1000 +redis.testOnBorrow=true \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/config/spring/applicationContext.xml b/modules/hibernate5/hibernate5_2_17/test/config/spring/applicationContext.xml new file mode 100644 index 0000000..0523d88 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/config/spring/applicationContext.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + org.hibernate.dialect.MySQL5InnoDBDialect + true + true + false + 2 + true + false + true + true + update + org.springframework.orm.hibernate5.SpringSessionContext + true + true + net.oschina.j2cache.hibernate5.J2CacheRegionFactory + + true + true + + + + + net.oschina.j2cache.hibernate5 + + + + + + + + + + \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java new file mode 100644 index 0000000..28aec2e --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java @@ -0,0 +1,152 @@ +package net.oschina.j2cache.hibernate5; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Map; + +import net.oschina.j2cache.hibernate5.service.IArticleService; +import org.hibernate.criterion.MatchMode; +import org.hibernate.criterion.Restrictions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import net.oschina.j2cache.J2Cache; +import net.oschina.j2cache.hibernate5.bean.Article; +import net.oschina.j2cache.hibernate5.service.ArticleService; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "classpath*:spring/applicationContext.xml" }) +public class J2CacheRegionFactoryTest { + + private final static Logger LOG = LoggerFactory.getLogger(J2CacheRegionFactoryTest.class); + + @Autowired + private IArticleService articleService; + + @Before + public void setUp() throws Exception { + this.tearDown(); + + Article article = new Article(); + article.setTitle("测试缓存"); + article.setSummary("测试数据摘要"); + this.articleService.save(article); + + Article article1 = new Article(); + article1.setTitle("测试缓存1"); + article1.setSummary("测试数据摘要1"); + this.articleService.save(article1); + } + + @After + public void tearDown() throws Exception { + for (Article art : this.articleService + .find(Restrictions.like("title", "测试缓存", MatchMode.START))) { + this.articleService.delete(art.getId()); + } + } + + @Test + public void findUnique() { + + // 查询单个对象 + Article article = this.articleService + .findUnique(Restrictions.like("title", "测试缓存1", MatchMode.START)); + LOG.debug("第一次查询,缓存查询结果:" + article); + + article = this.articleService + .findUnique(Restrictions.like("title", "测试缓存1", MatchMode.START)); + LOG.debug("第二次查询,从缓存中获取:" + article); + + // 直接从缓存中读取数据 + + Map narticle = + getCacheValue("net.oschina.j2cache.hibernate5.bean.Article", article.getId()); + LOG.debug("直接从缓存中读取数据:" + narticle); + + // 验证结果 + assert article.getTitle() + .equals(narticle.get("title")); + + // 修改数据后 + Article saveartice = new Article(); + saveartice.setId(article.getId()); + saveartice.setTitle("测试缓存1"); + saveartice.setSummary("修改数据摘要"); + articleService.save(saveartice); + + // 缓存数据会删除 + narticle = getCacheValue("net.oschina.j2cache.hibernate5.bean.Article", article.getId()); + LOG.debug("修改后直接从缓存中读取数据:" + narticle); + // 发现还是原来的值,因为hibernate的缓存是存在于三个位置的,第一个为查询sql及条件作为的key。第二个为缓存单个对象的过期时间。第三个才是缓存的对象 + + article = this.articleService + .findUnique(Restrictions.like("title", "测试缓存1", MatchMode.START)); + LOG.debug("再次查询,缓存查询结果:" + article);// 会重新缓存结果 + + narticle = getCacheValue("net.oschina.j2cache.hibernate5.bean.Article", article.getId()); + LOG.debug("再次直接从缓存中读取数据:" + narticle); + + // 验证结果 + assert article.getTitle() + .equals(narticle.get("title")); + } + + @Test + public void find() { + // 查询list + List
articleList = this.articleService.find(); + LOG.debug("第一次查询,缓存查询结果:" + articleList); + + articleList = this.articleService.find(); + LOG.debug("第二次查询,从缓存中获取:" + articleList); + + // 修改数据后 + Article saveartice = new Article(); + saveartice.setId(articleList.get(0) + .getId()); + saveartice.setTitle("测试缓存1"); + saveartice.setSummary("修改数据摘要"); + articleService.save(saveartice); + // 缓存数据会删除 + + articleList = this.articleService.find(); + LOG.debug("再次查询,缓存查询结果:" + articleList);// 会重新缓存结果 + + // 测试新增数据 + Article newartice = new Article(); + newartice.setTitle("测试缓存2"); + newartice.setSummary("修改数据摘要"); + articleService.save(newartice); + // 缓存数据会删除 + + articleList = this.articleService.find(); + LOG.debug("再次查询,缓存查询结果:" + articleList);// 会重新缓存结果 + assert articleList.size() == 3; + + } + + private Map getCacheValue(String region, String key) { + try { + Object item = J2Cache.getChannel() + .get(region, key) + .getValue(); + if (item != null) + return (Map) BeanUtils.getPropertyDescriptor(item.getClass(), "value") + .getReadMethod() + .invoke(item); + } catch (IllegalAccessException | InvocationTargetException e) { + LOG.error(e.getMessage(), e); + } + return null; + } +} diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/bean/Article.java b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/bean/Article.java new file mode 100644 index 0000000..c657ee0 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/bean/Article.java @@ -0,0 +1,133 @@ +package net.oschina.j2cache.hibernate5.bean; + + +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +@Entity +@Table(name = "TEST_CACHE_ARTICLE") +@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) +public class Article implements Serializable { + + @Id + @Column(name = "ID", nullable = false, insertable = true, updatable = true) + @GenericGenerator(name="systemUUID",strategy="uuid") + @GeneratedValue(generator="systemUUID") + private String id; + /** + * 文章标题 + */ + @Column(name = "TITLE") + private String title; + /** + * 摘要 + */ + @Column(name = "SUMMARY") + private String summary; + /** + * 发布标识 + */ + @Column(name = "ISSUE") + private Boolean issue = false; + + /** + * 创建人 + */ + @Column(name = "CREATOR", length = 20) + private String creator; + /** + * 创建时间 + */ + @Temporal(TemporalType.TIMESTAMP) + @Column(updatable = false, name = "CREATE_TIME") + private Date createTime; + /** + * 最后修改人 + */ + @Column(name = "MODIFIER", length = 20) + private String modifier; + /** + * 最后修改时间 + */ + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "MODIFY_TIME") + private Date modifyTime; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public Boolean getIssue() { + return issue; + } + + public void setIssue(Boolean issue) { + this.issue = issue; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public String getModifier() { + return modifier; + } + + public void setModifier(String modifier) { + this.modifier = modifier; + } + + public Date getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Date modifyTime) { + this.modifyTime = modifyTime; + } + + @Override + public String toString() { + return "Article[hashCode="+this.hashCode()+"]{" + + "id='" + id + '\'' + + ", title='" + title + '\'' + + ", summary='" + summary + '\'' + + '}'; + } +} diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java new file mode 100644 index 0000000..64d5ee6 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java @@ -0,0 +1,54 @@ +package net.oschina.j2cache.hibernate5.service; + +import net.oschina.j2cache.hibernate5.bean.Article; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Criterion; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.transaction.Transactional; +import java.util.List; + +@Transactional +@Service +public class ArticleService implements IArticleService { + + @Resource + private SessionFactory sessionFactory; + + protected Session getSession() { + return this.sessionFactory.getCurrentSession(); + } + + public void save(Article article) { + getSession().saveOrUpdate(article); + } + + public List
find(Criterion... criterions) { + Criteria criteria = getSession().createCriteria(Article.class); + for (Criterion c : criterions) { + criteria.add(c); + } + criteria.setCacheable(true); + return criteria.list(); + } + + public void delete(String id) { + getSession().delete(getSession().get(Article.class, id)); + } + + public Article findUnique(Criterion... criterions) { + Criteria criteria = getSession().createCriteria(Article.class); + for (Criterion c : criterions) { + criteria.add(c); + } + criteria.setCacheable(true); + return (Article)criteria.uniqueResult(); + } + + public Article get(String id) { + return (Article)getSession().get(Article.class,id); + } +} diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java new file mode 100644 index 0000000..ec72ed6 --- /dev/null +++ b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2014-Now http://j2eplus.com All rights reserved. + */ +package net.oschina.j2cache.hibernate5.service; + +import net.oschina.j2cache.hibernate5.bean.Article; +import org.hibernate.Criteria; +import org.hibernate.criterion.Criterion; + +import javax.transaction.Transactional; +import java.util.List; + +/** + * This guy is lazy, nothing left. + * + * @author Tandy 2018/9/20 13:54 + */ +public interface IArticleService { + + public void save(Article article); + + public List
find(Criterion... criterions); + + public void delete(String id); + + public Article findUnique(Criterion... criterions); + + public Article get(String id); +} -- Gitee From 50f4f0c81ecd6b3c9a3283872ffe20953e7faf91 Mon Sep 17 00:00:00 2001 From: tandy <879620309@qq.com> Date: Thu, 27 Sep 2018 19:42:48 +0800 Subject: [PATCH 003/131] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hibernate5/AbstractJ2CacheRegionFactory.java | 8 -------- .../j2cache/hibernate5/service/IArticleService.java | 10 ---------- 2 files changed, 18 deletions(-) diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java index e2a3e48..7ac9849 100644 --- a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java +++ b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java @@ -1,6 +1,3 @@ -/** - * Copyright (c) 2014-Now http://j2eplus.com All rights reserved. - */ package net.oschina.j2cache.hibernate5; import net.oschina.j2cache.CacheChannel; @@ -16,11 +13,6 @@ import org.hibernate.cache.spi.access.AccessType; import java.util.Properties; -/** - * This guy is lazy, nothing left. - * - * @author Tandy 2018/9/16 17:37 - */ public abstract class AbstractJ2CacheRegionFactory implements RegionFactory { protected SessionFactoryOptions settings; diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java index ec72ed6..1fb2500 100644 --- a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java +++ b/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java @@ -1,20 +1,10 @@ -/** - * Copyright (c) 2014-Now http://j2eplus.com All rights reserved. - */ package net.oschina.j2cache.hibernate5.service; import net.oschina.j2cache.hibernate5.bean.Article; -import org.hibernate.Criteria; import org.hibernate.criterion.Criterion; -import javax.transaction.Transactional; import java.util.List; -/** - * This guy is lazy, nothing left. - * - * @author Tandy 2018/9/20 13:54 - */ public interface IArticleService { public void save(Article article); -- Gitee From af7f844d2ad377602530c444352784f1ed3b3842 Mon Sep 17 00:00:00 2001 From: tandy <879620309@qq.com> Date: Thu, 27 Sep 2018 20:06:34 +0800 Subject: [PATCH 004/131] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/hibernate5/util/SlewClock.class | Bin 4020 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.class diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.class b/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.class deleted file mode 100644 index e45fa2069daf9f631767efdc05e3c931c28c513a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4020 zcmbtX`A;0z9skU-yR$nCr!g3Ouq0q(5_ap87#zo#BLOeq04BEE#vLyM4Bp+Lv$NQ# z>%?j6Ug=%;u$`uN>0#UkT8tej?N6yxRh1$|QKkL^{k>9^NW|{vy;<0e>qs;m#JunO ze&6>#=IvkZ-gzCsUfj{p3M-6yOly3d)vyCe@k$9?TEio-HO%0X;^hcJMi5*<$f}st zP=a$B&f_@&eM+D&2tl6~r!I!@d@)|YCBginiq8n-X9H9$9-r8KPVin9(C3R0#TQh3 zQNx$;WeqRkDr-1eo@rqh))G8r?YpeR1{q=L%0?M%ip$%(zwvA8`sX*wMWLdS-O#`?N@h7}x) zr%g9zXA)CZ+K5f>P8f+PGd5+NF`cyGn)_l|*Gk4llIFRtq@6h1Sg4YcO1g*pdPh$W zbe`xN=!`2+`iUEf_w*dg<1}x7q;sT)2l^DKUB`!qdj>}pG{>inS;Nzju+xdGU{2 zMia$8hxEHs7PA*ymtAXlq1GC@n51LRSngC|mK12+=8R(|n9gwpwZqx8%eon}G8VOV zrqi}-xR#x!(&_?l@;sES3623PnG~kcD`q(`ZYEuW>#X7I+Q&7MG|idZevg7kfvmo? zYdTJLh6ePUPna`8oyY@A)$R7glouS&W!#^#(>B9*&PXN|6kB;AETdDR&RipLcEFgC zkz<3h>r{N7akX*@?=oCb*OSL-7p*2w@Qg_W!w|G5CNic=Bc$CTV6?rtzhC&K<_eLW z!oban3L=MVIFo{-ljFB6$924nP8C1U@d|#Z<45A?kMR>7`>9X~@{#m{y80u(-n zUkZ`G((wtg-G$u>_FlLck^V6VkqO(0T)3FZL|i*!j8A7Xu0)COwkAY#N5&m%!i}o< zwT|E5hK?azQ?Mm@fZ&1XcJb>3&ne|SI13o7_|ORqeaDUb^H#ms#wsmh~FzX zK>lcMG(~fxDViTmQ8AjLA_W=ONX?i|)U!WjoLBJ&9ZR^SV;Q$UgdiESC@i+I2 z(N-iIBIuYYdzJ-XV1YMr*`&EvTHRMQ?=0wa4=YB&T6YT;J2hiC98KdRqTgg!vUlIl z>bWSV2tN>GMlvfpE^qRH;ZD&&nL~9}kcTGd6YVb0pPMurbKfBu+?-(HUitmsP8#Dn zMuM6S6taxC4jZhaKyXgTe`93SQldC2RwGj|T5IlC*lQ$Q+j))wVx+zAw}PfZ-ST_i zvGYNn`Tgt3zUZITJ4D zY+XQb32H-IpgPc|)?Gz-8KEVFtJQhZUqLe&>Km4zUB%x%_-K8DDFiH__{z(xBJ11K zYPBs~ATm5JCFp-bNxNFBzJbB&K&`rj(ks`|MN)3JjIw2vFQH;>U)dH~z=p~ynpPbm z?KU?0A)x9xJl3xHJLa%U*jcX`($YpL%o9Rf8@bxF0zv>GA{znGxCf>wb zs9|y-Qevb5ugfFr7 zUSi!{=lA|5tL+YJ?XN7BH!1BcruuDK^moGlU@85R#q=*~c!$NYf&rG{pc2GWN?3X| zpj2|d2~W!coIx>dt)Qm;2#{wLvIz|mr&3cLt=!MDdYhgeBcJ%u@jQkxLh3s_=TXDd zGs<%u!qj@4P!T=4k(2CGYB7dq7_SrjKaG+V_>_ALR6z0b0p5l0J?!xNx!y%1Q3UQ$ zg`}%E2}Q-J;CpEC`|r^Xh1!m&_~<>_UqX28A&zheAER=w6?bzLPnlPPZ$S0W!C!QP zD4)!uXdKXDVOapalEWMmcy_giNT52BYSwD_Xv?3WhUcKRu!QGH^6J5B?vsqqDH&VQ z+~VinX}aP0%@ZrAq&HoDQh3+m2{A3Qtid4HrUh)eye(o@q1H0m{MG(28!=Q(dsRVM zz~*IaxnJS4D5VN9O(Jq;G~o<`FPD2_!8jqmbdiH<1$BOD0`HPJ6B>9h@Dds?FQT}zsbIIc za(j8LM_a_E*RbPc6`F6MWf8vD@W{zqcytlL{EXYi;u7;Q!~mA^Zwt!UNaegNR?yc< WT02R)4^tfBVy-G|s(QqNq5lB+`^yUe -- Gitee From 62e0195e1079cafb13413b29eb41dd7e1e01faa7 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Fri, 28 Sep 2018 07:23:22 +0800 Subject: [PATCH 005/131] =?UTF-8?q?=E8=B0=83=E6=95=B4=20hibernate=205=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hibernate5/{hibernate5_2_17 => }/pom.xml | 3 +++ modules/hibernate5/readme.md | 3 +++ .../j2cache/hibernate5/AbstractJ2CacheRegionFactory.java | 0 .../src/net/oschina/j2cache/hibernate5/CacheRegion.java | 0 .../src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java | 0 .../net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java | 0 .../oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java | 0 .../j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java | 0 .../nonstop/HibernateNonstopCacheExceptionHandler.java | 0 .../j2cache/hibernate5/nonstop/NonStopCacheException.java | 0 .../nonstop/NonstopAwareCollectionRegionAccessStrategy.java | 0 .../nonstop/NonstopAwareEntityRegionAccessStrategy.java | 0 .../nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java | 0 .../j2cache/hibernate5/regions/J2CacheCollectionRegion.java | 0 .../oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java | 0 .../j2cache/hibernate5/regions/J2CacheEntityRegion.java | 0 .../j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java | 0 .../j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java | 0 .../j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java | 0 .../j2cache/hibernate5/regions/J2CacheTimestampsRegion.java | 0 .../hibernate5/regions/J2CacheTransactionalDataRegion.java | 0 .../hibernate5/strategy/AbstractJ2CacheAccessStrategy.java | 0 .../strategy/AbstractReadWriteJ2CacheAccessStrategy.java | 0 .../hibernate5/strategy/J2CacheAccessStrategyFactory.java | 0 .../hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java | 0 ...onStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java | 0 .../NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java | 0 ...NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java | 0 .../hibernate5/strategy/NonstopAccessStrategyFactory.java | 0 .../ReadOnlyJ2CacheCollectionRegionAccessStrategy.java | 0 .../strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java | 0 .../strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java | 0 .../ReadWriteJ2CacheCollectionRegionAccessStrategy.java | 0 .../strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java | 0 .../ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java | 0 .../TransactionalJ2CacheCollectionRegionAccessStrategy.java | 0 .../TransactionalJ2CacheEntityRegionAccessStrategy.java | 0 .../TransactionalJ2CacheNaturalIdRegionAccessStrategy.java | 0 .../src/net/oschina/j2cache/hibernate5/util/SlewClock.java | 0 .../oschina/j2cache/hibernate5/util/TimeProviderLoader.java | 0 .../src/net/oschina/j2cache/hibernate5/util/Timestamper.java | 0 .../j2cache/hibernate5/util/lang/VicariousThreadLocal.java | 0 .../test/config/commons-logging.properties | 0 .../hibernate5/{hibernate5_2_17 => }/test/config/ehcache.xml | 0 .../hibernate5/{hibernate5_2_17 => }/test/config/ehcache3.xml | 0 .../{hibernate5_2_17 => }/test/config/j2cache.properties | 0 modules/hibernate5/{hibernate5_2_17 => }/test/config/log4j.xml | 0 .../hibernate5/{hibernate5_2_17 => }/test/config/network.xml | 0 .../{hibernate5_2_17 => }/test/config/props/jdbc.properties | 0 .../{hibernate5_2_17 => }/test/config/redis.properties | 0 .../test/config/spring/applicationContext.xml | 0 .../oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java | 0 .../test/src/net/oschina/j2cache/hibernate5/bean/Article.java | 0 .../net/oschina/j2cache/hibernate5/service/ArticleService.java | 0 .../oschina/j2cache/hibernate5/service/IArticleService.java | 0 pom.xml | 1 + 56 files changed, 7 insertions(+) rename modules/hibernate5/{hibernate5_2_17 => }/pom.xml (97%) create mode 100644 modules/hibernate5/readme.md rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/CacheRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/util/SlewClock.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/util/Timestamper.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/commons-logging.properties (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/ehcache.xml (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/ehcache3.xml (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/j2cache.properties (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/log4j.xml (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/network.xml (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/props/jdbc.properties (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/redis.properties (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/config/spring/applicationContext.xml (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/src/net/oschina/j2cache/hibernate5/bean/Article.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java (100%) rename modules/hibernate5/{hibernate5_2_17 => }/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java (100%) diff --git a/modules/hibernate5/hibernate5_2_17/pom.xml b/modules/hibernate5/pom.xml similarity index 97% rename from modules/hibernate5/hibernate5_2_17/pom.xml rename to modules/hibernate5/pom.xml index 26260b7..3a2a9c3 100644 --- a/modules/hibernate5/hibernate5_2_17/pom.xml +++ b/modules/hibernate5/pom.xml @@ -6,10 +6,13 @@ j2cache net.oschina.j2cache 2.7.0-release + ../../pom.xml + 4.0.0 j2cache-hibernate5 + 1.0.0-beta1 jar J2Cache - hibernate5 diff --git a/modules/hibernate5/readme.md b/modules/hibernate5/readme.md new file mode 100644 index 0000000..6036be2 --- /dev/null +++ b/modules/hibernate5/readme.md @@ -0,0 +1,3 @@ +# Hibernate 5 支持模块 + +基于 Hibernate 5.2.17 开发,感谢 [@tandy](https://gitee.com/tandy) \ No newline at end of file diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/AbstractJ2CacheRegionFactory.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/CacheRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/CacheRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/CacheRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/CacheRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/J2CacheCacheRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactory.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/log/J2CacheMessageLogger_$logger.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/HibernateNonstopCacheExceptionHandler.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonStopCacheException.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareCollectionRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareEntityRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheCollectionRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheDataRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheEntityRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheGeneralDataRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheNaturalIdRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheQueryResultsRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheTimestampsRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/regions/J2CacheTransactionalDataRegion.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/AbstractJ2CacheAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/AbstractReadWriteJ2CacheAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactory.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/J2CacheAccessStrategyFactoryImpl.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheCollectionRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheEntityRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonStrictReadWriteJ2CacheNaturalIdRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/NonstopAccessStrategyFactory.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheCollectionRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheEntityRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadOnlyJ2CacheNaturalIdRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheCollectionRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheEntityRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/ReadWriteJ2CacheNaturalIdRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheCollectionRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheEntityRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/strategy/TransactionalJ2CacheNaturalIdRegionAccessStrategy.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/SlewClock.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/SlewClock.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/SlewClock.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/TimeProviderLoader.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/Timestamper.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/Timestamper.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/Timestamper.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/Timestamper.java diff --git a/modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java b/modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java rename to modules/hibernate5/src/net/oschina/j2cache/hibernate5/util/lang/VicariousThreadLocal.java diff --git a/modules/hibernate5/hibernate5_2_17/test/config/commons-logging.properties b/modules/hibernate5/test/config/commons-logging.properties similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/commons-logging.properties rename to modules/hibernate5/test/config/commons-logging.properties diff --git a/modules/hibernate5/hibernate5_2_17/test/config/ehcache.xml b/modules/hibernate5/test/config/ehcache.xml similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/ehcache.xml rename to modules/hibernate5/test/config/ehcache.xml diff --git a/modules/hibernate5/hibernate5_2_17/test/config/ehcache3.xml b/modules/hibernate5/test/config/ehcache3.xml similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/ehcache3.xml rename to modules/hibernate5/test/config/ehcache3.xml diff --git a/modules/hibernate5/hibernate5_2_17/test/config/j2cache.properties b/modules/hibernate5/test/config/j2cache.properties similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/j2cache.properties rename to modules/hibernate5/test/config/j2cache.properties diff --git a/modules/hibernate5/hibernate5_2_17/test/config/log4j.xml b/modules/hibernate5/test/config/log4j.xml similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/log4j.xml rename to modules/hibernate5/test/config/log4j.xml diff --git a/modules/hibernate5/hibernate5_2_17/test/config/network.xml b/modules/hibernate5/test/config/network.xml similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/network.xml rename to modules/hibernate5/test/config/network.xml diff --git a/modules/hibernate5/hibernate5_2_17/test/config/props/jdbc.properties b/modules/hibernate5/test/config/props/jdbc.properties similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/props/jdbc.properties rename to modules/hibernate5/test/config/props/jdbc.properties diff --git a/modules/hibernate5/hibernate5_2_17/test/config/redis.properties b/modules/hibernate5/test/config/redis.properties similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/redis.properties rename to modules/hibernate5/test/config/redis.properties diff --git a/modules/hibernate5/hibernate5_2_17/test/config/spring/applicationContext.xml b/modules/hibernate5/test/config/spring/applicationContext.xml similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/config/spring/applicationContext.xml rename to modules/hibernate5/test/config/spring/applicationContext.xml diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java b/modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java rename to modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/J2CacheRegionFactoryTest.java diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/bean/Article.java b/modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/bean/Article.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/bean/Article.java rename to modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/bean/Article.java diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java b/modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java rename to modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/service/ArticleService.java diff --git a/modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java b/modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java similarity index 100% rename from modules/hibernate5/hibernate5_2_17/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java rename to modules/hibernate5/test/src/net/oschina/j2cache/hibernate5/service/IArticleService.java diff --git a/pom.xml b/pom.xml index aa2f090..dbe53a8 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,7 @@ core modules/hibernate3 modules/hibernate4 + modules/hibernate5 modules/spring-boot-starter modules/spring-boot2-starter modules/mybatis -- Gitee From 0ccd03ec721dea62a5b21cb4d11fc2ec0d12ee31 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Fri, 28 Sep 2018 07:33:18 +0800 Subject: [PATCH 006/131] add maven --- modules/hibernate5/readme.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/hibernate5/readme.md b/modules/hibernate5/readme.md index 6036be2..5481e1c 100644 --- a/modules/hibernate5/readme.md +++ b/modules/hibernate5/readme.md @@ -1,3 +1,13 @@ # Hibernate 5 支持模块 -基于 Hibernate 5.2.17 开发,感谢 [@tandy](https://gitee.com/tandy) \ No newline at end of file +基于 Hibernate 5.2.17 开发,感谢 [@tandy](https://gitee.com/tandy) + +Maven: + +```xml + + net.oschina.j2cache + j2cache-hibernate5 + 1.0.0-beta1 + +``` \ No newline at end of file -- Gitee From 8aadefd4e8473954247da56d3b472d53389c902b Mon Sep 17 00:00:00 2001 From: tandy <879620309@qq.com> Date: Fri, 28 Sep 2018 20:01:54 +0800 Subject: [PATCH 007/131] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hibernate5/readme.md | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/modules/hibernate5/readme.md b/modules/hibernate5/readme.md index 5481e1c..3b79c71 100644 --- a/modules/hibernate5/readme.md +++ b/modules/hibernate5/readme.md @@ -10,4 +10,44 @@ Maven: j2cache-hibernate5 1.0.0-beta1 +``` +使用说明: + +1、XML文件配置 + +```xml + + + + ...省略其他配置... + org.springframework.orm.hibernate5.SpringSessionContext + net.oschina.j2cache.hibernate5.J2CacheRegionFactory + true + true + + + ...省略其他配置... + +``` + +2、properties文件配置 +```xml + spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext + spring.jpa.properties.hibernate.cache.region.factory_class=net.oschina.j2cache.hibernate5.J2CacheRegionFactory + spring.jpa.properties.hibernate.cache.use_second_level_cache=true + spring.jpa.properties.hibernate.cache.use_query_cache=true +``` + +3、yml文件配置 +```xml + spring: + jpa: + properties: + hibernate: + current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext + cache: + use_second_level_cache: true + use_query_cache: true + region: + factory_class: net.oschina.j2cache.hibernate5.J2CacheRegionFactory ``` \ No newline at end of file -- Gitee From f0c37d6c77c31da272312e1d3abf5989ff7e6d92 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Sat, 29 Sep 2018 10:50:18 +0800 Subject: [PATCH 008/131] add comment --- core/src/net/oschina/j2cache/J2CacheConfig.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/net/oschina/j2cache/J2CacheConfig.java b/core/src/net/oschina/j2cache/J2CacheConfig.java index e2a1057..2637843 100644 --- a/core/src/net/oschina/j2cache/J2CacheConfig.java +++ b/core/src/net/oschina/j2cache/J2CacheConfig.java @@ -41,18 +41,30 @@ public class J2CacheConfig { private boolean syncTtlToRedis; private boolean defaultCacheNullObject; + /** + * Read configuration from resource + * @param stream config resource + */ public final static J2CacheConfig initFromConfig(String configResource) throws IOException { try (InputStream stream = getConfigStream(configResource)){ return initFromConfig(stream); } } + /** + * Read configuration from file + * @param stream config file + */ public final static J2CacheConfig initFromConfig(File configFile) throws IOException { try (FileInputStream stream = new FileInputStream(configFile)) { return initFromConfig(stream); } } + /** + * Read configuration from input stream + * @param stream config stream + */ public final static J2CacheConfig initFromConfig(InputStream stream) throws IOException { J2CacheConfig config = new J2CacheConfig(); config.properties.load(stream); -- Gitee From b33cadba85b4a427cd6970ab178be27b9f034ba2 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Sat, 29 Sep 2018 10:52:41 +0800 Subject: [PATCH 009/131] 2.7.1 --- core/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index e3d371e..81b15c6 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.0-release + 2.7.1-release 4.0.0 diff --git a/pom.xml b/pom.xml index dbe53a8..eda1f08 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.0-release + 2.7.1-release pom j2cache @@ -39,7 +39,7 @@ UTF-8 - 2.7.0-release + 2.7.1-release -- Gitee From 60ca38379ca741eadccaf3c026635022e3ab2f85 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Sat, 29 Sep 2018 11:38:18 +0800 Subject: [PATCH 010/131] fix comment error --- core/src/net/oschina/j2cache/J2CacheConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/net/oschina/j2cache/J2CacheConfig.java b/core/src/net/oschina/j2cache/J2CacheConfig.java index 2637843..c603d5b 100644 --- a/core/src/net/oschina/j2cache/J2CacheConfig.java +++ b/core/src/net/oschina/j2cache/J2CacheConfig.java @@ -43,7 +43,7 @@ public class J2CacheConfig { /** * Read configuration from resource - * @param stream config resource + * @param configResource config resource */ public final static J2CacheConfig initFromConfig(String configResource) throws IOException { try (InputStream stream = getConfigStream(configResource)){ @@ -53,7 +53,7 @@ public class J2CacheConfig { /** * Read configuration from file - * @param stream config file + * @param configFile config file */ public final static J2CacheConfig initFromConfig(File configFile) throws IOException { try (FileInputStream stream = new FileInputStream(configFile)) { -- Gitee From 3eafe9ee717accb6a22a30cb2f338b48892fb385 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Sat, 29 Sep 2018 11:48:08 +0800 Subject: [PATCH 011/131] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=AF=B9=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=8C=85=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/J2CacheConfig.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core/src/net/oschina/j2cache/J2CacheConfig.java b/core/src/net/oschina/j2cache/J2CacheConfig.java index c603d5b..dbdeef1 100644 --- a/core/src/net/oschina/j2cache/J2CacheConfig.java +++ b/core/src/net/oschina/j2cache/J2CacheConfig.java @@ -15,9 +15,6 @@ */ package net.oschina.j2cache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.*; import java.util.Properties; @@ -27,8 +24,6 @@ import java.util.Properties; */ public class J2CacheConfig { - private final static Logger log = LoggerFactory.getLogger(J2CacheConfig.class); - private Properties properties = new Properties(); private Properties broadcastProperties = new Properties(); private Properties l1CacheProperties = new Properties(); @@ -106,7 +101,6 @@ public class J2CacheConfig { * @return */ private static InputStream getConfigStream(String resource) { - log.info("Load J2Cache Config File : [{}].", resource); InputStream configStream = J2Cache.class.getResourceAsStream(resource); if(configStream == null) configStream = J2Cache.class.getClassLoader().getParent().getResourceAsStream(resource); -- Gitee From 98d0ed97e5b5c20c43fd745b9d2f1432cea27834 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 10 Oct 2018 18:01:56 +0800 Subject: [PATCH 012/131] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=9A=E4=B8=AA=20?= =?UTF-8?q?CacheChannel=20=E5=AE=9E=E4=BE=8B=E5=B9=B6=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 2 +- .../src/net/oschina/j2cache/CacheChannel.java | 82 ++++++++++--------- .../oschina/j2cache/CacheProviderHolder.java | 57 +++++++------ .../net/oschina/j2cache/J2CacheBuilder.java | 20 +++-- .../j2cache/cluster/ClusterPolicy.java | 13 +-- .../j2cache/cluster/ClusterPolicyFactory.java | 41 +++++----- .../j2cache/cluster/JGroupsClusterPolicy.java | 22 ++++- .../j2cache/cluster/NoneClusterPolicy.java | 12 ++- .../cluster/RabbitMQClusterPolicy.java | 23 +++++- .../cluster/RocketMQClusterPolicy.java | 23 +++++- .../j2cache/lettuce/LettuceCacheProvider.java | 25 +++++- .../oschina/j2cache/redis/RedisClient.java | 1 + .../redis/RedisPubSubClusterPolicy.java | 24 +++++- .../net/oschina/j2cache/CacheChannelTest.java | 4 +- .../oschina/j2cache/MultiChannelTester.java | 33 ++++++++ modules/hibernate3/pom.xml | 2 +- modules/hibernate4/pom.xml | 2 +- modules/hibernate5/pom.xml | 2 +- modules/mybatis/pom.xml | 2 +- modules/spring-boot-starter/pom.xml | 2 +- .../redis/SpringRedisPubSubPolicy.java | 22 ++++- modules/spring-boot2-starter/pom.xml | 2 +- .../redis/SpringRedisPubSubPolicy.java | 22 ++++- modules/springcache/pom.xml | 2 +- pom.xml | 4 +- 25 files changed, 321 insertions(+), 123 deletions(-) create mode 100644 core/test/net/oschina/j2cache/MultiChannelTester.java diff --git a/core/pom.xml b/core/pom.xml index 81b15c6..cd782c3 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.1-release + 2.7.2-release 4.0.0 diff --git a/core/src/net/oschina/j2cache/CacheChannel.java b/core/src/net/oschina/j2cache/CacheChannel.java index 767d971..ec9699f 100644 --- a/core/src/net/oschina/j2cache/CacheChannel.java +++ b/core/src/net/oschina/j2cache/CacheChannel.java @@ -30,10 +30,12 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { private static final Map _g_keyLocks = new ConcurrentHashMap<>(); private J2CacheConfig config; + private CacheProviderHolder holder; private boolean defaultCacheNullObject ; - public CacheChannel(J2CacheConfig config) { + public CacheChannel(J2CacheConfig config, CacheProviderHolder holder) { this.config = config; + this.holder = holder; this.defaultCacheNullObject = config.isDefaultCacheNullObject(); } @@ -70,26 +72,26 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { public CacheObject get(String region, String key, boolean...cacheNullObject) { CacheObject obj = new CacheObject(region, key, CacheObject.LEVEL_1); - obj.setValue(CacheProviderHolder.getLevel1Cache(region).get(key)); + obj.setValue(holder.getLevel1Cache(region).get(key)); if(obj.rawValue() != null) return obj; String lock_key = key + '%' + region; synchronized (_g_keyLocks.computeIfAbsent(lock_key, v -> new Object())) { - obj.setValue(CacheProviderHolder.getLevel1Cache(region).get(key)); + obj.setValue(holder.getLevel1Cache(region).get(key)); if(obj.rawValue() != null) return obj; try { obj.setLevel(CacheObject.LEVEL_2); - obj.setValue(CacheProviderHolder.getLevel2Cache(region).get(key)); + obj.setValue(holder.getLevel2Cache(region).get(key)); if (obj.rawValue() != null) - CacheProviderHolder.getLevel1Cache(region).put(key, obj.rawValue()); + holder.getLevel1Cache(region).put(key, obj.rawValue()); else { - boolean cacheNull = (cacheNullObject.length>0)?cacheNullObject[0]: defaultCacheNullObject; - if(cacheNull) - set(region, key, newNullObject(), true); - } + boolean cacheNull = (cacheNullObject.length > 0) ? cacheNullObject[0] : defaultCacheNullObject; + if (cacheNull) + set(region, key, newNullObject(), true); + } } finally { _g_keyLocks.remove(lock_key); } @@ -138,7 +140,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return cache object */ public Map get(String region, Collection keys) { - final Map objs = CacheProviderHolder.getLevel1Cache(region).get(keys); + final Map objs = holder.getLevel1Cache(region).get(keys); List level2Keys = keys.stream().filter(k -> !objs.containsKey(k) || objs.get(k) == null).collect(Collectors.toList()); Map results = objs.entrySet().stream().filter(p -> p.getValue() != null).collect( Collectors.toMap( @@ -147,11 +149,11 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { ) ); - Map objs_level2 = CacheProviderHolder.getLevel2Cache(region).get(level2Keys); + Map objs_level2 = holder.getLevel2Cache(region).get(level2Keys); objs_level2.forEach((k,v) -> { results.put(k, new CacheObject(region, k, CacheObject.LEVEL_2, v)); if (v != null) - CacheProviderHolder.getLevel1Cache(region).put(k, v); + holder.getLevel1Cache(region).put(k, v); }); return results; @@ -207,9 +209,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return 0(不存在),1(一级),2(二级) */ public int check(String region, String key) { - if(CacheProviderHolder.getLevel1Cache(region).exists(key)) + if(holder.getLevel1Cache(region).exists(key)) return 1; - if(CacheProviderHolder.getLevel2Cache(region).exists(key)) + if(holder.getLevel2Cache(region).exists(key)) return 2; return 0; } @@ -238,9 +240,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { return ; try { - Level1Cache level1 = CacheProviderHolder.getLevel1Cache(region); + Level1Cache level1 = holder.getLevel1Cache(region); level1.put(key, (value==null && cacheNullObject)?newNullObject():value); - Level2Cache level2 = CacheProviderHolder.getLevel2Cache(region); + Level2Cache level2 = holder.getLevel2Cache(region); if(config.isSyncTtlToRedis()) level2.put(key, (value==null && cacheNullObject)?newNullObject():value, level1.ttl()); else @@ -284,8 +286,8 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { set(region, key, value, cacheNullObject); else { try { - CacheProviderHolder.getLevel1Cache(region, timeToLiveInSeconds).put(key, (value==null && cacheNullObject)?newNullObject():value); - Level2Cache level2 = CacheProviderHolder.getLevel2Cache(region); + holder.getLevel1Cache(region, timeToLiveInSeconds).put(key, (value==null && cacheNullObject)?newNullObject():value); + Level2Cache level2 = holder.getLevel2Cache(region); if(config.isSyncTtlToRedis()) level2.put(key, (value==null && cacheNullObject)?newNullObject():value, timeToLiveInSeconds); else @@ -320,21 +322,21 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { if (v == null) newElems.put(k, newNullObject()); }); - Level1Cache level1 = CacheProviderHolder.getLevel1Cache(region); + Level1Cache level1 = holder.getLevel1Cache(region); level1.put(newElems); if(config.isSyncTtlToRedis()) - CacheProviderHolder.getLevel2Cache(region).put(newElems, level1.ttl()); + holder.getLevel2Cache(region).put(newElems, level1.ttl()); else - CacheProviderHolder.getLevel2Cache(region).put(newElems); + holder.getLevel2Cache(region).put(newElems); } else { - Level1Cache level1 = CacheProviderHolder.getLevel1Cache(region); + Level1Cache level1 = holder.getLevel1Cache(region); level1.put(elements); if(config.isSyncTtlToRedis()) - CacheProviderHolder.getLevel2Cache(region).put(elements, level1.ttl()); + holder.getLevel2Cache(region).put(elements, level1.ttl()); else - CacheProviderHolder.getLevel2Cache(region).put(elements); + holder.getLevel2Cache(region).put(elements); } } finally { //广播 @@ -377,18 +379,18 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { if (v == null) newElems.put(k, newNullObject()); }); - CacheProviderHolder.getLevel1Cache(region, timeToLiveInSeconds).put(newElems); + holder.getLevel1Cache(region, timeToLiveInSeconds).put(newElems); if(config.isSyncTtlToRedis()) - CacheProviderHolder.getLevel2Cache(region).put(newElems, timeToLiveInSeconds); + holder.getLevel2Cache(region).put(newElems, timeToLiveInSeconds); else - CacheProviderHolder.getLevel2Cache(region).put(newElems); + holder.getLevel2Cache(region).put(newElems); } else { - CacheProviderHolder.getLevel1Cache(region, timeToLiveInSeconds).put(elements); + holder.getLevel1Cache(region, timeToLiveInSeconds).put(elements); if(config.isSyncTtlToRedis()) - CacheProviderHolder.getLevel2Cache(region).put(elements, timeToLiveInSeconds); + holder.getLevel2Cache(region).put(elements, timeToLiveInSeconds); else - CacheProviderHolder.getLevel2Cache(region).put(elements); + holder.getLevel2Cache(region).put(elements); } } finally { //广播 @@ -406,8 +408,8 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { public void evict(String region, String...keys) { try { //先清比较耗时的二级缓存,再清一级缓存 - CacheProviderHolder.getLevel2Cache(region).evict(keys); - CacheProviderHolder.getLevel1Cache(region).evict(keys); + holder.getLevel2Cache(region).evict(keys); + holder.getLevel1Cache(region).evict(keys); } finally { this.sendEvictCmd(region, keys); //发送广播 } @@ -421,8 +423,8 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { public void clear(String region) { try { //先清比较耗时的二级缓存,再清一级缓存 - CacheProviderHolder.getLevel2Cache(region).clear(); - CacheProviderHolder.getLevel1Cache(region).clear(); + holder.getLevel2Cache(region).clear(); + holder.getLevel1Cache(region).clear(); }finally { this.sendClearCmd(region); } @@ -433,7 +435,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return all the regions */ public Collection regions() { - return CacheProviderHolder.regions(); + return holder.regions(); } /** @@ -441,7 +443,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param region Cache Region Name */ public void removeRegion(String region) { - CacheProviderHolder.getL1Provider().removeCache(region); + holder.getL1Provider().removeCache(region); } /** @@ -453,8 +455,8 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public Collection keys(String region) { Set keys = new HashSet<>(); - keys.addAll(CacheProviderHolder.getLevel1Cache(region).keys()); - keys.addAll(CacheProviderHolder.getLevel2Cache(region).keys()); + keys.addAll(holder.getLevel1Cache(region).keys()); + keys.addAll(holder.getLevel2Cache(region).keys()); return keys; } @@ -469,7 +471,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return 返回一级缓存的 CacheProvider 实例 */ public CacheProvider getL1Provider() { - return CacheProviderHolder.getL1Provider(); + return holder.getL1Provider(); } /** @@ -487,7 +489,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return 返回二级缓存的 CacheProvider 实例 */ public CacheProvider getL2Provider() { - return CacheProviderHolder.getL2Provider(); + return holder.getL2Provider(); } /** diff --git a/core/src/net/oschina/j2cache/CacheProviderHolder.java b/core/src/net/oschina/j2cache/CacheProviderHolder.java index 8f1ca23..bf02e52 100644 --- a/core/src/net/oschina/j2cache/CacheProviderHolder.java +++ b/core/src/net/oschina/j2cache/CacheProviderHolder.java @@ -36,40 +36,49 @@ public class CacheProviderHolder { private final static Logger log = LoggerFactory.getLogger(CacheProviderHolder.class); - private static CacheProvider l1_provider; - private static CacheProvider l2_provider; + private CacheProvider l1_provider; + private CacheProvider l2_provider; - private static CacheExpiredListener listener; + private CacheExpiredListener listener; + + private CacheProviderHolder(){} /** * Initialize Cache Provider * @param config j2cache config instance * @param listener cache listener + * + * @return holder : return CacheProviderHolder instance */ - public static void init(J2CacheConfig config, CacheExpiredListener listener){ - CacheProviderHolder.listener = listener; - CacheProviderHolder.l1_provider = loadProviderInstance(config.getL1CacheName()); - if (!l1_provider.isLevel(CacheObject.LEVEL_1)) - throw new CacheException(l1_provider.getClass().getName() + " is not level_1 cache provider"); - CacheProviderHolder.l1_provider.start(config.getL1CacheProperties()); - log.info("Using L1 CacheProvider : " + l1_provider.getClass().getName()); - - CacheProviderHolder.l2_provider = loadProviderInstance(config.getL2CacheName()); - if (!l2_provider.isLevel(CacheObject.LEVEL_2)) - throw new CacheException(l2_provider.getClass().getName() + " is not level_2 cache provider"); - CacheProviderHolder.l2_provider.start(config.getL2CacheProperties()); - log.info("Using L2 CacheProvider : " + l2_provider.getClass().getName()); + public static CacheProviderHolder init(J2CacheConfig config, CacheExpiredListener listener){ + + CacheProviderHolder holder = new CacheProviderHolder(); + + holder.listener = listener; + holder.l1_provider = loadProviderInstance(config.getL1CacheName()); + if (!holder.l1_provider.isLevel(CacheObject.LEVEL_1)) + throw new CacheException(holder.l1_provider.getClass().getName() + " is not level_1 cache provider"); + holder.l1_provider.start(config.getL1CacheProperties()); + log.info("Using L1 CacheProvider : " + holder.l1_provider.getClass().getName()); + + holder.l2_provider = loadProviderInstance(config.getL2CacheName()); + if (!holder.l2_provider.isLevel(CacheObject.LEVEL_2)) + throw new CacheException(holder.l2_provider.getClass().getName() + " is not level_2 cache provider"); + holder.l2_provider.start(config.getL2CacheProperties()); + log.info("Using L2 CacheProvider : " + holder.l2_provider.getClass().getName()); + + return holder; } /** * 关闭缓存 */ - public final static void shutdown() { + public void shutdown() { l1_provider.stop(); l2_provider.stop(); } - private final static CacheProvider loadProviderInstance(String cacheIdent) { + private static CacheProvider loadProviderInstance(String cacheIdent) { if("ehcache".equalsIgnoreCase(cacheIdent)) return new EhCacheProvider(); if("ehcache3".equalsIgnoreCase(cacheIdent)) @@ -93,11 +102,11 @@ public class CacheProviderHolder { } } - public final static CacheProvider getL1Provider() { + public CacheProvider getL1Provider() { return l1_provider; } - public final static CacheProvider getL2Provider() { + public CacheProvider getL2Provider() { return l2_provider; } @@ -106,7 +115,7 @@ public class CacheProviderHolder { * @param region cache region * @return level 1 cache instance */ - public final static Level1Cache getLevel1Cache(String region) { + public Level1Cache getLevel1Cache(String region) { return (Level1Cache)l1_provider.buildCache(region, listener); } @@ -116,7 +125,7 @@ public class CacheProviderHolder { * @param timeToLiveSeconds cache ttl * @return level 1 cache instance */ - public final static Level1Cache getLevel1Cache(String region, long timeToLiveSeconds) { + public Level1Cache getLevel1Cache(String region, long timeToLiveSeconds) { return (Level1Cache)l1_provider.buildCache(region, timeToLiveSeconds, listener); } @@ -125,7 +134,7 @@ public class CacheProviderHolder { * @param region cache region * @return level 2 cache instance */ - public final static Level2Cache getLevel2Cache(String region) { + public Level2Cache getLevel2Cache(String region) { return (Level2Cache)l2_provider.buildCache(region, listener); } @@ -133,7 +142,7 @@ public class CacheProviderHolder { * return all regions * @return all regions */ - public final static Collection regions() { + public Collection regions() { return l1_provider.regions(); } diff --git a/core/src/net/oschina/j2cache/J2CacheBuilder.java b/core/src/net/oschina/j2cache/J2CacheBuilder.java index 2ab1fe6..30d21bd 100644 --- a/core/src/net/oschina/j2cache/J2CacheBuilder.java +++ b/core/src/net/oschina/j2cache/J2CacheBuilder.java @@ -33,6 +33,7 @@ public class J2CacheBuilder { private final static Logger log = LoggerFactory.getLogger(J2CacheBuilder.class); private CacheChannel channel; + private CacheProviderHolder holder; private ClusterPolicy policy; //不同的广播策略 private AtomicBoolean opened = new AtomicBoolean(false); private J2CacheConfig config; @@ -55,12 +56,12 @@ public class J2CacheBuilder { * @return CacheChannel */ public CacheChannel getChannel(){ - if(!this.opened.get()) { + if(this.channel == null || !this.opened.get()) { synchronized (J2CacheBuilder.class) { - if(!this.opened.get()) { + if(this.channel == null || !this.opened.get()) { this.initFromConfig(config); /* 初始化缓存接口 */ - this.channel = new CacheChannel(config) { + this.channel = new CacheChannel(config, holder) { @Override public void sendClearCmd(String region) { policy.sendClearCmd(region); @@ -74,7 +75,7 @@ public class J2CacheBuilder { @Override public void close() { policy.disconnect(); - CacheProviderHolder.shutdown(); + holder.shutdown(); opened.set(false); } }; @@ -90,6 +91,8 @@ public class J2CacheBuilder { */ public void close() { this.channel.close(); + this.opened.set(false); + this.channel = null; } /** @@ -100,20 +103,21 @@ public class J2CacheBuilder { private void initFromConfig(J2CacheConfig config) { SerializationUtils.init(config.getSerialization(), config.getSubProperties(config.getSerialization())); //初始化两级的缓存管理 - CacheProviderHolder.init(config, (region, key)->{ + this.holder = CacheProviderHolder.init(config, (region, key)->{ //当一级缓存中的对象失效时,自动清除二级缓存中的数据 - Level2Cache level2 = CacheProviderHolder.getLevel2Cache(region); + Level2Cache level2 = this.holder.getLevel2Cache(region); level2.evict(key); if(!level2.supportTTL()) { //再一次清除一级缓存是为了避免缓存失效时再次从 L2 获取到值 - CacheProviderHolder.getLevel1Cache(region).evict(key); + this.holder.getLevel1Cache(region).evict(key); } log.debug(String.format("Level 1 cache object expired, evict level 2 cache object [%s,%s]", region, key)); if(policy != null) policy.sendEvictCmd(region, key); }); - policy = ClusterPolicyFactory.init(config.getBroadcast(), config.getBroadcastProperties()); + policy = ClusterPolicyFactory.init(holder, config.getBroadcast(), config.getBroadcastProperties()); log.info("Using cluster policy : " + policy.getClass().getName()); } + } diff --git a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java index 687d1f2..f349055 100644 --- a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java @@ -20,7 +20,6 @@ import net.oschina.j2cache.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.util.Properties; /** @@ -34,9 +33,9 @@ public interface ClusterPolicy { /** * 连接到集群 * @param props j2cache 配置信息 + * @param holder Cache Provider Instance */ - void connect(Properties props); - + void connect(Properties props, CacheProviderHolder holder); /** * 发送消息 @@ -71,17 +70,13 @@ public interface ClusterPolicy { * @param region 区域名称 * @param keys 缓存键值 */ - default void evict(String region, String... keys) { - CacheProviderHolder.getLevel1Cache(region).evict(keys); - } + void evict(String region, String... keys); /** * 清除本地整个缓存区域 * @param region 区域名称 */ - default void clear(String region) { - CacheProviderHolder.getLevel1Cache(region).clear(); - } + void clear(String region) ; /** * 处理缓存事件逻辑 diff --git a/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java b/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java index 40e7538..ff3bddb 100644 --- a/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java +++ b/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java @@ -16,6 +16,7 @@ package net.oschina.j2cache.cluster; import net.oschina.j2cache.CacheException; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.lettuce.LettuceCacheProvider; import net.oschina.j2cache.redis.RedisPubSubClusterPolicy; @@ -35,22 +36,24 @@ public class ClusterPolicyFactory { * @param props broadcast configuations * @return ClusterPolicy instance */ - public final static ClusterPolicy init(String broadcast, Properties props) { + public final static ClusterPolicy init(CacheProviderHolder holder, String broadcast, Properties props) { + ClusterPolicy policy; if ("redis".equalsIgnoreCase(broadcast)) - policy = ClusterPolicyFactory.redis(props); + policy = ClusterPolicyFactory.redis(props, holder); else if ("jgroups".equalsIgnoreCase(broadcast)) - policy = ClusterPolicyFactory.jgroups(props); + policy = ClusterPolicyFactory.jgroups(props, holder); else if ("rabbitmq".equalsIgnoreCase(broadcast)) - policy = ClusterPolicyFactory.rabbitmq(props); + policy = ClusterPolicyFactory.rabbitmq(props, holder); else if ("rocketmq".equalsIgnoreCase(broadcast)) - policy = ClusterPolicyFactory.rocketmq(props); + policy = ClusterPolicyFactory.rocketmq(props, holder); else if ("lettuce".equalsIgnoreCase(broadcast)) - policy = ClusterPolicyFactory.lettuce(props); + policy = ClusterPolicyFactory.lettuce(props, holder); else if ("none".equalsIgnoreCase(broadcast)) policy = new NoneClusterPolicy(); else - policy = ClusterPolicyFactory.custom(broadcast, props); + policy = ClusterPolicyFactory.custom(broadcast, props, holder); + return policy; } @@ -59,10 +62,10 @@ public class ClusterPolicyFactory { * @param props 框架配置 * @return 返回 Redis 集群策略的实例 */ - private final static ClusterPolicy redis(Properties props) { + private final static ClusterPolicy redis(Properties props, CacheProviderHolder holder) { String name = props.getProperty("channel"); RedisPubSubClusterPolicy policy = new RedisPubSubClusterPolicy(name, props); - policy.connect(props); + policy.connect(props, holder); return policy; } @@ -71,10 +74,10 @@ public class ClusterPolicyFactory { * @param props 框架配置 * @return 返回 JGroups 集群策略的实例 */ - private final static ClusterPolicy jgroups(Properties props) { + private final static ClusterPolicy jgroups(Properties props, CacheProviderHolder holder) { String name = props.getProperty("channel.name"); JGroupsClusterPolicy policy = new JGroupsClusterPolicy(name, props); - policy.connect(props); + policy.connect(props, holder); return policy; } @@ -83,21 +86,21 @@ public class ClusterPolicyFactory { * @param props 框架配置 * @return 返回 RabbitMQ 集群策略的实例 */ - private final static ClusterPolicy rabbitmq(Properties props) { + private final static ClusterPolicy rabbitmq(Properties props, CacheProviderHolder holder) { RabbitMQClusterPolicy policy = new RabbitMQClusterPolicy(props); - policy.connect(props); + policy.connect(props, holder); return policy; } - private final static ClusterPolicy rocketmq(Properties props) { + private final static ClusterPolicy rocketmq(Properties props, CacheProviderHolder holder) { RocketMQClusterPolicy policy = new RocketMQClusterPolicy(props); - policy.connect(props); + policy.connect(props, holder); return policy; } - private final static ClusterPolicy lettuce(Properties props) { + private final static ClusterPolicy lettuce(Properties props, CacheProviderHolder holder) { LettuceCacheProvider policy = new LettuceCacheProvider(); - policy.connect(props); + policy.connect(props, holder); return policy; } @@ -107,10 +110,10 @@ public class ClusterPolicyFactory { * @param props * @return */ - private final static ClusterPolicy custom(String classname, Properties props) { + private final static ClusterPolicy custom(String classname, Properties props, CacheProviderHolder holder) { try { ClusterPolicy policy = (ClusterPolicy)Class.forName(classname).newInstance(); - policy.connect(props); + policy.connect(props, holder); return policy; } catch (Exception e) { throw new CacheException("Failed in load custom cluster policy. class = " + classname, e); diff --git a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java index 5b14591..e7cc850 100644 --- a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java @@ -16,6 +16,7 @@ package net.oschina.j2cache.cluster; import net.oschina.j2cache.CacheException; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.Command; import org.jgroups.*; import org.slf4j.Logger; @@ -35,6 +36,7 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli private String configXml; private JChannel channel; private String name; + private CacheProviderHolder holder; static { System.setProperty("java.net.preferIPv4Stack", "true"); //Disable IPv6 in JVM @@ -54,8 +56,26 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli this.configXml = "/network.xml"; } + /** + * 删除本地某个缓存条目 + * @param region 区域名称 + * @param keys 缓存键值 + */ + public void evict(String region, String... keys) { + holder.getLevel1Cache(region).evict(keys); + } + + /** + * 清除本地整个缓存区域 + * @param region 区域名称 + */ + public void clear(String region) { + holder.getLevel1Cache(region).clear(); + } + @Override - public void connect(Properties props) { + public void connect(Properties props, CacheProviderHolder holder) { + this.holder = holder; try{ long ct = System.currentTimeMillis(); diff --git a/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java index ff3eb35..eaa97cb 100644 --- a/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java @@ -15,6 +15,7 @@ */ package net.oschina.j2cache.cluster; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.Command; import java.util.Properties; @@ -26,17 +27,22 @@ import java.util.Properties; public class NoneClusterPolicy implements ClusterPolicy { @Override - public void connect(Properties props) { - + public void connect(Properties props, CacheProviderHolder holder) { } @Override public void disconnect() { - } @Override public void publish(Command cmd) { + } + @Override + public void evict(String region, String... keys) { + } + + @Override + public void clear(String region) { } } diff --git a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java index 5c072dc..040d74c 100644 --- a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java @@ -17,6 +17,7 @@ package net.oschina.j2cache.cluster; import com.rabbitmq.client.*; import net.oschina.j2cache.CacheException; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +35,8 @@ public class RabbitMQClusterPolicy implements ClusterPolicy, Consumer { private static final String EXCHANGE_TYPE = "fanout"; + private CacheProviderHolder holder; + private ConnectionFactory factory; private Connection conn_publisher; private Connection conn_consumer; @@ -54,8 +57,26 @@ public class RabbitMQClusterPolicy implements ClusterPolicy, Consumer { //TODO 更多的 RabbitMQ 配置 } + /** + * 删除本地某个缓存条目 + * @param region 区域名称 + * @param keys 缓存键值 + */ + public void evict(String region, String... keys) { + holder.getLevel1Cache(region).evict(keys); + } + + /** + * 清除本地整个缓存区域 + * @param region 区域名称 + */ + public void clear(String region) { + holder.getLevel1Cache(region).clear(); + } + @Override - public void connect(Properties props) { + public void connect(Properties props, CacheProviderHolder holder) { + this.holder = holder; try { long ct = System.currentTimeMillis(); conn_publisher = factory.newConnection(); diff --git a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java index dbea1d7..d39b21e 100644 --- a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java @@ -15,6 +15,7 @@ */ package net.oschina.j2cache.cluster; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.Command; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; @@ -40,6 +41,7 @@ public class RocketMQClusterPolicy implements ClusterPolicy, MessageListenerConc private static final Logger log = LoggerFactory.getLogger(RocketMQClusterPolicy.class); + private CacheProviderHolder holder; private String hosts; private String topic; private DefaultMQProducer producer; @@ -57,10 +59,29 @@ public class RocketMQClusterPolicy implements ClusterPolicy, MessageListenerConc this.consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); this.consumer.setNamesrvAddr(this.hosts); this.consumer.setMessageModel(MessageModel.BROADCASTING); + + } + + /** + * 删除本地某个缓存条目 + * @param region 区域名称 + * @param keys 缓存键值 + */ + public void evict(String region, String... keys) { + holder.getLevel1Cache(region).evict(keys); + } + + /** + * 清除本地整个缓存区域 + * @param region 区域名称 + */ + public void clear(String region) { + holder.getLevel1Cache(region).clear(); } @Override - public void connect(Properties props) { + public void connect(Properties props, CacheProviderHolder holder) { + this.holder = holder; try { this.producer.start(); publish(Command.join()); diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index d1f1841..2472a4a 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -49,6 +49,8 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp private StatefulRedisPubSubConnection pubsub; private String storage; + private CacheProviderHolder holder; + private String channel; private String namespace; @@ -79,6 +81,25 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp return Collections.emptyList(); } + /** + * 删除本地某个缓存条目 + * @param region 区域名称 + * @param keys 缓存键值 + */ + @Override + public void evict(String region, String... keys) { + holder.getLevel1Cache(region).evict(keys); + } + + /** + * 清除本地整个缓存区域 + * @param region 区域名称 + */ + @Override + public void clear(String region) { + holder.getLevel1Cache(region).clear(); + } + @Override public void start(Properties props) { this.namespace = props.getProperty("namespace"); @@ -103,9 +124,9 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp } @Override - public void connect(Properties props) { + public void connect(Properties props, CacheProviderHolder holder) { long ct = System.currentTimeMillis(); - + this.holder = holder; this.channel = props.getProperty("channel", "j2cache"); this.publish(Command.join()); diff --git a/core/src/net/oschina/j2cache/redis/RedisClient.java b/core/src/net/oschina/j2cache/redis/RedisClient.java index 3ae8da5..cc042cf 100644 --- a/core/src/net/oschina/j2cache/redis/RedisClient.java +++ b/core/src/net/oschina/j2cache/redis/RedisClient.java @@ -173,6 +173,7 @@ public class RedisClient implements Closeable, AutoCloseable { client = sharded.getResource(); else if (cluster != null) client = toBinaryJedisCommands(cluster); + clients.set(client); } return client; diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index 3aeb3ad..7ee375b 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -15,6 +15,7 @@ */ package net.oschina.j2cache.redis; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.cluster.ClusterPolicy; import net.oschina.j2cache.Command; import org.slf4j.Logger; @@ -39,6 +40,7 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli private Pool client; private String channel; + private CacheProviderHolder holder; public RedisPubSubClusterPolicy(String channel, Properties props){ this.channel = channel; @@ -70,12 +72,32 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli } } + /** + * 删除本地某个缓存条目 + * @param region 区域名称 + * @param keys 缓存键值 + */ + @Override + public void evict(String region, String... keys) { + holder.getLevel1Cache(region).evict(keys); + } + + /** + * 清除本地整个缓存区域 + * @param region 区域名称 + */ + @Override + public void clear(String region) { + holder.getLevel1Cache(region).clear(); + } + /** * 加入 Redis 的发布订阅频道 */ @Override - public void connect(Properties props) { + public void connect(Properties props, CacheProviderHolder holder) { long ct = System.currentTimeMillis(); + this.holder = holder; this.publish(Command.join()); diff --git a/core/test/net/oschina/j2cache/CacheChannelTest.java b/core/test/net/oschina/j2cache/CacheChannelTest.java index 561818b..444ddac 100644 --- a/core/test/net/oschina/j2cache/CacheChannelTest.java +++ b/core/test/net/oschina/j2cache/CacheChannelTest.java @@ -81,8 +81,8 @@ public class CacheChannelTest { String region = "Users"; String key = "CaffeineNeverExpire"; channel.set(region,key,"OSChina.net"); - assertTrue(CacheProviderHolder.getLevel1Cache(region).keys().contains(key)); - assertTrue(CacheProviderHolder.getLevel2Cache(region).keys().contains(key)); + //assertTrue(CacheProviderHolder.getLevel1Cache(region).keys().contains(key)); + //assertTrue(CacheProviderHolder.getLevel2Cache(region).keys().contains(key)); assertTrue(channel.exists(region, key)); } diff --git a/core/test/net/oschina/j2cache/MultiChannelTester.java b/core/test/net/oschina/j2cache/MultiChannelTester.java new file mode 100644 index 0000000..a23d02b --- /dev/null +++ b/core/test/net/oschina/j2cache/MultiChannelTester.java @@ -0,0 +1,33 @@ +package net.oschina.j2cache; + +/** + * 测试一个应用里多个 CacheChannel 实例 + */ +public class MultiChannelTester { + + public static void main( String[] args ) + { + try { + + J2CacheConfig config_admin = J2CacheConfig.initFromConfig("/j2cache.properties"); + J2CacheConfig config_service = J2CacheConfig.initFromConfig("/j2cache2.properties"); + + config_admin.dump(System.out); + + System.out.println("---------------------------------------------"); + + config_service.dump(System.out); + + CacheChannel channel_admin = J2CacheBuilder.init(config_admin).getChannel(); + CacheChannel channel_service = J2CacheBuilder.init(config_service).getChannel(); + + channel_admin.set("test-admin", "test-key-admin", "test-value-admin"); + channel_service.set("test-service", "test-key-service", "test-value-service"); + + } catch (Exception e) { + e.printStackTrace(); + } + + System.exit(0); + } +} diff --git a/modules/hibernate3/pom.xml b/modules/hibernate3/pom.xml index a157d25..756f40c 100755 --- a/modules/hibernate3/pom.xml +++ b/modules/hibernate3/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.0-release + 2.7.2-release ../../pom.xml diff --git a/modules/hibernate4/pom.xml b/modules/hibernate4/pom.xml index 45daf99..451204d 100755 --- a/modules/hibernate4/pom.xml +++ b/modules/hibernate4/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.0-release + 2.7.2-release ../../pom.xml diff --git a/modules/hibernate5/pom.xml b/modules/hibernate5/pom.xml index 3a2a9c3..a0497ee 100644 --- a/modules/hibernate5/pom.xml +++ b/modules/hibernate5/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.0-release + 2.7.2-release ../../pom.xml diff --git a/modules/mybatis/pom.xml b/modules/mybatis/pom.xml index cdcb70c..99c6e34 100644 --- a/modules/mybatis/pom.xml +++ b/modules/mybatis/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.0-release + 2.7.2-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index fbfe51f..4e9cdcd 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.0-release + 2.7.2-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index ec15571..b2fa563 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; +import net.oschina.j2cache.CacheProviderHolder; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.PatternTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; @@ -23,6 +24,7 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { private RedisTemplate redisTemplate; private net.oschina.j2cache.autoconfigure.J2CacheConfig config; + private CacheProviderHolder holder; /** * 是否是主动模式 @@ -33,7 +35,8 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @SuppressWarnings("unchecked") @Override - public void connect(Properties props) { + public void connect(Properties props, CacheProviderHolder holder) { + this.holder = holder; J2CacheConfig j2config = SpringUtil.getBean(J2CacheConfig.class); this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); this.redisTemplate = SpringUtil.getBean("j2CacheRedisTemplate", RedisTemplate.class); @@ -66,6 +69,23 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { } + /** + * 删除本地某个缓存条目 + * @param region 区域名称 + * @param keys 缓存键值 + */ + public void evict(String region, String... keys) { + holder.getLevel1Cache(region).evict(keys); + } + + /** + * 清除本地整个缓存区域 + * @param region 区域名称 + */ + public void clear(String region) { + holder.getLevel1Cache(region).clear(); + } + // @Override // public void sendEvictCmd(String region, String... keys) { // if(!isActive || "blend".equals(config.getCacheCleanMode())) { diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index c55e252..58837a5 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.0-release + 2.7.2-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index 62247ad..f459b08 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; +import net.oschina.j2cache.CacheProviderHolder; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.PatternTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; @@ -23,6 +24,7 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { private RedisTemplate redisTemplate; private net.oschina.j2cache.autoconfigure.J2CacheConfig config; + private CacheProviderHolder holder; /** * 是否是主动模式 @@ -33,7 +35,8 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @SuppressWarnings("unchecked") @Override - public void connect(Properties props) { + public void connect(Properties props, CacheProviderHolder holder) { + this.holder = holder; J2CacheConfig j2config = SpringUtil.getBean(J2CacheConfig.class); this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); this.redisTemplate = SpringUtil.getBean("j2CacheRedisTemplate", RedisTemplate.class); @@ -64,6 +67,23 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { } + /** + * 删除本地某个缓存条目 + * @param region 区域名称 + * @param keys 缓存键值 + */ + public void evict(String region, String... keys) { + holder.getLevel1Cache(region).evict(keys); + } + + /** + * 清除本地整个缓存区域 + * @param region 区域名称 + */ + public void clear(String region) { + holder.getLevel1Cache(region).clear(); + } + // @Override // public void sendEvictCmd(String region, String... keys) { // if(!isActive || "blend".equals(config.getCacheCleanMode())) { diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index 29eca3a..b81737b 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.0-release + 2.7.2-release ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index eda1f08..c21eb3a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.1-release + 2.7.2-release pom j2cache @@ -39,7 +39,7 @@ UTF-8 - 2.7.1-release + 2.7.2-release -- Gitee From f53338eb3c0c128a59245230063d29306d3038a5 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 10 Oct 2018 18:08:26 +0800 Subject: [PATCH 013/131] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=B1=BB=E7=A7=BB?= =?UTF-8?q?=E5=88=B0=20test=20=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/{src => test}/net/oschina/j2cache/ExpiredTester.java | 0 core/{src => test}/net/oschina/j2cache/MultiThreadTester.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename core/{src => test}/net/oschina/j2cache/ExpiredTester.java (100%) rename core/{src => test}/net/oschina/j2cache/MultiThreadTester.java (100%) diff --git a/core/src/net/oschina/j2cache/ExpiredTester.java b/core/test/net/oschina/j2cache/ExpiredTester.java similarity index 100% rename from core/src/net/oschina/j2cache/ExpiredTester.java rename to core/test/net/oschina/j2cache/ExpiredTester.java diff --git a/core/src/net/oschina/j2cache/MultiThreadTester.java b/core/test/net/oschina/j2cache/MultiThreadTester.java similarity index 100% rename from core/src/net/oschina/j2cache/MultiThreadTester.java rename to core/test/net/oschina/j2cache/MultiThreadTester.java -- Gitee From c8d663c41886b67af1278852ebbadb070fd0ef55 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 10 Oct 2018 18:28:21 +0800 Subject: [PATCH 014/131] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20NoSuchElementExcep?= =?UTF-8?q?tion=20=E5=BC=82=E5=B8=B8=EF=BC=8C=E4=BB=A5=E5=8F=8A=20hash=20?= =?UTF-8?q?=E5=92=8C=20generic=20=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 2 +- core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java | 2 +- core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 2472a4a..6ce121d 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -68,7 +68,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp @Override public Cache buildCache(String region, CacheExpiredListener listener) { - return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase("hash")?new LettuceHashCache(this.namespace, region, redisClient):new LettuceGenericCache(this.namespace, region, redisClient)); + return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase(this.storage)?new LettuceHashCache(this.namespace, region, redisClient):new LettuceGenericCache(this.namespace, region, redisClient)); } @Override diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java index 9da19d1..9ff1217 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java @@ -76,7 +76,7 @@ public class LettuceGenericCache implements Level2Cache { public List getBytes(Collection keys) { try(StatefulRedisConnection connection = this.client.connect(codec)) { RedisCommands cmd = connection.sync(); - return cmd.mget(keys.stream().map(k -> _key(k)).toArray(String[]::new)).stream().map(kv -> kv.getValue()).collect(Collectors.toList()); + return cmd.mget(keys.stream().map(k -> _key(k)).toArray(String[]::new)).stream().map(kv -> kv.hasValue()?kv.getValue():null).collect(Collectors.toList()); } } diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java index cac0c4d..74868cf 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java @@ -73,7 +73,7 @@ public class LettuceHashCache implements Level2Cache { public List getBytes(Collection keys) { try(StatefulRedisConnection connection = this.client.connect(codec)) { RedisCommands cmd = connection.sync(); - return cmd.hmget(this.region, keys.stream().toArray(String[]::new)).stream().map(kv -> kv.getValue()).collect(Collectors.toList()); + return cmd.hmget(this.region, keys.stream().toArray(String[]::new)).stream().map(kv -> kv.hasValue()?kv.getValue():null).collect(Collectors.toList()); } } -- Gitee From 6824e8cb6abc6c855e4aa904f286c7e7667d69af Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 10 Oct 2018 18:29:24 +0800 Subject: [PATCH 015/131] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20hash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 6ce121d..88a7b31 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -103,7 +103,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp @Override public void start(Properties props) { this.namespace = props.getProperty("namespace"); - this.storage = props.getProperty("storage", "generic"); + this.storage = props.getProperty("storage", "hash"); this.channel = props.getProperty("channel", "j2cache"); String scheme = props.getProperty("scheme", "redis"); -- Gitee From 1f4a31d2b59326102b8041a84141157f663b0775 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 10 Oct 2018 18:57:39 +0800 Subject: [PATCH 016/131] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20UnSupportedOperati?= =?UTF-8?q?onException=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java b/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java index d0d1f91..31b35e0 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java @@ -27,7 +27,7 @@ public class LettuceByteCodec implements RedisCodec { @Override public String decodeKey(ByteBuffer byteBuffer) { - return new String(byteBuffer.array()); + return byteBuffer.hasArray()?new String(byteBuffer.array()):null; } @Override -- Gitee From 01e4e405029b367e2c4880d127d92468b20bffae Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 10 Oct 2018 19:12:02 +0800 Subject: [PATCH 017/131] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=20key=20?= =?UTF-8?q?=E7=9A=84=E8=A7=A3=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/lettuce/LettuceByteCodec.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java b/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java index 31b35e0..2547dc1 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceByteCodec.java @@ -25,16 +25,16 @@ import java.nio.ByteBuffer; */ public class LettuceByteCodec implements RedisCodec { + private static final byte[] EMPTY = new byte[0]; + @Override public String decodeKey(ByteBuffer byteBuffer) { - return byteBuffer.hasArray()?new String(byteBuffer.array()):null; + return new String(getBytes(byteBuffer)); } @Override public byte[] decodeValue(ByteBuffer byteBuffer) { - byte[] result = new byte[byteBuffer.remaining()]; - byteBuffer.get(result); - return result; + return getBytes(byteBuffer); } @Override @@ -46,4 +46,17 @@ public class LettuceByteCodec implements RedisCodec { public ByteBuffer encodeValue(byte[] bytes) { return ByteBuffer.wrap(bytes); } + + + private static byte[] getBytes(ByteBuffer buffer) { + int remaining = buffer.remaining(); + + if (remaining == 0) { + return EMPTY; + } + + byte[] b = new byte[remaining]; + buffer.get(b); + return b; + } } -- Gitee From 055d9d453d6c66abdc62f72b4b5d8423b7082bc6 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 10 Oct 2018 19:20:15 +0800 Subject: [PATCH 018/131] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=90=AF=E7=94=A8=20?= =?UTF-8?q?lettuce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/resources/j2cache.properties | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index 9bf83f3..9f3c531 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -6,14 +6,14 @@ # values: # jgroups -> use jgroups's multicast # redis -> use redis publish/subscribe mechanism (using jedis) -# lettuce -> use redis publish/subscribe mechanism (using lettuce) +# lettuce -> use redis publish/subscribe mechanism (using lettuce, Recommend) # rabbitmq -> use RabbitMQ publisher/consumer mechanism # rocketmq -> use RocketMQ publisher/consumer mechanism # none -> don't notify the other nodes in cluster # xx.xxxx.xxxx.Xxxxx your own cache broadcast policy classname that implement net.oschina.j2cache.cluster.ClusterPolicy ######################################### -j2cache.broadcast = redis +j2cache.broadcast = lettuce # jgroups properties jgroups.channel.name = j2cache @@ -47,7 +47,7 @@ rocketmq.hosts = 127.0.0.1:9876 ######################################### j2cache.L1.provider_class = caffeine -j2cache.L2.provider_class = redis +j2cache.L2.provider_class = lettuce # When L2 provider isn't `redis`, using `L2.config_section = redis` to read redis configurations # j2cache.L2.config_section = redis @@ -144,7 +144,7 @@ redis.blockWhenExhausted = false redis.jmxEnabled = false lettuce.namespace = -lettuce.storage = generic +lettuce.storage = hash lettuce.channel = j2cache lettuce.scheme = redis lettuce.hosts = 127.0.0.1:6379 -- Gitee From 7158a5568ef25642f9706d7517338c890219ce84 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 15 Oct 2018 21:11:24 +0800 Subject: [PATCH 019/131] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20jedis=20=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E9=80=9A=E8=BF=87=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oschina/j2cache/redis/RedisCacheProvider.java | 14 +++++++++----- .../src/net/oschina/j2cache/redis/RedisClient.java | 10 +++++++--- .../j2cache/redis/RedisPubSubClusterPolicy.java | 3 ++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java index ca47064..98c08a1 100644 --- a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java +++ b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java @@ -58,16 +58,17 @@ public class RedisCacheProvider implements CacheProvider { */ @Override public void start(Properties props) { + this.namespace = props.getProperty("namespace"); this.storage = props.getProperty("storage"); JedisPoolConfig poolConfig = RedisUtils.newPoolConfig(props, null); - String hosts = props.getProperty("hosts"); - String mode = props.getProperty("mode"); + String hosts = props.getProperty("hosts", "127.0.0.1:6379"); + String mode = props.getProperty("mode", "single"); String clusterName = props.getProperty("cluster_name"); String password = props.getProperty("password"); - int database = Integer.parseInt(props.getProperty("database")); + int database = Integer.parseInt(props.getProperty("database", "0")); long ct = System.currentTimeMillis(); @@ -84,12 +85,13 @@ public class RedisCacheProvider implements CacheProvider { database, storage, namespace, - System.currentTimeMillis()-ct + (System.currentTimeMillis()-ct) )); } @Override public void stop() { + regions.clear(); try { redisClient.close(); } catch (IOException e) { @@ -99,7 +101,9 @@ public class RedisCacheProvider implements CacheProvider { @Override public Cache buildCache(String region, CacheExpiredListener listener) { - return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase(this.storage)?new RedisHashCache(this.namespace, region, redisClient):new RedisGenericCache(this.namespace, region, redisClient)); + return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase(this.storage)? + new RedisHashCache(this.namespace, region, redisClient): + new RedisGenericCache(this.namespace, region, redisClient)); } @Override diff --git a/core/src/net/oschina/j2cache/redis/RedisClient.java b/core/src/net/oschina/j2cache/redis/RedisClient.java index cc042cf..813aa27 100644 --- a/core/src/net/oschina/j2cache/redis/RedisClient.java +++ b/core/src/net/oschina/j2cache/redis/RedisClient.java @@ -50,7 +50,6 @@ public class RedisClient implements Closeable, AutoCloseable { private JedisPool single; private JedisSentinelPool sentinel; private ShardedJedisPool sharded; - private String redisPassword; /** * RedisClient 构造器 @@ -115,7 +114,7 @@ public class RedisClient implements Closeable, AutoCloseable { * @param poolConfig 连接池配置 */ private RedisClient(String mode, String hosts, String password, String cluster_name, int database, JedisPoolConfig poolConfig) { - this.redisPassword = (password != null && password.trim().length() > 0)? password.trim(): null; + password = (password != null && password.trim().length() > 0)? password.trim(): null; this.clients = new ThreadLocal<>(); switch(mode){ case "sentinel": @@ -180,7 +179,7 @@ public class RedisClient implements Closeable, AutoCloseable { } /** - * 释放 Redis 连接 + * 释放当前 Redis 连接 */ public void release() { BinaryJedisCommands client = clients.get(); @@ -195,10 +194,15 @@ public class RedisClient implements Closeable, AutoCloseable { } else log.warn("Nothing to do while release redis client."); + clients.remove(); } } + /** + * 释放连接池 + * @throws IOException + */ @Override public void close() throws IOException { if(single != null) diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index 7ee375b..2fed8bd 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -103,13 +103,14 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli Thread subscribeThread = new Thread(()-> { //当 Redis 重启会导致订阅线程断开连接,需要进行重连 - while(true) { + while(!client.isClosed()) { try (Jedis jedis = client.getResource()){ jedis.subscribe(this, channel); log.info("Disconnect to redis channel: " + channel); break; } catch (JedisConnectionException e) { log.error("Failed connect to redis, reconnect it.", e); + if(!client.isClosed()) try { Thread.sleep(1000); } catch (InterruptedException ie){ -- Gitee From 5fa0c4866e3a2bb0ff45f5f1871e68551e0b679d Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 15 Oct 2018 21:16:56 +0800 Subject: [PATCH 020/131] =?UTF-8?q?=E6=94=AF=E6=8C=81=20redis=20cluster=20?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oschina/j2cache/lettuce/LettuceCache.java | 56 +++++++++++++ .../j2cache/lettuce/LettuceCacheProvider.java | 80 ++++++++++++------- .../j2cache/lettuce/LettuceGenericCache.java | 46 +++++------ .../j2cache/lettuce/LettuceHashCache.java | 52 ++++++------ 4 files changed, 150 insertions(+), 84 deletions(-) create mode 100644 core/src/net/oschina/j2cache/lettuce/LettuceCache.java diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceCache.java new file mode 100644 index 0000000..29eac2d --- /dev/null +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCache.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2015-2017, Winter Lau (javayou@gmail.com). + *

+ * 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 net.oschina.j2cache.lettuce; + +import io.lettuce.core.AbstractRedisClient; +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.sync.BaseRedisCommands; +import io.lettuce.core.cluster.RedisClusterClient; +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import net.oschina.j2cache.Level2Cache; + +/** + * Lettuce 的基类,封装了普通 Redis 连接和集群 Redis 连接的差异 + * + * @author Winter Lau(javayou@gmail.com) + */ +public abstract class LettuceCache implements Level2Cache { + + private static final LettuceByteCodec codec = new LettuceByteCodec(); + + protected String namespace; + protected String region; + protected AbstractRedisClient client; + + protected StatefulConnection connect() { + if(client instanceof RedisClient) + return ((RedisClient)client).connect(codec); + else if(client instanceof RedisClusterClient) + return ((RedisClusterClient)client).connect(codec); + return null; + } + + protected BaseRedisCommands sync(StatefulConnection conn) { + if(conn instanceof StatefulRedisClusterConnection) + return ((StatefulRedisClusterConnection)conn).sync(); + else if(conn instanceof StatefulRedisConnection) + return ((StatefulRedisConnection)conn).sync(); + return null; + } + +} diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 88a7b31..cc33710 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -15,7 +15,9 @@ */ package net.oschina.j2cache.lettuce; +import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.RedisClient; +import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.pubsub.RedisPubSubAdapter; import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; @@ -45,8 +47,8 @@ import java.util.concurrent.ConcurrentHashMap; */ public class LettuceCacheProvider extends RedisPubSubAdapter implements CacheProvider, ClusterPolicy { - private static RedisClient redisClient; - private StatefulRedisPubSubConnection pubsub; + private static AbstractRedisClient redisClient; + private StatefulRedisPubSubConnection pubsub_subscriber; private String storage; private CacheProviderHolder holder; @@ -66,9 +68,40 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp return CacheObject.LEVEL_2; } + @Override + public void start(Properties props) { + this.namespace = props.getProperty("namespace"); + this.storage = props.getProperty("storage", "hash"); + this.channel = props.getProperty("channel", "j2cache"); + + String scheme = props.getProperty("scheme", "redis"); + String hosts = props.getProperty("hosts", "127.0.0.1:6379"); + String password = props.getProperty("password"); + int database = Integer.parseInt(props.getProperty("database", "0")); + String sentinelMasterId = props.getProperty("sentinelMasterId"); + + boolean isCluster = false; + if("redis-cluster".equalsIgnoreCase(scheme)) { + scheme = "redis"; + isCluster = true; + } + + String redis_url = String.format("%s://%s@%s/%d#%s", scheme, password, hosts, database, sentinelMasterId); + + redisClient = isCluster?RedisClusterClient.create(redis_url):RedisClient.create(redis_url); + } + + @Override + public void stop() { + regions.clear(); + redisClient.shutdown(); + } + @Override public Cache buildCache(String region, CacheExpiredListener listener) { - return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase(this.storage)?new LettuceHashCache(this.namespace, region, redisClient):new LettuceGenericCache(this.namespace, region, redisClient)); + return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase(this.storage)? + new LettuceHashCache(this.namespace, region, redisClient): + new LettuceGenericCache(this.namespace, region, redisClient)); } @Override @@ -100,27 +133,16 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp holder.getLevel1Cache(region).clear(); } - @Override - public void start(Properties props) { - this.namespace = props.getProperty("namespace"); - this.storage = props.getProperty("storage", "hash"); - this.channel = props.getProperty("channel", "j2cache"); - - String scheme = props.getProperty("scheme", "redis"); - String hosts = props.getProperty("hosts", "127.0.0.1:6379"); - String password = props.getProperty("password"); - int database = Integer.parseInt(props.getProperty("database", "0")); - String sentinelMasterId = props.getProperty("sentinelMasterId"); - - String redis_url = String.format("%s://%s@%s/%d#%s", scheme, password, hosts, database, sentinelMasterId); - - redisClient = RedisClient.create(redis_url); - } - - @Override - public void stop() { - regions.clear(); - redisClient.shutdown(); + /** + * Get PubSub connection + * @return connection instance + */ + private StatefulRedisPubSubConnection pubsub() { + if(redisClient instanceof RedisClient) + return ((RedisClient)redisClient).connectPubSub(); + else if(redisClient instanceof RedisClusterClient) + return ((RedisClusterClient)redisClient).connectPubSub(); + return null; } @Override @@ -130,9 +152,9 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp this.channel = props.getProperty("channel", "j2cache"); this.publish(Command.join()); - this.pubsub = redisClient.connectPubSub(); - this.pubsub.addListener(this); - RedisPubSubAsyncCommands async = this.pubsub.async(); + this.pubsub_subscriber = this.pubsub(); + this.pubsub_subscriber.addListener(this); + RedisPubSubAsyncCommands async = this.pubsub_subscriber.async(); async.subscribe(this.channel); log.info("Connected to redis channel:" + this.channel + ", time " + (System.currentTimeMillis()-ct) + " ms."); @@ -146,7 +168,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp @Override public void publish(Command cmd) { - try (StatefulRedisPubSubConnection connection = redisClient.connectPubSub()){ + try (StatefulRedisPubSubConnection connection = this.pubsub()){ RedisPubSubCommands sync = connection.sync(); sync.publish(this.channel, cmd.json()); } @@ -158,7 +180,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp this.publish(Command.quit()); super.unsubscribed(this.channel, 1); } finally { - this.pubsub.close(); + this.pubsub_subscriber.close(); } } } diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java index 9ff1217..22c5d7b 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java @@ -15,10 +15,10 @@ */ package net.oschina.j2cache.lettuce; -import io.lettuce.core.RedisClient; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.api.sync.RedisCommands; -import net.oschina.j2cache.Level2Cache; +import io.lettuce.core.AbstractRedisClient; +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.api.sync.RedisKeyCommands; +import io.lettuce.core.api.sync.RedisStringCommands; import java.util.Arrays; import java.util.Collection; @@ -30,15 +30,9 @@ import java.util.stream.Collectors; * Redis 缓存操作封装,基于 region+_key 实现多个 Region 的缓存( * @author Winter Lau(javayou@gmail.com) */ -public class LettuceGenericCache implements Level2Cache { +public class LettuceGenericCache extends LettuceCache { - private static final LettuceByteCodec codec = new LettuceByteCodec(); - - private String namespace; - private String region; - private RedisClient client; - - public LettuceGenericCache(String namespace, String region, RedisClient client) { + public LettuceGenericCache(String namespace, String region, AbstractRedisClient client) { if (region == null || region.isEmpty()) region = "_"; // 缺省region @@ -66,56 +60,56 @@ public class LettuceGenericCache implements Level2Cache { @Override public byte[] getBytes(String key) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); return cmd.get(_key(key)); } } @Override public List getBytes(Collection keys) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); return cmd.mget(keys.stream().map(k -> _key(k)).toArray(String[]::new)).stream().map(kv -> kv.hasValue()?kv.getValue():null).collect(Collectors.toList()); } } @Override public void setBytes(String key, byte[] bytes) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); cmd.set(_key(key), bytes); } } @Override public void setBytes(Map bytes) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); cmd.mset(bytes.entrySet().stream().collect(Collectors.toMap(k -> _key(k.getKey()), Map.Entry::getValue))); } } @Override public Collection keys() { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisKeyCommands cmd = (RedisKeyCommands)super.sync(connection); return cmd.keys(this.region + ":*").stream().map(k -> k.substring(this.region.length()+1)).collect(Collectors.toList()); } } @Override public void evict(String... keys) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisKeyCommands cmd = (RedisKeyCommands)super.sync(connection); cmd.del(Arrays.stream(keys).map(k -> _key(k)).toArray(String[]::new)); } } @Override public void clear() { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisKeyCommands cmd = (RedisKeyCommands)super.sync(connection); List keys = cmd.keys(this.region + ":*"); if(keys != null && keys.size() > 0) cmd.del(keys.stream().toArray(String[]::new)); diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java index 74868cf..29be647 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java @@ -15,10 +15,10 @@ */ package net.oschina.j2cache.lettuce; -import io.lettuce.core.RedisClient; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.api.sync.RedisCommands; -import net.oschina.j2cache.Level2Cache; +import io.lettuce.core.AbstractRedisClient; +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.api.sync.RedisHashCommands; +import io.lettuce.core.api.sync.RedisKeyCommands; import java.util.Collection; import java.util.List; @@ -31,21 +31,15 @@ import java.util.stream.Collectors; * * 重要提示!!! hash 存储模式无法单独对 key 设置 expire */ -public class LettuceHashCache implements Level2Cache { +public class LettuceHashCache extends LettuceCache { - private static final LettuceByteCodec codec = new LettuceByteCodec(); - - private String namespace; - private String region; - private RedisClient client; - - public LettuceHashCache(String namespace, String region, RedisClient client) { + public LettuceHashCache(String namespace, String region, AbstractRedisClient client) { if (region == null || region.isEmpty()) region = "_"; // 缺省region - this.client = client; - this.namespace = namespace; - this.region = getRegionName(region); + super.client = client; + super.namespace = namespace; + super.region = getRegionName(region); } /** @@ -63,56 +57,56 @@ public class LettuceHashCache implements Level2Cache { @Override public byte[] getBytes(String key) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisHashCommands cmd = (RedisHashCommands)super.sync(connection); return cmd.hget(this.region, key); } } @Override public List getBytes(Collection keys) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisHashCommands cmd = (RedisHashCommands)super.sync(connection); return cmd.hmget(this.region, keys.stream().toArray(String[]::new)).stream().map(kv -> kv.hasValue()?kv.getValue():null).collect(Collectors.toList()); } } @Override public void setBytes(String key, byte[] bytes) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisHashCommands cmd = (RedisHashCommands)super.sync(connection); cmd.hset(this.region, key, bytes); } } @Override public void setBytes(Map bytes) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisHashCommands cmd = (RedisHashCommands)super.sync(connection); cmd.hmset(this.region, bytes); } } @Override public Collection keys() { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisHashCommands cmd = (RedisHashCommands)super.sync(connection); return cmd.hkeys(this.region); } } @Override public void evict(String... keys) { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisHashCommands cmd = (RedisHashCommands)super.sync(connection); cmd.hdel(this.region, keys); } } @Override public void clear() { - try(StatefulRedisConnection connection = this.client.connect(codec)) { - RedisCommands cmd = connection.sync(); + try(StatefulConnection connection = super.connect()) { + RedisKeyCommands cmd = (RedisKeyCommands)super.sync(connection); cmd.del(this.region); } } -- Gitee From 6b2b9b36226fb53f0b79f542fbce1ab73a2d9527 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 15 Oct 2018 21:17:29 +0800 Subject: [PATCH 021/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/oschina/j2cache/CacheChannel.java | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/CacheChannel.java b/core/src/net/oschina/j2cache/CacheChannel.java index ec9699f..f813748 100644 --- a/core/src/net/oschina/j2cache/CacheChannel.java +++ b/core/src/net/oschina/j2cache/CacheChannel.java @@ -32,11 +32,13 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { private J2CacheConfig config; private CacheProviderHolder holder; private boolean defaultCacheNullObject ; + private boolean closed; public CacheChannel(J2CacheConfig config, CacheProviderHolder holder) { this.config = config; this.holder = holder; this.defaultCacheNullObject = config.isDefaultCacheNullObject(); + this.closed = false; } private NullObject newNullObject() { @@ -71,6 +73,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public CacheObject get(String region, String key, boolean...cacheNullObject) { + if(closed) + throw new IllegalStateException("CacheChannel closed"); + CacheObject obj = new CacheObject(region, key, CacheObject.LEVEL_1); obj.setValue(holder.getLevel1Cache(region).get(key)); if(obj.rawValue() != null) @@ -109,6 +114,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return cache object */ public CacheObject get(String region, String key, Function loader, boolean...cacheNullObject) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + CacheObject cache = get(region, key, false); if (cache.rawValue() != null) @@ -140,6 +149,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return cache object */ public Map get(String region, Collection keys) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + final Map objs = holder.getLevel1Cache(region).get(keys); List level2Keys = keys.stream().filter(k -> !objs.containsKey(k) || objs.get(k) == null).collect(Collectors.toList()); Map results = objs.entrySet().stream().filter(p -> p.getValue() != null).collect( @@ -168,6 +181,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return multiple cache data */ public Map get(String region, Collection keys, Function loader, boolean...cacheNullObject) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + Map results = get(region, keys); results.entrySet().stream().filter(e -> e.getValue().rawValue() == null).forEach( e -> { String lock_key = e.getKey() + '@' + region; @@ -209,6 +226,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return 0(不存在),1(一级),2(二级) */ public int check(String region, String key) { + if(closed) + throw new IllegalStateException("CacheChannel closed"); + if(holder.getLevel1Cache(region).exists(key)) return 1; if(holder.getLevel2Cache(region).exists(key)) @@ -236,6 +256,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param cacheNullObject if allow cache null object */ public void set(String region, String key, Object value, boolean cacheNullObject) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + if (!cacheNullObject && value == null) return ; @@ -279,6 +303,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param cacheNullObject if allow cache null object */ public void set(String region, String key, Object value, long timeToLiveInSeconds, boolean cacheNullObject) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + if (!cacheNullObject && value == null) return ; @@ -314,6 +342,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param cacheNullObject if allow cache null object */ public void set(String region, Map elements, boolean cacheNullObject) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + try { if (cacheNullObject && elements.containsValue(null)) { Map newElems = new HashMap<>(); @@ -368,6 +400,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param cacheNullObject if allow cache null object */ public void set(String region, Map elements, long timeToLiveInSeconds, boolean cacheNullObject) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + if(timeToLiveInSeconds <= 0) set(region, elements, cacheNullObject); else { @@ -406,6 +442,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param keys: Cache key */ public void evict(String region, String...keys) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + try { //先清比较耗时的二级缓存,再清一级缓存 holder.getLevel2Cache(region).evict(keys); @@ -421,6 +461,10 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param region: Cache region name */ public void clear(String region) { + + if(closed) + throw new IllegalStateException("CacheChannel closed"); + try { //先清比较耗时的二级缓存,再清一级缓存 holder.getLevel2Cache(region).clear(); @@ -435,6 +479,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return all the regions */ public Collection regions() { + if(closed) + throw new IllegalStateException("CacheChannel closed"); + return holder.regions(); } @@ -443,6 +490,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param region Cache Region Name */ public void removeRegion(String region) { + if(closed) + throw new IllegalStateException("CacheChannel closed"); + holder.getL1Provider().removeCache(region); } @@ -454,6 +504,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return key list */ public Collection keys(String region) { + if(closed) + throw new IllegalStateException("CacheChannel closed"); + Set keys = new HashSet<>(); keys.addAll(holder.getLevel1Cache(region).keys()); keys.addAll(holder.getLevel2Cache(region).keys()); @@ -464,7 +517,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * Close J2Cache */ @Override - public abstract void close(); + public void close() { + this.closed = true; + } /** * 获取一级缓存接口 -- Gitee From 57eb07dda4fd8a453992c7ae07a8fe4a08c66c09 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 15 Oct 2018 21:18:11 +0800 Subject: [PATCH 022/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/J2CacheBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/J2CacheBuilder.java b/core/src/net/oschina/j2cache/J2CacheBuilder.java index 30d21bd..8808654 100644 --- a/core/src/net/oschina/j2cache/J2CacheBuilder.java +++ b/core/src/net/oschina/j2cache/J2CacheBuilder.java @@ -74,6 +74,7 @@ public class J2CacheBuilder { @Override public void close() { + super.close(); policy.disconnect(); holder.shutdown(); opened.set(false); @@ -91,7 +92,6 @@ public class J2CacheBuilder { */ public void close() { this.channel.close(); - this.opened.set(false); this.channel = null; } -- Gitee From 76cccce6f62ead15b909c6e57485e7f16a9f8408 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 15 Oct 2018 21:37:11 +0800 Subject: [PATCH 023/131] 2.7.2 --- core/pom.xml | 2 +- core/resources/j2cache.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index cd782c3..245da77 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -26,7 +26,7 @@ io.lettuce lettuce-core - 5.1.0.RELEASE + 5.1.1.RELEASE provided diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index 9f3c531..74336c5 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -13,7 +13,7 @@ # xx.xxxx.xxxx.Xxxxx your own cache broadcast policy classname that implement net.oschina.j2cache.cluster.ClusterPolicy ######################################### -j2cache.broadcast = lettuce +j2cache.broadcast = redis # jgroups properties jgroups.channel.name = j2cache @@ -47,7 +47,7 @@ rocketmq.hosts = 127.0.0.1:9876 ######################################### j2cache.L1.provider_class = caffeine -j2cache.L2.provider_class = lettuce +j2cache.L2.provider_class = redis # When L2 provider isn't `redis`, using `L2.config_section = redis` to read redis configurations # j2cache.L2.config_section = redis -- Gitee From 804bb5d5179cd367b0c0be7ec214d8c4c5714e5e Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 17 Oct 2018 07:34:23 +0800 Subject: [PATCH 024/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20lettuce.scheme=20?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/resources/j2cache.properties | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index 74336c5..55cd602 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -143,6 +143,16 @@ redis.timeBetweenEvictionRunsMillis = 300000 redis.blockWhenExhausted = false redis.jmxEnabled = false +######################################### +# Lettuce scheme +# +# redis -> single redis server +# rediss -> single redis server with ssl +# redis-sentinel -> redis sentinel +# redis-cluster -> cluster servers +# +######################################### + lettuce.namespace = lettuce.storage = hash lettuce.channel = j2cache -- Gitee From 327c94aabf2f3d1c4d76bd2a284f07fcf6428669 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Thu, 18 Oct 2018 16:09:14 +0800 Subject: [PATCH 025/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20j2cache=20?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b757a40..f41567b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,14 @@ J2Cache 是 OSChina 目前正在使用的两级缓存框架(要求至少 Java 由于大量的缓存读取会导致 L2 的网络成为整个系统的瓶颈,因此 L1 的目标是降低对 L2 的读取次数。 该缓存框架主要用于集群环境中。单机也可使用,用于避免应用重启导致的缓存冷启动后对后端业务的冲击。 -J2Cache 和普通缓存框架有何不同,它解决了什么问题? [https://my.oschina.net/javayou/blog/1931381](https://my.oschina.net/javayou/blog/1931381) +J2Cache 相关文章: + +- [J2Cache 和普通缓存框架有何不同,它解决了什么问题?](https://my.oschina.net/javayou/blog/1931381) +- [如何让 J2Cache 在多种编程语言环境中使用](https://my.oschina.net/javayou/blog/2247729) +- [J2Cache 中使用 Lettuce 替代 Jedis 管理 Redis 连接](https://my.oschina.net/javayou/blog/2247710) +- [如何通过 J2Cache 实现分布式 session 存储](https://my.oschina.net/javayou/blog/2117109) +- [J2Cache 没有 Redis 也可以实现多节点的缓存同步](https://my.oschina.net/javayou/blog/1865908) +- [微服务的架构里应该使用 J2Cache 两级缓存框架](https://my.oschina.net/javayou/blog/1827480) J2Cache 已经有 Python 语言版本了,详情请看 [https://gitee.com/ld/Py3Cache](https://gitee.com/ld/Py3Cache) -- Gitee From e2f2694be1f9f3f0ad24ad66731fa5995d32ad40 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Tue, 23 Oct 2018 12:20:14 +0800 Subject: [PATCH 026/131] fixed #INP76 --- core/pom.xml | 2 +- core/src/net/oschina/j2cache/Command.java | 19 ++----------------- .../j2cache/cluster/ClusterPolicy.java | 9 ++++++++- .../j2cache/cluster/JGroupsClusterPolicy.java | 7 +++++++ .../j2cache/cluster/NoneClusterPolicy.java | 7 +++++++ .../cluster/RabbitMQClusterPolicy.java | 7 +++++++ .../cluster/RocketMQClusterPolicy.java | 6 ++++++ .../j2cache/lettuce/LettuceCacheProvider.java | 7 +++++++ .../redis/RedisPubSubClusterPolicy.java | 7 +++++++ modules/spring-boot-starter/pom.xml | 2 +- .../redis/SpringRedisMessageListener.java | 9 +++++++-- .../redis/SpringRedisPubSubPolicy.java | 6 ++++++ modules/spring-boot2-starter/pom.xml | 2 +- .../redis/SpringRedisMessageListener.java | 9 +++++++-- .../redis/SpringRedisPubSubPolicy.java | 13 +++++++++---- modules/springcache/pom.xml | 2 +- pom.xml | 4 ++-- 17 files changed, 86 insertions(+), 32 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 245da77..d45c9b2 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.2-release + 2.7.3-release 4.0.0 diff --git a/core/src/net/oschina/j2cache/Command.java b/core/src/net/oschina/j2cache/Command.java index 9049424..60d7d93 100644 --- a/core/src/net/oschina/j2cache/Command.java +++ b/core/src/net/oschina/j2cache/Command.java @@ -19,7 +19,6 @@ import java.util.Random; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONException; -import com.alibaba.fastjson.annotation.JSONField; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,19 +30,18 @@ import org.slf4j.LoggerFactory; public class Command { private final static Logger log = LoggerFactory.getLogger(Command.class); - private final static int SRC_ID = genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 public final static byte OPT_JOIN = 0x01; //加入集群 public final static byte OPT_EVICT_KEY = 0x02; //删除缓存 public final static byte OPT_CLEAR_KEY = 0x03; //清除缓存 public final static byte OPT_QUIT = 0x04; //退出集群 - private int src = SRC_ID; + private int src; private int operator; private String region; private String[] keys; - private static int genRandomSrc() { + public final static int genRandomSrc() { long ct = System.currentTimeMillis(); Random rnd_seed = new Random(ct); return (int)(rnd_seed.nextInt(10000) * 1000 + ct % 1000); @@ -57,14 +55,6 @@ public class Command { this.keys = keys; } - /** - * 返回本地的专有标识 - * @return 节点标识 - */ - public static final int LocalID() { - return SRC_ID; - } - public static Command join() { return new Command(OPT_JOIN, null); } @@ -86,11 +76,6 @@ public class Command { return null; } - @JSONField(serialize = false) - public boolean isLocal() { - return this.src == SRC_ID; - } - public int getOperator() { return operator; } diff --git a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java index f349055..f178d1c 100644 --- a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java @@ -78,13 +78,20 @@ public interface ClusterPolicy { */ void clear(String region) ; + /** + * 判断是否本地实例的命令 + * @param cmd 命令信息 + * @return + */ + boolean isLocalCommand(Command cmd) ; + /** * 处理缓存事件逻辑 * @param cmd the received command */ default void handleCommand(Command cmd) { try { - if (cmd == null || cmd.isLocal()) + if (cmd == null || isLocalCommand(cmd)) return; switch (cmd.getOperator()) { diff --git a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java index e7cc850..54215a0 100644 --- a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java @@ -33,6 +33,8 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli private final static Logger log = LoggerFactory.getLogger(JGroupsClusterPolicy.class); + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private String configXml; private JChannel channel; private String name; @@ -56,6 +58,11 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli this.configXml = "/network.xml"; } + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + /** * 删除本地某个缓存条目 * @param region 区域名称 diff --git a/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java index eaa97cb..da2c7eb 100644 --- a/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java @@ -26,6 +26,13 @@ import java.util.Properties; */ public class NoneClusterPolicy implements ClusterPolicy { + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + @Override public void connect(Properties props, CacheProviderHolder holder) { } diff --git a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java index 040d74c..d56624c 100644 --- a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java @@ -33,6 +33,8 @@ public class RabbitMQClusterPolicy implements ClusterPolicy, Consumer { private static final Logger log = LoggerFactory.getLogger(RabbitMQClusterPolicy.class); + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private static final String EXCHANGE_TYPE = "fanout"; private CacheProviderHolder holder; @@ -57,6 +59,11 @@ public class RabbitMQClusterPolicy implements ClusterPolicy, Consumer { //TODO 更多的 RabbitMQ 配置 } + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + /** * 删除本地某个缓存条目 * @param region 区域名称 diff --git a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java index d39b21e..00147a1 100644 --- a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java @@ -41,6 +41,8 @@ public class RocketMQClusterPolicy implements ClusterPolicy, MessageListenerConc private static final Logger log = LoggerFactory.getLogger(RocketMQClusterPolicy.class); + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private CacheProviderHolder holder; private String hosts; private String topic; @@ -59,7 +61,11 @@ public class RocketMQClusterPolicy implements ClusterPolicy, MessageListenerConc this.consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); this.consumer.setNamesrvAddr(this.hosts); this.consumer.setMessageModel(MessageModel.BROADCASTING); + } + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; } /** diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index cc33710..7888f94 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -47,6 +47,8 @@ import java.util.concurrent.ConcurrentHashMap; */ public class LettuceCacheProvider extends RedisPubSubAdapter implements CacheProvider, ClusterPolicy { + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private static AbstractRedisClient redisClient; private StatefulRedisPubSubConnection pubsub_subscriber; private String storage; @@ -68,6 +70,11 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp return CacheObject.LEVEL_2; } + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + @Override public void start(Properties props) { this.namespace = props.getProperty("namespace"); diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index 2fed8bd..4c310e8 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -38,6 +38,8 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli private final static Logger log = LoggerFactory.getLogger(RedisPubSubClusterPolicy.class); + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private Pool client; private String channel; private CacheProviderHolder holder; @@ -72,6 +74,11 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli } } + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + /** * 删除本地某个缓存条目 * @param region 区域名称 diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index 4e9cdcd..abbf037 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.2-release + 2.7.3-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java index efaf107..debfa7c 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java @@ -17,6 +17,7 @@ import net.oschina.j2cache.util.SerializationUtils; public class SpringRedisMessageListener implements MessageListener{ private static Logger logger = LoggerFactory.getLogger(SpringRedisMessageListener.class); + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private ClusterPolicy clusterPolicy; @@ -26,7 +27,11 @@ public class SpringRedisMessageListener implements MessageListener{ this.clusterPolicy = clusterPolicy; this.channel = channel; } - + + private boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + @Override public void onMessage(Message message, byte[] pattern) { byte[] messageChannel = message.getChannel(); @@ -36,7 +41,7 @@ public class SpringRedisMessageListener implements MessageListener{ } try { Command cmd = Command.parse(String.valueOf(SerializationUtils.deserialize(messageBody))); - if (cmd == null || cmd.isLocal()) + if (cmd == null || isLocalCommand(cmd)) return; switch (cmd.getOperator()) { diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index b2fa563..a44c63d 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -21,6 +21,7 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; */ public class SpringRedisPubSubPolicy implements ClusterPolicy { + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private RedisTemplate redisTemplate; private net.oschina.j2cache.autoconfigure.J2CacheConfig config; @@ -33,6 +34,11 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { private String channel = "j2cache_channel"; + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + @SuppressWarnings("unchecked") @Override public void connect(Properties props, CacheProviderHolder holder) { diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index 58837a5..a237d59 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.2-release + 2.7.3-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java index efaf107..debfa7c 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java @@ -17,6 +17,7 @@ import net.oschina.j2cache.util.SerializationUtils; public class SpringRedisMessageListener implements MessageListener{ private static Logger logger = LoggerFactory.getLogger(SpringRedisMessageListener.class); + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private ClusterPolicy clusterPolicy; @@ -26,7 +27,11 @@ public class SpringRedisMessageListener implements MessageListener{ this.clusterPolicy = clusterPolicy; this.channel = channel; } - + + private boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + @Override public void onMessage(Message message, byte[] pattern) { byte[] messageChannel = message.getChannel(); @@ -36,7 +41,7 @@ public class SpringRedisMessageListener implements MessageListener{ } try { Command cmd = Command.parse(String.valueOf(SerializationUtils.deserialize(messageBody))); - if (cmd == null || cmd.isLocal()) + if (cmd == null || isLocalCommand(cmd)) return; switch (cmd.getOperator()) { diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index f459b08..5901e0a 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -20,7 +20,9 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; * @author zhangsaizz */ public class SpringRedisPubSubPolicy implements ClusterPolicy { - + + private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private RedisTemplate redisTemplate; private net.oschina.j2cache.autoconfigure.J2CacheConfig config; @@ -32,7 +34,12 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { private static boolean isActive = false; private String channel = "j2cache_channel"; - + + @Override + public boolean isLocalCommand(Command cmd) { + return cmd.getSrc() == LOCAL_COMMAND_ID; + } + @SuppressWarnings("unchecked") @Override public void connect(Properties props, CacheProviderHolder holder) { @@ -106,12 +113,10 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { redisTemplate.convertAndSend(this.channel, cmd.json()); } } - @Override public void disconnect() { redisTemplate.convertAndSend(this.channel, Command.quit().json()); } - } diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index b81737b..ef1e8ff 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.2-release + 2.7.3-release ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index c21eb3a..e497d5e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.2-release + 2.7.3-release pom j2cache @@ -39,7 +39,7 @@ UTF-8 - 2.7.2-release + 2.7.3-release -- Gitee From 059fda5f7615a71a24635493af2acf29faca4040 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 24 Oct 2018 10:16:26 +0800 Subject: [PATCH 027/131] fixed #INTQZ --- core/pom.xml | 2 +- .../src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java | 2 +- core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java | 2 +- .../net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java | 2 +- .../net/oschina/j2cache/cluster/RocketMQClusterPolicy.java | 2 +- .../src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 2 +- .../net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java | 2 +- modules/spring-boot-starter/pom.xml | 2 +- .../cache/support/redis/SpringRedisMessageListener.java | 2 +- .../j2cache/cache/support/redis/SpringRedisPubSubPolicy.java | 2 +- modules/spring-boot2-starter/pom.xml | 2 +- .../cache/support/redis/SpringRedisMessageListener.java | 2 +- .../j2cache/cache/support/redis/SpringRedisPubSubPolicy.java | 2 +- modules/springcache/pom.xml | 2 +- pom.xml | 4 ++-- 15 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d45c9b2..4aa46b6 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.3-release + 2.7.4-release 4.0.0 diff --git a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java index 54215a0..95c342f 100644 --- a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java @@ -33,7 +33,7 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli private final static Logger log = LoggerFactory.getLogger(JGroupsClusterPolicy.class); - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private String configXml; private JChannel channel; diff --git a/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java index da2c7eb..a0e40ac 100644 --- a/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/NoneClusterPolicy.java @@ -26,7 +26,7 @@ import java.util.Properties; */ public class NoneClusterPolicy implements ClusterPolicy { - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 @Override public boolean isLocalCommand(Command cmd) { diff --git a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java index d56624c..d1774df 100644 --- a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java @@ -33,7 +33,7 @@ public class RabbitMQClusterPolicy implements ClusterPolicy, Consumer { private static final Logger log = LoggerFactory.getLogger(RabbitMQClusterPolicy.class); - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private static final String EXCHANGE_TYPE = "fanout"; diff --git a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java index 00147a1..f33b050 100644 --- a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java @@ -41,7 +41,7 @@ public class RocketMQClusterPolicy implements ClusterPolicy, MessageListenerConc private static final Logger log = LoggerFactory.getLogger(RocketMQClusterPolicy.class); - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private CacheProviderHolder holder; private String hosts; diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 7888f94..33c05be 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -47,7 +47,7 @@ import java.util.concurrent.ConcurrentHashMap; */ public class LettuceCacheProvider extends RedisPubSubAdapter implements CacheProvider, ClusterPolicy { - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private static AbstractRedisClient redisClient; private StatefulRedisPubSubConnection pubsub_subscriber; diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index 4c310e8..34bc5dd 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -38,7 +38,7 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli private final static Logger log = LoggerFactory.getLogger(RedisPubSubClusterPolicy.class); - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private Pool client; private String channel; diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index abbf037..7d3a244 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.3-release + 2.7.4-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java index debfa7c..ff7e780 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java @@ -17,7 +17,7 @@ import net.oschina.j2cache.util.SerializationUtils; public class SpringRedisMessageListener implements MessageListener{ private static Logger logger = LoggerFactory.getLogger(SpringRedisMessageListener.class); - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private ClusterPolicy clusterPolicy; diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index a44c63d..b08ef66 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -21,7 +21,7 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; */ public class SpringRedisPubSubPolicy implements ClusterPolicy { - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private RedisTemplate redisTemplate; private net.oschina.j2cache.autoconfigure.J2CacheConfig config; diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index a237d59..4a33e53 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.3-release + 2.7.4-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java index debfa7c..ff7e780 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisMessageListener.java @@ -17,7 +17,7 @@ import net.oschina.j2cache.util.SerializationUtils; public class SpringRedisMessageListener implements MessageListener{ private static Logger logger = LoggerFactory.getLogger(SpringRedisMessageListener.class); - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private ClusterPolicy clusterPolicy; diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index 5901e0a..7583dc7 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -21,7 +21,7 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; */ public class SpringRedisPubSubPolicy implements ClusterPolicy { - private final static int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 private RedisTemplate redisTemplate; diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index ef1e8ff..7554667 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.3-release + 2.7.4-release ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index e497d5e..163ec6b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.3-release + 2.7.4-release pom j2cache @@ -39,7 +39,7 @@ UTF-8 - 2.7.3-release + 2.7.4-release -- Gitee From 4a2077cd7331babdc03d87c307d627522407e3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=87?= Date: Wed, 24 Oct 2018 15:18:40 +0800 Subject: [PATCH 028/131] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E5=9C=A8pub?= =?UTF-8?q?lish=20command=E6=97=B6=EF=BC=8C=E8=AE=BE=E7=BD=AE=E5=BD=93?= =?UTF-8?q?=E5=89=8Dcommand=E5=8F=91=E5=B8=83=E8=80=85=E7=9A=84LOCAL=5FCOM?= =?UTF-8?q?MAND=5FID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java | 1 + core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java | 1 + core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java | 1 + core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 1 + core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java | 1 + 5 files changed, 5 insertions(+) diff --git a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java index 95c342f..f69da0b 100644 --- a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java @@ -125,6 +125,7 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli @Override public void publish(Command cmd) { try { + cmd.setSrc(LOCAL_COMMAND_ID); Message msg = new Message(null, cmd.json()); channel.send(msg); } catch (Exception e) { diff --git a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java index d1774df..0609ffe 100644 --- a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java @@ -125,6 +125,7 @@ public class RabbitMQClusterPolicy implements ClusterPolicy, Consumer { } } try { + cmd.setSrc(LOCAL_COMMAND_ID); channel_publisher.basicPublish(exchange, "", null, cmd.json().getBytes()); } catch (IOException e ) { throw new CacheException("Failed to publish cmd to RabbitMQ!", e); diff --git a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java index f33b050..6af2bea 100644 --- a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java @@ -102,6 +102,7 @@ public class RocketMQClusterPolicy implements ClusterPolicy, MessageListenerConc @Override public void publish(Command cmd) { + cmd.setSrc(LOCAL_COMMAND_ID); Message msg = new Message(topic,"","", cmd.json().getBytes()); try { this.producer.send(msg); diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 33c05be..e582b83 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -175,6 +175,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp @Override public void publish(Command cmd) { + cmd.setSrc(LOCAL_COMMAND_ID); try (StatefulRedisPubSubConnection connection = this.pubsub()){ RedisPubSubCommands sync = connection.sync(); sync.publish(this.channel, cmd.json()); diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index 34bc5dd..4f3fea5 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -150,6 +150,7 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli @Override public void publish(Command cmd) { + cmd.setSrc(LOCAL_COMMAND_ID); try (Jedis jedis = client.getResource()) { jedis.publish(channel, cmd.json()); } -- Gitee From 56b700521d3dc056f1ac120973372da61ce262dd Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Thu, 25 Oct 2018 14:59:12 +0800 Subject: [PATCH 029/131] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20Command=20?= =?UTF-8?q?=E7=9A=84=20src=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/cache/support/redis/SpringRedisPubSubPolicy.java | 1 + .../j2cache/cache/support/redis/SpringRedisPubSubPolicy.java | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index b08ef66..94a4194 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -111,6 +111,7 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @Override public void publish(Command cmd) { + cmd.setSrc(LOCAL_COMMAND_ID); if (!isActive || "blend".equals(config.getCacheCleanMode())) { redisTemplate.convertAndSend(this.channel, cmd.json()); } diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index 7583dc7..26abc57 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -109,6 +109,7 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @Override public void publish(Command cmd) { + cmd.setSrc(LOCAL_COMMAND_ID); if(!isActive || "blend".equals(config.getCacheCleanMode())) { redisTemplate.convertAndSend(this.channel, cmd.json()); } -- Gitee From 2a30ecf3173dc5e7e158f9b7af5deb14952aa202 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 29 Oct 2018 14:27:58 +0800 Subject: [PATCH 030/131] 2.7.5 --- core/pom.xml | 2 +- modules/spring-boot-starter/pom.xml | 2 +- modules/spring-boot2-starter/pom.xml | 2 +- pom.xml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 4aa46b6..6230066 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.4-release + 2.7.5-release 4.0.0 diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index 7d3a244..4692996 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.4-release + 2.7.5-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index 4a33e53..0755767 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.4-release + 2.7.5-release ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 163ec6b..a62bcc5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.4-release + 2.7.5-release pom j2cache @@ -39,7 +39,7 @@ UTF-8 - 2.7.4-release + 2.7.5-release -- Gitee From 40cf5051af45157452dc8b011251f3eececb3a6a Mon Sep 17 00:00:00 2001 From: zhangsaizz <937425288@qq.com> Date: Mon, 29 Oct 2018 14:46:25 +0800 Subject: [PATCH 031/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/spring-boot2-starter/readme.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/spring-boot2-starter/readme.md b/modules/spring-boot2-starter/readme.md index cfe2047..23c1121 100644 --- a/modules/spring-boot2-starter/readme.md +++ b/modules/spring-boot2-starter/readme.md @@ -34,7 +34,10 @@ j2cache.broadcast = net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPol j2cache.L2.provider_class = net.oschina.j2cache.cache.support.redis.SpringRedisProvider j2cache.L2.config_section = redis ``` - - - +在application.properties中支持redis客户端 +* jedis +* lettuce +``` +j2cache.redis-client=jedis +``` -- Gitee From 211a56965f7892c9c4111e077f9705f345a529d9 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Tue, 30 Oct 2018 14:00:53 +0800 Subject: [PATCH 032/131] fixed #INUP3 --- .../j2cache/lettuce/LettuceGenericCache.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java index 22c5d7b..58754f7 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java @@ -90,6 +90,35 @@ public class LettuceGenericCache extends LettuceCache { } } + + /** + * 设置缓存数据字节数组(带有效期) + * @param key cache key + * @param bytes cache data + * @param timeToLiveInSeconds cache ttl + */ + @Override + public void setBytes(String key, byte[] bytes, long timeToLiveInSeconds){ + try(StatefulConnection connection = super.connect()) { + RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); + cmd.setex(_key(key), timeToLiveInSeconds, bytes); + } + } + + /** + * 批量设置带 TTL 的缓存数据 + * @param bytes cache data + * @param timeToLiveInSeconds cache ttl + */ + @Override + public void setBytes(Map bytes, long timeToLiveInSeconds) { + try(StatefulConnection connection = super.connect()) { + RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); + bytes.forEach((k,v)->cmd.setex(_key(k), timeToLiveInSeconds, v)); + } + } + + @Override public Collection keys() { try(StatefulConnection connection = super.connect()) { -- Gitee From c43d7859944505e4c4e97da2de9e51a8f3a9855e Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Tue, 30 Oct 2018 15:13:11 +0800 Subject: [PATCH 033/131] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=92=8C=20core=20=E7=9A=84=E4=BE=9D=E8=B5=96=E5=85=B3?= =?UTF-8?q?=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hibernate3/pom.xml | 2 +- modules/hibernate4/pom.xml | 2 +- modules/hibernate5/pom.xml | 2 +- modules/mybatis/pom.xml | 2 +- modules/spring-boot-starter/pom.xml | 2 +- modules/spring-boot2-starter/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/hibernate3/pom.xml b/modules/hibernate3/pom.xml index 756f40c..e60f8ca 100755 --- a/modules/hibernate3/pom.xml +++ b/modules/hibernate3/pom.xml @@ -20,7 +20,7 @@ net.oschina.j2cache j2cache-core ${j2cache-version} - compile + provided org.hibernate diff --git a/modules/hibernate4/pom.xml b/modules/hibernate4/pom.xml index 451204d..952cebd 100755 --- a/modules/hibernate4/pom.xml +++ b/modules/hibernate4/pom.xml @@ -21,7 +21,7 @@ net.oschina.j2cache j2cache-core ${j2cache-version} - compile + provided org.hibernate diff --git a/modules/hibernate5/pom.xml b/modules/hibernate5/pom.xml index a0497ee..688f1c1 100644 --- a/modules/hibernate5/pom.xml +++ b/modules/hibernate5/pom.xml @@ -26,7 +26,7 @@ net.oschina.j2cache j2cache-core ${j2cache-version} - compile + provided org.hibernate diff --git a/modules/mybatis/pom.xml b/modules/mybatis/pom.xml index 99c6e34..5d74f12 100644 --- a/modules/mybatis/pom.xml +++ b/modules/mybatis/pom.xml @@ -17,7 +17,7 @@ net.oschina.j2cache j2cache-core ${j2cache-version} - compile + provided org.mybatis diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index 4692996..fa8d28a 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -17,7 +17,7 @@ net.oschina.j2cache j2cache-core ${j2cache-version} - compile + provided org.springframework.boot diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index 0755767..948e90d 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -23,7 +23,7 @@ slf4j-simple - compile + provided org.springframework.boot -- Gitee From f31a33108a75f88fc2a7ff286df45e05a963b935 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Tue, 30 Oct 2018 15:15:20 +0800 Subject: [PATCH 034/131] =?UTF-8?q?2.7.6=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20lettuce=20=E6=97=B6=20redis=20=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=90=8C=E6=AD=A5=20ttl=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 6230066..c475c8e 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.5-release + 2.7.6-release 4.0.0 diff --git a/pom.xml b/pom.xml index a62bcc5..1455283 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.5-release + 2.7.6-release pom j2cache @@ -39,7 +39,7 @@ UTF-8 - 2.7.5-release + 2.7.6-release -- Gitee From aa30707f964e1a2be11060f476f5c046672a5e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Wed, 14 Nov 2018 18:15:45 +0800 Subject: [PATCH 035/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20jeesite=20?= =?UTF-8?q?=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f41567b..3ed6855 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,7 @@ channel.close(); * https://gitee.com/xchao/j-im * https://gitee.com/fuyang_lipengjun/platform * https://gitee.com/xcOschina/freeter-admin +* https://gitee.com/thinkgem/jeesite 更多项目收集中,如果你的项目用了,请告诉我 -- Gitee From fa7c0556a50311a47743bc5be67c4e586ee6b5ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Wed, 14 Nov 2018 18:17:25 +0800 Subject: [PATCH 036/131] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20jeesite=20?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ed6855..f7ddb0f 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ channel.close(); * https://gitee.com/xchao/j-im * https://gitee.com/fuyang_lipengjun/platform * https://gitee.com/xcOschina/freeter-admin -* https://gitee.com/thinkgem/jeesite +* https://gitee.com/thinkgem/jeesite4 更多项目收集中,如果你的项目用了,请告诉我 -- Gitee From c67d09be289fd28b40c46b9e0c68ace5b5e3dc58 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Fri, 16 Nov 2018 07:11:26 +0800 Subject: [PATCH 037/131] =?UTF-8?q?=E5=87=8F=E5=B0=91=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=EF=BC=8C=E5=A2=9E=E5=8A=A0=20TTL=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java index 25f4b9a..ad22039 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java @@ -76,10 +76,9 @@ public class EhCacheProvider implements CacheProvider { return caches.computeIfAbsent(regionName, v -> { net.sf.ehcache.Cache cache = manager.getCache(regionName); if (cache == null) { - log.warn("Could not find configuration [" + regionName + "]; using defaults."); manager.addCache(regionName); cache = manager.getCache(regionName); - log.info("started Ehcache region: " + regionName); + log.warn(String.format("Could not find configuration [" + regionName + "]; using defaults (TTL:%d).", cache.getCacheConfiguration().getTimeToLiveSeconds())); } return new EhCache(cache, listener); }); -- Gitee From a6afb02925286ee57ab5b5f5dbba394985b7a43d Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Fri, 16 Nov 2018 07:24:57 +0800 Subject: [PATCH 038/131] =?UTF-8?q?=E4=BC=98=E5=8C=96=20ehcache=20?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++---- core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java | 2 +- core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java | 4 +++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f7ddb0f..aab7a1d 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,6 @@ channel.close(); ## TODO ## -1. 当 ehcache 配置模板为永久时的处理 -2. 应用重启,从 Redis 获取数据后,一级缓存的有效期大于预设值 -3. 多节点强一致性? -4. 欢迎大家给 J2Cache 提建议 \ No newline at end of file +1. 应用重启,从 Redis 获取数据后,一级缓存的有效期大于预设值 +2. 多节点强一致性? +3. 欢迎大家给 J2Cache 提建议 \ No newline at end of file diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java index ad22039..bfaaf5f 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java @@ -78,7 +78,7 @@ public class EhCacheProvider implements CacheProvider { if (cache == null) { manager.addCache(regionName); cache = manager.getCache(regionName); - log.warn(String.format("Could not find configuration [" + regionName + "]; using defaults (TTL:%d).", cache.getCacheConfiguration().getTimeToLiveSeconds())); + log.warn(String.format("Could not find configuration [%s]; using defaults (TTL:%d seconds).", regionName, cache.getCacheConfiguration().getTimeToLiveSeconds())); } return new EhCache(cache, listener); }); diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java index 9c235a4..8e02eeb 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java @@ -78,7 +78,9 @@ public class EhCacheProvider3 implements CacheProvider { CacheConfiguration defaultCacheConfig = manager.getRuntimeConfiguration().getCacheConfigurations().get(DEFAULT_TPL); CacheConfiguration cacheCfg = CacheConfigurationBuilder.newCacheConfigurationBuilder(defaultCacheConfig).build(); cache = manager.createCache(region, cacheCfg); - log.info("Could not find configuration [" + region + "]; using defaults."); + Duration dura = cache.getRuntimeConfiguration().getExpiry().getExpiryForCreation(null, null); + long ttl = dura.isInfinite()?-1:dura.getTimeUnit().toSeconds(dura.getLength()); + log.warn(String.format("Could not find configuration [%s]; using defaults (TTL:%d seconds).", region, ttl)); } return new EhCache3(region, cache, listener); }); -- Gitee From 0baf8312e2db73abea7b293f2dbbc5f0281cf67c Mon Sep 17 00:00:00 2001 From: chenzy01 Date: Mon, 19 Nov 2018 15:42:01 +0800 Subject: [PATCH 039/131] test log --- .../net/oschina/j2cache/J2CacheBuilder.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/net/oschina/j2cache/J2CacheBuilder.java b/core/src/net/oschina/j2cache/J2CacheBuilder.java index 8808654..1032bcb 100644 --- a/core/src/net/oschina/j2cache/J2CacheBuilder.java +++ b/core/src/net/oschina/j2cache/J2CacheBuilder.java @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * 使用自定义配置构建 J2Cache + * * @author Winter Lau (javayou@gmail.com) */ public class J2CacheBuilder { @@ -44,7 +45,8 @@ public class J2CacheBuilder { /** * 初始化 J2Cache,这是一个很重的操作,请勿重复执行 - * @param config j2cache config instance + * + * @param config j2cache config instance * @return J2CacheBuilder instance */ public final static J2CacheBuilder init(J2CacheConfig config) { @@ -53,12 +55,13 @@ public class J2CacheBuilder { /** * 返回缓存操作接口 + * * @return CacheChannel */ - public CacheChannel getChannel(){ - if(this.channel == null || !this.opened.get()) { + public CacheChannel getChannel() { + if (this.channel == null || !this.opened.get()) { synchronized (J2CacheBuilder.class) { - if(this.channel == null || !this.opened.get()) { + if (this.channel == null || !this.opened.get()) { this.initFromConfig(config); /* 初始化缓存接口 */ this.channel = new CacheChannel(config, holder) { @@ -97,27 +100,28 @@ public class J2CacheBuilder { /** * 加载配置 + * * @return * @throws IOException */ private void initFromConfig(J2CacheConfig config) { SerializationUtils.init(config.getSerialization(), config.getSubProperties(config.getSerialization())); //初始化两级的缓存管理 - this.holder = CacheProviderHolder.init(config, (region, key)->{ + this.holder = CacheProviderHolder.init(config, (region, key) -> { //当一级缓存中的对象失效时,自动清除二级缓存中的数据 Level2Cache level2 = this.holder.getLevel2Cache(region); level2.evict(key); - if(!level2.supportTTL()) { + if (!level2.supportTTL()) { //再一次清除一级缓存是为了避免缓存失效时再次从 L2 获取到值 this.holder.getLevel1Cache(region).evict(key); } log.debug(String.format("Level 1 cache object expired, evict level 2 cache object [%s,%s]", region, key)); - if(policy != null) + if (policy != null) policy.sendEvictCmd(region, key); }); policy = ClusterPolicyFactory.init(holder, config.getBroadcast(), config.getBroadcastProperties()); - log.info("Using cluster policy : " + policy.getClass().getName()); + log.info("Using cluster policy : {}", policy.getClass().getName()); } } -- Gitee From bded6fbfa87d2a1fc455c2f75b322017b35836b4 Mon Sep 17 00:00:00 2001 From: chenzy01 Date: Mon, 19 Nov 2018 16:04:21 +0800 Subject: [PATCH 040/131] log pattern --- core/src/net/oschina/j2cache/CacheProviderHolder.java | 4 ++-- core/src/net/oschina/j2cache/cluster/ClusterPolicy.java | 4 ++-- .../net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java | 4 ++-- core/src/net/oschina/j2cache/util/SerializationUtils.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/net/oschina/j2cache/CacheProviderHolder.java b/core/src/net/oschina/j2cache/CacheProviderHolder.java index bf02e52..7a7f932 100644 --- a/core/src/net/oschina/j2cache/CacheProviderHolder.java +++ b/core/src/net/oschina/j2cache/CacheProviderHolder.java @@ -59,13 +59,13 @@ public class CacheProviderHolder { if (!holder.l1_provider.isLevel(CacheObject.LEVEL_1)) throw new CacheException(holder.l1_provider.getClass().getName() + " is not level_1 cache provider"); holder.l1_provider.start(config.getL1CacheProperties()); - log.info("Using L1 CacheProvider : " + holder.l1_provider.getClass().getName()); + log.info("Using L1 CacheProvider : {}", holder.l1_provider.getClass().getName()); holder.l2_provider = loadProviderInstance(config.getL2CacheName()); if (!holder.l2_provider.isLevel(CacheObject.LEVEL_2)) throw new CacheException(holder.l2_provider.getClass().getName() + " is not level_2 cache provider"); holder.l2_provider.start(config.getL2CacheProperties()); - log.info("Using L2 CacheProvider : " + holder.l2_provider.getClass().getName()); + log.info("Using L2 CacheProvider : {}", holder.l2_provider.getClass().getName()); return holder; } diff --git a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java index f178d1c..48a82ed 100644 --- a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java @@ -96,7 +96,7 @@ public interface ClusterPolicy { switch (cmd.getOperator()) { case Command.OPT_JOIN: - log.info("Node-"+cmd.getSrc() + " joined !"); + log.info("Node-{} joined !", cmd.getSrc()); break; case Command.OPT_EVICT_KEY: this.evict(cmd.getRegion(), cmd.getKeys()); @@ -107,7 +107,7 @@ public interface ClusterPolicy { log.debug("Received cache clear message, region=" + cmd.getRegion()); break; case Command.OPT_QUIT: - log.info("Node-"+cmd.getSrc() + " quit !"); + log.info("Node-{} quit !", cmd.getSrc()); break; default: log.warn("Unknown message type = " + cmd.getOperator()); diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index 4f3fea5..ea3f255 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -113,7 +113,7 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli while(!client.isClosed()) { try (Jedis jedis = client.getResource()){ jedis.subscribe(this, channel); - log.info("Disconnect to redis channel: " + channel); + log.info("Disconnect to redis channel: {}", channel); break; } catch (JedisConnectionException e) { log.error("Failed connect to redis, reconnect it.", e); @@ -130,7 +130,7 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli subscribeThread.setDaemon(true); subscribeThread.start(); - log.info("Connected to redis channel:" + channel + ", time " + (System.currentTimeMillis()-ct) + " ms."); + log.info("Connected to redis channel:{}, time {} ms.", channel, (System.currentTimeMillis()-ct)); } /** diff --git a/core/src/net/oschina/j2cache/util/SerializationUtils.java b/core/src/net/oschina/j2cache/util/SerializationUtils.java index fbef193..3535073 100644 --- a/core/src/net/oschina/j2cache/util/SerializationUtils.java +++ b/core/src/net/oschina/j2cache/util/SerializationUtils.java @@ -63,7 +63,7 @@ public class SerializationUtils { } } } - log.info("Using Serializer -> [" + g_serializer.name() + ":" + g_serializer.getClass().getName() + ']'); + log.info("Using Serializer -> [{}:{}]", g_serializer.name(), g_serializer.getClass().getName()); } /** -- Gitee From 58e79edfc2f4d5af5445f87d4ae2d4055d32d068 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 19 Nov 2018 16:25:01 +0800 Subject: [PATCH 041/131] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=BC=83?= =?UTF-8?q?=E7=94=A8=20String.format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java | 6 +++--- .../net/oschina/j2cache/cluster/JGroupsClusterPolicy.java | 6 +++--- .../net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java | 2 +- core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java | 4 ++-- core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java | 6 +++--- .../net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 2 +- .../oschina/j2cache/memcached/XmemcachedCacheProvider.java | 4 ++-- core/src/net/oschina/j2cache/redis/RedisCacheProvider.java | 4 ++-- core/src/net/oschina/j2cache/redis/RedisClient.java | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index ca5e2e1..81fd370 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -69,7 +69,7 @@ public class CaffeineProvider implements CacheProvider { if (config == null) throw new CacheException(String.format("Undefined [default] caffeine cache")); - log.warn(String.format("Caffeine cache [%s] not defined, using default.", region)); + log.warn("Caffeine cache [{}] not defined, using default.", region); } return newCaffeineCache(region, config.size, config.expire, listener); }); @@ -88,7 +88,7 @@ public class CaffeineProvider implements CacheProvider { throw new CacheException(String.format("Undefined caffeine cache region name = %s", region)); } - log.info(String.format("Started caffeine region [%s] with TTL: %d", region, timeToLiveInSeconds)); + log.info("Started caffeine region [{}] with TTL: {}", region, timeToLiveInSeconds); return newCaffeineCache(region, config.size, timeToLiveInSeconds, listener); }); @@ -166,7 +166,7 @@ public class CaffeineProvider implements CacheProvider { private void saveCacheConfig(String region, String region_config) { CacheConfig cfg = CacheConfig.parse(region_config); if(cfg == null) - log.warn(String.format("Illegal caffeine cache config [%s=%s]", region, region_config)); + log.warn("Illegal caffeine cache config [{}={}]", region, region_config); else cacheConfigs.put(region, cfg); } diff --git a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java index f69da0b..3b35a8e 100644 --- a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java @@ -94,7 +94,7 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli channel.connect(name); this.publish(Command.join()); - log.info("Connected to jgroups channel:" + name + ", time " + (System.currentTimeMillis()-ct) + " ms."); + log.info("Connected to jgroups channel:{}, time {}ms.", name, (System.currentTimeMillis()-ct)); } catch (Exception e){ throw new CacheException(e); @@ -117,8 +117,8 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli @Override public void viewAccepted(View view) { - log.info(String.format("Group Members Changed, LIST: %s", - String.join(",", view.getMembers().stream().map(a -> a.toString()).toArray(String[]::new))) + log.info("Group Members Changed, LIST: {}", + String.join(",", view.getMembers().stream().map(a -> a.toString()).toArray(String[]::new)) ); } diff --git a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java index 0609ffe..f6917ea 100644 --- a/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RabbitMQClusterPolicy.java @@ -99,7 +99,7 @@ public class RabbitMQClusterPolicy implements ClusterPolicy, Consumer { channel_consumer.basicConsume(queueName, true, this); - log.info("Connected to RabbitMQ:" + conn_consumer + ", time " + (System.currentTimeMillis()-ct) + " ms."); + log.info("Connected to RabbitMQ:{}, time {}ms", conn_consumer, System.currentTimeMillis()-ct); } catch (Exception e) { throw new CacheException(String.format("Failed to connect to RabbitMQ (%s:%d)", factory.getHost(), factory.getPort()), e); } diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java index bfaaf5f..a14e164 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java @@ -78,7 +78,7 @@ public class EhCacheProvider implements CacheProvider { if (cache == null) { manager.addCache(regionName); cache = manager.getCache(regionName); - log.warn(String.format("Could not find configuration [%s]; using defaults (TTL:%d seconds).", regionName, cache.getCacheConfiguration().getTimeToLiveSeconds())); + log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds).", regionName, cache.getCacheConfiguration().getTimeToLiveSeconds()); } return new EhCache(cache, listener); }); @@ -98,7 +98,7 @@ public class EhCacheProvider implements CacheProvider { net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(cfg); manager.addCache(cache); - log.info(String.format("Started Ehcache region [%s] with TTL: %d", region, timeToLiveInSeconds)); + log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds); return new EhCache(cache, listener); }); diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java index 8e02eeb..b274d6e 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java @@ -80,7 +80,7 @@ public class EhCacheProvider3 implements CacheProvider { cache = manager.createCache(region, cacheCfg); Duration dura = cache.getRuntimeConfiguration().getExpiry().getExpiryForCreation(null, null); long ttl = dura.isInfinite()?-1:dura.getTimeUnit().toSeconds(dura.getLength()); - log.warn(String.format("Could not find configuration [%s]; using defaults (TTL:%d seconds).", region, ttl)); + log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds).", region, ttl); } return new EhCache3(region, cache, listener); }); @@ -94,7 +94,7 @@ public class EhCacheProvider3 implements CacheProvider { .withExpiry(Expirations.timeToLiveExpiration(Duration.of(timeToLiveInSeconds, TimeUnit.SECONDS))) .build(); org.ehcache.Cache cache = manager.createCache(region, conf); - log.info(String.format("Started Ehcache region [%s] with TTL: %d", region, timeToLiveInSeconds)); + log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds); return new EhCache3(region, cache, listener); }); @@ -116,7 +116,7 @@ public class EhCacheProvider3 implements CacheProvider { try { this.defaultHeapSize = Long.parseLong(sDefaultHeapSize); }catch(Exception e) { - log.warn(String.format("Failed to read ehcache3.defaultHeapSize = %s , use default %d", sDefaultHeapSize, defaultHeapSize)); + log.warn("Failed to read ehcache3.defaultHeapSize = {} , use default {}", sDefaultHeapSize, defaultHeapSize); } String configXml = props.getProperty("configXml"); if(configXml == null || configXml.trim().length() == 0) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index e582b83..5c2166e 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -164,7 +164,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp RedisPubSubAsyncCommands async = this.pubsub_subscriber.async(); async.subscribe(this.channel); - log.info("Connected to redis channel:" + this.channel + ", time " + (System.currentTimeMillis()-ct) + " ms."); + log.info("Connected to redis channel:{}, time {}ms.", this.channel, System.currentTimeMillis()-ct); } @Override diff --git a/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java b/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java index fa49034..833e3b9 100644 --- a/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java +++ b/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java @@ -72,12 +72,12 @@ public class XmemcachedCacheProvider implements CacheProvider { try { client = builder.build(); - log.info(String.format("Memcached client starts with servers(%s),auth(%s),pool-size(%s),time(%dms)", + log.info("Memcached client starts with servers({}),auth({}),pool-size({}),time({}ms)", servers, needAuth, builder.getConfiguration().getSelectorPoolSize(), System.currentTimeMillis() - ct - )); + ); } catch (IOException e) { log.error("Failed to connect to memcached", e); } diff --git a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java index 98c08a1..ada060f 100644 --- a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java +++ b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java @@ -80,13 +80,13 @@ public class RedisCacheProvider implements CacheProvider { .database(database) .poolConfig(poolConfig).newClient(); - log.info(String.format("Redis client starts with mode(%s),db(%d),storage(%s),namespace(%s),time(%dms)", + log.info("Redis client starts with mode({}),db({}),storage({}),namespace({}),time({}ms)", mode, database, storage, namespace, (System.currentTimeMillis()-ct) - )); + ); } @Override diff --git a/core/src/net/oschina/j2cache/redis/RedisClient.java b/core/src/net/oschina/j2cache/redis/RedisClient.java index 813aa27..573d358 100644 --- a/core/src/net/oschina/j2cache/redis/RedisClient.java +++ b/core/src/net/oschina/j2cache/redis/RedisClient.java @@ -152,7 +152,7 @@ public class RedisClient implements Closeable, AutoCloseable { break; } if(!"single".equalsIgnoreCase(mode)) - log.warn("Redis mode [" + mode + "] not defined. Using 'single'."); + log.warn("Redis mode [{}] not defined. Using 'single'.", mode); break; } } -- Gitee From 7c4a580365d7083076eb6a3c0a12ed7405cf51e6 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Thu, 22 Nov 2018 12:13:40 +0800 Subject: [PATCH 042/131] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=BC=83?= =?UTF-8?q?=E7=94=A8=20String.format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/Command.java | 2 +- core/src/net/oschina/j2cache/J2CacheBuilder.java | 2 +- core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java | 2 +- core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java | 2 +- core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java | 2 +- .../net/oschina/j2cache/redis/ReadonlyRedisCacheProvider.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/net/oschina/j2cache/Command.java b/core/src/net/oschina/j2cache/Command.java index 60d7d93..ffb214f 100644 --- a/core/src/net/oschina/j2cache/Command.java +++ b/core/src/net/oschina/j2cache/Command.java @@ -71,7 +71,7 @@ public class Command { try { return JSON.parseObject(json, Command.class); } catch (JSONException e) { - log.warn("Failed to parse j2cache command: " + json, e); + log.warn("Failed to parse j2cache command: {}", json, e); } return null; } diff --git a/core/src/net/oschina/j2cache/J2CacheBuilder.java b/core/src/net/oschina/j2cache/J2CacheBuilder.java index 1032bcb..7bfd416 100644 --- a/core/src/net/oschina/j2cache/J2CacheBuilder.java +++ b/core/src/net/oschina/j2cache/J2CacheBuilder.java @@ -115,7 +115,7 @@ public class J2CacheBuilder { //再一次清除一级缓存是为了避免缓存失效时再次从 L2 获取到值 this.holder.getLevel1Cache(region).evict(key); } - log.debug(String.format("Level 1 cache object expired, evict level 2 cache object [%s,%s]", region, key)); + log.debug("Level 1 cache object expired, evict level 2 cache object [{},{}]", region, key); if (policy != null) policy.sendEvictCmd(region, key); }); diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index 81fd370..16fac79 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -158,7 +158,7 @@ public class CaffeineProvider implements CacheProvider { this.saveCacheConfig(region, s_config); } } catch (IOException e) { - log.error("Failed to load caffeine regions define " + propertiesFile, e); + log.error("Failed to load caffeine regions define {}", propertiesFile, e); } } } diff --git a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java index 3b35a8e..80e4d68 100644 --- a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java @@ -129,7 +129,7 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli Message msg = new Message(null, cmd.json()); channel.send(msg); } catch (Exception e) { - log.error("Failed to send message to jgroups -> " + cmd, e); + log.error("Failed to send message to jgroups -> {}", cmd, e); } } } diff --git a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java index 6af2bea..ab696b2 100644 --- a/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/RocketMQClusterPolicy.java @@ -107,7 +107,7 @@ public class RocketMQClusterPolicy implements ClusterPolicy, MessageListenerConc try { this.producer.send(msg); } catch (Exception e) { - log.error(String.format("Failed to publish %s to RocketMQ", cmd.json()), e); + log.error("Failed to publish {} to RocketMQ", cmd.json(), e); } } diff --git a/core/src/net/oschina/j2cache/redis/ReadonlyRedisCacheProvider.java b/core/src/net/oschina/j2cache/redis/ReadonlyRedisCacheProvider.java index 92c5c1f..50a79bd 100644 --- a/core/src/net/oschina/j2cache/redis/ReadonlyRedisCacheProvider.java +++ b/core/src/net/oschina/j2cache/redis/ReadonlyRedisCacheProvider.java @@ -74,7 +74,7 @@ public class ReadonlyRedisCacheProvider extends RedisCacheProvider { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if(ignoreMethods.contains(methodName)) { - log.debug(String.format("Cache [%s] skipped.", methodName)); + log.debug("Cache [{}] skipped.", methodName); return null; } try { -- Gitee From b2f46fd1eb93af1524649b489568b26151db3be5 Mon Sep 17 00:00:00 2001 From: chenzy01 Date: Sat, 24 Nov 2018 10:22:05 +0800 Subject: [PATCH 043/131] if to switch --- .../src/net/oschina/j2cache/CacheChannel.java | 10 +- .../oschina/j2cache/CacheProviderHolder.java | 230 +++++++++--------- 2 files changed, 124 insertions(+), 116 deletions(-) diff --git a/core/src/net/oschina/j2cache/CacheChannel.java b/core/src/net/oschina/j2cache/CacheChannel.java index f813748..f99fc19 100644 --- a/core/src/net/oschina/j2cache/CacheChannel.java +++ b/core/src/net/oschina/j2cache/CacheChannel.java @@ -90,9 +90,9 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { try { obj.setLevel(CacheObject.LEVEL_2); obj.setValue(holder.getLevel2Cache(region).get(key)); - if (obj.rawValue() != null) + if (obj.rawValue() != null) { holder.getLevel1Cache(region).put(key, obj.rawValue()); - else { + }else { boolean cacheNull = (cacheNullObject.length > 0) ? cacheNullObject[0] : defaultCacheNullObject; if (cacheNull) set(region, key, newNullObject(), true); @@ -257,12 +257,12 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public void set(String region, String key, Object value, boolean cacheNullObject) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); - if (!cacheNullObject && value == null) return ; + if(closed) + throw new IllegalStateException("CacheChannel closed"); + try { Level1Cache level1 = holder.getLevel1Cache(region); level1.put(key, (value==null && cacheNullObject)?newNullObject():value); diff --git a/core/src/net/oschina/j2cache/CacheProviderHolder.java b/core/src/net/oschina/j2cache/CacheProviderHolder.java index 7a7f932..6b09a81 100644 --- a/core/src/net/oschina/j2cache/CacheProviderHolder.java +++ b/core/src/net/oschina/j2cache/CacheProviderHolder.java @@ -30,120 +30,128 @@ import java.util.Collection; /** * 两级的缓存管理器 + * * @author Winter Lau(javayou@gmail.com) */ public class CacheProviderHolder { - private final static Logger log = LoggerFactory.getLogger(CacheProviderHolder.class); - - private CacheProvider l1_provider; - private CacheProvider l2_provider; - - private CacheExpiredListener listener; - - private CacheProviderHolder(){} - - /** - * Initialize Cache Provider - * @param config j2cache config instance - * @param listener cache listener - * - * @return holder : return CacheProviderHolder instance - */ - public static CacheProviderHolder init(J2CacheConfig config, CacheExpiredListener listener){ - - CacheProviderHolder holder = new CacheProviderHolder(); - - holder.listener = listener; - holder.l1_provider = loadProviderInstance(config.getL1CacheName()); - if (!holder.l1_provider.isLevel(CacheObject.LEVEL_1)) - throw new CacheException(holder.l1_provider.getClass().getName() + " is not level_1 cache provider"); - holder.l1_provider.start(config.getL1CacheProperties()); - log.info("Using L1 CacheProvider : {}", holder.l1_provider.getClass().getName()); - - holder.l2_provider = loadProviderInstance(config.getL2CacheName()); - if (!holder.l2_provider.isLevel(CacheObject.LEVEL_2)) - throw new CacheException(holder.l2_provider.getClass().getName() + " is not level_2 cache provider"); - holder.l2_provider.start(config.getL2CacheProperties()); - log.info("Using L2 CacheProvider : {}", holder.l2_provider.getClass().getName()); - - return holder; - } - - /** - * 关闭缓存 - */ - public void shutdown() { - l1_provider.stop(); - l2_provider.stop(); - } - - private static CacheProvider loadProviderInstance(String cacheIdent) { - if("ehcache".equalsIgnoreCase(cacheIdent)) - return new EhCacheProvider(); - if("ehcache3".equalsIgnoreCase(cacheIdent)) - return new EhCacheProvider3(); - if("caffeine".equalsIgnoreCase(cacheIdent)) - return new CaffeineProvider(); - if("redis".equalsIgnoreCase(cacheIdent)) - return new RedisCacheProvider(); - if("readonly-redis".equalsIgnoreCase(cacheIdent)) - return new ReadonlyRedisCacheProvider(); - if("memcached".equalsIgnoreCase(cacheIdent)) - return new XmemcachedCacheProvider(); - if("lettuce".equalsIgnoreCase(cacheIdent)) - return new LettuceCacheProvider(); - if("none".equalsIgnoreCase(cacheIdent)) - return new NullCacheProvider(); - try { - return (CacheProvider) Class.forName(cacheIdent).newInstance(); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { - throw new CacheException("Failed to initialize cache providers", e); - } - } - - public CacheProvider getL1Provider() { - return l1_provider; - } - - public CacheProvider getL2Provider() { - return l2_provider; - } - - /** - * 一级缓存实例 - * @param region cache region - * @return level 1 cache instance - */ - public Level1Cache getLevel1Cache(String region) { - return (Level1Cache)l1_provider.buildCache(region, listener); - } - - /** - * 一级缓存实例 - * @param region cache region - * @param timeToLiveSeconds cache ttl - * @return level 1 cache instance - */ - public Level1Cache getLevel1Cache(String region, long timeToLiveSeconds) { - return (Level1Cache)l1_provider.buildCache(region, timeToLiveSeconds, listener); - } - - /** - * 二级缓存实例 - * @param region cache region - * @return level 2 cache instance - */ - public Level2Cache getLevel2Cache(String region) { - return (Level2Cache)l2_provider.buildCache(region, listener); - } - - /** - * return all regions - * @return all regions - */ - public Collection regions() { - return l1_provider.regions(); - } + private final static Logger log = LoggerFactory.getLogger(CacheProviderHolder.class); + + private CacheProvider l1_provider; + private CacheProvider l2_provider; + + private CacheExpiredListener listener; + + private CacheProviderHolder() { + } + + /** + * Initialize Cache Provider + * + * @param config j2cache config instance + * @param listener cache listener + * @return holder : return CacheProviderHolder instance + */ + public static CacheProviderHolder init(J2CacheConfig config, CacheExpiredListener listener) { + + CacheProviderHolder holder = new CacheProviderHolder(); + + holder.listener = listener; + holder.l1_provider = loadProviderInstance(config.getL1CacheName()); + if (!holder.l1_provider.isLevel(CacheObject.LEVEL_1)) + throw new CacheException(holder.l1_provider.getClass().getName() + " is not level_1 cache provider"); + holder.l1_provider.start(config.getL1CacheProperties()); + log.info("Using L1 CacheProvider : {}", holder.l1_provider.getClass().getName()); + + holder.l2_provider = loadProviderInstance(config.getL2CacheName()); + if (!holder.l2_provider.isLevel(CacheObject.LEVEL_2)) + throw new CacheException(holder.l2_provider.getClass().getName() + " is not level_2 cache provider"); + holder.l2_provider.start(config.getL2CacheProperties()); + log.info("Using L2 CacheProvider : {}", holder.l2_provider.getClass().getName()); + + return holder; + } + + /** + * 关闭缓存 + */ + public void shutdown() { + l1_provider.stop(); + l2_provider.stop(); + } + + private static CacheProvider loadProviderInstance(String cacheIdent) { + switch (cacheIdent.toLowerCase()) { + case "ehcache": + return new EhCacheProvider(); + case "ehcache3": + return new EhCacheProvider3(); + case "caffeine": + return new CaffeineProvider(); + case "redis": + return new RedisCacheProvider(); + case "readonly-redis": + return new ReadonlyRedisCacheProvider(); + case "memcached": + return new XmemcachedCacheProvider(); + case "lettuce": + return new LettuceCacheProvider(); + case "none": + return new NullCacheProvider(); + } + try { + return (CacheProvider) Class.forName(cacheIdent).newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + throw new CacheException("Failed to initialize cache providers", e); + } + } + + public CacheProvider getL1Provider() { + return l1_provider; + } + + public CacheProvider getL2Provider() { + return l2_provider; + } + + /** + * 一级缓存实例 + * + * @param region cache region + * @return level 1 cache instance + */ + public Level1Cache getLevel1Cache(String region) { + return (Level1Cache) l1_provider.buildCache(region, listener); + } + + /** + * 一级缓存实例 + * + * @param region cache region + * @param timeToLiveSeconds cache ttl + * @return level 1 cache instance + */ + public Level1Cache getLevel1Cache(String region, long timeToLiveSeconds) { + return (Level1Cache) l1_provider.buildCache(region, timeToLiveSeconds, listener); + } + + /** + * 二级缓存实例 + * + * @param region cache region + * @return level 2 cache instance + */ + public Level2Cache getLevel2Cache(String region) { + return (Level2Cache) l2_provider.buildCache(region, listener); + } + + /** + * return all regions + * + * @return all regions + */ + public Collection regions() { + return l1_provider.regions(); + } } -- Gitee From 99b31c943b6c26a4aa9afc804ea3d025bae70e23 Mon Sep 17 00:00:00 2001 From: navyl Date: Mon, 26 Nov 2018 11:28:19 +0800 Subject: [PATCH 044/131] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84j2cache=EF=BC=8C=E5=B9=B6=E4=B8=94=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9lettuce=E7=9A=84=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/spring-boot2-starter/pom.xml | 2 +- modules/spring-boot2-starter/readme.md | 2 +- .../autoconfigure/J2CacheSpringRedisAutoConfiguration.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index 948e90d..20e9b2a 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.5-release + 2.7.6-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot2-starter/readme.md b/modules/spring-boot2-starter/readme.md index 23c1121..0408f0e 100644 --- a/modules/spring-boot2-starter/readme.md +++ b/modules/spring-boot2-starter/readme.md @@ -32,7 +32,7 @@ j2cache.broadcast = net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPol 在j2cache.properties中配置,使用springRedis替换二级缓存 ``` j2cache.L2.provider_class = net.oschina.j2cache.cache.support.redis.SpringRedisProvider -j2cache.L2.config_section = redis +j2cache.L2.config_section = redis (如果要使用lettuce客户端请配置为lettuce) ``` 在application.properties中支持redis客户端 * jedis diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java index e49f280..ba6b171 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java @@ -68,7 +68,7 @@ public class J2CacheSpringRedisAutoConfiguration { public JedisConnectionFactory jedisConnectionFactory(net.oschina.j2cache.J2CacheConfig j2CacheConfig) { Properties l2CacheProperties = j2CacheConfig.getL2CacheProperties(); String hosts = l2CacheProperties.getProperty("hosts"); - String mode = l2CacheProperties.getProperty("mode"); + String mode = l2CacheProperties.getProperty("mode") == null ? "null" : l2CacheProperties.getProperty("mode"); String clusterName = l2CacheProperties.getProperty("cluster_name"); String password = l2CacheProperties.getProperty("password"); int database = l2CacheProperties.getProperty("database") == null ? 0 @@ -149,7 +149,7 @@ public class J2CacheSpringRedisAutoConfiguration { public LettuceConnectionFactory lettuceConnectionFactory(net.oschina.j2cache.J2CacheConfig j2CacheConfig) { Properties l2CacheProperties = j2CacheConfig.getL2CacheProperties(); String hosts = l2CacheProperties.getProperty("hosts"); - String mode = l2CacheProperties.getProperty("mode"); + String mode = l2CacheProperties.getProperty("mode") == null ? "null" : l2CacheProperties.getProperty("mode"); String clusterName = l2CacheProperties.getProperty("cluster_name"); String password = l2CacheProperties.getProperty("password"); int database = l2CacheProperties.getProperty("database") == null ? 0 -- Gitee From dcec35d203631614fd83d8bea71bda60afb254ba Mon Sep 17 00:00:00 2001 From: navyl Date: Wed, 28 Nov 2018 10:25:47 +0800 Subject: [PATCH 045/131] =?UTF-8?q?=E8=B0=83=E7=94=A8j2cache=E7=9A=84get?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0=E4=BD=BF=E7=94=A8=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/autoconfigure/J2CacheConfig.java | 4 +- .../j2cache/cache/support/J2CacheCache.java | 2 +- .../redis/SpringRedisGenericCache.java | 2 +- .../redis/SpringRedisPubSubPolicy.java | 61 ++++++++----------- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java index cb2b0e4..8c75317 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java @@ -26,9 +26,9 @@ public class J2CacheConfig { private String cacheCleanMode = "passive"; /** - * 是否允许缓存空值,默认:true + * 是否允许缓存空值,默认:false */ - private boolean allowNullValues = true; + private boolean allowNullValues = false; /** * 使用哪种redis客户端,默认:jedis diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java index 0ec59bd..9be5031 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java @@ -82,7 +82,7 @@ public class J2CacheCache extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { - CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key), super.isAllowNullValues()); + CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key)); if(cacheObject.rawValue() != null && cacheObject.rawValue().getClass().equals(NullObject.class) && super.isAllowNullValues()) { return NullValue.INSTANCE; } diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java index 66d1d32..8b4b1ae 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java @@ -95,7 +95,7 @@ public class SpringRedisGenericCache implements Level2Cache { log.debug(String.format("Invalid timeToLiveInSeconds value : %d , skipped it.", timeToLiveInSeconds)); setBytes(key, bytes); } else { - redisTemplate.opsForValue().getOperations().execute((RedisCallback>) redis -> { + redisTemplate.execute((RedisCallback>) redis -> { redis.setEx(_key(key), (int) timeToLiveInSeconds, bytes); return null; }); diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index 26abc57..47fd38f 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -47,29 +47,31 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { J2CacheConfig j2config = SpringUtil.getBean(J2CacheConfig.class); this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); this.redisTemplate = SpringUtil.getBean("j2CacheRedisTemplate", RedisTemplate.class); - if("active".equals(config.getCacheCleanMode())) { - isActive = true; - } String channel_name = j2config.getL2CacheProperties().getProperty("channel"); if(channel_name != null && !channel_name.isEmpty()) { this.channel = channel_name; } RedisMessageListenerContainer listenerContainer = SpringUtil.getBean("j2CacheRedisMessageListenerContainer", RedisMessageListenerContainer.class); + //设置键值回调 需要redis开启键值回调 + ConfigureNotifyKeyspaceEventsAction action = new ConfigureNotifyKeyspaceEventsAction(); + action.config(listenerContainer.getConnectionFactory().getConnection()); - listenerContainer.addMessageListener(new SpringRedisMessageListener(this, this.channel), new PatternTopic(this.channel)); - if(isActive || "blend".equals(config.getCacheCleanMode())) { - //设置键值回调 - ConfigureNotifyKeyspaceEventsAction action = new ConfigureNotifyKeyspaceEventsAction(); - action.config(listenerContainer.getConnectionFactory().getConnection()); - - String namespace = j2config.getL2CacheProperties().getProperty("namespace"); - String database = j2config.getL2CacheProperties().getProperty("database"); - String expired = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:expired"; - String del = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:del"; - List topics = new ArrayList<>(); - topics.add(new PatternTopic(expired)); - topics.add(new PatternTopic(del)); + String namespace = j2config.getL2CacheProperties().getProperty("namespace"); + String database = j2config.getL2CacheProperties().getProperty("database"); + String expired = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:expired"; + String del = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:del"; + List topics = new ArrayList<>(); + topics.add(new PatternTopic(expired)); + topics.add(new PatternTopic(del)); + + if("active".equals(config.getCacheCleanMode())) { + isActive = true; + listenerContainer.addMessageListener(new SpringRedisActiveMessageListener(this, namespace), topics); + }else if("blend".equals(config.getCacheCleanMode())) { listenerContainer.addMessageListener(new SpringRedisActiveMessageListener(this, namespace), topics); + listenerContainer.addMessageListener(new SpringRedisMessageListener(this, this.channel), new PatternTopic(this.channel)); + }else { + listenerContainer.addMessageListener(new SpringRedisMessageListener(this, this.channel), new PatternTopic(this.channel)); } } @@ -91,33 +93,22 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { holder.getLevel1Cache(region).clear(); } -// @Override -// public void sendEvictCmd(String region, String... keys) { -// if(!isActive || "blend".equals(config.getCacheCleanMode())) { -// String com = new Command(Command.OPT_EVICT_KEY, region, keys).json(); -// redisTemplate.convertAndSend(this.channel, com); -// } -// -// } -// @Override -// public void sendClearCmd(String region) { -// if(!isActive || "blend".equals(config.getCacheCleanMode())) { -// String com = new Command(Command.OPT_CLEAR_KEY, region, "").json(); -// redisTemplate.convertAndSend(this.channel, com); -// } -// } - @Override public void publish(Command cmd) { - cmd.setSrc(LOCAL_COMMAND_ID); - if(!isActive || "blend".equals(config.getCacheCleanMode())) { + if(!isActive) { + cmd.setSrc(LOCAL_COMMAND_ID); redisTemplate.convertAndSend(this.channel, cmd.json()); } } @Override public void disconnect() { - redisTemplate.convertAndSend(this.channel, Command.quit().json()); + if(!isActive) { + Command cmd = new Command(); + cmd.setSrc(LOCAL_COMMAND_ID); + cmd.setOperator(Command.OPT_QUIT); + redisTemplate.convertAndSend(this.channel, cmd.json()); + } } } -- Gitee From acedad043b548eeadb9424153892fc31ff81cbe6 Mon Sep 17 00:00:00 2001 From: navyl Date: Wed, 28 Nov 2018 10:26:16 +0800 Subject: [PATCH 046/131] =?UTF-8?q?=E8=B0=83=E7=94=A8j2cache=E7=9A=84get?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/oschina/j2cache/cache/support/J2CacheCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java index 0ec59bd..9be5031 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java @@ -82,7 +82,7 @@ public class J2CacheCache extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { - CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key), super.isAllowNullValues()); + CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key)); if(cacheObject.rawValue() != null && cacheObject.rawValue().getClass().equals(NullObject.class) && super.isAllowNullValues()) { return NullValue.INSTANCE; } -- Gitee From ec40b8d32bac439320504e8a149accf0799c42a1 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Fri, 30 Nov 2018 14:09:56 +0800 Subject: [PATCH 047/131] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20cluster=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9A=84=20publish=20=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/oschina/j2cache/session/CacheFacade.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/session-manager/src/main/java/net/oschina/j2cache/session/CacheFacade.java b/modules/session-manager/src/main/java/net/oschina/j2cache/session/CacheFacade.java index b2a32bd..415f0bd 100644 --- a/modules/session-manager/src/main/java/net/oschina/j2cache/session/CacheFacade.java +++ b/modules/session-manager/src/main/java/net/oschina/j2cache/session/CacheFacade.java @@ -17,9 +17,7 @@ package net.oschina.j2cache.session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPoolConfig; -import redis.clients.jedis.JedisPubSub; +import redis.clients.jedis.*; import redis.clients.jedis.exceptions.JedisConnectionException; import java.io.Closeable; @@ -116,8 +114,15 @@ public class CacheFacade extends JedisPubSub implements Closeable, AutoCloseable */ public void publish(Command cmd) { try { - Jedis jedis = (Jedis)redisClient.get(); - jedis.publish(pubsub_channel, cmd.toString()); + BinaryJedisCommands redis = redisClient.get(); + if(redis instanceof Jedis) { + Jedis jedis = (Jedis) redis; + jedis.publish(pubsub_channel, cmd.toString()); + } + else if(redis instanceof JedisCluster) { + JedisCluster jedis = (JedisCluster) redis; + jedis.publish(pubsub_channel, cmd.toString()); + } } finally { redisClient.release(); } -- Gitee From 1dc9721184a9a7c6b35d2f5e84fc83bfe1754968 Mon Sep 17 00:00:00 2001 From: wangqiang <377900058@qq.com> Date: Tue, 4 Dec 2018 14:09:47 +0800 Subject: [PATCH 048/131] =?UTF-8?q?.sh=20=E5=9C=A8windows=20=EF=BC=88Cygwi?= =?UTF-8?q?n=EF=BC=89=E4=B8=8B=E7=9A=84readline=E4=B8=8D=E8=B5=B7=E4=BD=9C?= =?UTF-8?q?=E7=94=A8=20=E3=80=82=E6=95=85=E6=8F=90=E4=BA=A4=E4=B8=80?= =?UTF-8?q?=E4=B8=AAbat=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtest.bat | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 runtest.bat diff --git a/runtest.bat b/runtest.bat new file mode 100644 index 0000000..05f6032 --- /dev/null +++ b/runtest.bat @@ -0,0 +1,2 @@ +title J2Cache test +mvn exec:java -pl core \ No newline at end of file -- Gitee From 8d390690a210416167409eb4cd8248fc82c067b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=87?= Date: Wed, 5 Dec 2018 15:40:49 +0800 Subject: [PATCH 049/131] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9Afix=20?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=20j2cache=E5=AE=9E=E4=BE=8B=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9B=B8=E5=90=8C=E7=9A=84region=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=95=B0=E6=8D=AE=E5=9C=A8redis=E4=B8=AD?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E4=B8=8D=E6=AD=A3=E5=B8=B8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/redis/RedisCacheProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java index ada060f..e1ade03 100644 --- a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java +++ b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java @@ -101,7 +101,7 @@ public class RedisCacheProvider implements CacheProvider { @Override public Cache buildCache(String region, CacheExpiredListener listener) { - return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase(this.storage)? + return regions.computeIfAbsent(this.namespace+":"+region, v -> "hash".equalsIgnoreCase(this.storage)? new RedisHashCache(this.namespace, region, redisClient): new RedisGenericCache(this.namespace, region, redisClient)); } -- Gitee From 77e19b0e26717bd52c2c1d71e259d2ad3c7eafa1 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 5 Dec 2018 19:12:38 +0800 Subject: [PATCH 050/131] =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E9=9D=99?= =?UTF-8?q?=E6=80=81=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/redis/RedisCacheProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java index e1ade03..b9176f4 100644 --- a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java +++ b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java @@ -40,7 +40,7 @@ public class RedisCacheProvider implements CacheProvider { private String namespace; private String storage; - private static final ConcurrentHashMap regions = new ConcurrentHashMap(); + private final ConcurrentHashMap regions = new ConcurrentHashMap(); @Override public String name() { -- Gitee From 244381bf112f28c796976debc3dd8dc307850827 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 5 Dec 2018 19:14:23 +0800 Subject: [PATCH 051/131] =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E9=9D=99?= =?UTF-8?q?=E6=80=81=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 4 ++-- .../oschina/j2cache/memcached/XmemcachedCacheProvider.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 5c2166e..947259c 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -58,7 +58,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp private String channel; private String namespace; - private static final ConcurrentHashMap regions = new ConcurrentHashMap(); + private final ConcurrentHashMap regions = new ConcurrentHashMap(); @Override public String name() { @@ -106,7 +106,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp @Override public Cache buildCache(String region, CacheExpiredListener listener) { - return regions.computeIfAbsent(region, v -> "hash".equalsIgnoreCase(this.storage)? + return regions.computeIfAbsent(this.namespace + ":" + region, v -> "hash".equalsIgnoreCase(this.storage)? new LettuceHashCache(this.namespace, region, redisClient): new LettuceGenericCache(this.namespace, region, redisClient)); } diff --git a/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java b/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java index 833e3b9..52bb734 100644 --- a/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java +++ b/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java @@ -41,7 +41,7 @@ public class XmemcachedCacheProvider implements CacheProvider { private static final Logger log = LoggerFactory.getLogger(XmemcachedCacheProvider.class); private MemcachedClient client ; - private static final ConcurrentHashMap regions = new ConcurrentHashMap(); + private final ConcurrentHashMap regions = new ConcurrentHashMap(); @Override public String name() { -- Gitee From d0325ac2362cef44c602a17d65d1a2e133f3eb87 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 10 Dec 2018 19:19:04 +0800 Subject: [PATCH 052/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memcached/XmemcachedCacheProvider.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java b/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java index 52bb734..f81ff41 100644 --- a/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java +++ b/core/src/net/oschina/j2cache/memcached/XmemcachedCacheProvider.java @@ -53,21 +53,21 @@ public class XmemcachedCacheProvider implements CacheProvider { long ct = System.currentTimeMillis(); - String servers = props.getProperty("servers"); - String username = props.getProperty("username"); - String password = props.getProperty("password"); + String servers = props.getProperty("servers", "127.0.0.1:11211"); + String username = props.getProperty("username", ""); + String password = props.getProperty("password", ""); MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(servers)); builder.setCommandFactory(new BinaryCommandFactory()); boolean needAuth = username != null && password != null && username.trim().length() > 0 && password.trim().length() > 0; if(needAuth) builder.addAuthInfo(AddrUtil.getOneAddress(servers), AuthInfo.typical(username, password)); - builder.setConnectionPoolSize(Integer.valueOf(props.getProperty("connectionPoolSize"))); - builder.setConnectTimeout(Long.valueOf(props.getProperty("connectTimeout"))); - builder.setHealSessionInterval(Long.valueOf(props.getProperty("healSessionInterval"))); - builder.setMaxQueuedNoReplyOperations(Integer.valueOf(props.getProperty("maxQueuedNoReplyOperations"))); - builder.setOpTimeout(Long.valueOf(props.getProperty("opTimeout"))); - builder.setSanitizeKeys("true".equalsIgnoreCase(props.getProperty("sanitizeKeys"))); + builder.setConnectionPoolSize(Integer.valueOf(props.getProperty("connectionPoolSize", "10"))); + builder.setConnectTimeout(Long.valueOf(props.getProperty("connectTimeout", "1000"))); + builder.setHealSessionInterval(Long.valueOf(props.getProperty("healSessionInterval", "1000"))); + builder.setMaxQueuedNoReplyOperations(Integer.valueOf(props.getProperty("maxQueuedNoReplyOperations", "100"))); + builder.setOpTimeout(Long.valueOf(props.getProperty("opTimeout", "100"))); + builder.setSanitizeKeys("true".equalsIgnoreCase(props.getProperty("sanitizeKeys", "false"))); try { client = builder.build(); -- Gitee From 07c5f1d0f7761eabf872241837df3b2c12874a85 Mon Sep 17 00:00:00 2001 From: zhuo_guangfei Date: Wed, 12 Dec 2018 18:40:28 +0800 Subject: [PATCH 053/131] =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=86j2cache?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=96=87=E4=BB=B6=E7=9A=84=E6=94=BE=E7=BD=AE?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=EF=BC=8C=E5=8F=AF=E4=BB=A5=E5=9C=A8classpath?= =?UTF-8?q?=E4=B8=8B=E9=9D=A2=EF=BC=8C=E4=B9=9F=E5=8F=AF=E4=BB=A5=E5=9C=A8?= =?UTF-8?q?=E6=9F=90=E4=B8=80=E4=B8=AA=E9=9D=9Eclasspath=E7=9A=84=E7=BB=9D?= =?UTF-8?q?=E5=AF=B9=E8=B7=AF=E5=BE=84=E4=B8=8B=E9=9D=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java b/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java index c41ecb2..4f40ca1 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java @@ -24,7 +24,7 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; @ConditionalOnClass(J2Cache.class) @EnableConfigurationProperties({J2CacheConfig.class}) @Configuration -@PropertySource(value = "${j2cache.config-location}") +@PropertySource(value = {"${j2cache.config-location}","file:${j2cache.config-location}"},ignoreResourceNotFound = true ) public class J2CacheAutoConfiguration { @Autowired -- Gitee From 8203e8bf3de043eb8172d563f95a10655be52c20 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 12 Dec 2018 19:06:36 +0800 Subject: [PATCH 054/131] =?UTF-8?q?=E6=94=AF=E6=8C=81=20lettuce=20?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 9 ++++++- core/resources/j2cache.properties | 3 +++ .../oschina/j2cache/lettuce/LettuceCache.java | 19 ++++++-------- .../j2cache/lettuce/LettuceCacheProvider.java | 26 +++++++++++++++++-- .../j2cache/lettuce/LettuceGenericCache.java | 6 ++--- .../j2cache/lettuce/LettuceHashCache.java | 6 ++--- 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index c475c8e..ae02dd2 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -26,7 +26,14 @@ io.lettuce lettuce-core - 5.1.1.RELEASE + 5.1.3.RELEASE + provided + + + + org.apache.commons + commons-pool2 + 2.5.0 provided diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index 55cd602..84f5519 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -161,6 +161,9 @@ lettuce.hosts = 127.0.0.1:6379 lettuce.password = lettuce.database = 0 lettuce.sentinelMasterId = +lettuce.maxTotal = 100 +lettuce.maxIdle = 10 +lettuce.minIdle = 10 ######################################### # memcached server configurations diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceCache.java index 29eac2d..57c9f94 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCache.java @@ -15,14 +15,13 @@ */ package net.oschina.j2cache.lettuce; -import io.lettuce.core.AbstractRedisClient; -import io.lettuce.core.RedisClient; import io.lettuce.core.api.StatefulConnection; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.BaseRedisCommands; -import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import net.oschina.j2cache.CacheException; import net.oschina.j2cache.Level2Cache; +import org.apache.commons.pool2.impl.GenericObjectPool; /** * Lettuce 的基类,封装了普通 Redis 连接和集群 Redis 连接的差异 @@ -31,18 +30,16 @@ import net.oschina.j2cache.Level2Cache; */ public abstract class LettuceCache implements Level2Cache { - private static final LettuceByteCodec codec = new LettuceByteCodec(); - protected String namespace; protected String region; - protected AbstractRedisClient client; + protected GenericObjectPool> pool; protected StatefulConnection connect() { - if(client instanceof RedisClient) - return ((RedisClient)client).connect(codec); - else if(client instanceof RedisClusterClient) - return ((RedisClusterClient)client).connect(codec); - return null; + try { + return pool.borrowObject(); + } catch (Exception e) { + throw new CacheException(e); + } } protected BaseRedisCommands sync(StatefulConnection conn) { diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 947259c..d435961 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -17,13 +17,17 @@ package net.oschina.j2cache.lettuce; import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulConnection; import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.pubsub.RedisPubSubAdapter; import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; +import io.lettuce.core.support.ConnectionPoolSupport; import net.oschina.j2cache.*; import net.oschina.j2cache.cluster.ClusterPolicy; +import org.apache.commons.pool2.impl.GenericObjectPool; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import java.util.Collection; import java.util.Collections; @@ -49,7 +53,10 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private static final LettuceByteCodec codec = new LettuceByteCodec(); + private static AbstractRedisClient redisClient; + GenericObjectPool> pool; private StatefulRedisPubSubConnection pubsub_subscriber; private String storage; @@ -96,10 +103,25 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp String redis_url = String.format("%s://%s@%s/%d#%s", scheme, password, hosts, database, sentinelMasterId); redisClient = isCluster?RedisClusterClient.create(redis_url):RedisClient.create(redis_url); + + //connection pool configurations + GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); + poolConfig.setMaxTotal(Integer.parseInt(props.getProperty("maxTotal", "100"))); + poolConfig.setMaxIdle(Integer.parseInt(props.getProperty("maxIdle", "10"))); + poolConfig.setMinIdle(Integer.parseInt(props.getProperty("minIdle", "10"))); + + pool = ConnectionPoolSupport.createGenericObjectPool(() -> { + if(redisClient instanceof RedisClient) + return ((RedisClient)redisClient).connect(codec); + else if(redisClient instanceof RedisClusterClient) + return ((RedisClusterClient)redisClient).connect(codec); + return null; + }, poolConfig); } @Override public void stop() { + pool.close(); regions.clear(); redisClient.shutdown(); } @@ -107,8 +129,8 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp @Override public Cache buildCache(String region, CacheExpiredListener listener) { return regions.computeIfAbsent(this.namespace + ":" + region, v -> "hash".equalsIgnoreCase(this.storage)? - new LettuceHashCache(this.namespace, region, redisClient): - new LettuceGenericCache(this.namespace, region, redisClient)); + new LettuceHashCache(this.namespace, region, pool): + new LettuceGenericCache(this.namespace, region, pool)); } @Override diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java index 58754f7..2c1eb94 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java @@ -15,10 +15,10 @@ */ package net.oschina.j2cache.lettuce; -import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.api.StatefulConnection; import io.lettuce.core.api.sync.RedisKeyCommands; import io.lettuce.core.api.sync.RedisStringCommands; +import org.apache.commons.pool2.impl.GenericObjectPool; import java.util.Arrays; import java.util.Collection; @@ -32,11 +32,11 @@ import java.util.stream.Collectors; */ public class LettuceGenericCache extends LettuceCache { - public LettuceGenericCache(String namespace, String region, AbstractRedisClient client) { + public LettuceGenericCache(String namespace, String region, GenericObjectPool> pool) { if (region == null || region.isEmpty()) region = "_"; // 缺省region - this.client = client; + super.pool = pool; this.namespace = namespace; this.region = getRegionName(region); } diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java index 29be647..593a478 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceHashCache.java @@ -15,10 +15,10 @@ */ package net.oschina.j2cache.lettuce; -import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.api.StatefulConnection; import io.lettuce.core.api.sync.RedisHashCommands; import io.lettuce.core.api.sync.RedisKeyCommands; +import org.apache.commons.pool2.impl.GenericObjectPool; import java.util.Collection; import java.util.List; @@ -33,11 +33,11 @@ import java.util.stream.Collectors; */ public class LettuceHashCache extends LettuceCache { - public LettuceHashCache(String namespace, String region, AbstractRedisClient client) { + public LettuceHashCache(String namespace, String region, GenericObjectPool> pool) { if (region == null || region.isEmpty()) region = "_"; // 缺省region - super.client = client; + super.pool = pool; super.namespace = namespace; super.region = getRegionName(region); } -- Gitee From cbacd56cc18fcbcc3af4230cf6ec47aa9cb0e8c6 Mon Sep 17 00:00:00 2001 From: navyl Date: Thu, 13 Dec 2018 09:51:02 +0800 Subject: [PATCH 055/131] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=8F=AF=E4=BB=A5=E5=BC=80=E5=90=AF=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E4=BA=8C=E7=BA=A7=E7=BC=93=E5=AD=98=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=94=AF=E6=8C=81=E5=9C=A8spring=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E5=86=99j2cache=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E7=BB=86?= =?UTF-8?q?=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../J2CacheAutoConfiguration.java | 2 +- .../j2cache/autoconfigure/J2CacheConfig.java | 14 ++++ .../J2CacheSpringRedisAutoConfiguration.java | 1 + .../support/redis/SpringRedisProvider.java | 6 ++ .../redis/SpringRedisPubSubPolicy.java | 20 ++++-- .../support/util/SpringJ2CacheConfigUtil.java | 6 +- .../test/src/com/test/ApplicationTests.java | 65 +++++++++++++++---- 7 files changed, 92 insertions(+), 22 deletions(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java index 1049c8c..c944e5c 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java @@ -24,7 +24,7 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; @ConditionalOnClass(J2Cache.class) @EnableConfigurationProperties({J2CacheConfig.class}) @Configuration -@PropertySource(value = "${j2cache.config-location}") +@PropertySource(value = "${j2cache.config-location}", encoding = "UTF-8", ignoreResourceNotFound = true) public class J2CacheAutoConfiguration { @Autowired diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java index 8c75317..490d68e 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java @@ -38,6 +38,11 @@ public class J2CacheConfig { * */ private String redisClient = "jedis"; + + /** + * 是否开启二级缓存 + */ + private boolean l2CacheOpen = true; public String getConfigLocation() { @@ -79,4 +84,13 @@ public class J2CacheConfig { public void setRedisClient(String redisClient) { this.redisClient = redisClient; } + + public boolean getL2CacheOpen() { + return l2CacheOpen; + } + + public void setL2CacheOpen(boolean l2CacheOpen) { + this.l2CacheOpen = l2CacheOpen; + } + } diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java index ba6b171..8a09f5d 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java @@ -53,6 +53,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException; @Configuration @AutoConfigureAfter({ RedisAutoConfiguration.class }) @AutoConfigureBefore({ J2CacheAutoConfiguration.class }) +@ConditionalOnProperty(value = "j2cache.l2-cache-open", havingValue = "true", matchIfMissing = true) public class J2CacheSpringRedisAutoConfiguration { private final static int MAX_ATTEMPTS = 3; diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java index 10cb7e1..febe691 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java @@ -23,6 +23,8 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; public class SpringRedisProvider implements CacheProvider { private RedisTemplate redisTemplate; + + private net.oschina.j2cache.autoconfigure.J2CacheConfig config; private String namespace; @@ -74,6 +76,10 @@ public class SpringRedisProvider implements CacheProvider { public void start(Properties props) { this.namespace = props.getProperty("namespace"); this.storage = props.getProperty("storage"); + this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); + if(config.getL2CacheOpen() == false) { + return; + } this.redisTemplate = SpringUtil.getBean("j2CacheRedisTemplate", RedisTemplate.class); } diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index 47fd38f..8b1a80c 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -5,15 +5,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import net.oschina.j2cache.CacheProviderHolder; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.PatternTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; -import net.oschina.j2cache.cluster.ClusterPolicy; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.Command; import net.oschina.j2cache.J2CacheConfig; import net.oschina.j2cache.cache.support.util.SpringUtil; +import net.oschina.j2cache.cluster.ClusterPolicy; /** * 使用spring redis实现订阅功能 @@ -26,6 +26,7 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { private RedisTemplate redisTemplate; private net.oschina.j2cache.autoconfigure.J2CacheConfig config; + private CacheProviderHolder holder; /** @@ -44,18 +45,17 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @Override public void connect(Properties props, CacheProviderHolder holder) { this.holder = holder; - J2CacheConfig j2config = SpringUtil.getBean(J2CacheConfig.class); this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); + if(config.getL2CacheOpen() == false) { + return; + } + J2CacheConfig j2config = SpringUtil.getBean(J2CacheConfig.class); this.redisTemplate = SpringUtil.getBean("j2CacheRedisTemplate", RedisTemplate.class); String channel_name = j2config.getL2CacheProperties().getProperty("channel"); if(channel_name != null && !channel_name.isEmpty()) { this.channel = channel_name; } RedisMessageListenerContainer listenerContainer = SpringUtil.getBean("j2CacheRedisMessageListenerContainer", RedisMessageListenerContainer.class); - //设置键值回调 需要redis开启键值回调 - ConfigureNotifyKeyspaceEventsAction action = new ConfigureNotifyKeyspaceEventsAction(); - action.config(listenerContainer.getConnectionFactory().getConnection()); - String namespace = j2config.getL2CacheProperties().getProperty("namespace"); String database = j2config.getL2CacheProperties().getProperty("database"); String expired = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:expired"; @@ -66,8 +66,14 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { if("active".equals(config.getCacheCleanMode())) { isActive = true; + //设置键值回调 需要redis支持键值回调 + ConfigureNotifyKeyspaceEventsAction action = new ConfigureNotifyKeyspaceEventsAction(); + action.config(listenerContainer.getConnectionFactory().getConnection()); listenerContainer.addMessageListener(new SpringRedisActiveMessageListener(this, namespace), topics); }else if("blend".equals(config.getCacheCleanMode())) { + //设置键值回调 需要redis支持键值回调 + ConfigureNotifyKeyspaceEventsAction action = new ConfigureNotifyKeyspaceEventsAction(); + action.config(listenerContainer.getConnectionFactory().getConnection()); listenerContainer.addMessageListener(new SpringRedisActiveMessageListener(this, namespace), topics); listenerContainer.addMessageListener(new SpringRedisMessageListener(this, this.channel), new PatternTopic(this.channel)); }else { diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index 867b9bf..8824ca2 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -1,7 +1,7 @@ package net.oschina.j2cache.cache.support.util; +import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.StandardEnvironment; -import org.springframework.core.io.support.ResourcePropertySource; import net.oschina.j2cache.J2CacheConfig; @@ -23,8 +23,8 @@ public class SpringJ2CacheConfigUtil { l2_config_section = config.getL2CacheName(); final String l2_section = l2_config_section; environment.getPropertySources().forEach(a -> { - if(a instanceof ResourcePropertySource) { - ResourcePropertySource c = (ResourcePropertySource) a; + if(a instanceof MapPropertySource) { + MapPropertySource c = (MapPropertySource) a; c.getSource().forEach((k,v) -> { String key = k; if (key.startsWith(config.getBroadcast() + ".")) { diff --git a/modules/spring-boot2-starter/test/src/com/test/ApplicationTests.java b/modules/spring-boot2-starter/test/src/com/test/ApplicationTests.java index 8911a75..7f9fd66 100644 --- a/modules/spring-boot2-starter/test/src/com/test/ApplicationTests.java +++ b/modules/spring-boot2-starter/test/src/com/test/ApplicationTests.java @@ -1,5 +1,8 @@ package com.test; +import java.io.IOException; +import java.util.Random; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -17,27 +20,60 @@ import net.oschina.j2cache.autoconfigure.J2CacheSpringCacheAutoConfiguration; import net.oschina.j2cache.autoconfigure.J2CacheSpringRedisAutoConfiguration; @RunWith(SpringRunner.class) -@SpringBootTest(classes = { TestService.class, J2CacheAutoConfiguration.class, - J2CacheSpringCacheAutoConfiguration.class, J2CacheSpringRedisAutoConfiguration.class }, properties = { - "j2cache.config-location=classpath:/com/test/j2cache-test.properties", "spring.cache.type=GENERIC", - "j2cache.open-spring-cache=true", "j2cache.j2CacheConfig.serialization=json","j2cache.redis-client=jedis"}) +@SpringBootTest(classes = { + TestService.class, + J2CacheAutoConfiguration.class, + J2CacheSpringCacheAutoConfiguration.class, + J2CacheSpringRedisAutoConfiguration.class }, + properties = { + "j2cache.config-location=classpath:/com/test/j2cache-test.properties", + "spring.cache.type=GENERIC", + "j2cache.open-spring-cache=true", + "j2cache.j2CacheConfig.serialization=json", + "j2cache.redis-client=jedis", + "j2cache.cache-clean-mode=active", + "j2cache.allow-null-values=true", + "j2cache.l2-cache-open=true" + }) public class ApplicationTests { @Autowired private TestService testService; - + @Autowired private CacheChannel cacheChannel; @Test - public void testCache() { + public void testCache() throws IOException { testService.reset(); testService.evict(); testService.getNum(); - Integer n = testService.getNum(); - Assert.isTrue(n == 1, "缓存未生效!"); + testService.getNum(); +// testService.getNum(); +// testService.getNum(); +// Integer n = testService.getNum(); +// Assert.isTrue(n == 1, "缓存未生效!"); + for (int i = 1; i < 200; i++) { + new Thread(() -> { + for (int j = 1; j < 1000; j++) { + Integer n = testService.getNum(); + try { + Random r = new Random(); + Thread.sleep(r.nextInt(100)); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// if(n == null) { +// System.out.println(Thread.currentThread().getId() + ":出现缓存为null:" + j); +// } + } + }).start(); + } + System.in.read(); + } - + @Test public void clearCache() { testService.reset(); @@ -47,7 +83,7 @@ public class ApplicationTests { Integer a = testService.getNum(); Assert.isTrue(a == 1, "清除缓存未生效!"); } - + @Test public void beanCache() { testService.reset(); @@ -57,11 +93,18 @@ public class ApplicationTests { Integer a = b.getNum(); Assert.isTrue(a == 1, "对象缓存未生效!"); } - + @Test public void test() { cacheChannel.set("test", "123", "321"); CacheObject a = cacheChannel.get("test", "123"); Assert.isTrue(a.getValue().equals("321"), "失败!"); } + + @Test + public void test1() { +// cacheChannel.set("test", "123", "321"); + CacheObject a = cacheChannel.get("test", "1233"); + Assert.isTrue(a.getValue().equals("321"), "失败!"); + } } -- Gitee From 14088e471857152ccbf87eb8c94f2f6f5c320187 Mon Sep 17 00:00:00 2001 From: zhangsaizz <937425288@qq.com> Date: Thu, 13 Dec 2018 09:58:49 +0800 Subject: [PATCH 056/131] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20readme.md=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/spring-boot2-starter/readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/spring-boot2-starter/readme.md b/modules/spring-boot2-starter/readme.md index 0408f0e..da76adf 100644 --- a/modules/spring-boot2-starter/readme.md +++ b/modules/spring-boot2-starter/readme.md @@ -40,4 +40,8 @@ j2cache.L2.config_section = redis (如果要使用lettuce客户端请配置为le ``` j2cache.redis-client=jedis ``` +在application.properties中支持关闭二级缓存 +``` +j2cache.l2-cache-open=false(默认开启) +``` -- Gitee From 590021060bdc914e090dc88053e5ea2bcf65826f Mon Sep 17 00:00:00 2001 From: navyl Date: Thu, 13 Dec 2018 10:20:06 +0800 Subject: [PATCH 057/131] =?UTF-8?q?=E6=94=B9=E5=96=84=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/autoconfigure/J2CacheConfig.java | 44 +++++++-- .../J2CacheSpringRedisAutoConfiguration.java | 2 + .../support/redis/SpringRedisProvider.java | 10 +++ .../redis/SpringRedisPubSubPolicy.java | 89 +++++++++---------- .../support/util/SpringJ2CacheConfigUtil.java | 5 +- .../support/redis/SpringRedisProvider.java | 4 + .../redis/SpringRedisPubSubPolicy.java | 6 +- 7 files changed, 103 insertions(+), 57 deletions(-) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java b/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java index 4e859da..490d68e 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheConfig.java @@ -17,17 +17,34 @@ public class J2CacheConfig { /** * 缓存清除模式, - * active:主动清除,二级缓存过期主动通知各节点清除,优点在于所有节点可以同时收到缓存清除 - * passive:被动清除,一级缓存过期进行通知各节点清除一二级缓存, - * blend:两种模式一起运作,对于各个节点缓存准确以及及时性要求高的可以使用,正常用前两种模式中一个就可 + *

    + *
  • active:主动清除,二级缓存过期主动通知各节点清除,优点在于所有节点可以同时收到缓存清除
  • + *
  • passive:被动清除,一级缓存过期进行通知各节点清除一二级缓存,
  • + *
  • blend:两种模式一起运作,对于各个节点缓存准确以及及时性要求高的可以使用,正常用前两种模式中一个就可
  • + *
*/ private String cacheCleanMode = "passive"; /** - * 是否允许缓存空值,默认:true + * 是否允许缓存空值,默认:false */ - private boolean allowNullValues = true; + private boolean allowNullValues = false; + + /** + * 使用哪种redis客户端,默认:jedis + * + */ + private String redisClient = "jedis"; + + /** + * 是否开启二级缓存 + */ + private boolean l2CacheOpen = true; + public String getConfigLocation() { return configLocation; } @@ -59,4 +76,21 @@ public class J2CacheConfig { public void setAllowNullValues(boolean allowNullValues) { this.allowNullValues = allowNullValues; } + + public String getRedisClient() { + return redisClient; + } + + public void setRedisClient(String redisClient) { + this.redisClient = redisClient; + } + + public boolean getL2CacheOpen() { + return l2CacheOpen; + } + + public void setL2CacheOpen(boolean l2CacheOpen) { + this.l2CacheOpen = l2CacheOpen; + } + } diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java b/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java index 0b35e3e..a7a5a55 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java @@ -14,6 +14,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -40,6 +41,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException; @Configuration @AutoConfigureAfter({ RedisAutoConfiguration.class }) @AutoConfigureBefore({ J2CacheAutoConfiguration.class }) +@ConditionalOnProperty(value = "j2cache.l2-cache-open", havingValue = "true", matchIfMissing = true) public class J2CacheSpringRedisAutoConfiguration { private final static int MAX_ATTEMPTS = 3; diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java index 10cb7e1..0ef416a 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java @@ -13,6 +13,7 @@ import net.oschina.j2cache.CacheChannel; import net.oschina.j2cache.CacheExpiredListener; import net.oschina.j2cache.CacheObject; import net.oschina.j2cache.CacheProvider; +import net.oschina.j2cache.NullCache; import net.oschina.j2cache.cache.support.util.SpringUtil; /** @@ -23,6 +24,8 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; public class SpringRedisProvider implements CacheProvider { private RedisTemplate redisTemplate; + + private net.oschina.j2cache.autoconfigure.J2CacheConfig config; private String namespace; @@ -47,6 +50,9 @@ public class SpringRedisProvider implements CacheProvider { @Override public Cache buildCache(String region, CacheExpiredListener listener) { + if(config.getL2CacheOpen() == false) { + return new NullCache(); + } Cache cache = caches.get(region); if (cache == null) { synchronized (SpringRedisProvider.class) { @@ -74,6 +80,10 @@ public class SpringRedisProvider implements CacheProvider { public void start(Properties props) { this.namespace = props.getProperty("namespace"); this.storage = props.getProperty("storage"); + this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); + if(config.getL2CacheOpen() == false) { + return; + } this.redisTemplate = SpringUtil.getBean("j2CacheRedisTemplate", RedisTemplate.class); } diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index 94a4194..eca5aa7 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -5,15 +5,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import net.oschina.j2cache.CacheProviderHolder; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.PatternTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; -import net.oschina.j2cache.cluster.ClusterPolicy; +import net.oschina.j2cache.CacheProviderHolder; import net.oschina.j2cache.Command; import net.oschina.j2cache.J2CacheConfig; import net.oschina.j2cache.cache.support.util.SpringUtil; +import net.oschina.j2cache.cluster.ClusterPolicy; /** * 使用spring redis实现订阅功能 @@ -22,16 +22,18 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; public class SpringRedisPubSubPolicy implements ClusterPolicy { private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private RedisTemplate redisTemplate; - + private net.oschina.j2cache.autoconfigure.J2CacheConfig config; + private CacheProviderHolder holder; - + /** * 是否是主动模式 */ private static boolean isActive = false; - + private String channel = "j2cache_channel"; @Override @@ -43,34 +45,39 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @Override public void connect(Properties props, CacheProviderHolder holder) { this.holder = holder; + this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); + if(config.getL2CacheOpen() == false) { + return; + } J2CacheConfig j2config = SpringUtil.getBean(J2CacheConfig.class); - this.config = SpringUtil.getBean(net.oschina.j2cache.autoconfigure.J2CacheConfig.class); this.redisTemplate = SpringUtil.getBean("j2CacheRedisTemplate", RedisTemplate.class); - if ("active".equals(config.getCacheCleanMode())) { - isActive = true; - } String channel_name = j2config.getL2CacheProperties().getProperty("channel"); - if (channel_name != null && !channel_name.isEmpty()) { + if(channel_name != null && !channel_name.isEmpty()) { this.channel = channel_name; } - RedisMessageListenerContainer listenerContainer = SpringUtil.getBean("j2CacheRedisMessageListenerContainer", - RedisMessageListenerContainer.class); - - listenerContainer.addMessageListener(new SpringRedisMessageListener(this, this.channel), - new PatternTopic(this.channel)); - if (isActive) { - // 设置键值回调 + RedisMessageListenerContainer listenerContainer = SpringUtil.getBean("j2CacheRedisMessageListenerContainer", RedisMessageListenerContainer.class); + String namespace = j2config.getL2CacheProperties().getProperty("namespace"); + String database = j2config.getL2CacheProperties().getProperty("database"); + String expired = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:expired"; + String del = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:del"; + List topics = new ArrayList<>(); + topics.add(new PatternTopic(expired)); + topics.add(new PatternTopic(del)); + + if("active".equals(config.getCacheCleanMode())) { + isActive = true; + //设置键值回调 需要redis支持键值回调 + ConfigureNotifyKeyspaceEventsAction action = new ConfigureNotifyKeyspaceEventsAction(); + action.config(listenerContainer.getConnectionFactory().getConnection()); + listenerContainer.addMessageListener(new SpringRedisActiveMessageListener(this, namespace), topics); + }else if("blend".equals(config.getCacheCleanMode())) { + //设置键值回调 需要redis支持键值回调 ConfigureNotifyKeyspaceEventsAction action = new ConfigureNotifyKeyspaceEventsAction(); action.config(listenerContainer.getConnectionFactory().getConnection()); - - String namespace = j2config.getL2CacheProperties().getProperty("namespace"); - String database = j2config.getL2CacheProperties().getProperty("database"); - String expired = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:expired"; - String del = "__keyevent@" + (database == null || "".equals(database) ? "0" : database) + "__:del"; - List topics = new ArrayList<>(); - topics.add(new PatternTopic(expired)); - topics.add(new PatternTopic(del)); listenerContainer.addMessageListener(new SpringRedisActiveMessageListener(this, namespace), topics); + listenerContainer.addMessageListener(new SpringRedisMessageListener(this, this.channel), new PatternTopic(this.channel)); + }else { + listenerContainer.addMessageListener(new SpringRedisMessageListener(this, this.channel), new PatternTopic(this.channel)); } } @@ -92,34 +99,22 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { holder.getLevel1Cache(region).clear(); } - // @Override - // public void sendEvictCmd(String region, String... keys) { - // if(!isActive || "blend".equals(config.getCacheCleanMode())) { - // String com = new Command(Command.OPT_EVICT_KEY, region, keys).json(); - // redisTemplate.convertAndSend(this.channel, com); - // } - // - // } - - // @Override - // public void sendClearCmd(String region) { - // if(!isActive || "blend".equals(config.getCacheCleanMode())) { - // String com = new Command(Command.OPT_CLEAR_KEY, region, "").json(); - // redisTemplate.convertAndSend(this.channel, com); - // } - // } - @Override - public void publish(Command cmd) { - cmd.setSrc(LOCAL_COMMAND_ID); - if (!isActive || "blend".equals(config.getCacheCleanMode())) { + public void publish(Command cmd) { + if(!isActive && config.getL2CacheOpen()) { + cmd.setSrc(LOCAL_COMMAND_ID); redisTemplate.convertAndSend(this.channel, cmd.json()); } - } + } @Override public void disconnect() { - redisTemplate.convertAndSend(this.channel, Command.quit().json()); + if(!isActive && config.getL2CacheOpen()) { + Command cmd = new Command(); + cmd.setSrc(LOCAL_COMMAND_ID); + cmd.setOperator(Command.OPT_QUIT); + redisTemplate.convertAndSend(this.channel, cmd.json()); + } } } diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index 867b9bf..5cbd4d8 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -1,5 +1,6 @@ package net.oschina.j2cache.cache.support.util; +import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.support.ResourcePropertySource; @@ -23,8 +24,8 @@ public class SpringJ2CacheConfigUtil { l2_config_section = config.getL2CacheName(); final String l2_section = l2_config_section; environment.getPropertySources().forEach(a -> { - if(a instanceof ResourcePropertySource) { - ResourcePropertySource c = (ResourcePropertySource) a; + if(a instanceof MapPropertySource) { + MapPropertySource c = (MapPropertySource) a; c.getSource().forEach((k,v) -> { String key = k; if (key.startsWith(config.getBroadcast() + ".")) { diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java index febe691..0ef416a 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisProvider.java @@ -13,6 +13,7 @@ import net.oschina.j2cache.CacheChannel; import net.oschina.j2cache.CacheExpiredListener; import net.oschina.j2cache.CacheObject; import net.oschina.j2cache.CacheProvider; +import net.oschina.j2cache.NullCache; import net.oschina.j2cache.cache.support.util.SpringUtil; /** @@ -49,6 +50,9 @@ public class SpringRedisProvider implements CacheProvider { @Override public Cache buildCache(String region, CacheExpiredListener listener) { + if(config.getL2CacheOpen() == false) { + return new NullCache(); + } Cache cache = caches.get(region); if (cache == null) { synchronized (SpringRedisProvider.class) { diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java index 8b1a80c..eca5aa7 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisPubSubPolicy.java @@ -22,7 +22,7 @@ import net.oschina.j2cache.cluster.ClusterPolicy; public class SpringRedisPubSubPolicy implements ClusterPolicy { private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 - + private RedisTemplate redisTemplate; private net.oschina.j2cache.autoconfigure.J2CacheConfig config; @@ -101,7 +101,7 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @Override public void publish(Command cmd) { - if(!isActive) { + if(!isActive && config.getL2CacheOpen()) { cmd.setSrc(LOCAL_COMMAND_ID); redisTemplate.convertAndSend(this.channel, cmd.json()); } @@ -109,7 +109,7 @@ public class SpringRedisPubSubPolicy implements ClusterPolicy { @Override public void disconnect() { - if(!isActive) { + if(!isActive && config.getL2CacheOpen()) { Command cmd = new Command(); cmd.setSrc(LOCAL_COMMAND_ID); cmd.setOperator(Command.OPT_QUIT); -- Gitee From 4199f180fd379ee3a5d827d0f0e5652d5b8604bd Mon Sep 17 00:00:00 2001 From: zhangsaizz <937425288@qq.com> Date: Thu, 13 Dec 2018 10:22:55 +0800 Subject: [PATCH 058/131] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20readme.md=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E4=BA=8C=E7=BA=A7=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E9=97=AD=E5=92=8C=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/spring-boot-starter/readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/spring-boot-starter/readme.md b/modules/spring-boot-starter/readme.md index 70b300f..4f1671a 100644 --- a/modules/spring-boot-starter/readme.md +++ b/modules/spring-boot-starter/readme.md @@ -34,5 +34,8 @@ j2cache.broadcast = net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPol j2cache.L2.provider_class = net.oschina.j2cache.cache.support.redis.SpringRedisProvider j2cache.L2.config_section = redis ``` - +在application.properties中支持关闭二级缓存 +``` +j2cache.l2-cache-open=false(默认开启) +``` -- Gitee From 8be82aa4ae30a6028d446b18fa582c07e11f28e0 Mon Sep 17 00:00:00 2001 From: zhuo_guangfei Date: Fri, 14 Dec 2018 13:44:04 +0800 Subject: [PATCH 059/131] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86pom=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=842.7.6-release=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=B8=BA2.7.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hibernate3/pom.xml | 2 +- modules/hibernate4/pom.xml | 2 +- modules/hibernate5/pom.xml | 2 +- modules/mybatis/pom.xml | 2 +- modules/spring-boot-starter/pom.xml | 2 +- modules/springcache/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/hibernate3/pom.xml b/modules/hibernate3/pom.xml index e60f8ca..5313479 100755 --- a/modules/hibernate3/pom.xml +++ b/modules/hibernate3/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.2-release + 2.7.6-release ../../pom.xml diff --git a/modules/hibernate4/pom.xml b/modules/hibernate4/pom.xml index 952cebd..455f490 100755 --- a/modules/hibernate4/pom.xml +++ b/modules/hibernate4/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.2-release + 2.7.6-release ../../pom.xml diff --git a/modules/hibernate5/pom.xml b/modules/hibernate5/pom.xml index 688f1c1..f575347 100644 --- a/modules/hibernate5/pom.xml +++ b/modules/hibernate5/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.2-release + 2.7.6-release ../../pom.xml diff --git a/modules/mybatis/pom.xml b/modules/mybatis/pom.xml index 5d74f12..2483b2a 100644 --- a/modules/mybatis/pom.xml +++ b/modules/mybatis/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.2-release + 2.7.6-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index fa8d28a..3b2cf6e 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.5-release + 2.7.6-release ../../pom.xml 4.0.0 diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index 7554667..3bbeaac 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.4-release + 2.7.6-release ../../pom.xml 4.0.0 -- Gitee From 754bb993ae5c2a28a519a2e4d15c20674e1402f1 Mon Sep 17 00:00:00 2001 From: zhuo_guangfei Date: Fri, 14 Dec 2018 13:52:43 +0800 Subject: [PATCH 060/131] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BF=AE=E6=94=B9pom?= =?UTF-8?q?=E7=9A=84=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/session-manager/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/session-manager/pom.xml b/modules/session-manager/pom.xml index aa9bfdb..c66b181 100644 --- a/modules/session-manager/pom.xml +++ b/modules/session-manager/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.0-release + 2.7.6-release ../../pom.xml -- Gitee From 6659b3628f0a3f0c99b7e57cc3d9014c8023f1d0 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Fri, 14 Dec 2018 14:18:06 +0800 Subject: [PATCH 061/131] 2.7.7 --- core/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/pom.xml b/core/pom.xml index ae02dd2..c144fa5 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -8,6 +8,7 @@ 4.0.0 j2cache-core + 2.7.7-release -- Gitee From e98dbaad7910a7582b7d23b9ff9cc38dd007da1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Tue, 18 Dec 2018 09:58:36 +0800 Subject: [PATCH 062/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aab7a1d..921e0f7 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ J2Cache 相关文章: - [如何通过 J2Cache 实现分布式 session 存储](https://my.oschina.net/javayou/blog/2117109) - [J2Cache 没有 Redis 也可以实现多节点的缓存同步](https://my.oschina.net/javayou/blog/1865908) - [微服务的架构里应该使用 J2Cache 两级缓存框架](https://my.oschina.net/javayou/blog/1827480) +- [J2Cache 和 JetCache 框架有何不同?](https://my.oschina.net/javayou/blog/2988523) J2Cache 已经有 Python 语言版本了,详情请看 [https://gitee.com/ld/Py3Cache](https://gitee.com/ld/Py3Cache) -- Gitee From 0c3d049f01151e98c888fa3dfec2074a74d73f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Wed, 26 Dec 2018 09:33:25 +0800 Subject: [PATCH 063/131] system write release file --- giteetest.release | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 giteetest.release diff --git a/giteetest.release b/giteetest.release new file mode 100644 index 0000000..a93f0ed --- /dev/null +++ b/giteetest.release @@ -0,0 +1,10 @@ +# 请参考 https://help.aliyun.com/document_detail/59293.html 了解更多关于release文件的编写方式 + +# 构建源码语言类型 +code.language=oracle-jdk1.8 + +# 构建打包使用的打包文件 +build.output=target/* + +# 应用部署脚本 +deploy.appctl.path=deploy.sh \ No newline at end of file -- Gitee From 03cd896703f1bd3680a8ce545775b566bffcfede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Wed, 26 Dec 2018 10:08:13 +0800 Subject: [PATCH 064/131] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6git?= =?UTF-8?q?eetest.release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- giteetest.release | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 giteetest.release diff --git a/giteetest.release b/giteetest.release deleted file mode 100644 index a93f0ed..0000000 --- a/giteetest.release +++ /dev/null @@ -1,10 +0,0 @@ -# 请参考 https://help.aliyun.com/document_detail/59293.html 了解更多关于release文件的编写方式 - -# 构建源码语言类型 -code.language=oracle-jdk1.8 - -# 构建打包使用的打包文件 -build.output=target/* - -# 应用部署脚本 -deploy.appctl.path=deploy.sh \ No newline at end of file -- Gitee From 1e13637a245093a6824b26a32c33eda38cebac3c Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Sat, 5 Jan 2019 12:24:58 +0800 Subject: [PATCH 065/131] readme maven --- modules/session-manager/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/session-manager/Readme.md b/modules/session-manager/Readme.md index 7b7e525..bcff725 100644 --- a/modules/session-manager/Readme.md +++ b/modules/session-manager/Readme.md @@ -10,7 +10,7 @@ net.oschina.j2cache j2cache-session-manager - 1.0.0 + xxx ``` 2. 配置 web.xml -- Gitee From 4424096339e4ea0e813f98cc76b27c5a369ac046 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Sat, 5 Jan 2019 12:29:43 +0800 Subject: [PATCH 066/131] maven dependancy --- modules/session-manager/pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/session-manager/pom.xml b/modules/session-manager/pom.xml index c66b181..e3dc182 100644 --- a/modules/session-manager/pom.xml +++ b/modules/session-manager/pom.xml @@ -32,6 +32,14 @@ commons-logging commons-logging 1.2 + provided + + + + org.apache.commons + commons-pool2 + 2.5.0 + provided -- Gitee From 5825715d363e5400737632fdc8e8cc63a6218793 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Sat, 5 Jan 2019 12:33:02 +0800 Subject: [PATCH 067/131] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/session-manager/Readme.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/session-manager/Readme.md b/modules/session-manager/Readme.md index bcff725..7a808b0 100644 --- a/modules/session-manager/Readme.md +++ b/modules/session-manager/Readme.md @@ -39,7 +39,18 @@ cookie.domain + + + redis.mode single @@ -87,4 +98,7 @@ /* ``` + + 更详细配置请参考 j2cache.properties 说明。 + 3. 启动应用并检查日志看是否启动正常 -- Gitee From d5b6a1629aab1a9c686f30b3d0ad28ca072bee48 Mon Sep 17 00:00:00 2001 From: jiangzeyin Date: Mon, 25 Feb 2019 09:49:45 +0800 Subject: [PATCH 068/131] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=B9=E6=8D=AEses?= =?UTF-8?q?sionId=E9=94=80=E6=AF=81session=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/session/J2CacheSessionFilter.java | 75 +++++++++++++------ 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java b/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java index 0112399..5ab7cdf 100644 --- a/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java +++ b/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java @@ -24,6 +24,7 @@ import java.util.UUID; /** * 实现基于 J2Cache 的分布式的 Session 管理 + * * @author Winter Lau (javayou@gmail.com) */ public class J2CacheSessionFilter implements Filter { @@ -39,15 +40,15 @@ public class J2CacheSessionFilter implements Filter { @Override public void init(FilterConfig config) { - this.cookieName = config.getInitParameter("cookie.name"); - this.cookieDomain = config.getInitParameter("cookie.domain"); - this.cookiePath = config.getInitParameter("cookie.path"); - this.cookieMaxAge = Integer.parseInt(config.getInitParameter("session.maxAge")); + this.cookieName = config.getInitParameter("cookie.name"); + this.cookieDomain = config.getInitParameter("cookie.domain"); + this.cookiePath = config.getInitParameter("cookie.path"); + this.cookieMaxAge = Integer.parseInt(config.getInitParameter("session.maxAge")); this.discardNonSerializable = "true".equalsIgnoreCase(config.getInitParameter("session.discardNonSerializable")); Properties redisConf = new Properties(); - for(String name : Collections.list(config.getInitParameterNames())) { - if(name.startsWith("redis.")) { + for (String name : Collections.list(config.getInitParameterNames())) { + if (name.startsWith("redis.")) { redisConf.setProperty(name.substring(6), config.getInitParameter(name)); } } @@ -64,9 +65,10 @@ public class J2CacheSessionFilter implements Filter { chain.doFilter(j2cacheRequest, res); } finally { //更新 session 的有效时间 - J2CacheSession session = (J2CacheSession)j2cacheRequest.getSession(false); - if(session != null && !session.isNew()) + J2CacheSession session = (J2CacheSession) j2cacheRequest.getSession(false); + if (session != null && !session.isNew()) { g_cache.updateSessionAccessTime(session.getSessionObject()); + } } } @@ -75,6 +77,39 @@ public class J2CacheSessionFilter implements Filter { g_cache.close(); } + /** + * 根据sessionId销毁session + * + * @param servletContext 上下文 + * @param sessionId id + * @return true 存在并销毁 + */ + public boolean invalidateById(ServletContext servletContext, String sessionId) { + J2CacheSession session = createSessionById(servletContext, sessionId); + if (session == null) { + return false; + } + session.invalidate(); + return true; + } + + /** + * 缓存中创建session 对象 + * + * @param servletContext 上下文 + * @param sessionId id + * @return 如果缓存中存在则返回 + */ + private J2CacheSession createSessionById(ServletContext servletContext, String sessionId) { + J2CacheSession session = null; + SessionObject ssnObject = g_cache.getSession(sessionId); + if (ssnObject != null) { + session = new J2CacheSession(servletContext, sessionId, g_cache); + session.setSessionObject(ssnObject); + session.setNew(false); + } + return session; + } /************************************************* * request 封装,用于重新处理 session 的实现 @@ -85,26 +120,21 @@ public class J2CacheSessionFilter implements Filter { private J2CacheSession session; public J2CacheRequestWrapper(ServletRequest req, ServletResponse res) { - super((HttpServletRequest)req); - this.response = (HttpServletResponse)res; + super((HttpServletRequest) req); + this.response = (HttpServletResponse) res; } @Override public HttpSession getSession(boolean create) { - if(session == null){ + if (session == null) { Cookie ssnCookie = getCookie(cookieName); if (ssnCookie != null) { String session_id = ssnCookie.getValue(); - SessionObject ssnObject = g_cache.getSession(session_id); - if(ssnObject != null) { - session = new J2CacheSession(getServletContext(), session_id, g_cache); - session.setSessionObject(ssnObject); - session.setNew(false); - } + session = createSessionById(getServletContext(), session_id); } - if(session == null && create) { + if (session == null && create) { String session_id = UUID.randomUUID().toString().replaceAll("-", ""); session = new J2CacheSession(getServletContext(), session_id, g_cache); g_cache.saveSession(session.getSessionObject()); @@ -124,10 +154,13 @@ public class J2CacheSessionFilter implements Filter { */ private Cookie getCookie(String name) { Cookie[] cookies = ((HttpServletRequest) getRequest()).getCookies(); - if (cookies != null) - for (Cookie cookie : cookies) - if (cookie.getName().equalsIgnoreCase(name)) + if (cookies != null) { + for (Cookie cookie : cookies) { + if (cookie.getName().equalsIgnoreCase(name)) { return cookie; + } + } + } return null; } -- Gitee From f695955264b1f22273fbcfa221e136ea7bd566f1 Mon Sep 17 00:00:00 2001 From: jiangzeyin Date: Wed, 27 Feb 2019 10:19:40 +0800 Subject: [PATCH 069/131] =?UTF-8?q?J2CacheConfig=20=E6=B7=BB=E5=8A=A0prope?= =?UTF-8?q?rties=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/oschina/j2cache/J2CacheConfig.java | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/core/src/net/oschina/j2cache/J2CacheConfig.java b/core/src/net/oschina/j2cache/J2CacheConfig.java index dbdeef1..0ee633c 100644 --- a/core/src/net/oschina/j2cache/J2CacheConfig.java +++ b/core/src/net/oschina/j2cache/J2CacheConfig.java @@ -20,6 +20,7 @@ import java.util.Properties; /** * J2Cache configurations + * * @author Winter Lau (javayou@gmail.com) */ public class J2CacheConfig { @@ -38,16 +39,18 @@ public class J2CacheConfig { /** * Read configuration from resource + * * @param configResource config resource */ public final static J2CacheConfig initFromConfig(String configResource) throws IOException { - try (InputStream stream = getConfigStream(configResource)){ + try (InputStream stream = getConfigStream(configResource)) { return initFromConfig(stream); } } /** * Read configuration from file + * * @param configFile config file */ public final static J2CacheConfig initFromConfig(File configFile) throws IOException { @@ -58,11 +61,24 @@ public class J2CacheConfig { /** * Read configuration from input stream + * * @param stream config stream */ public final static J2CacheConfig initFromConfig(InputStream stream) throws IOException { + Properties properties = new Properties(); + properties.load(stream); + return initFromConfig(properties); + } + + /** + * Read configuration from properties + * + * @param properties config properties + */ + public final static J2CacheConfig initFromConfig(Properties properties) { J2CacheConfig config = new J2CacheConfig(); - config.properties.load(stream); + config.properties = properties; + config.serialization = trim(config.properties.getProperty("j2cache.serialization")); config.broadcast = trim(config.properties.getProperty("j2cache.broadcast")); config.l1CacheName = trim(config.properties.getProperty("j2cache.L1.provider_class")); @@ -71,8 +87,9 @@ public class J2CacheConfig { config.defaultCacheNullObject = "true".equalsIgnoreCase(trim(config.properties.getProperty("j2cache.default_cache_null_object"))); String l2_config_section = trim(config.properties.getProperty("j2cache.L2.config_section")); - if (l2_config_section == null || l2_config_section.trim().equals("")) + if (l2_config_section == null || "".equals(l2_config_section.trim())) { l2_config_section = config.l2CacheName; + } config.broadcastProperties = config.getSubProperties(config.broadcast); config.l1CacheProperties = config.getSubProperties(config.l1CacheName); @@ -82,40 +99,45 @@ public class J2CacheConfig { /** * read sub properties by prefix - * @param i_prefix prefix of config + * + * @param i_prefix prefix of config * @return properties without prefix */ public Properties getSubProperties(String i_prefix) { Properties props = new Properties(); final String prefix = i_prefix + '.'; - properties.forEach((k,v) -> { - String key = (String)k; - if(key.startsWith(prefix)) - props.setProperty(key.substring(prefix.length()), trim((String)v)); + properties.forEach((k, v) -> { + String key = (String) k; + if (key.startsWith(prefix)) { + props.setProperty(key.substring(prefix.length()), trim((String) v)); + } }); return props; } /** * get j2cache properties stream + * * @return */ private static InputStream getConfigStream(String resource) { InputStream configStream = J2Cache.class.getResourceAsStream(resource); - if(configStream == null) + if (configStream == null) { configStream = J2Cache.class.getClassLoader().getParent().getResourceAsStream(resource); - if(configStream == null) + } + if (configStream == null) { throw new CacheException("Cannot find " + resource + " !!!"); + } return configStream; } public void dump(PrintStream writer) { writer.printf("j2cache.serialization = %s%n", this.serialization); - writer.printf("[%s]%n",this.broadcast); + writer.printf("[%s]%n", this.broadcast); broadcastProperties.list(writer); - writer.printf("[%s]%n",this.l1CacheName); + writer.printf("[%s]%n", this.l1CacheName); l1CacheProperties.list(writer); - writer.printf("[%s]%n",this.l2CacheName); + writer.printf("[%s]%n", this.l2CacheName); l2CacheProperties.list(writer); } -- Gitee From 1ab659fa0162d2baccdf192312a4fe8b509bdb09 Mon Sep 17 00:00:00 2001 From: jiangzeyin Date: Wed, 27 Feb 2019 10:20:06 +0800 Subject: [PATCH 070/131] =?UTF-8?q?Revert=20"=E6=B7=BB=E5=8A=A0=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEsessionId=E9=94=80=E6=AF=81session=E6=96=B9=E6=B3=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d5b6a162 --- .../j2cache/session/J2CacheSessionFilter.java | 75 ++++++------------- 1 file changed, 21 insertions(+), 54 deletions(-) diff --git a/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java b/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java index 5ab7cdf..0112399 100644 --- a/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java +++ b/modules/session-manager/src/main/java/net/oschina/j2cache/session/J2CacheSessionFilter.java @@ -24,7 +24,6 @@ import java.util.UUID; /** * 实现基于 J2Cache 的分布式的 Session 管理 - * * @author Winter Lau (javayou@gmail.com) */ public class J2CacheSessionFilter implements Filter { @@ -40,15 +39,15 @@ public class J2CacheSessionFilter implements Filter { @Override public void init(FilterConfig config) { - this.cookieName = config.getInitParameter("cookie.name"); - this.cookieDomain = config.getInitParameter("cookie.domain"); - this.cookiePath = config.getInitParameter("cookie.path"); - this.cookieMaxAge = Integer.parseInt(config.getInitParameter("session.maxAge")); + this.cookieName = config.getInitParameter("cookie.name"); + this.cookieDomain = config.getInitParameter("cookie.domain"); + this.cookiePath = config.getInitParameter("cookie.path"); + this.cookieMaxAge = Integer.parseInt(config.getInitParameter("session.maxAge")); this.discardNonSerializable = "true".equalsIgnoreCase(config.getInitParameter("session.discardNonSerializable")); Properties redisConf = new Properties(); - for (String name : Collections.list(config.getInitParameterNames())) { - if (name.startsWith("redis.")) { + for(String name : Collections.list(config.getInitParameterNames())) { + if(name.startsWith("redis.")) { redisConf.setProperty(name.substring(6), config.getInitParameter(name)); } } @@ -65,10 +64,9 @@ public class J2CacheSessionFilter implements Filter { chain.doFilter(j2cacheRequest, res); } finally { //更新 session 的有效时间 - J2CacheSession session = (J2CacheSession) j2cacheRequest.getSession(false); - if (session != null && !session.isNew()) { + J2CacheSession session = (J2CacheSession)j2cacheRequest.getSession(false); + if(session != null && !session.isNew()) g_cache.updateSessionAccessTime(session.getSessionObject()); - } } } @@ -77,39 +75,6 @@ public class J2CacheSessionFilter implements Filter { g_cache.close(); } - /** - * 根据sessionId销毁session - * - * @param servletContext 上下文 - * @param sessionId id - * @return true 存在并销毁 - */ - public boolean invalidateById(ServletContext servletContext, String sessionId) { - J2CacheSession session = createSessionById(servletContext, sessionId); - if (session == null) { - return false; - } - session.invalidate(); - return true; - } - - /** - * 缓存中创建session 对象 - * - * @param servletContext 上下文 - * @param sessionId id - * @return 如果缓存中存在则返回 - */ - private J2CacheSession createSessionById(ServletContext servletContext, String sessionId) { - J2CacheSession session = null; - SessionObject ssnObject = g_cache.getSession(sessionId); - if (ssnObject != null) { - session = new J2CacheSession(servletContext, sessionId, g_cache); - session.setSessionObject(ssnObject); - session.setNew(false); - } - return session; - } /************************************************* * request 封装,用于重新处理 session 的实现 @@ -120,21 +85,26 @@ public class J2CacheSessionFilter implements Filter { private J2CacheSession session; public J2CacheRequestWrapper(ServletRequest req, ServletResponse res) { - super((HttpServletRequest) req); - this.response = (HttpServletResponse) res; + super((HttpServletRequest)req); + this.response = (HttpServletResponse)res; } @Override public HttpSession getSession(boolean create) { - if (session == null) { + if(session == null){ Cookie ssnCookie = getCookie(cookieName); if (ssnCookie != null) { String session_id = ssnCookie.getValue(); - session = createSessionById(getServletContext(), session_id); + SessionObject ssnObject = g_cache.getSession(session_id); + if(ssnObject != null) { + session = new J2CacheSession(getServletContext(), session_id, g_cache); + session.setSessionObject(ssnObject); + session.setNew(false); + } } - if (session == null && create) { + if(session == null && create) { String session_id = UUID.randomUUID().toString().replaceAll("-", ""); session = new J2CacheSession(getServletContext(), session_id, g_cache); g_cache.saveSession(session.getSessionObject()); @@ -154,13 +124,10 @@ public class J2CacheSessionFilter implements Filter { */ private Cookie getCookie(String name) { Cookie[] cookies = ((HttpServletRequest) getRequest()).getCookies(); - if (cookies != null) { - for (Cookie cookie : cookies) { - if (cookie.getName().equalsIgnoreCase(name)) { + if (cookies != null) + for (Cookie cookie : cookies) + if (cookie.getName().equalsIgnoreCase(name)) return cookie; - } - } - } return null; } -- Gitee From e29c36643fb99cefb911b7f85b771a7bbc89a528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=BF=98=E5=88=9D=E5=BF=83?= Date: Wed, 27 Feb 2019 11:38:43 +0800 Subject: [PATCH 071/131] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E4=B8=AD=E5=A4=AE=E4=BB=93=E5=BA=93=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 921e0f7..ef7a4a7 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ J2Cache 默认使用 [Caffeine](https://www.oschina.net/p/ben-manes-caffeine) xxxxx ``` +中央仓库地址:[>>飞机](https://mvnrepository.com/artifact/net.oschina.j2cache/j2cache-core) **二. 准备配置** -- Gitee From e39554bebc7a45eb25070295857ba460b030faa3 Mon Sep 17 00:00:00 2001 From: wxk <26745181272@qq.com> Date: Thu, 14 Mar 2019 14:32:48 +0800 Subject: [PATCH 072/131] =?UTF-8?q?=E8=A7=A3=E5=86=B3EhCache=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=8E=B7=E5=8F=96=E4=B8=BAnull?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java | 2 +- core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java index a14e164..5878654 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java @@ -133,7 +133,7 @@ public class EhCacheProvider implements CacheProvider { if (manager == null) { // 指定了配置文件路径? 加载之 if (props.containsKey(KEY_EHCACHE_CONFIG_XML)) { - URL url = getClass().getResource(props.getProperty(KEY_EHCACHE_CONFIG_XML)); + URL url = getClass().getClassLoader().getResource(props.getProperty(KEY_EHCACHE_CONFIG_XML)); manager = CacheManager.newInstance(url); } else { // 加载默认实例 diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java index b274d6e..41d152a 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java @@ -121,7 +121,7 @@ public class EhCacheProvider3 implements CacheProvider { String configXml = props.getProperty("configXml"); if(configXml == null || configXml.trim().length() == 0) configXml = "/ehcache3.xml"; - URL myUrl = getClass().getResource(configXml); + URL myUrl = getClass().getClassLoader().getResource(configXml); Configuration xmlConfig = new XmlConfiguration(myUrl); manager = CacheManagerBuilder.newCacheManager(xmlConfig); manager.init(); -- Gitee From 66e3abfab66f0310976e8c9d538b950a4b0d8739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Fri, 22 Mar 2019 22:35:36 +0800 Subject: [PATCH 073/131] =?UTF-8?q?logo=20=E5=B1=85=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ef7a4a7..0788a28 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -![J2Cache](docs/J2Cache.png) - -# J2Cache —— 基于内存和 Redis 的两级 Java 缓存框架 - +

+ J2Cache +

+

+

J2Cache —— 基于内存和 Redis 的两级 Java 缓存框架

+

专用QQ群: `379110351` JavaDoc [https://apidoc.gitee.com/ld/J2Cache/](https://apidoc.gitee.com/ld/J2Cache/) -- Gitee From 927f6e70a7a901239bd3a75cd34481de0b59a94c Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Mon, 25 Mar 2019 15:52:11 +0800 Subject: [PATCH 074/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20lettuce=20?= =?UTF-8?q?=E7=9A=84=E8=BF=9E=E6=8E=A5=E8=B6=85=E6=97=B6=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=20lettuce.timeout=20=3D=20100000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/resources/j2cache.properties | 2 ++ .../net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index 84f5519..98c5c65 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -164,6 +164,8 @@ lettuce.sentinelMasterId = lettuce.maxTotal = 100 lettuce.maxIdle = 10 lettuce.minIdle = 10 +# timeout in milliseconds +lettuce.timeout = 10000 ######################################### # memcached server configurations diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index d435961..0be72e3 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -29,10 +29,12 @@ import net.oschina.j2cache.cluster.ClusterPolicy; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import java.time.Duration; import java.util.Collection; import java.util.Collections; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; /** * 使用 Lettuce 进行 Redis 的操作 @@ -103,6 +105,12 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp String redis_url = String.format("%s://%s@%s/%d#%s", scheme, password, hosts, database, sentinelMasterId); redisClient = isCluster?RedisClusterClient.create(redis_url):RedisClient.create(redis_url); + try { + int timeout = Integer.parseInt(props.getProperty("timeout", "10000")); + redisClient.setDefaultTimeout(Duration.ofMillis(timeout)); + }catch(Exception e){ + log.warn("Failed to set default timeout, using default 10000 milliseconds.", e); + } //connection pool configurations GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); -- Gitee From 27f033300eac25b25cb90b0b15763b14c2ab806a Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Wed, 3 Apr 2019 10:56:18 +0800 Subject: [PATCH 075/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8B=E7=BB=8D?= =?UTF-8?q?=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0788a28..2397fc3 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ J2Cache 是 OSChina 目前正在使用的两级缓存框架(要求至少 Java J2Cache 相关文章: - [J2Cache 和普通缓存框架有何不同,它解决了什么问题?](https://my.oschina.net/javayou/blog/1931381) +- [J2Cache 两级缓存中的 Region 到底是什么东西?](https://my.oschina.net/javayou/blog/3031773) - [如何让 J2Cache 在多种编程语言环境中使用](https://my.oschina.net/javayou/blog/2247729) - [J2Cache 中使用 Lettuce 替代 Jedis 管理 Redis 连接](https://my.oschina.net/javayou/blog/2247710) - [如何通过 J2Cache 实现分布式 session 存储](https://my.oschina.net/javayou/blog/2117109) -- Gitee From 120a85009bfad91ce75645436fceebd13044da6c Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Thu, 13 Jun 2019 19:05:18 +0800 Subject: [PATCH 076/131] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=EF=BC=8C=E6=BB=A1=E8=B6=B3=20javadoc=20=E8=A6=81=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/J2CacheConfig.java | 9 ++++++++- core/src/net/oschina/j2cache/cluster/ClusterPolicy.java | 2 +- .../oschina/j2cache/cluster/ClusterPolicyFactory.java | 1 + core/src/net/oschina/j2cache/redis/RedisClient.java | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/src/net/oschina/j2cache/J2CacheConfig.java b/core/src/net/oschina/j2cache/J2CacheConfig.java index 0ee633c..7286dc3 100644 --- a/core/src/net/oschina/j2cache/J2CacheConfig.java +++ b/core/src/net/oschina/j2cache/J2CacheConfig.java @@ -41,6 +41,8 @@ public class J2CacheConfig { * Read configuration from resource * * @param configResource config resource + * @return config instance + * @throws IOException config read io exception */ public final static J2CacheConfig initFromConfig(String configResource) throws IOException { try (InputStream stream = getConfigStream(configResource)) { @@ -52,6 +54,8 @@ public class J2CacheConfig { * Read configuration from file * * @param configFile config file + * @return config instance + * @throws IOException config read io exception */ public final static J2CacheConfig initFromConfig(File configFile) throws IOException { try (FileInputStream stream = new FileInputStream(configFile)) { @@ -63,6 +67,8 @@ public class J2CacheConfig { * Read configuration from input stream * * @param stream config stream + * @return config instance + * @throws IOException config read io exception */ public final static J2CacheConfig initFromConfig(InputStream stream) throws IOException { Properties properties = new Properties(); @@ -74,6 +80,7 @@ public class J2CacheConfig { * Read configuration from properties * * @param properties config properties + * @return config instance */ public final static J2CacheConfig initFromConfig(Properties properties) { J2CacheConfig config = new J2CacheConfig(); @@ -118,7 +125,7 @@ public class J2CacheConfig { /** * get j2cache properties stream * - * @return + * @return config stream */ private static InputStream getConfigStream(String resource) { InputStream configStream = J2Cache.class.getResourceAsStream(resource); diff --git a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java index 48a82ed..c938165 100644 --- a/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/ClusterPolicy.java @@ -81,7 +81,7 @@ public interface ClusterPolicy { /** * 判断是否本地实例的命令 * @param cmd 命令信息 - * @return + * @return true if the cmd sent by self */ boolean isLocalCommand(Command cmd) ; diff --git a/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java b/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java index ff3bddb..3f26c8a 100644 --- a/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java +++ b/core/src/net/oschina/j2cache/cluster/ClusterPolicyFactory.java @@ -32,6 +32,7 @@ public class ClusterPolicyFactory { /** * 初始化集群消息通知机制 + * @param holder CacheProviderHolder instance * @param broadcast j2cache.broadcast value * @param props broadcast configuations * @return ClusterPolicy instance diff --git a/core/src/net/oschina/j2cache/redis/RedisClient.java b/core/src/net/oschina/j2cache/redis/RedisClient.java index 573d358..ce2d8cc 100644 --- a/core/src/net/oschina/j2cache/redis/RedisClient.java +++ b/core/src/net/oschina/j2cache/redis/RedisClient.java @@ -201,7 +201,7 @@ public class RedisClient implements Closeable, AutoCloseable { /** * 释放连接池 - * @throws IOException + * @throws IOException io close exception */ @Override public void close() throws IOException { -- Gitee From 9509ff7f6c7a19a0a94fea346e3ee2dd80c564d2 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Thu, 13 Jun 2019 19:05:37 +0800 Subject: [PATCH 077/131] 2.7.8 core --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index c144fa5..31c2f32 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -8,7 +8,7 @@ 4.0.0 j2cache-core - 2.7.7-release + 2.7.8-release -- Gitee From 56587196b896cd6b52898554ec18961b0d1efc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Thu, 13 Jun 2019 19:18:48 +0800 Subject: [PATCH 078/131] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2397fc3..becfbd9 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ J2Cache 相关文章: - [J2Cache 没有 Redis 也可以实现多节点的缓存同步](https://my.oschina.net/javayou/blog/1865908) - [微服务的架构里应该使用 J2Cache 两级缓存框架](https://my.oschina.net/javayou/blog/1827480) - [J2Cache 和 JetCache 框架有何不同?](https://my.oschina.net/javayou/blog/2988523) +- [J2Cache 线上异常问题排查记录](https://my.oschina.net/keking/blog/3058409) J2Cache 已经有 Python 语言版本了,详情请看 [https://gitee.com/ld/Py3Cache](https://gitee.com/ld/Py3Cache) -- Gitee From cd0b32ee48b9897c8719fd4bd3c097385811870d Mon Sep 17 00:00:00 2001 From: eryan Date: Wed, 19 Jun 2019 19:44:50 +0800 Subject: [PATCH 079/131] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dkeys=E6=96=B9?= =?UTF-8?q?=E6=B3=95bug=EF=BC=8C=E5=8E=BB=E9=99=A4=E4=BA=8C=E7=BA=A7?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=BF=94=E5=9B=9Ekey=E5=80=BC=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E7=9A=84namespace=E4=BB=A5=E5=8F=8Aregion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/support/redis/SpringRedisGenericCache.java | 10 +++------- .../cache/support/redis/SpringRedisGenericCache.java | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java index 842aff3..2387915 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +45,7 @@ public class SpringRedisGenericCache implements Level2Cache { public void clear() { Collection keys = keys(); keys.stream().forEach(k -> { - redisTemplate.delete(k); + redisTemplate.delete(this.region + ":" + k); }); } @@ -66,12 +67,7 @@ public class SpringRedisGenericCache implements Level2Cache { @Override public Collection keys() { - Set list = redisTemplate.keys(this.region + ":*"); - List keys = new ArrayList<>(list.size()); - for (String s : list) { - keys.add(s); - } - return keys; + return redisTemplate.keys(this.region + ":*").stream().map(k->k.substring(this.region.length()+1)).collect(Collectors.toSet()); } @Override diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java index 8b4b1ae..49eb85b 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisGenericCache.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +45,7 @@ public class SpringRedisGenericCache implements Level2Cache { public void clear() { Collection keys = keys(); keys.stream().forEach(k -> { - redisTemplate.delete(k); + redisTemplate.delete(this.region + ":" + k); }); } @@ -66,12 +67,7 @@ public class SpringRedisGenericCache implements Level2Cache { @Override public Collection keys() { - Set list = redisTemplate.keys(this.region + ":*"); - List keys = new ArrayList<>(list.size()); - for (String s : list) { - keys.add(s); - } - return keys; + return redisTemplate.keys(this.region + ":*").stream().map(k->k.substring(this.region.length()+1)).collect(Collectors.toSet()); } @Override -- Gitee From b4f63654eb0c897c3e1574707d4536eeee83e35b Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Tue, 16 Jul 2019 10:15:22 +0800 Subject: [PATCH 080/131] fixed #IZ81Q --- .../oschina/j2cache/lettuce/LettuceGenericCache.java | 10 ++++++++-- .../net/oschina/j2cache/redis/RedisGenericCache.java | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java index 2c1eb94..6a1e48c 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java @@ -101,7 +101,10 @@ public class LettuceGenericCache extends LettuceCache { public void setBytes(String key, byte[] bytes, long timeToLiveInSeconds){ try(StatefulConnection connection = super.connect()) { RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); - cmd.setex(_key(key), timeToLiveInSeconds, bytes); + if (timeToLiveInSeconds > 0) + cmd.setex(_key(key), timeToLiveInSeconds, bytes); + else + cmd.set(_key(key), bytes); } } @@ -114,7 +117,10 @@ public class LettuceGenericCache extends LettuceCache { public void setBytes(Map bytes, long timeToLiveInSeconds) { try(StatefulConnection connection = super.connect()) { RedisStringCommands cmd = (RedisStringCommands)super.sync(connection); - bytes.forEach((k,v)->cmd.setex(_key(k), timeToLiveInSeconds, v)); + if (timeToLiveInSeconds > 0) + bytes.forEach((k,v)->cmd.setex(_key(k), timeToLiveInSeconds, v)); + else + bytes.forEach((k,v)->cmd.set(_key(k), v)); } } diff --git a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java index 61b1d70..fc61bd6 100644 --- a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java +++ b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java @@ -168,7 +168,13 @@ public class RedisGenericCache implements Level2Cache { } else */ - bytes.forEach((k,v) -> setBytes(k, v, timeToLiveInSeconds)); + + if (timeToLiveInSeconds <= 0) { + log.debug(String.format("Invalid timeToLiveInSeconds value : %d , skipped it.", timeToLiveInSeconds)); + setBytes(bytes); + } + else + bytes.forEach((k,v) -> setBytes(k, v, timeToLiveInSeconds)); } finally { client.release(); } -- Gitee From 72648a9a1ad8292f1da07c47b40842ef3a440d92 Mon Sep 17 00:00:00 2001 From: tangyh <244387066@qq.com> Date: Tue, 15 Oct 2019 11:54:11 +0800 Subject: [PATCH 081/131] =?UTF-8?q?1,=20=E8=A7=A3=E5=86=B3j2cache.properti?= =?UTF-8?q?es=E4=B8=AD=E7=9A=84=E9=85=8D=E7=BD=AE=E6=94=BE=E5=88=B0=20naco?= =?UTF-8?q?s=20=E4=B8=AD=E5=90=8E=EF=BC=8C=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=AF=BB=E5=8F=96=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84bug=202=EF=BC=8C=20=E8=A7=A3=E5=86=B3J2CacheA?= =?UTF-8?q?utoConfiguration=E7=B1=BB=E4=B8=AD=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=8D=E8=A7=84=E8=8C=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../J2CacheAutoConfiguration.java | 7 ++--- .../support/util/SpringJ2CacheConfigUtil.java | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java index c944e5c..71d4924 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheAutoConfiguration.java @@ -26,17 +26,16 @@ import net.oschina.j2cache.cache.support.util.SpringUtil; @Configuration @PropertySource(value = "${j2cache.config-location}", encoding = "UTF-8", ignoreResourceNotFound = true) public class J2CacheAutoConfiguration { - + @Autowired private StandardEnvironment standardEnvironment; @Bean public net.oschina.j2cache.J2CacheConfig j2CacheConfig() throws IOException{ - net.oschina.j2cache.J2CacheConfig cacheConfig = new net.oschina.j2cache.J2CacheConfig(); - cacheConfig = SpringJ2CacheConfigUtil.initFromConfig(standardEnvironment); + net.oschina.j2cache.J2CacheConfig cacheConfig = SpringJ2CacheConfigUtil.initFromConfig(standardEnvironment); return cacheConfig; } - + @Bean @DependsOn({"springUtil","j2CacheConfig"}) public CacheChannel cacheChannel(net.oschina.j2cache.J2CacheConfig j2CacheConfig) throws IOException { diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index 8824ca2..092abdd 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -1,10 +1,10 @@ package net.oschina.j2cache.cache.support.util; +import net.oschina.j2cache.J2CacheConfig; +import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.StandardEnvironment; -import net.oschina.j2cache.J2CacheConfig; - public class SpringJ2CacheConfigUtil { /** @@ -30,7 +30,7 @@ public class SpringJ2CacheConfigUtil { if (key.startsWith(config.getBroadcast() + ".")) { config.getBroadcastProperties().setProperty(key.substring((config.getBroadcast() + ".").length()), environment.getProperty(key)); - } + } if (key.startsWith(config.getL1CacheName() + ".")) { config.getL1CacheProperties().setProperty(key.substring((config.getL1CacheName() + ".").length()), environment.getProperty(key)); @@ -42,6 +42,30 @@ public class SpringJ2CacheConfigUtil { }); } }); + //配置在 nacos 中时,上面那段代码无法获取配置 + if (config.getL1CacheProperties().isEmpty() || config.getL2CacheProperties().isEmpty() || config.getBroadcastProperties().isEmpty()) { + environment.getPropertySources().forEach(a -> { + if (a instanceof CompositePropertySource) { + CompositePropertySource c = (CompositePropertySource) a; + String[] propertyNames = c.getPropertyNames(); + + for (String key : propertyNames) { + if (key.startsWith(config.getBroadcast() + ".")) { + config.getBroadcastProperties().setProperty(key.substring((config.getBroadcast() + ".").length()), + environment.getProperty(key)); + } + if (key.startsWith(config.getL1CacheName() + ".")) { + config.getL1CacheProperties().setProperty(key.substring((config.getL1CacheName() + ".").length()), + environment.getProperty(key)); + } + if (key.startsWith(l2_section + ".")) { + config.getL2CacheProperties().setProperty(key.substring((l2_section + ".").length()), + environment.getProperty(key)); + } + } + } + }); + } return config; } } -- Gitee From 31a58a880d6967fc263df4a2841c7be8b9752fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B9=8B=E8=A5=BF=E4=B8=9C?= Date: Thu, 31 Oct 2019 10:32:47 +0800 Subject: [PATCH 082/131] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0=20https://gitee.com/noear/?= =?UTF-8?q?weed3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index becfbd9..10027af 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,7 @@ channel.close(); * https://gitee.com/fuyang_lipengjun/platform * https://gitee.com/xcOschina/freeter-admin * https://gitee.com/thinkgem/jeesite4 +* https://gitee.com/noear/weed3 更多项目收集中,如果你的项目用了,请告诉我 -- Gitee From ad49f4dda7e77f4ad56dde52bf870f291035dd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B9=8B=E8=A5=BF=E4=B8=9C?= Date: Thu, 31 Oct 2019 10:34:06 +0800 Subject: [PATCH 083/131] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0=20https://gitee.com/noear/?= =?UTF-8?q?weed3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_EN.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README_EN.md b/README_EN.md index 7c82df0..ed65dfa 100644 --- a/README_EN.md +++ b/README_EN.md @@ -68,4 +68,5 @@ Defining the validity period of the cached data in the program will cause the ca * https://gitee.com/jfinal/jfinal * https://gitee.com/fuhai/jboot * https://gitee.com/tywo45/t-io +* https://gitee.com/noear/weed3 * ... \ No newline at end of file -- Gitee From ee277ba2557cd466a3c6cc6bf5e0c09d219cfdf2 Mon Sep 17 00:00:00 2001 From: eddy Date: Mon, 11 Nov 2019 16:47:24 +0800 Subject: [PATCH 084/131] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96kryo=E9=85=8D=E7=BD=AE=E9=94=AE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E3=80=82=20=E7=BC=93=E5=AD=98=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96kryo=E9=85=8D=E7=BD=AE=E9=94=AE=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=9C=A8j2cache.properties=E6=96=87=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E5=86=99=E9=94=99=E4=BA=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/resources/j2cache.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index 98c5c65..c2191a8 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -63,7 +63,7 @@ j2cache.default_cache_null_object = true # Cache Serialization Provider # values: # fst -> using fast-serialization (recommend) -# kyro -> using kyro serialization +# kryo -> using kryo serialization # json -> using fst's json serialization (testing) # fastjson -> using fastjson serialization (embed non-static class not support) # java -> java standard -- Gitee From 2f072baf43db6879e7083de70cb96acbd8df5248 Mon Sep 17 00:00:00 2001 From: wxk <2674518127@qq.com> Date: Thu, 28 Nov 2019 14:43:25 +0800 Subject: [PATCH 085/131] =?UTF-8?q?=E8=A7=A3=E5=86=B3Caffeine=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index 16fac79..ee6975f 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -150,7 +150,7 @@ public class CaffeineProvider implements CacheProvider { //加载 Caffeine 独立配置文件 String propertiesFile = props.getProperty("properties"); if(propertiesFile != null && propertiesFile.trim().length() > 0) { - try (InputStream stream = getClass().getResourceAsStream(propertiesFile)) { + try (InputStream stream = getClass().getClassLoader().getResourceAsStream(propertiesFile)) { Properties regionsProps = new Properties(); regionsProps.load(stream); for(String region : regionsProps.stringPropertyNames()) { -- Gitee From e4c26df279f38c1662eebe38963de3dd5ab8ed0a Mon Sep 17 00:00:00 2001 From: whcrow Date: Sun, 1 Dec 2019 19:36:21 +0800 Subject: [PATCH 086/131] =?UTF-8?q?=E4=B8=A4=E7=A7=8D=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E8=8E=B7=E5=8F=96Caffeine=E7=8B=AC=E7=AB=8B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/caffeine/CaffeineProvider.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index ee6975f..64a8db2 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -149,16 +149,29 @@ public class CaffeineProvider implements CacheProvider { } //加载 Caffeine 独立配置文件 String propertiesFile = props.getProperty("properties"); - if(propertiesFile != null && propertiesFile.trim().length() > 0) { - try (InputStream stream = getClass().getClassLoader().getResourceAsStream(propertiesFile)) { + if (propertiesFile != null && propertiesFile.trim().length() > 0) { + InputStream stream = null; + try { + stream = getClass().getResourceAsStream(propertiesFile); + if (stream == null) { + stream = getClass().getClassLoader().getResourceAsStream(propertiesFile); + } Properties regionsProps = new Properties(); regionsProps.load(stream); - for(String region : regionsProps.stringPropertyNames()) { + for (String region : regionsProps.stringPropertyNames()) { String s_config = regionsProps.getProperty(region).trim(); this.saveCacheConfig(region, s_config); } } catch (IOException e) { log.error("Failed to load caffeine regions define {}", propertiesFile, e); + } finally { + try { + if (stream != null) { + stream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } } } } -- Gitee From 4677ba4f1caeacb4f984b331520fe9e52f1958b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E4=BA=91=E6=9E=81=E9=80=9F=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98?= Date: Tue, 3 Dec 2019 17:30:25 +0800 Subject: [PATCH 087/131] =?UTF-8?q?2.7.9=20=E5=90=88=E5=B9=B6=E6=9C=80?= =?UTF-8?q?=E8=BF=91=E7=9A=84=E4=B8=80=E4=BA=9B=E5=B0=8F=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E6=8B=AC=E5=AF=B9=E6=B3=A8=E9=87=8A=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E6=BB=A1=E8=B6=B3=20javadoc=20?= =?UTF-8?q?=E8=A6=81=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 4 ++-- modules/hibernate3/pom.xml | 2 +- modules/hibernate4/pom.xml | 2 +- modules/hibernate5/pom.xml | 2 +- modules/mybatis/pom.xml | 2 +- modules/spring-boot-starter/pom.xml | 2 +- .../support/util/SpringJ2CacheConfigUtil.java | 2 ++ .../j2cache/cache/support/util/SpringUtil.java | 17 +++++++++-------- modules/spring-boot2-starter/pom.xml | 2 +- .../support/util/SpringJ2CacheConfigUtil.java | 2 ++ .../j2cache/cache/support/util/SpringUtil.java | 12 ------------ modules/springcache/pom.xml | 2 +- .../springcache/J2CacheSpringCacheAdapter.java | 5 ++++- pom.xml | 4 ++-- 14 files changed, 28 insertions(+), 32 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 31c2f32..fddb990 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,12 +3,12 @@ net.oschina.j2cache j2cache - 2.7.6-release + 2.7.9-release 4.0.0 j2cache-core - 2.7.8-release + 2.7.9-release diff --git a/modules/hibernate3/pom.xml b/modules/hibernate3/pom.xml index 5313479..5e63581 100755 --- a/modules/hibernate3/pom.xml +++ b/modules/hibernate3/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.6-release + 2.7.9-release ../../pom.xml diff --git a/modules/hibernate4/pom.xml b/modules/hibernate4/pom.xml index 455f490..f3efd9c 100755 --- a/modules/hibernate4/pom.xml +++ b/modules/hibernate4/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.6-release + 2.7.9-release ../../pom.xml diff --git a/modules/hibernate5/pom.xml b/modules/hibernate5/pom.xml index f575347..7089709 100644 --- a/modules/hibernate5/pom.xml +++ b/modules/hibernate5/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.6-release + 2.7.9-release ../../pom.xml diff --git a/modules/mybatis/pom.xml b/modules/mybatis/pom.xml index 2483b2a..67caead 100644 --- a/modules/mybatis/pom.xml +++ b/modules/mybatis/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.6-release + 2.7.9-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index 3b2cf6e..a12f3d6 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.6-release + 2.7.9-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index 5cbd4d8..ccbc156 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -10,6 +10,8 @@ public class SpringJ2CacheConfigUtil { /** * 从spring环境变量中查找j2cache配置 + * @param environment configuration + * @return j2cache config instance */ public final static J2CacheConfig initFromConfig(StandardEnvironment environment){ J2CacheConfig config = new J2CacheConfig(); diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java index 6623cad..c0a92cc 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java @@ -7,12 +7,16 @@ import org.springframework.context.ApplicationContextAware; /** * spring 工具类 * @author zhangsaizz - * */ public class SpringUtil implements ApplicationContextAware { private static ApplicationContext applicationContext; + /** + * setApplicationContext + * @param applicationContext application context + * @throws BeansException exception + */ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (SpringUtil.applicationContext == null) { @@ -22,28 +26,25 @@ public class SpringUtil implements ApplicationContextAware { /** * 获取applicationContext + * @return ApplicationContext */ public static ApplicationContext getApplicationContext() { return applicationContext; } /** - * 通过name获取 Bean. + * 通过name获取 Bean. + * @param name cache name + * @return cache object */ public static Object getBean(String name) { return getApplicationContext().getBean(name); } - /** - * 通过class获取Bean. - */ public static T getBean(Class clazz) { return getApplicationContext().getBean(clazz); } - /** - * 通过name,以及Clazz返回指定的Bean - */ public static T getBean(String name, Class clazz) { return getApplicationContext().getBean(name, clazz); } diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index 20e9b2a..b17cf06 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.6-release + 2.7.9-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index 092abdd..15878b3 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -9,6 +9,8 @@ public class SpringJ2CacheConfigUtil { /** * 从spring环境变量中查找j2cache配置 + * @param environment configuration + * @return j2cache configuration */ public final static J2CacheConfig initFromConfig(StandardEnvironment environment){ J2CacheConfig config = new J2CacheConfig(); diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java index 6623cad..7cdbcf4 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringUtil.java @@ -20,30 +20,18 @@ public class SpringUtil implements ApplicationContextAware { } } - /** - * 获取applicationContext - */ public static ApplicationContext getApplicationContext() { return applicationContext; } - /** - * 通过name获取 Bean. - */ public static Object getBean(String name) { return getApplicationContext().getBean(name); } - /** - * 通过class获取Bean. - */ public static T getBean(Class clazz) { return getApplicationContext().getBean(clazz); } - /** - * 通过name,以及Clazz返回指定的Bean - */ public static T getBean(String name, Class clazz) { return getApplicationContext().getBean(name, clazz); } diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index 3bbeaac..e75b939 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.6-release + 2.7.9-release ../../pom.xml 4.0.0 diff --git a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java index 10bf27b..0b7668a 100644 --- a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java +++ b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java @@ -7,6 +7,7 @@ import org.springframework.cache.support.AbstractValueAdaptingCache; import java.util.concurrent.Callable; /** + * Spring Cache Adapter * @author Chen */ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { @@ -18,6 +19,8 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { * Create an {@code AbstractValueAdaptingCache} with the given setting. * * @param allowNullValues whether to allow for {@code null} values + * @param j2Cache j2cache instance + * @param name cache region name */ protected J2CacheSpringCacheAdapter(boolean allowNullValues, CacheChannel j2Cache, String name) { super(allowNullValues); @@ -70,7 +73,7 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { * a {@link ValueRetrievalException} * * @param key the key whose associated value is to be returned - * @param valueLoader + * @param valueLoader value loader * @return the value to which this cache maps the specified key * @throws ValueRetrievalException if the {@code valueLoader} throws an exception * @since 4.3 diff --git a/pom.xml b/pom.xml index 1455283..a468be8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.6-release + 2.7.9-release pom j2cache @@ -133,7 +133,7 @@ modules/spring-boot2-starter modules/mybatis modules/springcache - modules/session-manager + -- Gitee From b74ca3c95603c636f104b10ab678e363a6575709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Tue, 3 Dec 2019 17:31:26 +0800 Subject: [PATCH 088/131] include session manager --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a468be8..3b5d9bf 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ modules/spring-boot2-starter modules/mybatis modules/springcache - + modules/session-manager -- Gitee From 8c3e9bb84338599bd20c21c2c6d73215a4ac5099 Mon Sep 17 00:00:00 2001 From: wxk <2674518127@qq.com> Date: Fri, 13 Dec 2019 11:42:46 +0800 Subject: [PATCH 089/131] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=A4=E7=A7=8D?= =?UTF-8?q?=E8=8E=B7=E5=8F=96EhCache=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/ehcache/EhCacheProvider.java | 197 +++++++++--------- .../j2cache/ehcache/EhCacheProvider3.java | 23 +- 2 files changed, 112 insertions(+), 108 deletions(-) diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java index 5878654..9589157 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java @@ -15,21 +15,20 @@ */ package net.oschina.j2cache.ehcache; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; - import net.oschina.j2cache.CacheChannel; +import net.oschina.j2cache.CacheExpiredListener; import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.CacheProvider; +import net.sf.ehcache.CacheManager; import net.sf.ehcache.config.CacheConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.oschina.j2cache.CacheExpiredListener; -import net.oschina.j2cache.CacheProvider; -import net.sf.ehcache.CacheManager; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; /** * EhCache 2.x 缓存管理器的封装,用来管理多个缓存区域 @@ -39,119 +38,121 @@ import net.sf.ehcache.CacheManager; */ public class EhCacheProvider implements CacheProvider { - private final static Logger log = LoggerFactory.getLogger(EhCacheProvider.class); + private final static Logger log = LoggerFactory.getLogger(EhCacheProvider.class); - public final static String KEY_EHCACHE_NAME = "name"; - public final static String KEY_EHCACHE_CONFIG_XML = "configXml"; + public final static String KEY_EHCACHE_NAME = "name"; + public final static String KEY_EHCACHE_CONFIG_XML = "configXml"; - private CacheManager manager; - private ConcurrentHashMap caches; + private CacheManager manager; + private ConcurrentHashMap caches; - @Override - public String name() { - return "ehcache"; - } + @Override + public String name() { + return "ehcache"; + } - @Override - public int level() { - return CacheObject.LEVEL_1; - } + @Override + public int level() { + return CacheObject.LEVEL_1; + } - @Override - public Collection regions() { - Collection regions = new ArrayList<>(); - caches.forEach((k,c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); - return regions; - } + @Override + public Collection regions() { + Collection regions = new ArrayList<>(); + caches.forEach((k, c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); + return regions; + } /** * Builds a Cache. * * @param regionName the regionName of the cache. Must match a cache configured in ehcache.xml - * @param listener cache listener + * @param listener cache listener * @return a newly built cache will be built and initialised */ @Override public EhCache buildCache(String regionName, CacheExpiredListener listener) { - return caches.computeIfAbsent(regionName, v -> { - net.sf.ehcache.Cache cache = manager.getCache(regionName); - if (cache == null) { - manager.addCache(regionName); - cache = manager.getCache(regionName); - log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds).", regionName, cache.getCacheConfiguration().getTimeToLiveSeconds()); - } - return new EhCache(cache, listener); - }); + return caches.computeIfAbsent(regionName, v -> { + net.sf.ehcache.Cache cache = manager.getCache(regionName); + if (cache == null) { + manager.addCache(regionName); + cache = manager.getCache(regionName); + log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds)." , regionName, cache.getCacheConfiguration().getTimeToLiveSeconds()); + } + return new EhCache(cache, listener); + }); } - @Override - public EhCache buildCache(String region, long timeToLiveInSeconds, CacheExpiredListener listener) { - EhCache ehcache = caches.computeIfAbsent(region, v -> { - //配置缓存 - CacheConfiguration cfg = manager.getConfiguration().getDefaultCacheConfiguration().clone(); - cfg.setName(region); - if(timeToLiveInSeconds > 0) { - cfg.setTimeToLiveSeconds(timeToLiveInSeconds); - cfg.setTimeToIdleSeconds(timeToLiveInSeconds); - } - - net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(cfg); - manager.addCache(cache); - - log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds); - - return new EhCache(cache, listener); - }); - - if (ehcache.ttl() != timeToLiveInSeconds) - throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d", region, ehcache.ttl(), timeToLiveInSeconds)); - - return ehcache; - } - - @Override - public void removeCache(String region) { - caches.remove(region); - manager.removeCache(region); - } - - /** - * init ehcache config - * - * @param props current configuration settings. - */ - public void start(Properties props) { - if (manager != null) { + @Override + public EhCache buildCache(String region, long timeToLiveInSeconds, CacheExpiredListener listener) { + EhCache ehcache = caches.computeIfAbsent(region, v -> { + //配置缓存 + CacheConfiguration cfg = manager.getConfiguration().getDefaultCacheConfiguration().clone(); + cfg.setName(region); + if (timeToLiveInSeconds > 0) { + cfg.setTimeToLiveSeconds(timeToLiveInSeconds); + cfg.setTimeToIdleSeconds(timeToLiveInSeconds); + } + + net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(cfg); + manager.addCache(cache); + + log.info("Started Ehcache region [{}] with TTL: {}" , region, timeToLiveInSeconds); + + return new EhCache(cache, listener); + }); + + if (ehcache.ttl() != timeToLiveInSeconds) + throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d" , region, ehcache.ttl(), timeToLiveInSeconds)); + + return ehcache; + } + + @Override + public void removeCache(String region) { + caches.remove(region); + manager.removeCache(region); + } + + /** + * init ehcache config + * + * @param props current configuration settings. + */ + public void start(Properties props) { + if (manager != null) { log.warn("Attempt to restart an already started EhCacheProvider."); return; } - - // 如果指定了名称,那么尝试获取已有实例 - String ehcacheName = (String)props.get(KEY_EHCACHE_NAME); - if (ehcacheName != null && ehcacheName.trim().length() > 0) - manager = CacheManager.getCacheManager(ehcacheName); - if (manager == null) { - // 指定了配置文件路径? 加载之 - if (props.containsKey(KEY_EHCACHE_CONFIG_XML)) { - URL url = getClass().getClassLoader().getResource(props.getProperty(KEY_EHCACHE_CONFIG_XML)); - manager = CacheManager.newInstance(url); - } else { - // 加载默认实例 - manager = CacheManager.getInstance(); - } - } + + // 如果指定了名称,那么尝试获取已有实例 + String ehcacheName = (String) props.get(KEY_EHCACHE_NAME); + if (ehcacheName != null && ehcacheName.trim().length() > 0) + manager = CacheManager.getCacheManager(ehcacheName); + if (manager == null) { + // 指定了配置文件路径? 加载之 + if (props.containsKey(KEY_EHCACHE_CONFIG_XML)) { + String propertiesFile = props.getProperty(KEY_EHCACHE_CONFIG_XML); + URL url = getClass().getResource(propertiesFile); + url = (url == null) ? getClass().getClassLoader().getResource(propertiesFile) : url; + manager = CacheManager.newInstance(url); + } else { + // 加载默认实例 + manager = CacheManager.getInstance(); + } + } caches = new ConcurrentHashMap<>(); - } + } - /** - * Callback to perform any necessary cleanup of the underlying cache implementation. - */ - public void stop() { - if (manager != null) { + /** + * Callback to perform any necessary cleanup of the underlying cache implementation. + */ + public void stop() { + if (manager != null) { manager.shutdown(); caches.clear(); manager = null; } - } + } } diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java index 41d152a..e3eae50 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java @@ -66,7 +66,7 @@ public class EhCacheProvider3 implements CacheProvider { @Override public Collection regions() { Collection regions = new ArrayList<>(); - caches.forEach((k,c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); + caches.forEach((k, c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); return regions; } @@ -79,8 +79,8 @@ public class EhCacheProvider3 implements CacheProvider { CacheConfiguration cacheCfg = CacheConfigurationBuilder.newCacheConfigurationBuilder(defaultCacheConfig).build(); cache = manager.createCache(region, cacheCfg); Duration dura = cache.getRuntimeConfiguration().getExpiry().getExpiryForCreation(null, null); - long ttl = dura.isInfinite()?-1:dura.getTimeUnit().toSeconds(dura.getLength()); - log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds).", region, ttl); + long ttl = dura.isInfinite() ? -1 : dura.getTimeUnit().toSeconds(dura.getLength()); + log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds)." , region, ttl); } return new EhCache3(region, cache, listener); }); @@ -94,12 +94,12 @@ public class EhCacheProvider3 implements CacheProvider { .withExpiry(Expirations.timeToLiveExpiration(Duration.of(timeToLiveInSeconds, TimeUnit.SECONDS))) .build(); org.ehcache.Cache cache = manager.createCache(region, conf); - log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds); + log.info("Started Ehcache region [{}] with TTL: {}" , region, timeToLiveInSeconds); return new EhCache3(region, cache, listener); }); if (ehcache.ttl() != timeToLiveInSeconds) - throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d", region, ehcache.ttl(), timeToLiveInSeconds)); + throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d" , region, ehcache.ttl(), timeToLiveInSeconds)); return ehcache; } @@ -115,14 +115,17 @@ public class EhCacheProvider3 implements CacheProvider { String sDefaultHeapSize = props.getProperty("defaultHeapSize"); try { this.defaultHeapSize = Long.parseLong(sDefaultHeapSize); - }catch(Exception e) { - log.warn("Failed to read ehcache3.defaultHeapSize = {} , use default {}", sDefaultHeapSize, defaultHeapSize); + } catch (Exception e) { + log.warn("Failed to read ehcache3.defaultHeapSize = {} , use default {}" , sDefaultHeapSize, defaultHeapSize); } String configXml = props.getProperty("configXml"); - if(configXml == null || configXml.trim().length() == 0) + if (configXml == null || configXml.trim().length() == 0) configXml = "/ehcache3.xml"; - URL myUrl = getClass().getClassLoader().getResource(configXml); - Configuration xmlConfig = new XmlConfiguration(myUrl); + + URL url = getClass().getResource(configXml); + url = (url == null) ? getClass().getClassLoader().getResource(configXml) : url; + + Configuration xmlConfig = new XmlConfiguration(url); manager = CacheManagerBuilder.newCacheManager(xmlConfig); manager.init(); } -- Gitee From 9c15096f3289dd0721dccf56ddf0c80c6dde96de Mon Sep 17 00:00:00 2001 From: wxk <2674518127@qq.com> Date: Fri, 13 Dec 2019 13:11:48 +0800 Subject: [PATCH 090/131] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=A4=E7=A7=8D?= =?UTF-8?q?=E8=8E=B7=E5=8F=96EhCache=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/ehcache/EhCacheProvider.java | 31 ++++++++++--------- .../j2cache/ehcache/EhCacheProvider3.java | 16 +++++----- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java index 9589157..1b8ceb9 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider.java @@ -15,20 +15,21 @@ */ package net.oschina.j2cache.ehcache; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + import net.oschina.j2cache.CacheChannel; -import net.oschina.j2cache.CacheExpiredListener; import net.oschina.j2cache.CacheObject; -import net.oschina.j2cache.CacheProvider; -import net.sf.ehcache.CacheManager; import net.sf.ehcache.config.CacheConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; +import net.oschina.j2cache.CacheExpiredListener; +import net.oschina.j2cache.CacheProvider; +import net.sf.ehcache.CacheManager; /** * EhCache 2.x 缓存管理器的封装,用来管理多个缓存区域 @@ -59,7 +60,7 @@ public class EhCacheProvider implements CacheProvider { @Override public Collection regions() { Collection regions = new ArrayList<>(); - caches.forEach((k, c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); + caches.forEach((k,c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); return regions; } @@ -67,7 +68,7 @@ public class EhCacheProvider implements CacheProvider { * Builds a Cache. * * @param regionName the regionName of the cache. Must match a cache configured in ehcache.xml - * @param listener cache listener + * @param listener cache listener * @return a newly built cache will be built and initialised */ @Override @@ -77,7 +78,7 @@ public class EhCacheProvider implements CacheProvider { if (cache == null) { manager.addCache(regionName); cache = manager.getCache(regionName); - log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds)." , regionName, cache.getCacheConfiguration().getTimeToLiveSeconds()); + log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds).", regionName, cache.getCacheConfiguration().getTimeToLiveSeconds()); } return new EhCache(cache, listener); }); @@ -89,7 +90,7 @@ public class EhCacheProvider implements CacheProvider { //配置缓存 CacheConfiguration cfg = manager.getConfiguration().getDefaultCacheConfiguration().clone(); cfg.setName(region); - if (timeToLiveInSeconds > 0) { + if(timeToLiveInSeconds > 0) { cfg.setTimeToLiveSeconds(timeToLiveInSeconds); cfg.setTimeToIdleSeconds(timeToLiveInSeconds); } @@ -97,13 +98,13 @@ public class EhCacheProvider implements CacheProvider { net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(cfg); manager.addCache(cache); - log.info("Started Ehcache region [{}] with TTL: {}" , region, timeToLiveInSeconds); + log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds); return new EhCache(cache, listener); }); if (ehcache.ttl() != timeToLiveInSeconds) - throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d" , region, ehcache.ttl(), timeToLiveInSeconds)); + throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d", region, ehcache.ttl(), timeToLiveInSeconds)); return ehcache; } @@ -126,7 +127,7 @@ public class EhCacheProvider implements CacheProvider { } // 如果指定了名称,那么尝试获取已有实例 - String ehcacheName = (String) props.get(KEY_EHCACHE_NAME); + String ehcacheName = (String)props.get(KEY_EHCACHE_NAME); if (ehcacheName != null && ehcacheName.trim().length() > 0) manager = CacheManager.getCacheManager(ehcacheName); if (manager == null) { diff --git a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java index e3eae50..22490fa 100644 --- a/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java +++ b/core/src/net/oschina/j2cache/ehcache/EhCacheProvider3.java @@ -66,7 +66,7 @@ public class EhCacheProvider3 implements CacheProvider { @Override public Collection regions() { Collection regions = new ArrayList<>(); - caches.forEach((k, c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); + caches.forEach((k,c) -> regions.add(new CacheChannel.Region(k, c.size(), c.ttl()))); return regions; } @@ -79,8 +79,8 @@ public class EhCacheProvider3 implements CacheProvider { CacheConfiguration cacheCfg = CacheConfigurationBuilder.newCacheConfigurationBuilder(defaultCacheConfig).build(); cache = manager.createCache(region, cacheCfg); Duration dura = cache.getRuntimeConfiguration().getExpiry().getExpiryForCreation(null, null); - long ttl = dura.isInfinite() ? -1 : dura.getTimeUnit().toSeconds(dura.getLength()); - log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds)." , region, ttl); + long ttl = dura.isInfinite()?-1:dura.getTimeUnit().toSeconds(dura.getLength()); + log.warn("Could not find configuration [{}]; using defaults (TTL:{} seconds).", region, ttl); } return new EhCache3(region, cache, listener); }); @@ -94,12 +94,12 @@ public class EhCacheProvider3 implements CacheProvider { .withExpiry(Expirations.timeToLiveExpiration(Duration.of(timeToLiveInSeconds, TimeUnit.SECONDS))) .build(); org.ehcache.Cache cache = manager.createCache(region, conf); - log.info("Started Ehcache region [{}] with TTL: {}" , region, timeToLiveInSeconds); + log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds); return new EhCache3(region, cache, listener); }); if (ehcache.ttl() != timeToLiveInSeconds) - throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d" , region, ehcache.ttl(), timeToLiveInSeconds)); + throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d", region, ehcache.ttl(), timeToLiveInSeconds)); return ehcache; } @@ -115,11 +115,11 @@ public class EhCacheProvider3 implements CacheProvider { String sDefaultHeapSize = props.getProperty("defaultHeapSize"); try { this.defaultHeapSize = Long.parseLong(sDefaultHeapSize); - } catch (Exception e) { - log.warn("Failed to read ehcache3.defaultHeapSize = {} , use default {}" , sDefaultHeapSize, defaultHeapSize); + }catch(Exception e) { + log.warn("Failed to read ehcache3.defaultHeapSize = {} , use default {}", sDefaultHeapSize, defaultHeapSize); } String configXml = props.getProperty("configXml"); - if (configXml == null || configXml.trim().length() == 0) + if(configXml == null || configXml.trim().length() == 0) configXml = "/ehcache3.xml"; URL url = getClass().getResource(configXml); -- Gitee From 38396e12a55f2e2b3ce140f1709051138a86adaf Mon Sep 17 00:00:00 2001 From: makejava <1353036300@qq.com> Date: Tue, 17 Dec 2019 21:59:26 +0800 Subject: [PATCH 091/131] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dspringcache=E5=9C=A8?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E5=85=81=E8=AE=B8=E7=BC=93=E5=AD=98null?= =?UTF-8?q?=E5=80=BC=E5=BE=97=E6=83=85=E5=86=B5=E4=B8=8B=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=BC=93=E5=AD=98null=E5=80=BC=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springcache/J2CacheSpringCacheAdapter.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java index 0b7668a..9859398 100644 --- a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java +++ b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java @@ -1,6 +1,8 @@ package net.oschina.j2cache.springcache; import net.oschina.j2cache.CacheChannel; +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.NullObject; import org.springframework.cache.CacheManager; import org.springframework.cache.support.AbstractValueAdaptingCache; @@ -42,7 +44,11 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { - return j2Cache.get(name, getKey(key)).getValue(); + Object value = j2Cache.get(name, getKey(key)).rawValue(); + if (value == null || value.getClass().equals(Object.class)) { + return null; + } + return value; } /** @@ -82,6 +88,9 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { public T get(Object key, Callable valueLoader) throws ValueRetrievalException { ValueWrapper val = get(key); if (val != null) { + if (val.get() instanceof NullObject) { + return null; + } return (T) val.get(); } T t; -- Gitee From c50c45f3cfb2f6dc4502ad93ec3c3dd0bd35c2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Fri, 27 Dec 2019 10:13:01 +0800 Subject: [PATCH 092/131] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20redis=20=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=95=B0=E9=87=8F=E8=A2=AB=20caffeine=20=E9=99=90?= =?UTF-8?q?=E5=88=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/oschina/j2cache/caffeine/CaffeineProvider.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index 64a8db2..18ab30e 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -118,8 +118,11 @@ public class CaffeineProvider implements CacheProvider { Caffeine caffeine = Caffeine.newBuilder(); caffeine = caffeine.maximumSize(size) .removalListener((k,v, cause) -> { - //程序删除的缓存不做通知处理,因为上层已经做了处理 - if(cause != RemovalCause.EXPLICIT && cause != RemovalCause.REPLACED) + /* + * 程序删除的缓存不做通知处理,因为上层已经做了处理 + * 当缓存数据不是因为手工删除和超出容量限制而被删除的情况,就不需要通知上层侦听器 + */ + if(cause != RemovalCause.EXPLICIT && cause != RemovalCause.REPLACED && cause != RemovalCause.SIZE) listener.notifyElementExpired(region, (String)k); }); if (expire > 0) { -- Gitee From 810776b0ba6f24cf30b5c51e54763551d5d46477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Fri, 27 Dec 2019 10:45:55 +0800 Subject: [PATCH 093/131] 2.8.0 release to maven repository --- core/pom.xml | 3 +-- core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java | 2 +- modules/hibernate3/pom.xml | 2 +- modules/hibernate4/pom.xml | 2 +- modules/hibernate5/pom.xml | 3 +-- modules/mybatis/pom.xml | 2 +- modules/session-manager/pom.xml | 2 +- modules/spring-boot-starter/pom.xml | 2 +- modules/spring-boot2-starter/pom.xml | 2 +- modules/springcache/pom.xml | 2 +- pom.xml | 2 +- 11 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index fddb990..de159c2 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,12 +3,11 @@ net.oschina.j2cache j2cache - 2.7.9-release + 2.8.0-release 4.0.0 j2cache-core - 2.7.9-release diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index 18ab30e..3f9d48e 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -120,7 +120,7 @@ public class CaffeineProvider implements CacheProvider { .removalListener((k,v, cause) -> { /* * 程序删除的缓存不做通知处理,因为上层已经做了处理 - * 当缓存数据不是因为手工删除和超出容量限制而被删除的情况,就不需要通知上层侦听器 + * 当缓存数据不是因为手工删除和超出容量限制而被删除的情况,就需要通知上层侦听器 */ if(cause != RemovalCause.EXPLICIT && cause != RemovalCause.REPLACED && cause != RemovalCause.SIZE) listener.notifyElementExpired(region, (String)k); diff --git a/modules/hibernate3/pom.xml b/modules/hibernate3/pom.xml index 5e63581..97cfa25 100755 --- a/modules/hibernate3/pom.xml +++ b/modules/hibernate3/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.9-release + 2.8.0-release ../../pom.xml diff --git a/modules/hibernate4/pom.xml b/modules/hibernate4/pom.xml index f3efd9c..f63e0cd 100755 --- a/modules/hibernate4/pom.xml +++ b/modules/hibernate4/pom.xml @@ -3,7 +3,7 @@ net.oschina.j2cache j2cache - 2.7.9-release + 2.8.0-release ../../pom.xml diff --git a/modules/hibernate5/pom.xml b/modules/hibernate5/pom.xml index 7089709..0d63e5b 100644 --- a/modules/hibernate5/pom.xml +++ b/modules/hibernate5/pom.xml @@ -5,14 +5,13 @@ j2cache net.oschina.j2cache - 2.7.9-release + 2.8.0-release ../../pom.xml 4.0.0 j2cache-hibernate5 - 1.0.0-beta1 jar J2Cache - hibernate5 diff --git a/modules/mybatis/pom.xml b/modules/mybatis/pom.xml index 67caead..1221ee0 100644 --- a/modules/mybatis/pom.xml +++ b/modules/mybatis/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.9-release + 2.8.0-release ../../pom.xml 4.0.0 diff --git a/modules/session-manager/pom.xml b/modules/session-manager/pom.xml index e3dc182..cd112af 100644 --- a/modules/session-manager/pom.xml +++ b/modules/session-manager/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.6-release + 2.8.0-release ../../pom.xml diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index a12f3d6..9b82bc7 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.9-release + 2.8.0-release ../../pom.xml 4.0.0 diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index b17cf06..1c8fd3b 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.9-release + 2.8.0-release ../../pom.xml 4.0.0 diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index e75b939..ac08040 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -5,7 +5,7 @@ j2cache net.oschina.j2cache - 2.7.9-release + 2.8.0-release ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 3b5d9bf..309b5b7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.oschina.j2cache j2cache - 2.7.9-release + 2.8.0-release pom j2cache -- Gitee From cf223d6d8fdc5457f3eefd52920e65e0cb54e71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Fri, 27 Dec 2019 11:17:56 +0800 Subject: [PATCH 094/131] fix j2cache.version defined in maven --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 309b5b7..6187c89 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ UTF-8 - 2.7.6-release + 2.8.0-release -- Gitee From b479365378492b02e00670c1fac367a7b5543d52 Mon Sep 17 00:00:00 2001 From: wxk <2674518127@qq.com> Date: Fri, 27 Dec 2019 11:42:17 +0800 Subject: [PATCH 095/131] =?UTF-8?q?=E5=85=A8=E5=B1=80core=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hibernate3/pom.xml | 3 +-- modules/hibernate4/pom.xml | 3 +-- modules/hibernate5/pom.xml | 1 - modules/mybatis/pom.xml | 3 +-- modules/spring-boot-starter/pom.xml | 3 +-- modules/spring-boot2-starter/pom.xml | 3 +-- modules/springcache/pom.xml | 3 +-- pom.xml | 17 +++++++++++++---- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/modules/hibernate3/pom.xml b/modules/hibernate3/pom.xml index 97cfa25..a6e9f89 100755 --- a/modules/hibernate3/pom.xml +++ b/modules/hibernate3/pom.xml @@ -19,7 +19,6 @@ net.oschina.j2cache j2cache-core - ${j2cache-version} provided @@ -32,4 +31,4 @@ J2Cache - hibernate3 - \ No newline at end of file + diff --git a/modules/hibernate4/pom.xml b/modules/hibernate4/pom.xml index f63e0cd..9e0de70 100755 --- a/modules/hibernate4/pom.xml +++ b/modules/hibernate4/pom.xml @@ -20,7 +20,6 @@ net.oschina.j2cache j2cache-core - ${j2cache-version} provided @@ -64,4 +63,4 @@ - \ No newline at end of file + diff --git a/modules/hibernate5/pom.xml b/modules/hibernate5/pom.xml index 0d63e5b..f8d58a3 100644 --- a/modules/hibernate5/pom.xml +++ b/modules/hibernate5/pom.xml @@ -24,7 +24,6 @@ net.oschina.j2cache j2cache-core - ${j2cache-version} provided diff --git a/modules/mybatis/pom.xml b/modules/mybatis/pom.xml index 1221ee0..7b3dd57 100644 --- a/modules/mybatis/pom.xml +++ b/modules/mybatis/pom.xml @@ -16,7 +16,6 @@ net.oschina.j2cache j2cache-core - ${j2cache-version} provided @@ -37,4 +36,4 @@ src/main/java - \ No newline at end of file + diff --git a/modules/spring-boot-starter/pom.xml b/modules/spring-boot-starter/pom.xml index 9b82bc7..fe9b994 100644 --- a/modules/spring-boot-starter/pom.xml +++ b/modules/spring-boot-starter/pom.xml @@ -16,7 +16,6 @@ net.oschina.j2cache j2cache-core - ${j2cache-version} provided @@ -69,4 +68,4 @@ 1.5.8.RELEASE - \ No newline at end of file + diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index 1c8fd3b..52f6555 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -16,7 +16,6 @@ net.oschina.j2cache j2cache-core - ${j2cache-version} org.slf4j @@ -75,4 +74,4 @@ 2.0.1.RELEASE - \ No newline at end of file + diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index ac08040..0a57fd5 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -22,7 +22,6 @@ net.oschina.j2cache j2cache-core - ${j2cache-version} junit @@ -34,4 +33,4 @@ test/src - \ No newline at end of file + diff --git a/pom.xml b/pom.xml index 309b5b7..bfa8c46 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - + net.oschina.j2cache j2cache 2.8.0-release @@ -36,10 +36,9 @@ https://oss.sonatype.org/service/local/staging/deploy/maven2/ - + UTF-8 - 2.7.6-release @@ -136,6 +135,16 @@ modules/session-manager + + + + net.oschina.j2cache + j2cache-core + ${project.version} + + + + @@ -154,4 +163,4 @@ - \ No newline at end of file + -- Gitee From ab47661973f8087c55c95867cd3f6ac24ab3df93 Mon Sep 17 00:00:00 2001 From: wxk <2674518127@qq.com> Date: Fri, 27 Dec 2019 15:10:26 +0800 Subject: [PATCH 096/131] =?UTF-8?q?boo2=E5=BA=8F=E5=88=97=E5=8C=96?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=90=91=E4=B8=8A=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/cache/support/util/J2CacheSerializer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/J2CacheSerializer.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/J2CacheSerializer.java index 906bddf..5748838 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/J2CacheSerializer.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/J2CacheSerializer.java @@ -2,6 +2,7 @@ package net.oschina.j2cache.cache.support.util; import java.io.IOException; +import org.nustaq.serialization.util.FSTUtil; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.SerializationException; @@ -11,12 +12,12 @@ import net.oschina.j2cache.util.SerializationUtils; public class J2CacheSerializer implements RedisSerializer{ @Override - public byte[] serialize(Object t) throws SerializationException { + public byte[] serialize(Object t) throws SerializationException { try { return SerializationUtils.serialize(t); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); + FSTUtil.rethrow(e); } return null; } @@ -26,8 +27,8 @@ public class J2CacheSerializer implements RedisSerializer{ try { return SerializationUtils.deserialize(bytes); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); + FSTUtil.rethrow(e); } return null; } -- Gitee From 841d27ac7b9894f908766f40f94ad4afba981427 Mon Sep 17 00:00:00 2001 From: wxk <2674518127@qq.com> Date: Thu, 2 Jan 2020 15:46:37 +0800 Subject: [PATCH 097/131] =?UTF-8?q?=E9=9B=86=E4=B8=AD=E5=BC=8F=E7=AE=A1?= =?UTF-8?q?=E7=90=86core=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 6187c89..bfa8c46 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - + net.oschina.j2cache j2cache 2.8.0-release @@ -36,10 +36,9 @@ https://oss.sonatype.org/service/local/staging/deploy/maven2/ - + UTF-8 - 2.8.0-release @@ -136,6 +135,16 @@ modules/session-manager + + + + net.oschina.j2cache + j2cache-core + ${project.version} + + + + @@ -154,4 +163,4 @@ - \ No newline at end of file + -- Gitee From 537b366f25929be0febd230e14101fa2a5346fd0 Mon Sep 17 00:00:00 2001 From: liuhuan <79523503@qq.com> Date: Sun, 5 Jan 2020 12:24:17 +0800 Subject: [PATCH 098/131] =?UTF-8?q?Object=E7=9A=84equals=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=AE=B9=E6=98=93=E6=8A=9B=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=8C=E7=94=A8java8=E7=9A=84Objects.equals?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/J2CacheCmd.java | 2 +- .../net/oschina/j2cache/cluster/JGroupsClusterPolicy.java | 2 +- .../j2cache/cache/support/redis/SpringRedisCache.java | 8 ++------ .../cache/support/util/SpringJ2CacheConfigUtil.java | 5 +++-- .../j2cache/cache/support/redis/SpringRedisCache.java | 8 ++------ .../cache/support/util/SpringJ2CacheConfigUtil.java | 4 +++- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/core/src/net/oschina/j2cache/J2CacheCmd.java b/core/src/net/oschina/j2cache/J2CacheCmd.java index 447a402..d6e3cbe 100644 --- a/core/src/net/oschina/j2cache/J2CacheCmd.java +++ b/core/src/net/oschina/j2cache/J2CacheCmd.java @@ -40,7 +40,7 @@ public class J2CacheCmd { try { line = reader.readLine("> "); - if(line == null || line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit")) + if(line == null || "quit".equalsIgnoreCase(line) || "exit".equalsIgnoreCase(line)) break; String[] cmds = line.split(" "); diff --git a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java index 80e4d68..b310adf 100644 --- a/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java +++ b/core/src/net/oschina/j2cache/cluster/JGroupsClusterPolicy.java @@ -51,7 +51,7 @@ public class JGroupsClusterPolicy extends ReceiverAdapter implements ClusterPoli */ public JGroupsClusterPolicy(String name, Properties props) { this.name = name; - if(this.name == null || this.name.trim().equalsIgnoreCase("")) + if(this.name == null || "".equalsIgnoreCase(this.name.trim())) this.name = "j2cache"; this.configXml = props.getProperty("configXml"); if(configXml == null || configXml.trim().length() == 0) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java index 6d232ae..312e19e 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java @@ -1,11 +1,7 @@ package net.oschina.j2cache.cache.support.redis; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisTemplate; @@ -54,7 +50,7 @@ public class SpringRedisCache implements Level2Cache { @Override public void evict(String... keys) { for (String k : keys) { - if (!k.equals("null")) { + if (!Objects.equals(k, "null")) { redisTemplate.opsForHash().delete(region, k); } else { redisTemplate.delete(region); diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index ccbc156..8a0e75f 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -6,6 +6,8 @@ import org.springframework.core.io.support.ResourcePropertySource; import net.oschina.j2cache.J2CacheConfig; +import java.util.Objects; + public class SpringJ2CacheConfigUtil { /** @@ -22,8 +24,7 @@ public class SpringJ2CacheConfigUtil { config.setSyncTtlToRedis(!"false".equalsIgnoreCase(environment.getProperty("j2cache.sync_ttl_to_redis"))); config.setDefaultCacheNullObject("true".equalsIgnoreCase(environment.getProperty("j2cache.default_cache_null_object"))); String l2_config_section = environment.getProperty("j2cache.L2.config_section"); - if (l2_config_section == null || l2_config_section.trim().equals("")) - l2_config_section = config.getL2CacheName(); + if (l2_config_section == null || Objects.equals(l2_config_section.trim(),"")) l2_config_section = config.getL2CacheName(); final String l2_section = l2_config_section; environment.getPropertySources().forEach(a -> { if(a instanceof MapPropertySource) { diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java index 6d232ae..312e19e 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java @@ -1,11 +1,7 @@ package net.oschina.j2cache.cache.support.redis; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisTemplate; @@ -54,7 +50,7 @@ public class SpringRedisCache implements Level2Cache { @Override public void evict(String... keys) { for (String k : keys) { - if (!k.equals("null")) { + if (!Objects.equals(k, "null")) { redisTemplate.opsForHash().delete(region, k); } else { redisTemplate.delete(region); diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index 15878b3..d554ecc 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -5,6 +5,8 @@ import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.StandardEnvironment; +import java.util.Objects; + public class SpringJ2CacheConfigUtil { /** @@ -21,7 +23,7 @@ public class SpringJ2CacheConfigUtil { config.setSyncTtlToRedis(!"false".equalsIgnoreCase(environment.getProperty("j2cache.sync_ttl_to_redis"))); config.setDefaultCacheNullObject("true".equalsIgnoreCase(environment.getProperty("j2cache.default_cache_null_object"))); String l2_config_section = environment.getProperty("j2cache.L2.config_section"); - if (l2_config_section == null || l2_config_section.trim().equals("")) + if (l2_config_section == null || Objects.equals(l2_config_section.trim(),"")) l2_config_section = config.getL2CacheName(); final String l2_section = l2_config_section; environment.getPropertySources().forEach(a -> { -- Gitee From c38e52428e8e96d08e7b849ee29968cd04140418 Mon Sep 17 00:00:00 2001 From: ZhengWeiwei <4647668@qq.com> Date: Fri, 17 Jan 2020 15:01:43 +0800 Subject: [PATCH 099/131] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BD=93?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=B8=BANullObject=E6=97=B6SpringCache?= =?UTF-8?q?=E6=9C=AA=E5=A4=84=E7=90=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java index 9859398..fda4f43 100644 --- a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java +++ b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java @@ -45,7 +45,7 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { Object value = j2Cache.get(name, getKey(key)).rawValue(); - if (value == null || value.getClass().equals(Object.class)) { + if (value == null || value.getClass().equals(NullObject.class) || value.getClass().equals(Object.class)) { return null; } return value; -- Gitee From 93d1901085bfd6acebad642c14111ce871ae9b5a Mon Sep 17 00:00:00 2001 From: whcrow Date: Sun, 9 Feb 2020 19:20:34 +0800 Subject: [PATCH 100/131] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8=20?= =?UTF-8?q?fse=20=E5=AE=9E=E7=8E=B0=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 7 +++ core/resources/j2cache.properties | 5 +- .../oschina/j2cache/util/FseSerializer.java | 54 +++++++++++++++++++ .../j2cache/util/SerializationUtils.java | 2 + 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 core/src/net/oschina/j2cache/util/FseSerializer.java diff --git a/core/pom.xml b/core/pom.xml index de159c2..becc161 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -123,6 +123,13 @@ provided + + com.jfireframework + fse + aegean-2.0 + provided + + J2Cache - core diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index c2191a8..bafac92 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -67,6 +67,7 @@ j2cache.default_cache_null_object = true # json -> using fst's json serialization (testing) # fastjson -> using fastjson serialization (embed non-static class not support) # java -> java standard +# fse -> using fse serialization # [classname implements Serializer] ######################################### @@ -98,8 +99,8 @@ caffeine.properties = /caffeine.properties # # single -> single redis server # sentinel -> master-slaves servers -# cluster -> cluster servers (数据库配置无效,使用 database = 0) -# sharded -> sharded servers (密码、数据库必须在 hosts 中指定,且连接池配置无效 ; redis://user:password@127.0.0.1:6379/0) +# cluster -> cluster servers (\u6570\u636E\u5E93\u914D\u7F6E\u65E0\u6548\uFF0C\u4F7F\u7528 database = 0\uFF09 +# sharded -> sharded servers (\u5BC6\u7801\u3001\u6570\u636E\u5E93\u5FC5\u987B\u5728 hosts \u4E2D\u6307\u5B9A\uFF0C\u4E14\u8FDE\u63A5\u6C60\u914D\u7F6E\u65E0\u6548 ; redis://user:password@127.0.0.1:6379/0\uFF09 # ######################################### diff --git a/core/src/net/oschina/j2cache/util/FseSerializer.java b/core/src/net/oschina/j2cache/util/FseSerializer.java new file mode 100644 index 0000000..3529852 --- /dev/null +++ b/core/src/net/oschina/j2cache/util/FseSerializer.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015-2020, whcrow (v@whcrow.com). + *

+ * 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 net.oschina.j2cache.util; + +import com.jfireframework.fse.ByteArray; +import com.jfireframework.fse.Fse; + +/** + * 使用 fse 实现序列化 + * + * @author whcrow (v@whcrow.com) + */ +public class FseSerializer implements Serializer { + + @Override + public String name() { + return "fse"; + } + + @Override + public byte[] serialize(Object obj) { + ByteArray buf = ByteArray.allocate(100); + new Fse().serialize(obj, buf); + byte[] resultBytes = buf.toArray(); + buf.clear(); + return resultBytes; + } + + @Override + public Object deserialize(byte[] bytes) { + if (bytes == null || bytes.length == 0) { + return null; + } + ByteArray buf = ByteArray.allocate(100); + buf.put(bytes); + Object result = new Fse().deSerialize(buf); + buf.clear(); + return result; + } + +} diff --git a/core/src/net/oschina/j2cache/util/SerializationUtils.java b/core/src/net/oschina/j2cache/util/SerializationUtils.java index 3535073..5172a52 100644 --- a/core/src/net/oschina/j2cache/util/SerializationUtils.java +++ b/core/src/net/oschina/j2cache/util/SerializationUtils.java @@ -55,6 +55,8 @@ public class SerializationUtils { g_serializer = new FstJSONSerializer(props); } else if ("fastjson".equals(ser)) { g_serializer = new FastjsonSerializer(); + } else if ("fse".equals(ser)) { + g_serializer = new FseSerializer(); } else { try { g_serializer = (Serializer) Class.forName(ser).newInstance(); -- Gitee From c85dd5c0301bb7f181a68f6c8b16b115af6fdc23 Mon Sep 17 00:00:00 2001 From: whcrow Date: Thu, 13 Feb 2020 15:38:06 +0800 Subject: [PATCH 101/131] =?UTF-8?q?=E5=90=8C=E6=AD=A5Fse=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 6 +++--- core/src/net/oschina/j2cache/util/FseSerializer.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index becc161..f19ef8a 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -124,9 +124,9 @@ - com.jfireframework - fse - aegean-2.0 + com.jfirer + Fse + 1.0 provided diff --git a/core/src/net/oschina/j2cache/util/FseSerializer.java b/core/src/net/oschina/j2cache/util/FseSerializer.java index 3529852..850bef2 100644 --- a/core/src/net/oschina/j2cache/util/FseSerializer.java +++ b/core/src/net/oschina/j2cache/util/FseSerializer.java @@ -15,8 +15,8 @@ */ package net.oschina.j2cache.util; -import com.jfireframework.fse.ByteArray; -import com.jfireframework.fse.Fse; +import com.jfirer.fse.ByteArray; +import com.jfirer.fse.Fse; /** * 使用 fse 实现序列化 -- Gitee From 2405c8e0f45a8d76b99ef2361f59c37420869aad Mon Sep 17 00:00:00 2001 From: storv Date: Thu, 5 Mar 2020 14:26:46 +0800 Subject: [PATCH 102/131] =?UTF-8?q?=E4=BF=AE=E6=94=B9springCache=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9A=84lookup=E6=96=B9=E6=B3=95=E9=80=82=E9=85=8DNul?= =?UTF-8?q?lObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/springcache/J2CacheSpringCacheAdapter.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java index fda4f43..2a41017 100644 --- a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java +++ b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java @@ -45,9 +45,12 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { Object value = j2Cache.get(name, getKey(key)).rawValue(); - if (value == null || value.getClass().equals(NullObject.class) || value.getClass().equals(Object.class)) { + if (value == null || value.getClass().equals(Object.class)) { return null; } + if (value.getClass().equals(NullObject.class)) { + return NullValue.INSTANCE; + } return value; } -- Gitee From a64a9ec0c1a6cea76c18a9f460c707a50e487da1 Mon Sep 17 00:00:00 2001 From: whcrow Date: Thu, 5 Mar 2020 17:05:46 +0800 Subject: [PATCH 103/131] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=20allow-null-values:=20true=EF=BC=8Cdefault=5Fcache?= =?UTF-8?q?=5Fnull=5Fobject:=20true=EF=BC=8C=E6=96=B9=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8SpringCache=E6=B3=A8=E8=A7=A3@Cacheable=20=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=89=A7=E8=A1=8C=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=8D=E4=BC=9A=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/oschina/j2cache/cache/support/J2CacheCache.java | 2 +- .../src/net/oschina/j2cache/cache/support/J2CacheCache.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java index 9be5031..3201694 100644 --- a/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java +++ b/modules/spring-boot-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java @@ -82,7 +82,7 @@ public class J2CacheCache extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { - CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key)); + CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key), false); if(cacheObject.rawValue() != null && cacheObject.rawValue().getClass().equals(NullObject.class) && super.isAllowNullValues()) { return NullValue.INSTANCE; } diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java index 9be5031..3201694 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java @@ -82,7 +82,7 @@ public class J2CacheCache extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { - CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key)); + CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key), false); if(cacheObject.rawValue() != null && cacheObject.rawValue().getClass().equals(NullObject.class) && super.isAllowNullValues()) { return NullValue.INSTANCE; } -- Gitee From 3c102b2f98a7b905474991a7628455d9a2f8061a Mon Sep 17 00:00:00 2001 From: yehao20 Date: Thu, 5 Mar 2020 17:13:07 +0800 Subject: [PATCH 104/131] =?UTF-8?q?=E6=8F=90=E5=8D=87sp=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/springcache/pom.xml | 2 +- .../oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/springcache/pom.xml b/modules/springcache/pom.xml index 0a57fd5..b633342 100644 --- a/modules/springcache/pom.xml +++ b/modules/springcache/pom.xml @@ -16,7 +16,7 @@ org.springframework spring-context-support - 4.3.6.RELEASE + 4.3.10.RELEASE diff --git a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java index 2a41017..6231ee1 100644 --- a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java +++ b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java @@ -5,6 +5,7 @@ import net.oschina.j2cache.CacheObject; import net.oschina.j2cache.NullObject; import org.springframework.cache.CacheManager; import org.springframework.cache.support.AbstractValueAdaptingCache; +import org.springframework.cache.support.NullValue; import java.util.concurrent.Callable; -- Gitee From 8b125bd7f95b2591703fa5378fd5e3f1e36fb26a Mon Sep 17 00:00:00 2001 From: yehao20 Date: Mon, 9 Mar 2020 08:49:03 +0800 Subject: [PATCH 105/131] =?UTF-8?q?=E6=98=AF=E5=90=A6=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=80=9A=E8=BF=87springCache=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/springcache/J2CacheSpringCacheAdapter.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java index 6231ee1..9fc6fa2 100644 --- a/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java +++ b/modules/springcache/src/net/oschina/j2cache/springcache/J2CacheSpringCacheAdapter.java @@ -1,7 +1,6 @@ package net.oschina.j2cache.springcache; import net.oschina.j2cache.CacheChannel; -import net.oschina.j2cache.CacheObject; import net.oschina.j2cache.NullObject; import org.springframework.cache.CacheManager; import org.springframework.cache.support.AbstractValueAdaptingCache; @@ -11,6 +10,7 @@ import java.util.concurrent.Callable; /** * Spring Cache Adapter + * * @author Chen */ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { @@ -22,8 +22,8 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { * Create an {@code AbstractValueAdaptingCache} with the given setting. * * @param allowNullValues whether to allow for {@code null} values - * @param j2Cache j2cache instance - * @param name cache region name + * @param j2Cache j2cache instance + * @param name cache region name */ protected J2CacheSpringCacheAdapter(boolean allowNullValues, CacheChannel j2Cache, String name) { super(allowNullValues); @@ -45,7 +45,7 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { @Override protected Object lookup(Object key) { - Object value = j2Cache.get(name, getKey(key)).rawValue(); + Object value = j2Cache.get(name, getKey(key), false).rawValue(); if (value == null || value.getClass().equals(Object.class)) { return null; } @@ -83,7 +83,7 @@ public class J2CacheSpringCacheAdapter extends AbstractValueAdaptingCache { * a {@link ValueRetrievalException} * * @param key the key whose associated value is to be returned - * @param valueLoader value loader + * @param valueLoader value loader * @return the value to which this cache maps the specified key * @throws ValueRetrievalException if the {@code valueLoader} throws an exception * @since 4.3 -- Gitee From 9f2165d4c633aa78e387d984a7e37ce295534b31 Mon Sep 17 00:00:00 2001 From: YANGLiiN Date: Fri, 13 Mar 2020 15:27:25 +0800 Subject: [PATCH 106/131] =?UTF-8?q?update=20spring-boot-dependencies.versi?= =?UTF-8?q?on=20=E4=BD=93=E9=AA=8C=E4=B8=80=E6=8A=8A=E8=BD=BB=E9=87=8F?= =?UTF-8?q?=E7=BA=A7pr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/spring-boot2-starter/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spring-boot2-starter/pom.xml b/modules/spring-boot2-starter/pom.xml index 52f6555..ac3a5d4 100644 --- a/modules/spring-boot2-starter/pom.xml +++ b/modules/spring-boot2-starter/pom.xml @@ -72,6 +72,6 @@ - 2.0.1.RELEASE + 2.2.5.RELEASE -- Gitee From edffadc1e1df14098bc26b47f6bec27dab9a4beb Mon Sep 17 00:00:00 2001 From: chench9 Date: Tue, 24 Mar 2020 17:06:03 +0800 Subject: [PATCH 107/131] add ssl config --- core/resources/j2cache.properties | 1 + .../oschina/j2cache/redis/RedisCacheProvider.java | 5 ++++- core/src/net/oschina/j2cache/redis/RedisClient.java | 12 +++++++++--- .../j2cache/redis/RedisPubSubClusterPolicy.java | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index bafac92..a803e52 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -127,6 +127,7 @@ redis.hosts = 127.0.0.1:6379 redis.timeout = 2000 redis.password = redis.database = 0 +redis.ssl = false ## redis pool properties redis.maxTotal = 100 diff --git a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java index b9176f4..eddf25d 100644 --- a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java +++ b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java @@ -69,6 +69,7 @@ public class RedisCacheProvider implements CacheProvider { String clusterName = props.getProperty("cluster_name"); String password = props.getProperty("password"); int database = Integer.parseInt(props.getProperty("database", "0")); + boolean ssl = Boolean.valueOf(props.getProperty("ssl", "false")); long ct = System.currentTimeMillis(); @@ -78,7 +79,9 @@ public class RedisCacheProvider implements CacheProvider { .password(password) .cluster(clusterName) .database(database) - .poolConfig(poolConfig).newClient(); + .poolConfig(poolConfig) + .ssl(ssl) + .newClient(); log.info("Redis client starts with mode({}),db({}),storage({}),namespace({}),time({}ms)", mode, diff --git a/core/src/net/oschina/j2cache/redis/RedisClient.java b/core/src/net/oschina/j2cache/redis/RedisClient.java index ce2d8cc..9968c4a 100644 --- a/core/src/net/oschina/j2cache/redis/RedisClient.java +++ b/core/src/net/oschina/j2cache/redis/RedisClient.java @@ -61,6 +61,7 @@ public class RedisClient implements Closeable, AutoCloseable { private String cluster; private int database; private JedisPoolConfig poolConfig; + private boolean ssl; public Builder(){} @@ -98,8 +99,12 @@ public class RedisClient implements Closeable, AutoCloseable { this.poolConfig = poolConfig; return this; } + public Builder ssl(boolean ssl) { + this.ssl = ssl; + return this; + } public RedisClient newClient() { - return new RedisClient(mode, hosts, password, cluster, database, poolConfig); + return new RedisClient(mode, hosts, password, cluster, database, poolConfig, ssl); } } @@ -112,8 +117,9 @@ public class RedisClient implements Closeable, AutoCloseable { * @param cluster_name 集群名称 * @param database 数据库 * @param poolConfig 连接池配置 + * @param ssl 使用ssl */ - private RedisClient(String mode, String hosts, String password, String cluster_name, int database, JedisPoolConfig poolConfig) { + private RedisClient(String mode, String hosts, String password, String cluster_name, int database, JedisPoolConfig poolConfig, boolean ssl) { password = (password != null && password.trim().length() > 0)? password.trim(): null; this.clients = new ThreadLocal<>(); switch(mode){ @@ -148,7 +154,7 @@ public class RedisClient implements Closeable, AutoCloseable { String[] infos = node.split(":"); String host = infos[0]; int port = (infos.length > 1)?Integer.parseInt(infos[1]):6379; - this.single = new JedisPool(poolConfig, host, port, CONNECT_TIMEOUT, password, database); + this.single = new JedisPool(poolConfig, host, port, CONNECT_TIMEOUT, password, database, ssl); break; } if(!"single".equalsIgnoreCase(mode)) diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index ea3f255..dc3b7d3 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -52,6 +52,7 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli password = null; int database = Integer.parseInt(props.getProperty("database", "0")); + boolean ssl = Boolean.valueOf(props.getProperty("ssl", "false")); JedisPoolConfig config = RedisUtils.newPoolConfig(props, null); @@ -70,7 +71,7 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli String[] infos = node.split(":"); String host = infos[0]; int port = (infos.length > 1)?Integer.parseInt(infos[1]):6379; - this.client = new JedisPool(config, host, port, timeout, password, database); + this.client = new JedisPool(config, host, port, timeout, password, database, ssl); } } -- Gitee From fc58a055c4ceb86e0b7e56e93a6de742b4f4dc25 Mon Sep 17 00:00:00 2001 From: eddy Date: Wed, 15 Apr 2020 17:13:50 +0800 Subject: [PATCH 108/131] =?UTF-8?q?update=20core/src/net/oschina/j2cache/l?= =?UTF-8?q?ettuce/LettuceCacheProvider.java.=20=E4=BF=AE=E5=A4=8Dredis?= =?UTF-8?q?=E4=BD=BF=E7=94=A8lettuce=E8=BF=9E=E6=8E=A5=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=AF=86=E7=A0=81=E4=B8=AD=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6'@'=E6=97=B6=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=9C=B0=E5=9D=80=E5=8F=8A=E5=AF=86=E7=A0=81=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=87=BA=E9=94=99=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/lettuce/LettuceCacheProvider.java | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 0be72e3..20fd5a0 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -15,8 +15,20 @@ */ package net.oschina.j2cache.lettuce; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.commons.pool2.impl.GenericObjectPool; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; + import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisURI; import io.lettuce.core.api.StatefulConnection; import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.pubsub.RedisPubSubAdapter; @@ -24,17 +36,15 @@ import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; import io.lettuce.core.support.ConnectionPoolSupport; -import net.oschina.j2cache.*; +import net.oschina.j2cache.Cache; +import net.oschina.j2cache.CacheChannel; +import net.oschina.j2cache.CacheExpiredListener; +import net.oschina.j2cache.CacheObject; +import net.oschina.j2cache.CacheProvider; +import net.oschina.j2cache.CacheProviderHolder; +import net.oschina.j2cache.Command; +import net.oschina.j2cache.Level2Cache; import net.oschina.j2cache.cluster.ClusterPolicy; -import org.apache.commons.pool2.impl.GenericObjectPool; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; - -import java.time.Duration; -import java.util.Collection; -import java.util.Collections; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; /** * 使用 Lettuce 进行 Redis 的操作 @@ -96,15 +106,28 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp int database = Integer.parseInt(props.getProperty("database", "0")); String sentinelMasterId = props.getProperty("sentinelMasterId"); - boolean isCluster = false; if("redis-cluster".equalsIgnoreCase(scheme)) { scheme = "redis"; - isCluster = true; + List redisURIs = new ArrayList<>(); + String[] hostArray = hosts.split(","); + for(String host : hostArray) { + String[] redisArray = host.split(":"); + RedisURI uri = RedisURI.create(redisArray[0], Integer.valueOf(redisArray[1])); + uri.setDatabase(database); + uri.setPassword(password); + uri.setSentinelMasterId(sentinelMasterId); + redisURIs.add(uri); + } + RedisClusterClient.create(redisURIs); } - - String redis_url = String.format("%s://%s@%s/%d#%s", scheme, password, hosts, database, sentinelMasterId); - - redisClient = isCluster?RedisClusterClient.create(redis_url):RedisClient.create(redis_url); + else { + String[] redisArray = hosts.split(":"); + RedisURI uri = RedisURI.create(redisArray[0], Integer.valueOf(redisArray[1])); + uri.setDatabase(database); + uri.setPassword(password); + redisClient = RedisClient.create(uri); + } + try { int timeout = Integer.parseInt(props.getProperty("timeout", "10000")); redisClient.setDefaultTimeout(Duration.ofMillis(timeout)); -- Gitee From c4f30e344b12133e8b4fcf5afa9eb27ef0d07df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Thu, 16 Apr 2020 06:37:37 +0800 Subject: [PATCH 109/131] fix mvn error: gpg: signing failed: Inappropriate ioctl for device --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index bfa8c46..e41aaa5 100644 --- a/pom.xml +++ b/pom.xml @@ -88,6 +88,12 @@ sign + + + --pinentry-mode + loopback + + -- Gitee From 265787ab19cdc7d9369a724cf1f51e9aef92f542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Thu, 16 Apr 2020 06:39:04 +0800 Subject: [PATCH 110/131] 2.8.1 --- CHANGES.md | 7 +++++++ core/pom.xml | 1 + 2 files changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 631cc73..fe9f7f5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # J2Cache 版本更新记录 +**j2cache-core 2.8.1 (2020-4-16)** + +* 修复redis使用lettuce连接时,设置密码中出现特殊字符'@'时连接地址及密码解析出错的异常(感谢 [@eddy](https://gitee.com/xqxyxchy)) +详情请看 [https://gitee.com/ld/J2Cache/pulls/149](https://gitee.com/ld/J2Cache/pulls/149) + + +------ **J2Cache 2.4.1-release (2018-8-xx)** diff --git a/core/pom.xml b/core/pom.xml index f19ef8a..dc97a3b 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -8,6 +8,7 @@ 4.0.0 j2cache-core + 2.8.1-release -- Gitee From 0e0af6200f1ac66204330c479f6a7cbc4267f53f Mon Sep 17 00:00:00 2001 From: eddy Date: Thu, 16 Apr 2020 20:51:22 +0800 Subject: [PATCH 111/131] =?UTF-8?q?redis=E4=BA=8C=E7=BA=A7=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=9A=84keys=E3=80=81clear=E6=96=B9=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8scan=E5=91=BD=E4=BB=A4=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/resources/j2cache.properties | 9 ++- .../oschina/j2cache/lettuce/LettuceCache.java | 1 + .../j2cache/lettuce/LettuceCacheProvider.java | 4 +- .../j2cache/lettuce/LettuceGenericCache.java | 56 ++++++++++++++++--- .../j2cache/redis/RedisCacheProvider.java | 5 +- .../j2cache/redis/RedisGenericCache.java | 55 +++++++++++++----- 6 files changed, 103 insertions(+), 27 deletions(-) diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index a803e52..0dc5aa0 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -99,8 +99,8 @@ caffeine.properties = /caffeine.properties # # single -> single redis server # sentinel -> master-slaves servers -# cluster -> cluster servers (\u6570\u636E\u5E93\u914D\u7F6E\u65E0\u6548\uFF0C\u4F7F\u7528 database = 0\uFF09 -# sharded -> sharded servers (\u5BC6\u7801\u3001\u6570\u636E\u5E93\u5FC5\u987B\u5728 hosts \u4E2D\u6307\u5B9A\uFF0C\u4E14\u8FDE\u63A5\u6C60\u914D\u7F6E\u65E0\u6548 ; redis://user:password@127.0.0.1:6379/0\uFF09 +# cluster -> cluster servers (\u6570\u636e\u5e93\u914d\u7f6e\u65e0\u6548\uff0c\u4f7f\u7528 database = 0\uff09 +# sharded -> sharded servers (\u5bc6\u7801\u3001\u6570\u636e\u5e93\u5fc5\u987b\u5728 hosts \u4e2d\u6307\u5b9a\uff0c\u4e14\u8fde\u63a5\u6c60\u914d\u7f6e\u65e0\u6548 ; redis://user:password@127.0.0.1:6379/0\uff09 # ######################################### @@ -120,6 +120,9 @@ redis.cluster_name = j2cache ## redis cache namespace optional, default[empty] redis.namespace = +## redis command scan parameter count, default[1000] +#redis.scanCount = 1000 + ## connection # Separate multiple redis nodes with commas, such as 192.168.0.10:6379,192.168.0.11:6379,192.168.0.12:6379 @@ -155,6 +158,8 @@ redis.jmxEnabled = false # ######################################### +## redis command scan parameter count, default[1000] +#lettuce.scanCount = 1000 lettuce.namespace = lettuce.storage = hash lettuce.channel = j2cache diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceCache.java index 57c9f94..6d15eeb 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCache.java @@ -33,6 +33,7 @@ public abstract class LettuceCache implements Level2Cache { protected String namespace; protected String region; protected GenericObjectPool> pool; + protected int scanCount; protected StatefulConnection connect() { try { diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 20fd5a0..9070d5f 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -76,6 +76,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp private String channel; private String namespace; + private int scanCount; private final ConcurrentHashMap regions = new ConcurrentHashMap(); @@ -97,6 +98,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp @Override public void start(Properties props) { this.namespace = props.getProperty("namespace"); + this.scanCount = Integer.valueOf(props.getProperty("scanCount", "1000")); this.storage = props.getProperty("storage", "hash"); this.channel = props.getProperty("channel", "j2cache"); @@ -161,7 +163,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp public Cache buildCache(String region, CacheExpiredListener listener) { return regions.computeIfAbsent(this.namespace + ":" + region, v -> "hash".equalsIgnoreCase(this.storage)? new LettuceHashCache(this.namespace, region, pool): - new LettuceGenericCache(this.namespace, region, pool)); + new LettuceGenericCache(this.namespace, region, pool, scanCount)); } @Override diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java index 6a1e48c..feb5894 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceGenericCache.java @@ -15,30 +15,36 @@ */ package net.oschina.j2cache.lettuce; -import io.lettuce.core.api.StatefulConnection; -import io.lettuce.core.api.sync.RedisKeyCommands; -import io.lettuce.core.api.sync.RedisStringCommands; -import org.apache.commons.pool2.impl.GenericObjectPool; - +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.pool2.impl.GenericObjectPool; + +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.api.sync.RedisKeyCommands; +import io.lettuce.core.api.sync.RedisStringCommands; + /** * Redis 缓存操作封装,基于 region+_key 实现多个 Region 的缓存( * @author Winter Lau(javayou@gmail.com) */ public class LettuceGenericCache extends LettuceCache { - public LettuceGenericCache(String namespace, String region, GenericObjectPool> pool) { + public LettuceGenericCache(String namespace, String region, GenericObjectPool> pool, int scanCount) { if (region == null || region.isEmpty()) region = "_"; // 缺省region super.pool = pool; this.namespace = namespace; this.region = getRegionName(region); + this.scanCount = scanCount; } /** @@ -125,14 +131,48 @@ public class LettuceGenericCache extends LettuceCache { } + /** + * 1、线上redis服务大概率会禁用或重命名keys命令; + * 2、keys命令效率太低容易致使redis宕机; + * 所以使用scan命令替换keys命令操作,增加可用性及提升执行性能 + */ @Override public Collection keys() { try(StatefulConnection connection = super.connect()) { RedisKeyCommands cmd = (RedisKeyCommands)super.sync(connection); - return cmd.keys(this.region + ":*").stream().map(k -> k.substring(this.region.length()+1)).collect(Collectors.toList()); + + Collection keys = keys(cmd); + + return keys.stream().map(k -> k.substring(this.region.length()+1)).collect(Collectors.toList()); } } + private Collection keys(RedisKeyCommands cmd) { + Collection keys = new ArrayList<>(); + String cursor = "0"; + Collection partKeys = null; + ScanCursor scanCursor = ScanCursor.INITIAL; + ScanArgs scanArgs = new ScanArgs(); + scanArgs.match(this.region + ":*").limit(scanCount); + KeyScanCursor keyScanCursor = null; + while (!scanCursor.isFinished()) { + keyScanCursor = cmd.scan(scanCursor, scanArgs); + partKeys = keyScanCursor.getKeys(); + if(partKeys != null && partKeys.size() != 0) { + keys.addAll(partKeys); + } + cursor = keyScanCursor.getCursor(); + if("0".equals(cursor)) { + scanCursor = ScanCursor.FINISHED; + } + else { + scanCursor = ScanCursor.of(cursor); + } + } + + return keys; + } + @Override public void evict(String... keys) { try(StatefulConnection connection = super.connect()) { @@ -145,7 +185,7 @@ public class LettuceGenericCache extends LettuceCache { public void clear() { try(StatefulConnection connection = super.connect()) { RedisKeyCommands cmd = (RedisKeyCommands)super.sync(connection); - List keys = cmd.keys(this.region + ":*"); + Collection keys = keys(cmd); if(keys != null && keys.size() > 0) cmd.del(keys.stream().toArray(String[]::new)); } diff --git a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java index eddf25d..aacfb81 100644 --- a/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java +++ b/core/src/net/oschina/j2cache/redis/RedisCacheProvider.java @@ -39,6 +39,7 @@ public class RedisCacheProvider implements CacheProvider { private RedisClient redisClient; private String namespace; private String storage; + private int scanCount; private final ConcurrentHashMap regions = new ConcurrentHashMap(); @@ -58,7 +59,7 @@ public class RedisCacheProvider implements CacheProvider { */ @Override public void start(Properties props) { - + this.scanCount = Integer.valueOf(props.getProperty("scanCount", "1000")); this.namespace = props.getProperty("namespace"); this.storage = props.getProperty("storage"); @@ -106,7 +107,7 @@ public class RedisCacheProvider implements CacheProvider { public Cache buildCache(String region, CacheExpiredListener listener) { return regions.computeIfAbsent(this.namespace+":"+region, v -> "hash".equalsIgnoreCase(this.storage)? new RedisHashCache(this.namespace, region, redisClient): - new RedisGenericCache(this.namespace, region, redisClient)); + new RedisGenericCache(this.namespace, region, redisClient, scanCount)); } @Override diff --git a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java index fc61bd6..4348e39 100644 --- a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java +++ b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java @@ -15,22 +15,26 @@ */ package net.oschina.j2cache.redis; -import net.oschina.j2cache.CacheException; -import net.oschina.j2cache.Level2Cache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import redis.clients.jedis.BinaryJedis; -import redis.clients.jedis.BinaryJedisCommands; -import redis.clients.jedis.MultiKeyBinaryCommands; -import redis.clients.jedis.MultiKeyCommands; - import java.io.UnsupportedEncodingException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.oschina.j2cache.CacheException; +import net.oschina.j2cache.Level2Cache; +import redis.clients.jedis.BinaryJedis; +import redis.clients.jedis.BinaryJedisCommands; +import redis.clients.jedis.MultiKeyBinaryCommands; +import redis.clients.jedis.MultiKeyCommands; +import redis.clients.jedis.ScanParams; +import redis.clients.jedis.ScanResult; + /** * Redis 缓存操作封装,基于 region+_key 实现多个 Region 的缓存( * @author Winter Lau(javayou@gmail.com) @@ -42,6 +46,7 @@ public class RedisGenericCache implements Level2Cache { private String namespace; private String region; private RedisClient client; + private int scanCount; /** * 缓存构造 @@ -49,13 +54,14 @@ public class RedisGenericCache implements Level2Cache { * @param region 缓存区域的名称 * @param client 缓存客户端接口 */ - public RedisGenericCache(String namespace, String region, RedisClient client) { + public RedisGenericCache(String namespace, String region, RedisClient client, int scanCount) { if (region == null || region.isEmpty()) region = "_"; // 缺省region this.client = client; this.namespace = namespace; this.region = _regionName(region); + this.scanCount = scanCount; } @Override @@ -190,14 +196,17 @@ public class RedisGenericCache implements Level2Cache { } /** - * 性能可能极其低下,谨慎使用 + * 1、线上redis服务大概率会禁用或重命名keys命令; + * 2、keys命令效率太低容易致使redis宕机; + * 所以使用scan命令替换keys命令操作,增加可用性及提升执行性能 */ @Override public Collection keys() { try { BinaryJedisCommands cmd = client.get(); if (cmd instanceof MultiKeyCommands) { - Collection keys = ((MultiKeyCommands) cmd).keys(this.region + ":*"); + Collection keys = keys(cmd); + return keys.stream().map(k -> k.substring(this.region.length()+1)).collect(Collectors.toList()); } } finally { @@ -206,6 +215,23 @@ public class RedisGenericCache implements Level2Cache { throw new CacheException("keys() not implemented in Redis Generic Mode"); } + private Collection keys(BinaryJedisCommands cmd) { + Collection keys = new ArrayList<>(); + String cursor = "0"; + ScanParams params = new ScanParams(); + params.match(this.region + ":*").count(scanCount); + Collection partKeys = null; + do { + ScanResult scanResult = ((MultiKeyCommands) cmd).scan(cursor, params); + partKeys = scanResult.getResult(); + if(partKeys != null ) { + keys.addAll(partKeys); + cursor = scanResult.getStringCursor(); + } + }while(partKeys != null && partKeys.size() != 0); + return keys; + } + @Override public void evict(String...keys) { try { @@ -224,14 +250,15 @@ public class RedisGenericCache implements Level2Cache { } /** - * 性能可能极其低下,谨慎使用 + * 已使用scan命令替换keys命令操作 */ @Override public void clear() { try { BinaryJedisCommands cmd = client.get(); if (cmd instanceof MultiKeyCommands) { - String[] keys = ((MultiKeyCommands) cmd).keys(this.region + ":*").stream().toArray(String[]::new); + Collection keysCollection = keys(cmd); + String[] keys = keysCollection.stream().toArray(String[]::new); if (keys != null && keys.length > 0) ((MultiKeyCommands) cmd).del(keys); } -- Gitee From 5c499457425a22beeb7798fff2ed0b1f7ce26ee0 Mon Sep 17 00:00:00 2001 From: yeefawn <6566869+yeefawn@user.noreply.gitee.com> Date: Wed, 22 Apr 2020 14:07:57 +0800 Subject: [PATCH 112/131] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9A=84=E6=93=8D=E4=BD=9C=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8redisTemplate..delete(region)=E4=BB=A3=E6=9B=BFredisTe?= =?UTF-8?q?mplate.opsForHash().delete(region)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oschina/j2cache/cache/support/redis/SpringRedisCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java index 312e19e..2538d00 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/redis/SpringRedisCache.java @@ -39,7 +39,7 @@ public class SpringRedisCache implements Level2Cache { @Override public void clear() { - redisTemplate.opsForHash().delete(region); + redisTemplate.delete(region); } @Override -- Gitee From 71b58e107c2a04a5e9f6f0092d61313d4ba8a826 Mon Sep 17 00:00:00 2001 From: "vasin.liu" Date: Sun, 26 Apr 2020 11:31:41 +0800 Subject: [PATCH 113/131] =?UTF-8?q?#2.8.1-release=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=9C=A8=E4=BD=BF=E7=94=A8redis-cluster=E6=97=B6redisClient?= =?UTF-8?q?=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AF=BC=E8=87=B4NPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index 9070d5f..ce5e4fa 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -120,7 +120,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp uri.setSentinelMasterId(sentinelMasterId); redisURIs.add(uri); } - RedisClusterClient.create(redisURIs); + redisClient = RedisClusterClient.create(redisURIs); } else { String[] redisArray = hosts.split(":"); -- Gitee From 2a103ac3ce8cb934228f00e2d9413bd98e5c5a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Sun, 26 Apr 2020 12:26:23 +0800 Subject: [PATCH 114/131] 2.8.2 --- CHANGES.md | 5 +++++ core/pom.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index fe9f7f5..b4913a3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # J2Cache 版本更新记录 +**j2cache-core 2.8.2 (2020-4-26)** + +1. 修复在使用redis-cluster时redisClient未初始化导致NPE +2. redis二级缓存的keys、clear方法使用scan命令实现(以应对云平台Redis服务对keys命令的限制) + **j2cache-core 2.8.1 (2020-4-16)** * 修复redis使用lettuce连接时,设置密码中出现特殊字符'@'时连接地址及密码解析出错的异常(感谢 [@eddy](https://gitee.com/xqxyxchy)) diff --git a/core/pom.xml b/core/pom.xml index dc97a3b..b52c949 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -8,7 +8,7 @@ 4.0.0 j2cache-core - 2.8.1-release + 2.8.2-release -- Gitee From 7838cabb19c44df88257561fc6f53b5d7ffbbb80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E8=96=AF?= Date: Sun, 26 Apr 2020 12:51:33 +0800 Subject: [PATCH 115/131] =?UTF-8?q?=E5=8D=87=E7=BA=A7=20amqp-client=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E8=80=81=E7=89=88=E6=9C=AC=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index b52c949..c872a56 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -99,7 +99,7 @@ com.rabbitmq amqp-client - 5.3.0 + 5.9.0 provided -- Gitee From e11fb3b54983a986cb7042effef6c4b2908f7c3f Mon Sep 17 00:00:00 2001 From: ysjsgzq <15320436211@163.com> Date: Thu, 7 May 2020 19:19:15 +0800 Subject: [PATCH 116/131] =?UTF-8?q?update=20core/src/net/oschina/j2cache/r?= =?UTF-8?q?edis/RedisGenericCache.java.=20=E4=BF=AE=E5=A4=8D=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=8E=B7=E5=8F=96redis=E4=B8=AD=E6=8C=87=E5=AE=9Aregi?= =?UTF-8?q?on=E4=B8=8B=E6=89=80=E6=9C=89key=E6=AD=BB=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/redis/RedisGenericCache.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java index 4348e39..3b32311 100644 --- a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java +++ b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java @@ -218,17 +218,19 @@ public class RedisGenericCache implements Level2Cache { private Collection keys(BinaryJedisCommands cmd) { Collection keys = new ArrayList<>(); String cursor = "0"; - ScanParams params = new ScanParams(); - params.match(this.region + ":*").count(scanCount); - Collection partKeys = null; - do { - ScanResult scanResult = ((MultiKeyCommands) cmd).scan(cursor, params); - partKeys = scanResult.getResult(); - if(partKeys != null ) { - keys.addAll(partKeys); - cursor = scanResult.getStringCursor(); - } - }while(partKeys != null && partKeys.size() != 0); + ScanParams scanParams = new ScanParams(); + scanParams.match(this.region + ":*"); + scanParams.count(scanCount); // 这个不是返回结果的数量,应该是每次scan的数量 + ScanResult scan = ((MultiKeyCommands) cmd).scan(cursor, scanParams); + while (null != scan.getStringCursor()) { + keys.addAll(scan.getResult()); // 这一次scan match到的结果 + if (!StringUtils.equals(cursor, scan.getStringCursor())) { // 不断拿着新的cursor scan,最终会拿到所有匹配的值 + scan = ((MultiKeyCommands) cmd).scan(scan.getStringCursor(), scanParams); + continue; + } else { + break; + } + } return keys; } -- Gitee From 5ea26f66c67e651f06ad3fabe40d89cad59fb8cc Mon Sep 17 00:00:00 2001 From: nuccch2010 Date: Sun, 24 May 2020 21:14:10 +0800 Subject: [PATCH 117/131] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=87=8A=E6=94=BERed?= =?UTF-8?q?is=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=97=B6=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E7=9A=84=E6=97=A0=E7=94=A8=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/redis/RedisClient.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/src/net/oschina/j2cache/redis/RedisClient.java b/core/src/net/oschina/j2cache/redis/RedisClient.java index 9968c4a..85054ba 100644 --- a/core/src/net/oschina/j2cache/redis/RedisClient.java +++ b/core/src/net/oschina/j2cache/redis/RedisClient.java @@ -198,9 +198,6 @@ public class RedisClient implements Closeable, AutoCloseable { log.error("Failed to release jedis connection.", e); } } - else - log.warn("Nothing to do while release redis client."); - clients.remove(); } } -- Gitee From 8b1aa8ad472e4e04fdc797610f4a9e2026e64e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E5=A4=A9=E4=BD=A0=E8=83=96=E4=BA=86=E5=90=97?= Date: Fri, 19 Jun 2020 09:54:26 +0800 Subject: [PATCH 118/131] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BC=8F=E6=8E=89?= =?UTF-8?q?=E7=9A=84StringUtils=E4=BE=9D=E8=B5=96=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/redis/RedisGenericCache.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java index 3b32311..c06663f 100644 --- a/core/src/net/oschina/j2cache/redis/RedisGenericCache.java +++ b/core/src/net/oschina/j2cache/redis/RedisGenericCache.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -205,8 +206,8 @@ public class RedisGenericCache implements Level2Cache { try { BinaryJedisCommands cmd = client.get(); if (cmd instanceof MultiKeyCommands) { - Collection keys = keys(cmd); - + Collection keys = keys(cmd); + return keys.stream().map(k -> k.substring(this.region.length()+1)).collect(Collectors.toList()); } } finally { @@ -215,10 +216,10 @@ public class RedisGenericCache implements Level2Cache { throw new CacheException("keys() not implemented in Redis Generic Mode"); } - private Collection keys(BinaryJedisCommands cmd) { - Collection keys = new ArrayList<>(); - String cursor = "0"; - ScanParams scanParams = new ScanParams(); + private Collection keys(BinaryJedisCommands cmd) { + Collection keys = new ArrayList<>(); + String cursor = "0"; + ScanParams scanParams = new ScanParams(); scanParams.match(this.region + ":*"); scanParams.count(scanCount); // 这个不是返回结果的数量,应该是每次scan的数量 ScanResult scan = ((MultiKeyCommands) cmd).scan(cursor, scanParams); @@ -231,8 +232,8 @@ public class RedisGenericCache implements Level2Cache { break; } } - return keys; - } + return keys; + } @Override public void evict(String...keys) { @@ -259,7 +260,7 @@ public class RedisGenericCache implements Level2Cache { try { BinaryJedisCommands cmd = client.get(); if (cmd instanceof MultiKeyCommands) { - Collection keysCollection = keys(cmd); + Collection keysCollection = keys(cmd); String[] keys = keysCollection.stream().toArray(String[]::new); if (keys != null && keys.length > 0) ((MultiKeyCommands) cmd).del(keys); @@ -270,4 +271,4 @@ public class RedisGenericCache implements Level2Cache { client.release(); } } -} +} \ No newline at end of file -- Gitee From 59711d72633775d0901b461aaa89f6fb4c818297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E5=90=8E?= <244387066@qq.com> Date: Fri, 19 Jun 2020 11:26:01 +0800 Subject: [PATCH 119/131] =?UTF-8?q?update=20README.md.=20=E6=9C=AC?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=BD=BF=E7=94=A8=E4=BA=86j2cache=EF=BC=8C?= =?UTF-8?q?=E5=B8=8C=E6=9C=9B=E8=83=BD=E5=8A=A0=E4=B8=AA=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 10027af..017339b 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,7 @@ channel.close(); * https://gitee.com/xcOschina/freeter-admin * https://gitee.com/thinkgem/jeesite4 * https://gitee.com/noear/weed3 +* https://gitee.com/zuihou111/zuihou-admin-cloud 更多项目收集中,如果你的项目用了,请告诉我 -- Gitee From 7db342dd4457634956bb7dfb8f398f19ed080e1a Mon Sep 17 00:00:00 2001 From: nuccch2010 Date: Wed, 8 Jul 2020 22:59:12 +0800 Subject: [PATCH 120/131] fix refresh redis cluster topology for lettuce client --- core/resources/j2cache.properties | 2 + .../j2cache/lettuce/LettuceCacheProvider.java | 38 +++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/resources/j2cache.properties b/core/resources/j2cache.properties index 0dc5aa0..dfc8d7a 100644 --- a/core/resources/j2cache.properties +++ b/core/resources/j2cache.properties @@ -173,6 +173,8 @@ lettuce.maxIdle = 10 lettuce.minIdle = 10 # timeout in milliseconds lettuce.timeout = 10000 +# redis cluster topology refresh interval in milliseconds +lettuce.clusterTopologyRefresh = 3000 ######################################### # memcached server configurations diff --git a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java index ce5e4fa..38a5008 100644 --- a/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java +++ b/core/src/net/oschina/j2cache/lettuce/LettuceCacheProvider.java @@ -15,36 +15,26 @@ */ package net.oschina.j2cache.lettuce; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.commons.pool2.impl.GenericObjectPool; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; - import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.cluster.ClusterClientOptions; +import io.lettuce.core.cluster.ClusterTopologyRefreshOptions; import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.pubsub.RedisPubSubAdapter; import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; import io.lettuce.core.support.ConnectionPoolSupport; -import net.oschina.j2cache.Cache; -import net.oschina.j2cache.CacheChannel; -import net.oschina.j2cache.CacheExpiredListener; -import net.oschina.j2cache.CacheObject; -import net.oschina.j2cache.CacheProvider; -import net.oschina.j2cache.CacheProviderHolder; -import net.oschina.j2cache.Command; -import net.oschina.j2cache.Level2Cache; +import net.oschina.j2cache.*; import net.oschina.j2cache.cluster.ClusterPolicy; +import org.apache.commons.pool2.impl.GenericObjectPool; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; + +import java.time.Duration; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; /** * 使用 Lettuce 进行 Redis 的操作 @@ -107,6 +97,7 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp String password = props.getProperty("password"); int database = Integer.parseInt(props.getProperty("database", "0")); String sentinelMasterId = props.getProperty("sentinelMasterId"); + long clusterTopologyRefreshMs = Long.valueOf(props.getProperty("clusterTopologyRefresh", "3000")); if("redis-cluster".equalsIgnoreCase(scheme)) { scheme = "redis"; @@ -121,6 +112,15 @@ public class LettuceCacheProvider extends RedisPubSubAdapter imp redisURIs.add(uri); } redisClient = RedisClusterClient.create(redisURIs); + ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions.builder() + //开启自适应刷新 + .enableAdaptiveRefreshTrigger(ClusterTopologyRefreshOptions.RefreshTrigger.MOVED_REDIRECT, ClusterTopologyRefreshOptions.RefreshTrigger.PERSISTENT_RECONNECTS) + .enableAllAdaptiveRefreshTriggers() + .adaptiveRefreshTriggersTimeout(Duration.ofMillis(clusterTopologyRefreshMs)) + //开启定时刷新,时间间隔根据实际情况修改 + .enablePeriodicRefresh(Duration.ofMillis(clusterTopologyRefreshMs)) + .build(); + ((RedisClusterClient)redisClient).setOptions(ClusterClientOptions.builder().topologyRefreshOptions(topologyRefreshOptions).build()); } else { String[] redisArray = hosts.split(":"); -- Gitee From 100b892e0ec57c3048f3ba1cbf0a2bd292e2dc7a Mon Sep 17 00:00:00 2001 From: nuccch2010 Date: Sat, 11 Jul 2020 12:17:16 +0800 Subject: [PATCH 121/131] fix log for caffine cache config not defined --- core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index 3f9d48e..abfd9e5 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -65,11 +65,10 @@ public class CaffeineProvider implements CacheProvider { return caches.computeIfAbsent(region, v -> { CacheConfig config = cacheConfigs.get(region); if (config == null) { + log.warn("Caffeine cache [{}] not defined, using default.", region); config = cacheConfigs.get(DEFAULT_REGION); if (config == null) throw new CacheException(String.format("Undefined [default] caffeine cache")); - - log.warn("Caffeine cache [{}] not defined, using default.", region); } return newCaffeineCache(region, config.size, config.expire, listener); }); -- Gitee From 63897e779248375a1e2e886677f3772e22331d18 Mon Sep 17 00:00:00 2001 From: liutao Date: Wed, 15 Jul 2020 15:47:43 +0800 Subject: [PATCH 122/131] =?UTF-8?q?docs:=20=E7=BC=93=E5=AD=98=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=97=B6=E9=97=B4=E8=AF=B4=E6=98=8E=E7=94=B1=E6=AF=AB?= =?UTF-8?q?=E7=A7=92=E6=94=B9=E4=B8=BA=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index abfd9e5..50afd2a 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -107,8 +107,8 @@ public class CaffeineProvider implements CacheProvider { * 返回对 Caffeine cache 的 封装 * @param region region name * @param size max cache object size in memory - * @param expire cache object expire time in millisecond - * if this parameter set to 0 or negative numbers + * @param expire cache object expire time in second + * if this parameter set to 0s or negative numbers * means never expire * @param listener j2cache cache listener * @return CaffeineCache -- Gitee From c17fe95515b331c805eaac95a78442893829044c Mon Sep 17 00:00:00 2001 From: nuccch2010 Date: Fri, 31 Jul 2020 20:47:11 +0800 Subject: [PATCH 123/131] fix publish for jedis cluster --- .../redis/RedisPubSubClusterPolicy.java | 101 ++++++++++++++---- 1 file changed, 83 insertions(+), 18 deletions(-) diff --git a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java index dc3b7d3..2a1d95e 100755 --- a/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java +++ b/core/src/net/oschina/j2cache/redis/RedisPubSubClusterPolicy.java @@ -16,14 +16,15 @@ package net.oschina.j2cache.redis; import net.oschina.j2cache.CacheProviderHolder; -import net.oschina.j2cache.cluster.ClusterPolicy; import net.oschina.j2cache.Command; +import net.oschina.j2cache.cluster.ClusterPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.*; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.util.Pool; +import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Properties; @@ -39,10 +40,15 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli private final static Logger log = LoggerFactory.getLogger(RedisPubSubClusterPolicy.class); private int LOCAL_COMMAND_ID = Command.genRandomSrc(); //命令源标识,随机生成,每个节点都有唯一标识 + private static int CONNECT_TIMEOUT = 5000; //Redis连接超时时间 + private static int SO_TIMEOUT = 5000; + private static int MAX_ATTEMPTS = 3; private Pool client; + private JedisCluster cluster; private String channel; private CacheProviderHolder holder; + private boolean clusterMode = false; public RedisPubSubClusterPolicy(String channel, Properties props){ this.channel = channel; @@ -60,13 +66,23 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli if(node == null || node.trim().length() == 0) node = props.getProperty("hosts"); - if("sentinel".equalsIgnoreCase(props.getProperty("mode"))){ + String mode = props.getProperty("mode"); + if ("sentinel".equalsIgnoreCase(mode)) { Set hosts = new HashSet(); hosts.addAll(Arrays.asList(node.split(","))); String masterName = props.getProperty("cluster_name", "j2cache"); this.client = new JedisSentinelPool(masterName, hosts, config, timeout, password, database); - } - else { + } else if ("cluster".equalsIgnoreCase(mode)) { + String[] nodeArray = node.split(","); + Set nodeSet = new HashSet(nodeArray.length); + for (String nodeItem : nodeArray) { + String[] arr = nodeItem.split(":"); + nodeSet.add(new HostAndPort(arr[0], Integer.valueOf(arr[1]))); + } + JedisPoolConfig poolConfig = RedisUtils.newPoolConfig(props, null); + this.cluster = new JedisCluster(nodeSet, CONNECT_TIMEOUT, SO_TIMEOUT, MAX_ATTEMPTS, password, poolConfig); + this.clusterMode = true; + } else { node = node.split(",")[0]; //取第一台主机 String[] infos = node.split(":"); String host = infos[0]; @@ -110,19 +126,39 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli this.publish(Command.join()); Thread subscribeThread = new Thread(()-> { - //当 Redis 重启会导致订阅线程断开连接,需要进行重连 - while(!client.isClosed()) { - try (Jedis jedis = client.getResource()){ - jedis.subscribe(this, channel); - log.info("Disconnect to redis channel: {}", channel); - break; - } catch (JedisConnectionException e) { - log.error("Failed connect to redis, reconnect it.", e); - if(!client.isClosed()) + if (clusterMode) { + // 如果出现集群节点宕机,需要重连 + while (cluster != null) { try { - Thread.sleep(1000); - } catch (InterruptedException ie){ + this.cluster.subscribe(this, channel); + break; + } catch (Exception e) { + log.error("failed connect redis cluster, reconnect it.", e); + e.printStackTrace(); + if (cluster != null) { + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { + break; + } + } + } + } + } else { + //当 Redis 重启会导致订阅线程断开连接,需要进行重连 + while(!client.isClosed()) { + try (Jedis jedis = client.getResource()){ + jedis.subscribe(this, channel); + log.info("Disconnect to redis channel: {}", channel); break; + } catch (JedisConnectionException e) { + log.error("Failed connect to redis, reconnect it.", e); + if(!client.isClosed()) + try { + Thread.sleep(1000); + } catch (InterruptedException ie){ + break; + } } } } @@ -144,7 +180,8 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli if(this.isSubscribed()) this.unsubscribe(); } finally { - this.client.close(); + close(); + //this.client.close(); //subscribeThread will auto terminate } } @@ -152,8 +189,12 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli @Override public void publish(Command cmd) { cmd.setSrc(LOCAL_COMMAND_ID); - try (Jedis jedis = client.getResource()) { - jedis.publish(channel, cmd.json()); + if (this.clusterMode) { + this.cluster.publish(channel, cmd.json()); + } else { + try (Jedis jedis = client.getResource()) { + jedis.publish(channel, cmd.json()); + } } } @@ -168,4 +209,28 @@ public class RedisPubSubClusterPolicy extends JedisPubSub implements ClusterPoli handleCommand(cmd); } + @Override + public void unsubscribe() { + if (!this.clusterMode) { + super.unsubscribe(); + } + } + + private void close() { + try { + if (this.client != null) { + this.client.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + try { + if (this.cluster != null) { + this.cluster.close(); + } + this.cluster = null; + } catch (IOException e) { + e.printStackTrace(); + } + } } -- Gitee From e9508059f255da7208390514b02958fe045a3e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=97=E6=9D=91?= <2853879293@qq.com> Date: Fri, 21 Aug 2020 10:31:27 +0800 Subject: [PATCH 124/131] =?UTF-8?q?=E6=94=AF=E6=8C=81SpringCache=E4=B8=AD@?= =?UTF-8?q?Cacheable=E6=B3=A8=E8=A7=A3=E7=9A=84sync=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E7=BC=93=E5=AD=98=E5=A4=B1=E6=95=88=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E8=B5=B7=E7=9A=84=E5=B9=B6=E5=8F=91=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=9C=89=E4=B8=80=E4=B8=AA=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=A9=BF=E9=80=8F=E5=88=B0=E5=90=8E=E7=AB=AF=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=EF=BC=8C=E5=85=B6=E4=BD=99=E7=BA=BF=E7=A8=8B=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E6=9F=A5=E8=AF=A2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/oschina/j2cache/cache/support/J2CacheCache.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java index 3201694..46c6ff5 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java @@ -46,7 +46,12 @@ public class J2CacheCache extends AbstractValueAdaptingCache { } @Override - public T get(Object key, Callable valueLoader) { + public synchronized T get(Object key, Callable valueLoader) { + ValueWrapper valueWrapper = this.get(key); + if(valueWrapper != null) { + return (T) valueWrapper.get(); + } + T value; try { value = valueLoader.call(); -- Gitee From 749b84d4fe5782d38e8e14a6a2066da14cb05a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=97=E6=9D=91?= <2853879293@qq.com> Date: Fri, 21 Aug 2020 10:34:12 +0800 Subject: [PATCH 125/131] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/oschina/j2cache/cache/support/J2CacheCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java index 46c6ff5..b839789 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java @@ -48,7 +48,7 @@ public class J2CacheCache extends AbstractValueAdaptingCache { @Override public synchronized T get(Object key, Callable valueLoader) { ValueWrapper valueWrapper = this.get(key); - if(valueWrapper != null) { + if (valueWrapper != null) { return (T) valueWrapper.get(); } -- Gitee From 24ebda7307c2d8fbb431cb136dcbeac2014fff86 Mon Sep 17 00:00:00 2001 From: qixiaobo Date: Thu, 17 Sep 2020 14:17:31 +0800 Subject: [PATCH 126/131] https://gitee.com/ld/J2Cache/issues/I1VJUW fix if more than one instances init at the same time. We use secureRandom insteadof random --- core/src/net/oschina/j2cache/Command.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/net/oschina/j2cache/Command.java b/core/src/net/oschina/j2cache/Command.java index ffb214f..55f57d5 100644 --- a/core/src/net/oschina/j2cache/Command.java +++ b/core/src/net/oschina/j2cache/Command.java @@ -15,7 +15,7 @@ */ package net.oschina.j2cache; -import java.util.Random; +import java.security.SecureRandom; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONException; @@ -40,11 +40,11 @@ public class Command { private int operator; private String region; private String[] keys; - - public final static int genRandomSrc() { + + public static int genRandomSrc() { long ct = System.currentTimeMillis(); - Random rnd_seed = new Random(ct); - return (int)(rnd_seed.nextInt(10000) * 1000 + ct % 1000); + SecureRandom rndSeed = new SecureRandom(); + return (int) (rndSeed.nextInt(10000) * 1000 + ct % 1000); } public Command(){}//just for json deserialize , dont remove it. -- Gitee From b80348427425628d8dca9b60cf69af01a5005982 Mon Sep 17 00:00:00 2001 From: Winter Lau Date: Tue, 6 Oct 2020 21:03:56 +0800 Subject: [PATCH 127/131] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A3=80=E6=9F=A5=E6=96=B9=E6=B3=95,?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=20putAll=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/oschina/j2cache/CacheChannel.java | 107 ++++++++---------- 1 file changed, 48 insertions(+), 59 deletions(-) diff --git a/core/src/net/oschina/j2cache/CacheChannel.java b/core/src/net/oschina/j2cache/CacheChannel.java index f99fc19..1c676ee 100644 --- a/core/src/net/oschina/j2cache/CacheChannel.java +++ b/core/src/net/oschina/j2cache/CacheChannel.java @@ -45,6 +45,11 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { return new NullObject(); } + private void assertNotClose() { + if(closed) + throw new IllegalStateException("CacheChannel closed"); + } + /** *

Just for Inner Use.

* @@ -73,8 +78,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public CacheObject get(String region, String key, boolean...cacheNullObject) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); CacheObject obj = new CacheObject(region, key, CacheObject.LEVEL_1); obj.setValue(holder.getLevel1Cache(region).get(key)); @@ -115,8 +119,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public CacheObject get(String region, String key, Function loader, boolean...cacheNullObject) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); CacheObject cache = get(region, key, false); @@ -150,8 +153,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public Map get(String region, Collection keys) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); final Map objs = holder.getLevel1Cache(region).get(keys); List level2Keys = keys.stream().filter(k -> !objs.containsKey(k) || objs.get(k) == null).collect(Collectors.toList()); @@ -182,8 +184,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public Map get(String region, Collection keys, Function loader, boolean...cacheNullObject) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); Map results = get(region, keys); results.entrySet().stream().filter(e -> e.getValue().rawValue() == null).forEach( e -> { @@ -226,8 +227,8 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return 0(不存在),1(一级),2(二级) */ public int check(String region, String key) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + + this.assertNotClose(); if(holder.getLevel1Cache(region).exists(key)) return 1; @@ -257,12 +258,11 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public void set(String region, String key, Object value, boolean cacheNullObject) { + this.assertNotClose(); + if (!cacheNullObject && value == null) return ; - if(closed) - throw new IllegalStateException("CacheChannel closed"); - try { Level1Cache level1 = holder.getLevel1Cache(region); level1.put(key, (value==null && cacheNullObject)?newNullObject():value); @@ -304,8 +304,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public void set(String region, String key, Object value, long timeToLiveInSeconds, boolean cacheNullObject) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); if (!cacheNullObject && value == null) return ; @@ -343,13 +342,11 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public void set(String region, Map elements, boolean cacheNullObject) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); try { if (cacheNullObject && elements.containsValue(null)) { - Map newElems = new HashMap<>(); - newElems.putAll(elements); + Map newElems = new HashMap<>(elements); newElems.forEach((k,v) -> { if (v == null) newElems.put(k, newNullObject()); @@ -401,37 +398,36 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public void set(String region, Map elements, long timeToLiveInSeconds, boolean cacheNullObject) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); - if(timeToLiveInSeconds <= 0) + if(timeToLiveInSeconds <= 0) { set(region, elements, cacheNullObject); - else { - try { - if (cacheNullObject && elements.containsValue(null)) { - Map newElems = new HashMap<>(); - newElems.putAll(elements); - newElems.forEach((k,v) -> { - if (v == null) - newElems.put(k, newNullObject()); - }); - holder.getLevel1Cache(region, timeToLiveInSeconds).put(newElems); - if(config.isSyncTtlToRedis()) - holder.getLevel2Cache(region).put(newElems, timeToLiveInSeconds); - else - holder.getLevel2Cache(region).put(newElems); - } - else { - holder.getLevel1Cache(region, timeToLiveInSeconds).put(elements); - if(config.isSyncTtlToRedis()) - holder.getLevel2Cache(region).put(elements, timeToLiveInSeconds); - else - holder.getLevel2Cache(region).put(elements); - } - } finally { - //广播 - this.sendEvictCmd(region, elements.keySet().stream().toArray(String[]::new)); + return; + } + + try { + if (cacheNullObject && elements.containsValue(null)) { + Map newElems = new HashMap<>(elements); + newElems.forEach((k,v) -> { + if (v == null) + newElems.put(k, newNullObject()); + }); + holder.getLevel1Cache(region, timeToLiveInSeconds).put(newElems); + if(config.isSyncTtlToRedis()) + holder.getLevel2Cache(region).put(newElems, timeToLiveInSeconds); + else + holder.getLevel2Cache(region).put(newElems); + } + else { + holder.getLevel1Cache(region, timeToLiveInSeconds).put(elements); + if(config.isSyncTtlToRedis()) + holder.getLevel2Cache(region).put(elements, timeToLiveInSeconds); + else + holder.getLevel2Cache(region).put(elements); } + } finally { + //广播 + this.sendEvictCmd(region, elements.keySet().stream().toArray(String[]::new)); } } @@ -443,8 +439,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public void evict(String region, String...keys) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); try { //先清比较耗时的二级缓存,再清一级缓存 @@ -462,8 +457,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { */ public void clear(String region) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); try { //先清比较耗时的二级缓存,再清一级缓存 @@ -479,9 +473,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return all the regions */ public Collection regions() { - if(closed) - throw new IllegalStateException("CacheChannel closed"); - + this.assertNotClose(); return holder.regions(); } @@ -490,9 +482,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @param region Cache Region Name */ public void removeRegion(String region) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); - + this.assertNotClose(); holder.getL1Provider().removeCache(region); } @@ -504,8 +494,7 @@ public abstract class CacheChannel implements Closeable , AutoCloseable { * @return key list */ public Collection keys(String region) { - if(closed) - throw new IllegalStateException("CacheChannel closed"); + this.assertNotClose(); Set keys = new HashSet<>(); keys.addAll(holder.getLevel1Cache(region).keys()); -- Gitee From b7ac28d3cb6084a9974ed1f803dcafa084d873fd Mon Sep 17 00:00:00 2001 From: caiqyxyx Date: Tue, 24 Nov 2020 23:30:40 +0800 Subject: [PATCH 128/131] fix typo --- .../src/net/oschina/j2cache/cache/support/J2CacheCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java index b839789..1d58ff9 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/J2CacheCache.java @@ -36,7 +36,7 @@ public class J2CacheCache extends AbstractValueAdaptingCache { return this.j2CacheName; } - public void setJ2CacheNmae(String name) { + public void setJ2CacheName(String name) { this.j2CacheName = name; } -- Gitee From d2534c426dc4c529e5a6a3d31b36831993dc0e35 Mon Sep 17 00:00:00 2001 From: wangxk <2674518127@qq.com> Date: Thu, 3 Dec 2020 14:04:32 +0800 Subject: [PATCH 129/131] fix: lettuce Connection reset by peer --- .../autoconfigure/J2CacheSpringRedisAutoConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java index 8a09f5d..9afd767 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/autoconfigure/J2CacheSpringRedisAutoConfiguration.java @@ -46,7 +46,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException; /** * 对spring redis支持的配置入口 - * + * * @author zhangsaizz * */ @@ -208,6 +208,7 @@ public class J2CacheSpringRedisAutoConfiguration { log.warn("Redis mode [" + mode + "] not defined. Using 'single'."); break; } + connectionFactory.setValidateConnection(true); return connectionFactory; } -- Gitee From 1218b39145d2b1228a92077977c367a06164b64e Mon Sep 17 00:00:00 2001 From: chenhuaguang Date: Fri, 15 Jan 2021 14:30:53 +0800 Subject: [PATCH 130/131] =?UTF-8?q?Caffeine=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A8=A1=E7=B3=8A=E5=8C=B9=E9=85=8D=EF=BC=8C?= =?UTF-8?q?=E6=AF=94=E5=A6=82key=5F*=E5=8C=B9=E9=85=8Dkey=5F001,key=5F002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../j2cache/caffeine/CaffeineProvider.java | 17 +- .../oschina/j2cache/util/AntPathMatcher.java | 408 ++++++++++++++++++ .../oschina/j2cache/util/PatternMatcher.java | 24 ++ .../net/oschina/j2cache/util/StringUtils.java | 297 +++++++++++++ .../oschina/j2cache/PatternMatcherTest.java | 14 + 5 files changed, 758 insertions(+), 2 deletions(-) create mode 100644 core/src/net/oschina/j2cache/util/AntPathMatcher.java create mode 100644 core/src/net/oschina/j2cache/util/PatternMatcher.java create mode 100644 core/src/net/oschina/j2cache/util/StringUtils.java create mode 100644 core/test/net/oschina/j2cache/PatternMatcherTest.java diff --git a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java index 50afd2a..f187de8 100644 --- a/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java +++ b/core/src/net/oschina/j2cache/caffeine/CaffeineProvider.java @@ -18,6 +18,8 @@ package net.oschina.j2cache.caffeine; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.RemovalCause; import net.oschina.j2cache.*; +import net.oschina.j2cache.util.AntPathMatcher; +import net.oschina.j2cache.util.PatternMatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,6 +27,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Collection; import java.util.ArrayList; +import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -42,6 +45,7 @@ public class CaffeineProvider implements CacheProvider { private final static String DEFAULT_REGION = "default"; private ConcurrentHashMap caches = new ConcurrentHashMap<>(); private ConcurrentHashMap cacheConfigs = new ConcurrentHashMap<>(); + private PatternMatcher patternMatcher = new AntPathMatcher(); @Override public String name() { @@ -63,7 +67,7 @@ public class CaffeineProvider implements CacheProvider { @Override public Cache buildCache(String region, CacheExpiredListener listener) { return caches.computeIfAbsent(region, v -> { - CacheConfig config = cacheConfigs.get(region); + CacheConfig config = findCacheConfig(region); if (config == null) { log.warn("Caffeine cache [{}] not defined, using default.", region); config = cacheConfigs.get(DEFAULT_REGION); @@ -77,7 +81,7 @@ public class CaffeineProvider implements CacheProvider { @Override public Cache buildCache(String region, long timeToLiveInSeconds, CacheExpiredListener listener) { CaffeineCache cache = caches.computeIfAbsent(region, v -> { - CacheConfig config = cacheConfigs.get(region); + CacheConfig config = findCacheConfig(region); if(config != null && config.expire != timeToLiveInSeconds) throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d", region, config.expire, timeToLiveInSeconds)); @@ -178,6 +182,15 @@ public class CaffeineProvider implements CacheProvider { } } + private CacheConfig findCacheConfig(String region){ + for (Map.Entry entry : cacheConfigs.entrySet()) { + if(patternMatcher.matches(entry.getKey(),region)){ + return entry.getValue(); + } + } + return null; + } + private void saveCacheConfig(String region, String region_config) { CacheConfig cfg = CacheConfig.parse(region_config); if(cfg == null) diff --git a/core/src/net/oschina/j2cache/util/AntPathMatcher.java b/core/src/net/oschina/j2cache/util/AntPathMatcher.java new file mode 100644 index 0000000..21a72ff --- /dev/null +++ b/core/src/net/oschina/j2cache/util/AntPathMatcher.java @@ -0,0 +1,408 @@ +package net.oschina.j2cache.util; + +/** + *

PathMatcher implementation for Ant-style path patterns. + * Examples are provided below.

+ * + *

Part of this mapping code has been kindly borrowed from + * Apache Ant. + * + *

The mapping matches URLs using the following rules:
+ *

    + *
  • ? matches one character
  • + *
  • * matches zero or more characters
  • + *
  • ** matches zero or more 'directories' in a path
  • + *
+ * + *

Some examples:
+ *

    + *
  • com/t?st.jsp - matches com/test.jsp but also + * com/tast.jsp or com/txst.jsp
  • + *
  • com/*.jsp - matches all .jsp files in the + * com directory
  • + *
  • com/**/test.jsp - matches all test.jsp + * files underneath the com path
  • + *
  • org/apache/shiro/**/*.jsp - matches all .jsp + * files underneath the org/apache/shiro path
  • + *
  • org/**/servlet/bla.jsp - matches + * org/apache/shiro/servlet/bla.jsp but also + * org/apache/shiro/testing/servlet/bla.jsp and + * org/servlet/bla.jsp
  • + *
+ * + *

N.B.: This class was borrowed (with much appreciation) from the + * Spring Framework with modifications. We didn't want to reinvent the + * wheel of great work they've done, but also didn't want to force every Shiro user to depend on Spring

+ * + *

As per the Apache 2.0 license, the original copyright notice and all author and copyright information have + * remained in tact.

+ * + * @since 16.07.2003 + */ +public class AntPathMatcher implements PatternMatcher { + + //TODO - complete JavaDoc + + /** + * Default path separator: "/" + */ + public static final String DEFAULT_PATH_SEPARATOR = "/"; + + private String pathSeparator = DEFAULT_PATH_SEPARATOR; + + + /** + * Set the path separator to use for pattern parsing. + * Default is "/", as in Ant. + */ + public void setPathSeparator(String pathSeparator) { + this.pathSeparator = (pathSeparator != null ? pathSeparator : DEFAULT_PATH_SEPARATOR); + } + + + public boolean isPattern(String path) { + return (path.indexOf('*') != -1 || path.indexOf('?') != -1); + } + + public boolean matches(String pattern, String source) { + return match(pattern, source); + } + + public boolean match(String pattern, String path) { + return doMatch(pattern, path, true); + } + + public boolean matchStart(String pattern, String path) { + return doMatch(pattern, path, false); + } + + + /** + * Actually match the given path against the given pattern. + * + * @param pattern the pattern to match against + * @param path the path String to test + * @param fullMatch whether a full pattern match is required + * (else a pattern match as far as the given base path goes is sufficient) + * @return true if the supplied path matched, + * false if it didn't + */ + protected boolean doMatch(String pattern, String path, boolean fullMatch) { + if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) { + return false; + } + + String[] pattDirs = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator); + String[] pathDirs = StringUtils.tokenizeToStringArray(path, this.pathSeparator); + + int pattIdxStart = 0; + int pattIdxEnd = pattDirs.length - 1; + int pathIdxStart = 0; + int pathIdxEnd = pathDirs.length - 1; + + // Match all elements up to the first ** + while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) { + String patDir = pattDirs[pattIdxStart]; + if ("**".equals(patDir)) { + break; + } + if (!matchStrings(patDir, pathDirs[pathIdxStart])) { + return false; + } + pattIdxStart++; + pathIdxStart++; + } + + if (pathIdxStart > pathIdxEnd) { + // Path is exhausted, only match if rest of pattern is * or **'s + if (pattIdxStart > pattIdxEnd) { + return (pattern.endsWith(this.pathSeparator) ? + path.endsWith(this.pathSeparator) : !path.endsWith(this.pathSeparator)); + } + if (!fullMatch) { + return true; + } + if (pattIdxStart == pattIdxEnd && pattDirs[pattIdxStart].equals("*") && + path.endsWith(this.pathSeparator)) { + return true; + } + for (int i = pattIdxStart; i <= pattIdxEnd; i++) { + if (!pattDirs[i].equals("**")) { + return false; + } + } + return true; + } else if (pattIdxStart > pattIdxEnd) { + // String not exhausted, but pattern is. Failure. + return false; + } else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) { + // Path start definitely matches due to "**" part in pattern. + return true; + } + + // up to last '**' + while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) { + String patDir = pattDirs[pattIdxEnd]; + if (patDir.equals("**")) { + break; + } + if (!matchStrings(patDir, pathDirs[pathIdxEnd])) { + return false; + } + pattIdxEnd--; + pathIdxEnd--; + } + if (pathIdxStart > pathIdxEnd) { + // String is exhausted + for (int i = pattIdxStart; i <= pattIdxEnd; i++) { + if (!pattDirs[i].equals("**")) { + return false; + } + } + return true; + } + + while (pattIdxStart != pattIdxEnd && pathIdxStart <= pathIdxEnd) { + int patIdxTmp = -1; + for (int i = pattIdxStart + 1; i <= pattIdxEnd; i++) { + if (pattDirs[i].equals("**")) { + patIdxTmp = i; + break; + } + } + if (patIdxTmp == pattIdxStart + 1) { + // '**/**' situation, so skip one + pattIdxStart++; + continue; + } + // Find the pattern between padIdxStart & padIdxTmp in str between + // strIdxStart & strIdxEnd + int patLength = (patIdxTmp - pattIdxStart - 1); + int strLength = (pathIdxEnd - pathIdxStart + 1); + int foundIdx = -1; + + strLoop: + for (int i = 0; i <= strLength - patLength; i++) { + for (int j = 0; j < patLength; j++) { + String subPat = (String) pattDirs[pattIdxStart + j + 1]; + String subStr = (String) pathDirs[pathIdxStart + i + j]; + if (!matchStrings(subPat, subStr)) { + continue strLoop; + } + } + foundIdx = pathIdxStart + i; + break; + } + + if (foundIdx == -1) { + return false; + } + + pattIdxStart = patIdxTmp; + pathIdxStart = foundIdx + patLength; + } + + for (int i = pattIdxStart; i <= pattIdxEnd; i++) { + if (!pattDirs[i].equals("**")) { + return false; + } + } + + return true; + } + + /** + * Tests whether or not a string matches against a pattern. + * The pattern may contain two special characters:
+ * '*' means zero or more characters
+ * '?' means one and only one character + * + * @param pattern pattern to match against. + * Must not be null. + * @param str string which must be matched against the pattern. + * Must not be null. + * @return true if the string matches against the + * pattern, or false otherwise. + */ + private boolean matchStrings(String pattern, String str) { + char[] patArr = pattern.toCharArray(); + char[] strArr = str.toCharArray(); + int patIdxStart = 0; + int patIdxEnd = patArr.length - 1; + int strIdxStart = 0; + int strIdxEnd = strArr.length - 1; + char ch; + + boolean containsStar = false; + for (char aPatArr : patArr) { + if (aPatArr == '*') { + containsStar = true; + break; + } + } + + if (!containsStar) { + // No '*'s, so we make a shortcut + if (patIdxEnd != strIdxEnd) { + return false; // Pattern and string do not have the same size + } + for (int i = 0; i <= patIdxEnd; i++) { + ch = patArr[i]; + if (ch != '?') { + if (ch != strArr[i]) { + return false;// Character mismatch + } + } + } + return true; // String matches against pattern + } + + + if (patIdxEnd == 0) { + return true; // Pattern contains only '*', which matches anything + } + + // Process characters before first star + while ((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) { + if (ch != '?') { + if (ch != strArr[strIdxStart]) { + return false;// Character mismatch + } + } + patIdxStart++; + strIdxStart++; + } + if (strIdxStart > strIdxEnd) { + // All characters in the string are used. Check if only '*'s are + // left in the pattern. If so, we succeeded. Otherwise failure. + for (int i = patIdxStart; i <= patIdxEnd; i++) { + if (patArr[i] != '*') { + return false; + } + } + return true; + } + + // Process characters after last star + while ((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) { + if (ch != '?') { + if (ch != strArr[strIdxEnd]) { + return false;// Character mismatch + } + } + patIdxEnd--; + strIdxEnd--; + } + if (strIdxStart > strIdxEnd) { + // All characters in the string are used. Check if only '*'s are + // left in the pattern. If so, we succeeded. Otherwise failure. + for (int i = patIdxStart; i <= patIdxEnd; i++) { + if (patArr[i] != '*') { + return false; + } + } + return true; + } + + // process pattern between stars. padIdxStart and patIdxEnd point + // always to a '*'. + while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { + int patIdxTmp = -1; + for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { + if (patArr[i] == '*') { + patIdxTmp = i; + break; + } + } + if (patIdxTmp == patIdxStart + 1) { + // Two stars next to each other, skip the first one. + patIdxStart++; + continue; + } + // Find the pattern between padIdxStart & padIdxTmp in str between + // strIdxStart & strIdxEnd + int patLength = (patIdxTmp - patIdxStart - 1); + int strLength = (strIdxEnd - strIdxStart + 1); + int foundIdx = -1; + strLoop: + for (int i = 0; i <= strLength - patLength; i++) { + for (int j = 0; j < patLength; j++) { + ch = patArr[patIdxStart + j + 1]; + if (ch != '?') { + if (ch != strArr[strIdxStart + i + j]) { + continue strLoop; + } + } + } + + foundIdx = strIdxStart + i; + break; + } + + if (foundIdx == -1) { + return false; + } + + patIdxStart = patIdxTmp; + strIdxStart = foundIdx + patLength; + } + + // All characters in the string are used. Check if only '*'s are left + // in the pattern. If so, we succeeded. Otherwise failure. + for (int i = patIdxStart; i <= patIdxEnd; i++) { + if (patArr[i] != '*') { + return false; + } + } + + return true; + } + + /** + * Given a pattern and a full path, determine the pattern-mapped part. + *

For example: + *

    + *
  • '/docs/cvs/commit.html' and '/docs/cvs/commit.html -> ''
  • + *
  • '/docs/*' and '/docs/cvs/commit -> 'cvs/commit'
  • + *
  • '/docs/cvs/*.html' and '/docs/cvs/commit.html -> 'commit.html'
  • + *
  • '/docs/**' and '/docs/cvs/commit -> 'cvs/commit'
  • + *
  • '/docs/**\/*.html' and '/docs/cvs/commit.html -> 'cvs/commit.html'
  • + *
  • '/*.html' and '/docs/cvs/commit.html -> 'docs/cvs/commit.html'
  • + *
  • '*.html' and '/docs/cvs/commit.html -> '/docs/cvs/commit.html'
  • + *
  • '*' and '/docs/cvs/commit.html -> '/docs/cvs/commit.html'
  • + *
+ *

Assumes that {@link #match} returns true for 'pattern' + * and 'path', but does not enforce this. + */ + public String extractPathWithinPattern(String pattern, String path) { + String[] patternParts = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator); + String[] pathParts = StringUtils.tokenizeToStringArray(path, this.pathSeparator); + + StringBuilder buffer = new StringBuilder(); + + // Add any path parts that have a wildcarded pattern part. + int puts = 0; + for (int i = 0; i < patternParts.length; i++) { + String patternPart = patternParts[i]; + if ((patternPart.indexOf('*') > -1 || patternPart.indexOf('?') > -1) && pathParts.length >= i + 1) { + if (puts > 0 || (i == 0 && !pattern.startsWith(this.pathSeparator))) { + buffer.append(this.pathSeparator); + } + buffer.append(pathParts[i]); + puts++; + } + } + + // Append any trailing path parts. + for (int i = patternParts.length; i < pathParts.length; i++) { + if (puts > 0 || i > 0) { + buffer.append(this.pathSeparator); + } + buffer.append(pathParts[i]); + } + + return buffer.toString(); + } + +} + diff --git a/core/src/net/oschina/j2cache/util/PatternMatcher.java b/core/src/net/oschina/j2cache/util/PatternMatcher.java new file mode 100644 index 0000000..303ff73 --- /dev/null +++ b/core/src/net/oschina/j2cache/util/PatternMatcher.java @@ -0,0 +1,24 @@ +package net.oschina.j2cache.util; + +/** + * Interface for components that can match source strings against a specified pattern string. + *

+ * Different implementations can support different pattern types, for example, Ant style path expressions, or + * regular expressions, or other types of text based patterns. + * + * @see org.apache.shiro.util.AntPathMatcher AntPathMatcher + * @since 0.9 RC2 + */ +public interface PatternMatcher { + + /** + * Returns true if the given source matches the specified pattern, + * false otherwise. + * + * @param pattern the pattern to match against + * @param source the source to match + * @return true if the given source matches the specified pattern, + * false otherwise. + */ + boolean matches(String pattern, String source); +} diff --git a/core/src/net/oschina/j2cache/util/StringUtils.java b/core/src/net/oschina/j2cache/util/StringUtils.java new file mode 100644 index 0000000..fa3d4fc --- /dev/null +++ b/core/src/net/oschina/j2cache/util/StringUtils.java @@ -0,0 +1,297 @@ +package net.oschina.j2cache.util; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; + +public class StringUtils { + public static final String EMPTY_STRING = ""; + public static final char DEFAULT_DELIMITER_CHAR = ','; + public static final char DEFAULT_QUOTE_CHAR = '"'; + + public StringUtils() { + } + + public static boolean hasText(String str) { + if (!hasLength(str)) { + return false; + } else { + int strLen = str.length(); + + for(int i = 0; i < strLen; ++i) { + if (!Character.isWhitespace(str.charAt(i))) { + return true; + } + } + + return false; + } + } + + public static boolean hasLength(String str) { + return str != null && str.length() > 0; + } + + public static boolean startsWithIgnoreCase(String str, String prefix) { + if (str != null && prefix != null) { + if (str.startsWith(prefix)) { + return true; + } else if (str.length() < prefix.length()) { + return false; + } else { + String lcStr = str.substring(0, prefix.length()).toLowerCase(); + String lcPrefix = prefix.toLowerCase(); + return lcStr.equals(lcPrefix); + } + } else { + return false; + } + } + + public static String clean(String in) { + String out = in; + if (in != null) { + out = in.trim(); + if (out.equals("")) { + out = null; + } + } + + return out; + } + + public static String toString(Object[] array) { + return toDelimitedString(array, ","); + } + + public static String toDelimitedString(Object[] array, String delimiter) { + if (array != null && array.length != 0) { + StringBuilder sb = new StringBuilder(); + + for(int i = 0; i < array.length; ++i) { + if (i > 0) { + sb.append(delimiter); + } + + sb.append(array[i]); + } + + return sb.toString(); + } else { + return ""; + } + } + + public static String toDelimitedString(Collection c, String delimiter) { + return c != null && !c.isEmpty() ? join(c.iterator(), delimiter) : ""; + } + + public static String[] tokenizeToStringArray(String str, String delimiters) { + return tokenizeToStringArray(str, delimiters, true, true); + } + + public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) { + if (str == null) { + return null; + } else { + StringTokenizer st = new StringTokenizer(str, delimiters); + ArrayList tokens = new ArrayList(); + + while(true) { + String token; + do { + if (!st.hasMoreTokens()) { + return toStringArray(tokens); + } + + token = st.nextToken(); + if (trimTokens) { + token = token.trim(); + } + } while(ignoreEmptyTokens && token.length() <= 0); + + tokens.add(token); + } + } + } + + public static String[] toStringArray(Collection collection) { + return collection == null ? null : (String[])collection.toArray(new String[collection.size()]); + } + + public static String[] splitKeyValue(String aLine) throws ParseException { + String line = clean(aLine); + if (line == null) { + return null; + } else { + String[] split = line.split(" ", 2); + String msg; + if (split.length != 2) { + split = line.split("=", 2); + if (split.length != 2) { + msg = "Unable to determine Key/Value pair from line [" + line + "]. There is no space from which the split location could be determined."; + throw new ParseException(msg, 0); + } + } + + split[0] = clean(split[0]); + split[1] = clean(split[1]); + if (split[1].startsWith("=")) { + split[1] = clean(split[1].substring(1)); + } + + if (split[0] == null) { + msg = "No valid key could be found in line [" + line + "] to form a key/value pair."; + throw new ParseException(msg, 0); + } else if (split[1] == null) { + msg = "No corresponding value could be found in line [" + line + "] for key [" + split[0] + "]"; + throw new ParseException(msg, 0); + } else { + return split; + } + } + } + + public static String[] split(String line) { + return split(line, ','); + } + + public static String[] split(String line, char delimiter) { + return split(line, delimiter, '"'); + } + + public static String[] split(String line, char delimiter, char quoteChar) { + return split(line, delimiter, quoteChar, quoteChar); + } + + public static String[] split(String line, char delimiter, char beginQuoteChar, char endQuoteChar) { + return split(line, delimiter, beginQuoteChar, endQuoteChar, false, true); + } + + public static String[] split(String aLine, char delimiter, char beginQuoteChar, char endQuoteChar, boolean retainQuotes, boolean trimTokens) { + String line = clean(aLine); + if (line == null) { + return null; + } else { + List tokens = new ArrayList(); + StringBuilder sb = new StringBuilder(); + boolean inQuotes = false; + + for(int i = 0; i < line.length(); ++i) { + char c = line.charAt(i); + if (c == beginQuoteChar) { + if (inQuotes && line.length() > i + 1 && line.charAt(i + 1) == beginQuoteChar) { + sb.append(line.charAt(i + 1)); + ++i; + } else { + inQuotes = !inQuotes; + if (retainQuotes) { + sb.append(c); + } + } + } else if (c == endQuoteChar) { + inQuotes = !inQuotes; + if (retainQuotes) { + sb.append(c); + } + } else if (c == delimiter && !inQuotes) { + String s = sb.toString(); + if (trimTokens) { + s = s.trim(); + } + + tokens.add(s); + sb = new StringBuilder(); + } else { + sb.append(c); + } + } + + String s = sb.toString(); + if (trimTokens) { + s = s.trim(); + } + + tokens.add(s); + return (String[])tokens.toArray(new String[tokens.size()]); + } + } + + public static String join(Iterator iterator, String separator) { + String empty = ""; + if (iterator == null) { + return null; + } else if (!iterator.hasNext()) { + return ""; + } else { + Object first = iterator.next(); + if (!iterator.hasNext()) { + return first == null ? "" : first.toString(); + } else { + StringBuilder buf = new StringBuilder(256); + if (first != null) { + buf.append(first); + } + + while(iterator.hasNext()) { + if (separator != null) { + buf.append(separator); + } + + Object obj = iterator.next(); + if (obj != null) { + buf.append(obj); + } + } + + return buf.toString(); + } + } + } + + public static Set splitToSet(String delimited, String separator) { + if (delimited != null && separator != null) { + String[] split = split(delimited, separator.charAt(0)); + return asSet(split); + } else { + return null; + } + } + + public static String uppercaseFirstChar(String in) { + if (in != null && in.length() != 0) { + int length = in.length(); + StringBuilder sb = new StringBuilder(length); + sb.append(Character.toUpperCase(in.charAt(0))); + if (length > 1) { + String remaining = in.substring(1); + sb.append(remaining); + } + + return sb.toString(); + } else { + return in; + } + } + + private static Set asSet(E... elements) { + if (elements != null && elements.length != 0) { + if (elements.length == 1) { + return Collections.singleton(elements[0]); + } else { + LinkedHashSet set = new LinkedHashSet(elements.length * 4 / 3 + 1); + Collections.addAll(set, elements); + return set; + } + } else { + return Collections.emptySet(); + } + } +} + diff --git a/core/test/net/oschina/j2cache/PatternMatcherTest.java b/core/test/net/oschina/j2cache/PatternMatcherTest.java new file mode 100644 index 0000000..4aa0582 --- /dev/null +++ b/core/test/net/oschina/j2cache/PatternMatcherTest.java @@ -0,0 +1,14 @@ +package net.oschina.j2cache; + +import net.oschina.j2cache.util.AntPathMatcher; +import net.oschina.j2cache.util.PatternMatcher; + +public class PatternMatcherTest { + + public static void main(String[] args) { + PatternMatcher matcher = new AntPathMatcher(); + System.out.println(matcher.matches("abc_*","abc_sdfsd")); + System.out.println(matcher.matches("asf_*","dsffsd")); + System.out.println(matcher.matches("default","default")); + } +} -- Gitee From 954c406731fdef129e545bc21260dd3ecfa0dac2 Mon Sep 17 00:00:00 2001 From: watilion Date: Tue, 9 Mar 2021 20:31:57 +0800 Subject: [PATCH 131/131] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8spring-cloud-starter-alibaba-nacos-config=E9=9B=86?= =?UTF-8?q?=E6=88=90nacos=E6=97=B6=E6=97=A0=E6=B3=95=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/util/SpringJ2CacheConfigUtil.java | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java index d554ecc..e3cf870 100644 --- a/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java +++ b/modules/spring-boot2-starter/src/net/oschina/j2cache/cache/support/util/SpringJ2CacheConfigUtil.java @@ -2,6 +2,7 @@ package net.oschina.j2cache.cache.support.util; import net.oschina.j2cache.J2CacheConfig; import org.springframework.core.env.CompositePropertySource; +import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.StandardEnvironment; @@ -49,26 +50,31 @@ public class SpringJ2CacheConfigUtil { //配置在 nacos 中时,上面那段代码无法获取配置 if (config.getL1CacheProperties().isEmpty() || config.getL2CacheProperties().isEmpty() || config.getBroadcastProperties().isEmpty()) { environment.getPropertySources().forEach(a -> { - if (a instanceof CompositePropertySource) { - CompositePropertySource c = (CompositePropertySource) a; - String[] propertyNames = c.getPropertyNames(); - - for (String key : propertyNames) { - if (key.startsWith(config.getBroadcast() + ".")) { - config.getBroadcastProperties().setProperty(key.substring((config.getBroadcast() + ".").length()), - environment.getProperty(key)); - } - if (key.startsWith(config.getL1CacheName() + ".")) { - config.getL1CacheProperties().setProperty(key.substring((config.getL1CacheName() + ".").length()), - environment.getProperty(key)); - } - if (key.startsWith(l2_section + ".")) { - config.getL2CacheProperties().setProperty(key.substring((l2_section + ".").length()), - environment.getProperty(key)); - } - } - } - }); + String[] propertyNames = new String[0]; + if (a instanceof CompositePropertySource) { + CompositePropertySource c = (CompositePropertySource) a; + propertyNames = c.getPropertyNames(); + } else if (a instanceof EnumerablePropertySource){ + EnumerablePropertySource c = (EnumerablePropertySource) a; + propertyNames = c.getPropertyNames(); + } + if (propertyNames.length > 0){ + for (String key : propertyNames) { + if (key.startsWith(config.getBroadcast() + ".")) { + config.getBroadcastProperties().setProperty(key.substring((config.getBroadcast() + ".").length()), + environment.getProperty(key)); + } + if (key.startsWith(config.getL1CacheName() + ".")) { + config.getL1CacheProperties().setProperty(key.substring((config.getL1CacheName() + ".").length()), + environment.getProperty(key)); + } + if (key.startsWith(l2_section + ".")) { + config.getL2CacheProperties().setProperty(key.substring((l2_section + ".").length()), + environment.getProperty(key)); + } + } + } + }); } return config; } -- Gitee