|
| 1 | +/* |
| 2 | + * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as |
| 3 | + * indicated by the @author tags or express copyright attribution |
| 4 | + * statements applied by the authors. All third-party contributions are |
| 5 | + * distributed under license by Red Hat Middleware LLC. |
| 6 | + * |
| 7 | + * This copyrighted material is made available to anyone wishing to use, modify, |
| 8 | + * copy, or redistribute it subject to the terms and conditions of the GNU |
| 9 | + * Lesser General Public License, as published by the Free Software Foundation. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 14 | + * for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this distribution; if not, write to: |
| 18 | + * Free Software Foundation, Inc. |
| 19 | + * 51 Franklin Street, Fifth Floor |
| 20 | + * Boston, MA 02110-1301 USA |
| 21 | + */ |
| 22 | +package org.hibernate; |
| 23 | + |
| 24 | +import java.io.Serializable; |
| 25 | + |
| 26 | +/** |
| 27 | + * Provides an API for querying/managing the second level cache regions. |
| 28 | + * <p/> |
| 29 | + * CAUTION: None of these methods respect any isolation or transactional |
| 30 | + * semantics associated with the underlying caches. Specifically, evictions |
| 31 | + * perform an immediate "hard" removal outside any transactions and/or locking |
| 32 | + * scheme(s). |
| 33 | + * |
| 34 | + * @author Steve Ebersole |
| 35 | + */ |
| 36 | +public interface Cache { |
| 37 | + /** |
| 38 | + * Determine whether the cache contains data for the given entity "instance". |
| 39 | + * <p/> |
| 40 | + * The semantic here is whether the cache contains data visible for the |
| 41 | + * current call context. |
| 42 | + * |
| 43 | + * @param entityClass The entity class. |
| 44 | + * @param identifier The entity identifier |
| 45 | + * |
| 46 | + * @return True if the underlying cache contains corresponding data; false |
| 47 | + * otherwise. |
| 48 | + */ |
| 49 | + public boolean containsEntity(Class entityClass, Serializable identifier); |
| 50 | + |
| 51 | + /** |
| 52 | + * Determine whether the cache contains data for the given entity "instance". |
| 53 | + * <p/> |
| 54 | + * The semantic here is whether the cache contains data visible for the |
| 55 | + * current call context. |
| 56 | + * |
| 57 | + * @param entityName The entity name. |
| 58 | + * @param identifier The entity identifier |
| 59 | + * |
| 60 | + * @return True if the underlying cache contains corresponding data; false otherwise. |
| 61 | + */ |
| 62 | + public boolean containsEntity(String entityName, Serializable identifier); |
| 63 | + |
| 64 | + /** |
| 65 | + * Evicts the entity data for a particular entity "instance". |
| 66 | + * |
| 67 | + * @param entityClass The entity class. |
| 68 | + * @param identifier The entity identifier |
| 69 | + */ |
| 70 | + public void evictEntity(Class entityClass, Serializable identifier); |
| 71 | + |
| 72 | + /** |
| 73 | + * Evicts the entity data for a particular entity "instance". |
| 74 | + * |
| 75 | + * @param entityName The entity name. |
| 76 | + * @param identifier The entity identifier |
| 77 | + */ |
| 78 | + public void evictEntity(String entityName, Serializable identifier); |
| 79 | + |
| 80 | + /** |
| 81 | + * Evicts all entity data from the given region (i.e. for all entities of |
| 82 | + * type). |
| 83 | + * |
| 84 | + * @param entityClass The entity class. |
| 85 | + */ |
| 86 | + public void evictEntityRegion(Class entityClass); |
| 87 | + |
| 88 | + /** |
| 89 | + * Evicts all entity data from the given region (i.e. for all entities of |
| 90 | + * type). |
| 91 | + * |
| 92 | + * @param entityName The entity name. |
| 93 | + */ |
| 94 | + public void evictEntityRegion(String entityName); |
| 95 | + |
| 96 | + /** |
| 97 | + * Evict data from all entity regions. |
| 98 | + */ |
| 99 | + public void evictEntityRegions(); |
| 100 | + |
| 101 | + /** |
| 102 | + * Determine whether the cache contains data for the given collection. |
| 103 | + * <p/> |
| 104 | + * The semantic here is whether the cache contains data visible for the |
| 105 | + * current call context. |
| 106 | + * |
| 107 | + * @param role The name of the collection role (in form |
| 108 | + * [owner-entity-name].[collection-property-name]) whose regions should be |
| 109 | + * evicted. |
| 110 | + * @param ownerIdentifier The identifier of the owning entity |
| 111 | + * |
| 112 | + * @return True if the underlying cache contains corresponding data; false otherwise. |
| 113 | + */ |
| 114 | + public boolean containsCollection(String role, Serializable ownerIdentifier); |
| 115 | + |
| 116 | + /** |
| 117 | + * Evicts the cache data for the given identified collection instance. |
| 118 | + * |
| 119 | + * @param role The "collection role" (in form [owner-entity-name].[collection-property-name]). |
| 120 | + * @param ownerIdentifier The identifier of the owning entity |
| 121 | + */ |
| 122 | + public void evictCollection(String role, Serializable ownerIdentifier); |
| 123 | + |
| 124 | + /** |
| 125 | + * Evicts all entity data from the given region (i.e. evicts cached data |
| 126 | + * for all of the specified c9ollection role). |
| 127 | + * |
| 128 | + * @param role The "collection role" (in form [owner-entity-name].[collection-property-name]). |
| 129 | + */ |
| 130 | + public void evictCollectionRegion(String role); |
| 131 | + |
| 132 | + /** |
| 133 | + * Evict data from all collection regions. |
| 134 | + */ |
| 135 | + public void evictCollectionRegions(); |
| 136 | + |
| 137 | + /** |
| 138 | + * Determine whether the cache contains data for the given query. |
| 139 | + * <p/> |
| 140 | + * The semantic here is whether the cache contains any data for the given |
| 141 | + * region name since query result caches are not transactionally isolated. |
| 142 | + * |
| 143 | + * @param regionName The cache name given to the query. |
| 144 | + * |
| 145 | + * @return True if the underlying cache contains corresponding data; false otherwise. |
| 146 | + */ |
| 147 | + public boolean containsQuery(String regionName); |
| 148 | + |
| 149 | + /** |
| 150 | + * Evicts all cached query results from the default region. |
| 151 | + */ |
| 152 | + public void evictDefaultQueryRegion(); |
| 153 | + |
| 154 | + /** |
| 155 | + * Evicts all cached query results under the given name. |
| 156 | + * |
| 157 | + * @param regionName The cache name associated to the queries being cached. |
| 158 | + */ |
| 159 | + public void evictQueryRegion(String regionName); |
| 160 | + |
| 161 | + /** |
| 162 | + * Evict data from all query regions. |
| 163 | + */ |
| 164 | + public void evictQueryRegions(); |
| 165 | +} |
0 commit comments