View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package net.sf.ehcache.hibernate.ccs;
17  
18  import java.util.Comparator;
19  
20  import org.hibernate.cache.CacheException;
21  import org.hibernate.cache.access.SoftLock;
22  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  /***
27   * Ehcache specific non-strict read/write cache concurrency strategy.
28   * <p>
29   * This is the Ehcache specific equivalent to Hibernate's NonstrictReadWriteCache.
30   *
31   * @author Chris Dennis
32   */
33  @Deprecated
34  public class EhcacheNonstrictReadWriteCache extends AbstractEhcacheConcurrencyStrategy {
35  
36      private static final Logger LOG = LoggerFactory.getLogger(EhcacheNonstrictReadWriteCache.class);
37  
38      /***
39       * {@inheritDoc}
40       */
41      public Object get(Object key, long txTimestamp) throws CacheException {
42          return cache.get(key);
43      }
44  
45      /***
46       * {@inheritDoc}
47       */
48      public boolean put(Object key, Object value, long txTimestamp, Object version, Comparator versionComparator, boolean minimalPut)
49              throws CacheException {
50          if (minimalPut && cache.get(key) != null) {
51              return false;
52          } else {
53              cache.put(key, value);
54              return true;
55          }
56      }
57  
58      /***
59       * Caching is non-strict so soft locks are not implemented.
60       */
61      public SoftLock lock(Object key, Object version) throws CacheException {
62          return null;
63      }
64  
65      /***
66       * Removes the stale item.
67       */
68      public void evict(Object key) throws CacheException {
69          cache.remove(key);
70      }
71  
72      /***
73       * Removes the invalidated item.
74       */
75      public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
76          evict(key);
77          return false;
78      }
79  
80      /***
81       * A No-Op, since we are an asynchronous cache concurrency strategy.
82       */
83      public boolean insert(Object key, Object value, Object currentVersion) throws CacheException {
84          return false;
85      }
86  
87      /***
88       * Removes the invalidated item.
89       */
90      public void release(Object key, SoftLock lock) throws CacheException {
91          cache.remove(key);
92      }
93  
94      /***
95       * Removes the invalidated item.
96       */
97      public boolean afterUpdate(Object key, Object value, Object version, SoftLock lock) throws CacheException {
98          release(key, lock);
99          return false;
100     }
101 
102     /***
103      * A No-Op.
104      */
105     public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
106         return false;
107     }
108 
109     /***
110      * {@inheritDoc}
111      */
112     @Override
113     public String toString() {
114         return cache + "(non-strict-read-write)";
115     }
116 }