|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| EhCacheServiceImpl.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
* @(#)EhCacheServiceImpl.java
|
|
| 3 |
*
|
|
| 4 |
* JFoxSOAF, Service-Oriented Application Framework
|
|
| 5 |
*
|
|
| 6 |
* Copyright(c) JFoxSOAF Team
|
|
| 7 |
*
|
|
| 8 |
* Licensed under the GNU LGPL, Version 2.1 (the "License");
|
|
| 9 |
* you may not use this file except in compliance with the License.
|
|
| 10 |
* You may obtain a copy of the License at
|
|
| 11 |
*
|
|
| 12 |
* http://www.gnu.org/copyleft/lesser.html
|
|
| 13 |
*
|
|
| 14 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 17 |
* See the License for the specific language governing permissions and
|
|
| 18 |
* limitations under the License.
|
|
| 19 |
*
|
|
| 20 |
* For more information, please visit:
|
|
| 21 |
* http://www.jfox.cn/confluence/display/JFoxSOAF/Home
|
|
| 22 |
* http://www.huihoo.org/jfox/jfoxsoaf
|
|
| 23 |
*/
|
|
| 24 |
|
|
| 25 |
package org.huihoo.jfox.soaf.services.cache;
|
|
| 26 |
|
|
| 27 |
import java.io.IOException;
|
|
| 28 |
import java.io.Serializable;
|
|
| 29 |
|
|
| 30 |
import net.sf.ehcache.Cache;
|
|
| 31 |
import net.sf.ehcache.CacheException;
|
|
| 32 |
import net.sf.ehcache.Element;
|
|
| 33 |
|
|
| 34 |
import org.huihoo.jfox.soaf.exception.CacheServiceException;
|
|
| 35 |
|
|
| 36 |
/**
|
|
| 37 |
* <p>
|
|
| 38 |
* Support for ehcache.
|
|
| 39 |
* </p>
|
|
| 40 |
*
|
|
| 41 |
* @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
|
|
| 42 |
* @version $Revision: 1.1 $ $Date: 2005/05/22 06:48:52 $
|
|
| 43 |
* @version Revision: 1.0
|
|
| 44 |
*/
|
|
| 45 |
|
|
| 46 |
public class EhCacheServiceImpl implements CacheService { |
|
| 47 |
|
|
| 48 |
private Cache cache;
|
|
| 49 |
|
|
| 50 |
/**
|
|
| 51 |
* Creates a new pluggable cache based on a cache name.
|
|
| 52 |
*
|
|
| 53 |
* @param cache The underlying EhCache instance to use.
|
|
| 54 |
*/
|
|
| 55 | 0 |
public EhCacheServiceImpl(Cache cache) {
|
| 56 | 0 |
this.cache = cache;
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/**
|
|
| 60 |
* @see org.huihoo.jfox.soaf.services.cache.CacheService#get(java.lang.Object)
|
|
| 61 |
*/
|
|
| 62 | 0 |
public Object get(Object key) throws CacheServiceException { |
| 63 | 0 |
try {
|
| 64 | 0 |
if (key == null) { |
| 65 | 0 |
return null; |
| 66 |
} else {
|
|
| 67 | 0 |
Element element = cache.get((Serializable) key); |
| 68 | 0 |
if (element == null) { |
| 69 | 0 |
return null; |
| 70 |
} else {
|
|
| 71 | 0 |
return element.getValue();
|
| 72 |
} |
|
| 73 |
} |
|
| 74 |
} catch (CacheException e) {
|
|
| 75 | 0 |
throw new CacheServiceException(e); |
| 76 |
} |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/**
|
|
| 80 |
* @see org.huihoo.jfox.soaf.services.cache.CacheService#put(java.lang.Object,
|
|
| 81 |
* java.lang.Object)
|
|
| 82 |
*/
|
|
| 83 | 0 |
public void put(Object key, Object value) throws CacheServiceException { |
| 84 | 0 |
try {
|
| 85 | 0 |
Element element = new Element((Serializable) key,
|
| 86 |
(Serializable) value); |
|
| 87 | 0 |
cache.put(element); |
| 88 |
} catch (IllegalArgumentException e) {
|
|
| 89 | 0 |
throw new CacheServiceException(e); |
| 90 |
} catch (IllegalStateException e) {
|
|
| 91 | 0 |
throw new CacheServiceException(e); |
| 92 |
} |
|
| 93 |
|
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/**
|
|
| 97 |
* @see org.huihoo.jfox.soaf.services.cache.CacheService#remove(java.lang.Object)
|
|
| 98 |
*/
|
|
| 99 | 0 |
public void remove(Object key) throws CacheServiceException { |
| 100 | 0 |
try {
|
| 101 | 0 |
cache.remove((Serializable) key); |
| 102 |
} catch (ClassCastException e) {
|
|
| 103 | 0 |
throw new CacheServiceException(e); |
| 104 |
} catch (IllegalStateException e) {
|
|
| 105 | 0 |
throw new CacheServiceException(e); |
| 106 |
} |
|
| 107 |
|
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/**
|
|
| 111 |
* @see org.huihoo.jfox.soaf.services.cache.CacheService#clear()
|
|
| 112 |
*/
|
|
| 113 | 0 |
public void clear() throws CacheServiceException { |
| 114 | 0 |
try {
|
| 115 | 0 |
cache.removeAll(); |
| 116 |
} catch (IllegalStateException e) {
|
|
| 117 | 0 |
throw new CacheServiceException(e); |
| 118 |
} catch (IOException e) {
|
|
| 119 | 0 |
throw new CacheServiceException(e); |
| 120 |
} |
|
| 121 |
|
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
} |
|
||||||||||