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
17 package net.sf.ehcache.hibernate.nonstop;
18
19 import net.sf.ehcache.hibernate.regions.EhcacheCollectionRegion;
20 import net.sf.ehcache.hibernate.regions.EhcacheEntityRegion;
21 import net.sf.ehcache.hibernate.strategy.EhcacheAccessStrategyFactory;
22
23 import org.hibernate.cache.access.AccessType;
24 import org.hibernate.cache.access.CollectionRegionAccessStrategy;
25 import org.hibernate.cache.access.EntityRegionAccessStrategy;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /***
30 * Implementation of {@link EhcacheAccessStrategyFactory} that takes care of Nonstop cache exceptions using
31 * {@link HibernateNonstopCacheExceptionHandler}
32 *
33 * @author Abhishek Sanoujam
34 *
35 */
36 public class NonstopAccessStrategyFactory implements EhcacheAccessStrategyFactory {
37
38 private static final Logger LOG = LoggerFactory.getLogger(NonstopAccessStrategyFactory.class);
39 private final EhcacheAccessStrategyFactory actualFactory;
40
41 /***
42 * Constructor accepting the actual factory
43 *
44 * @param actualFactory
45 */
46 public NonstopAccessStrategyFactory(EhcacheAccessStrategyFactory actualFactory) {
47 this.actualFactory = actualFactory;
48 }
49
50 /***
51 * {@inheritDoc}
52 */
53 public EntityRegionAccessStrategy createEntityRegionAccessStrategy(EhcacheEntityRegion entityRegion, AccessType accessType) {
54 return new NonstopAwareEntityRegionAccessStrategy(actualFactory.createEntityRegionAccessStrategy(entityRegion, accessType),
55 HibernateNonstopCacheExceptionHandler.getInstance());
56 }
57
58 /***
59 * {@inheritDoc}
60 */
61 public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(EhcacheCollectionRegion collectionRegion,
62 AccessType accessType) {
63 return new NonstopAwareCollectionRegionAccessStrategy(actualFactory.createCollectionRegionAccessStrategy(collectionRegion,
64 accessType), HibernateNonstopCacheExceptionHandler.getInstance());
65 }
66
67 }