|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
| 5 | + * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 6 | + */ |
| 7 | +package org.hibernate.cache.infinispan.access; |
| 8 | + |
| 9 | +import org.hibernate.cache.CacheException; |
| 10 | +import org.hibernate.cache.spi.access.SoftLock; |
| 11 | +import org.hibernate.engine.spi.SessionImplementor; |
| 12 | + |
| 13 | +/** |
| 14 | + * Defines the strategy for access to entity or collection data in a Infinispan instance. |
| 15 | + * <p/> |
| 16 | + * The intent of this class is to encapsulate common code and serve as a delegate for |
| 17 | + * {@link org.hibernate.cache.spi.access.EntityRegionAccessStrategy} |
| 18 | + * and {@link org.hibernate.cache.spi.access.CollectionRegionAccessStrategy} implementations. |
| 19 | + * |
| 20 | + * @author Radim Vansa <[email protected]> |
| 21 | + */ |
| 22 | +public interface AccessDelegate { |
| 23 | + Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException; |
| 24 | + |
| 25 | + /** |
| 26 | + * Attempt to cache an object, after loading from the database. |
| 27 | + * |
| 28 | + * @param session Current session |
| 29 | + * @param key The item key |
| 30 | + * @param value The item |
| 31 | + * @param txTimestamp a timestamp prior to the transaction start time |
| 32 | + * @param version the item version number |
| 33 | + * @return <tt>true</tt> if the object was successfully cached |
| 34 | + */ |
| 35 | + boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version); |
| 36 | + |
| 37 | + /** |
| 38 | + * Attempt to cache an object, after loading from the database, explicitly |
| 39 | + * specifying the minimalPut behavior. |
| 40 | + * |
| 41 | + * @param session Current session. |
| 42 | + * @param key The item key |
| 43 | + * @param value The item |
| 44 | + * @param txTimestamp a timestamp prior to the transaction start time |
| 45 | + * @param version the item version number |
| 46 | + * @param minimalPutOverride Explicit minimalPut flag |
| 47 | + * @return <tt>true</tt> if the object was successfully cached |
| 48 | + * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} |
| 49 | + */ |
| 50 | + boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) |
| 51 | + throws CacheException; |
| 52 | + |
| 53 | + /** |
| 54 | + * Called after an item has been inserted (before the transaction completes), |
| 55 | + * instead of calling evict(). |
| 56 | + * |
| 57 | + * @param session Current session |
| 58 | + * @param key The item key |
| 59 | + * @param value The item |
| 60 | + * @param version The item's version value |
| 61 | + * @return Were the contents of the cache actual changed by this operation? |
| 62 | + * @throws CacheException if the insert fails |
| 63 | + */ |
| 64 | + boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException; |
| 65 | + |
| 66 | + /** |
| 67 | + * Called after an item has been updated (before the transaction completes), |
| 68 | + * instead of calling evict(). |
| 69 | + * |
| 70 | + * @param session Current session |
| 71 | + * @param key The item key |
| 72 | + * @param value The item |
| 73 | + * @param currentVersion The item's current version value |
| 74 | + * @param previousVersion The item's previous version value |
| 75 | + * @return Whether the contents of the cache actual changed by this operation |
| 76 | + * @throws CacheException if the update fails |
| 77 | + */ |
| 78 | + boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) |
| 79 | + throws CacheException; |
| 80 | + |
| 81 | + /** |
| 82 | + * Called after an item has become stale (before the transaction completes). |
| 83 | + * |
| 84 | + * @param session Current session |
| 85 | + * @param key The key of the item to remove |
| 86 | + * @throws CacheException if removing the cached item fails |
| 87 | + */ |
| 88 | + void remove(SessionImplementor session, Object key) throws CacheException; |
| 89 | + |
| 90 | + /** |
| 91 | + * Called to evict data from the entire region |
| 92 | + * |
| 93 | + * @throws CacheException if eviction the region fails |
| 94 | + */ |
| 95 | + void removeAll() throws CacheException; |
| 96 | + |
| 97 | + /** |
| 98 | + * Forcibly evict an item from the cache immediately without regard for transaction |
| 99 | + * isolation. |
| 100 | + * |
| 101 | + * @param key The key of the item to remove |
| 102 | + * @throws CacheException if evicting the item fails |
| 103 | + */ |
| 104 | + void evict(Object key) throws CacheException; |
| 105 | + |
| 106 | + /** |
| 107 | + * Forcibly evict all items from the cache immediately without regard for transaction |
| 108 | + * isolation. |
| 109 | + * |
| 110 | + * @throws CacheException if evicting items fails |
| 111 | + */ |
| 112 | + void evictAll() throws CacheException; |
| 113 | + |
| 114 | + /** |
| 115 | + * Called when we have finished the attempted update/delete (which may or |
| 116 | + * may not have been successful), after transaction completion. This method |
| 117 | + * is used by "asynchronous" concurrency strategies. |
| 118 | + * |
| 119 | + * |
| 120 | + * @param session |
| 121 | + * @param key The item key |
| 122 | + * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} |
| 123 | + */ |
| 124 | + void unlockItem(SessionImplementor session, Object key) throws CacheException; |
| 125 | + |
| 126 | + /** |
| 127 | + * Called after an item has been inserted (after the transaction completes), |
| 128 | + * instead of calling release(). |
| 129 | + * This method is used by "asynchronous" concurrency strategies. |
| 130 | + * |
| 131 | + * |
| 132 | + * @param session |
| 133 | + * @param key The item key |
| 134 | + * @param value The item |
| 135 | + * @param version The item's version value |
| 136 | + * @return Were the contents of the cache actual changed by this operation? |
| 137 | + * @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region} |
| 138 | + */ |
| 139 | + boolean afterInsert(SessionImplementor session, Object key, Object value, Object version); |
| 140 | + |
| 141 | + /** |
| 142 | + * Called after an item has been updated (after the transaction completes), |
| 143 | + * instead of calling release(). This method is used by "asynchronous" |
| 144 | + * concurrency strategies. |
| 145 | + * |
| 146 | + * |
| 147 | + * @param session |
| 148 | + * @param key The item key |
| 149 | + * @param value The item |
| 150 | + * @param currentVersion The item's current version value |
| 151 | + * @param previousVersion The item's previous version value |
| 152 | + * @param lock The lock previously obtained from {@link #lockItem} |
| 153 | + * @return Were the contents of the cache actual changed by this operation? |
| 154 | + * @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region} |
| 155 | + */ |
| 156 | + boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock); |
| 157 | +} |
0 commit comments