List of usage examples for org.apache.ibatis.cache CacheException CacheException
public CacheException(Throwable cause)
From source file:com.dk3k.framework.redis.cache.mybatis.RedisConfigurationBuilder.java
License:Apache License
private void setConfigProperties(Properties properties, ConfigWithHost jedisConfig) { if (properties != null) { MetaObject metaCache = SystemMetaObject.forObject(jedisConfig); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String name = (String) entry.getKey(); String value = (String) entry.getValue(); if (metaCache.hasSetter(name)) { Class<?> type = metaCache.getSetterType(name); if (String.class == type) { metaCache.setValue(name, value); } else if (int.class == type || Integer.class == type) { metaCache.setValue(name, Integer.valueOf(value)); } else if (long.class == type || Long.class == type) { metaCache.setValue(name, Long.valueOf(value)); } else if (short.class == type || Short.class == type) { metaCache.setValue(name, Short.valueOf(value)); } else if (byte.class == type || Byte.class == type) { metaCache.setValue(name, Byte.valueOf(value)); } else if (float.class == type || Float.class == type) { metaCache.setValue(name, Float.valueOf(value)); } else if (boolean.class == type || Boolean.class == type) { metaCache.setValue(name, Boolean.valueOf(value)); } else if (double.class == type || Double.class == type) { metaCache.setValue(name, Double.valueOf(value)); } else { throw new CacheException("Unsupported property type: '" + name + "' of type " + type); }// ww w. j a va 2 s . c o m } } } }
From source file:com.lankr.tv_cloud.cache.SerializeUtil.java
License:Apache License
public static byte[] serialize(Object object) { ObjectOutputStream oos = null; ByteArrayOutputStream baos = null; try {/* ww w . j ava2 s. c om*/ baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(object); byte[] bytes = baos.toByteArray(); return bytes; } catch (Exception e) { throw new CacheException(e); } }
From source file:com.lankr.tv_cloud.cache.SerializeUtil.java
License:Apache License
public static Object unserialize(byte[] bytes) { if (bytes == null) { return null; }/* w w w .j av a2 s. c om*/ ByteArrayInputStream bais = null; try { bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); return ois.readObject(); } catch (Exception e) { throw new CacheException(e); } }
From source file:com.shine.his.common.mybatis.HISMybatisLRUCache.java
License:Apache License
/** * {@inheritDoc}//from www. j av a2s . com */ public Object getObject(Object key) { try { Element cachedElement = delegate.get(key); if (cachedElement == null) { return null; } return cachedElement.getObjectValue(); } catch (Throwable t) { throw new CacheException(t); } }
From source file:com.shine.his.common.mybatis.HISMybatisLRUCache.java
License:Apache License
/** * {@inheritDoc}//from ww w .j a v a 2 s . c o m */ public int getSize() { try { return delegate.getSize(); } catch (Throwable t) { throw new CacheException(t); } }
From source file:com.shine.his.common.mybatis.HISMybatisLRUCache.java
License:Apache License
/** * {@inheritDoc}//w ww . ja v a2 s. c o m */ public void putObject(Object key, Object value) { try { delegate.put(new Element(key, value)); } catch (Throwable t) { throw new CacheException(t); } cycleKeyList(key); }
From source file:com.shine.his.common.mybatis.HISMybatisLRUCache.java
License:Apache License
/** * {@inheritDoc}/*from w ww. ja v a 2 s . c o m*/ */ public Object removeObject(Object key) { try { Object obj = this.getObject(key); delegate.remove(key); return obj; } catch (Throwable t) { throw new CacheException(t); } }
From source file:com.zh.common.redis.RedisConfigurationBuilder.java
License:Apache License
private void setConfigProperties(Properties properties, RedisConfig jedisConfig) { if (properties != null) { MetaObject metaCache = SystemMetaObject.forObject(jedisConfig); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String name = (String) entry.getKey(); String value = (String) entry.getValue(); if (metaCache.hasSetter(name)) { Class<?> type = metaCache.getSetterType(name); if (String.class == type) { metaCache.setValue(name, value); } else if (int.class == type || Integer.class == type) { metaCache.setValue(name, Integer.valueOf(value)); } else if (long.class == type || Long.class == type) { metaCache.setValue(name, Long.valueOf(value)); } else if (short.class == type || Short.class == type) { metaCache.setValue(name, Short.valueOf(value)); } else if (byte.class == type || Byte.class == type) { metaCache.setValue(name, Byte.valueOf(value)); } else if (float.class == type || Float.class == type) { metaCache.setValue(name, Float.valueOf(value)); } else if (boolean.class == type || Boolean.class == type) { metaCache.setValue(name, Boolean.valueOf(value)); } else if (double.class == type || Double.class == type) { metaCache.setValue(name, Double.valueOf(value)); } else { throw new CacheException("Unsupported property type: '" + name + "' of type " + type); }//from ww w.j av a2 s . co m } } } }
From source file:org.cacheonix.plugin.mybatis.v300.MyBatisCache.java
License:LGPL
/** * Utility method./*from ww w . j a va 2 s.co m*/ * * @param object object to cast to Serializable. * @param description the object description. * @return a serializable object. * @throws CacheException if the object is not serializable */ private static Serializable castToSerializable(final Object object, final String description) throws CacheException { if (object == null) { return null; } if (object instanceof Serializable) { return (Serializable) object; } else { throw new CacheException( description + " must implement java.io.Serializable or java.io.Externalizable: " + object); } }
From source file:org.mybatis.caches.memcached.MemcachedClientWrapper.java
License:Apache License
/** * * * @param keyString/*w w w .j ava 2 s . c om*/ * @return * @throws Exception */ private Object retrieve(final String keyString) { Object retrieved = null; if (configuration.isUsingAsyncGet()) { Future<Object> future; if (configuration.isCompressionEnabled()) { future = client.asyncGet(keyString, new CompressorTranscoder()); } else { future = client.asyncGet(keyString); } try { retrieved = future.get(configuration.getTimeout(), configuration.getTimeUnit()); } catch (Exception e) { future.cancel(false); throw new CacheException(e); } } else { if (configuration.isCompressionEnabled()) { retrieved = client.get(keyString, new CompressorTranscoder()); } else { retrieved = client.get(keyString); } } return retrieved; }