• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CacheException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.ibatis.cache.CacheException的典型用法代码示例。如果您正苦于以下问题:Java CacheException类的具体用法?Java CacheException怎么用?Java CacheException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CacheException类属于org.apache.ibatis.cache包,在下文中一共展示了CacheException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: shouldInstantiateAndThrowAllCustomExceptions

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
@Test
public void shouldInstantiateAndThrowAllCustomExceptions() throws Exception {
  Class<?>[] exceptionTypes = {
      BindingException.class,
      CacheException.class,
      DataSourceException.class,
      ExecutorException.class,
      LogException.class,
      ParsingException.class,
      BuilderException.class,
      PluginException.class,
      ReflectionException.class,
      PersistenceException.class,
      SqlSessionException.class,
      TransactionException.class,
      TypeException.class, 
      ScriptingException.class
  };
  for (Class<?> exceptionType : exceptionTypes) {
    testExceptionConstructors(exceptionType);
  }

}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:24,代码来源:GeneralExceptionsTest.java


示例2: equals

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
  //只要id相等就认为两个cache相同
  if (getId() == null) {
    throw new CacheException("Cache instances require an ID.");
  }
  if (this == o) {
    return true;
  }
  if (!(o instanceof Cache)) {
    return false;
  }

  Cache otherCache = (Cache) o;
  return getId().equals(otherCache.getId());
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:17,代码来源:PerpetualCache.java


示例3: unserialize

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
public static Object unserialize(byte[] bytes) {
  if (bytes == null) {
    return null;
  }
  try {
    //use kryo unserialize first
    return KryoSerializer.unserialize(bytes);
  } catch (Exception e) {
    //if kryo unserialize fails, user jdk unserialize as a fallback
    try {
      return JDKSerializer.unserialize(bytes);
    } catch (CacheException cacheException) {
      throw cacheException;
    }

  }
}
 
开发者ID:mybatis,项目名称:redis-cache,代码行数:18,代码来源:SerializeUtil.java


示例4: decode

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Object decode(final CachedData cachedData) {
  byte[] buffer = cachedData.getData();

  ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
  GZIPInputStream gzis = null;
  ObjectInputStream ois = null;
  Object ret = null;

  try {
    gzis = new GZIPInputStream(bais);
    ois = new ObjectInputStream(gzis);
    ret = ois.readObject();
  } catch (Exception e) {
    throw new CacheException("Impossible to decompress cached object, see nested exceptions", e);
  } finally {
    closeQuietly(ois);
    closeQuietly(gzis);
    closeQuietly(bais);
  }
  return ret;
}
 
开发者ID:mybatis,项目名称:memcached-cache,代码行数:26,代码来源:CompressorTranscoder.java


示例5: encode

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public CachedData encode(final Object object) {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  GZIPOutputStream gzops = null;
  ObjectOutputStream oos = null;

  try {
    gzops = new GZIPOutputStream(baos);
    oos = new ObjectOutputStream(gzops);
    oos.writeObject(object);
  } catch (IOException e) {
    throw new CacheException("Impossible to compress object [" + object + "], see nested exceptions", e);
  } finally {
    closeQuietly(oos);
    closeQuietly(gzops);
    closeQuietly(baos);
  }

  byte[] buffer = baos.toByteArray();
  return new CachedData(SERIALIZED_COMPRESSED, buffer, CachedData.MAX_SIZE);
}
 
开发者ID:mybatis,项目名称:memcached-cache,代码行数:25,代码来源:CompressorTranscoder.java


示例6: storeInMemcached

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
/**
 * Tries to update an object value in memcached considering the cas validation
 * 
 * Returns true if the object passed the cas validation and was modified.
 * 
 * @param keyString
 * @param value
 * @return
 */
private boolean storeInMemcached(String keyString, ObjectWithCas value) {
  if (value != null && value.getObject() != null
      && !Serializable.class.isAssignableFrom(value.getObject().getClass())) {
    throw new CacheException("Object of type '" + value.getObject().getClass().getName()
        + "' that's non-serializable is not supported by Memcached");
  }

  CASResponse response;

  if (configuration.isCompressionEnabled()) {
    response = client.cas(keyString, value.getCas(), value.getObject(), new CompressorTranscoder());
  } else {
    response = client.cas(keyString, value.getCas(), value.getObject());
  }

  return (response.equals(CASResponse.OBSERVE_MODIFIED) || response.equals(CASResponse.OK));
}
 
开发者ID:mybatis,项目名称:memcached-cache,代码行数:27,代码来源:MemcachedClientWrapper.java


示例7: setCacheProperties

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private void setCacheProperties(Cache cache) {
  if (properties != null) {
    MetaObject metaCache = SystemMetaObject.forObject(cache);
    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 for cache: '" + name + "' of type " + type);
        }
      }
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:39,代码来源:CacheBuilder.java


示例8: newBaseCacheInstance

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private Cache newBaseCacheInstance(Class<? extends Cache> cacheClass, String id) {
  Constructor<? extends Cache> cacheConstructor = getBaseCacheConstructor(cacheClass);
  try {
    return cacheConstructor.newInstance(id);
  } catch (Exception e) {
    throw new CacheException("Could not instantiate cache implementation (" + cacheClass + "). Cause: " + e, e);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:CacheBuilder.java


示例9: getBaseCacheConstructor

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private Constructor<? extends Cache> getBaseCacheConstructor(Class<? extends Cache> cacheClass) {
  try {
    return cacheClass.getConstructor(String.class);
  } catch (Exception e) {
    throw new CacheException("Invalid base cache implementation (" + cacheClass + ").  " +
        "Base cache implementations must have a constructor that takes a String id as a parameter.  Cause: " + e, e);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:CacheBuilder.java


示例10: newCacheDecoratorInstance

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private Cache newCacheDecoratorInstance(Class<? extends Cache> cacheClass, Cache base) {
  Constructor<? extends Cache> cacheConstructor = getCacheDecoratorConstructor(cacheClass);
  try {
    return cacheConstructor.newInstance(base);
  } catch (Exception e) {
    throw new CacheException("Could not instantiate cache decorator (" + cacheClass + "). Cause: " + e, e);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:CacheBuilder.java


示例11: getCacheDecoratorConstructor

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private Constructor<? extends Cache> getCacheDecoratorConstructor(Class<? extends Cache> cacheClass) {
  try {
    return cacheClass.getConstructor(Cache.class);
  } catch (Exception e) {
    throw new CacheException("Invalid cache decorator (" + cacheClass + ").  " +
        "Cache decorators must have a constructor that takes a Cache instance as a parameter.  Cause: " + e, e);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:CacheBuilder.java


示例12: putObject

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
@Override
public void putObject(Object key, Object object) {
  if (object == null || object instanceof Serializable) {
    delegate.putObject(key, serialize((Serializable) object));
  } else {
    throw new CacheException("SharedCache failed to make a copy of a non-serializable object: " + object);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:SerializedCache.java


示例13: serialize

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private byte[] serialize(Serializable value) {
  try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(value);
    oos.flush();
    oos.close();
    return bos.toByteArray();
  } catch (Exception e) {
    throw new CacheException("Error serializing object.  Cause: " + e, e);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:13,代码来源:SerializedCache.java


示例14: deserialize

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private Serializable deserialize(byte[] value) {
  Serializable result;
  try {
    ByteArrayInputStream bis = new ByteArrayInputStream(value);
    ObjectInputStream ois = new CustomObjectInputStream(bis);
    result = (Serializable) ois.readObject();
    ois.close();
  } catch (Exception e) {
    throw new CacheException("Error deserializing object.  Cause: " + e, e);
  }
  return result;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:13,代码来源:SerializedCache.java


示例15: acquireLock

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private void acquireLock(Object key) {
  Lock lock = getLockForKey(key);
  if (timeout > 0) {
    try {
      boolean acquired = lock.tryLock(timeout, TimeUnit.MILLISECONDS);
      if (!acquired) {
        throw new CacheException("Couldn't get a lock in " + timeout + " for the key " +  key + " at the cache " + delegate.getId());  
      }
    } catch (InterruptedException e) {
      throw new CacheException("Got interrupted while trying to acquire lock for key " + key, e);
    }
  } else {
    lock.lock();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:16,代码来源:BlockingCache.java


示例16: equals

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
  if (getId() == null) {
    throw new CacheException("Cache instances require an ID.");
  }
  if (this == o) {
    return true;
  }
  if (!(o instanceof Cache)) {
    return false;
  }

  Cache otherCache = (Cache) o;
  return getId().equals(otherCache.getId());
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:16,代码来源:PerpetualCache.java


示例17: hashCode

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
@Override
public int hashCode() {
  if (getId() == null) {
    throw new CacheException("Cache instances require an ID.");
  }
  return getId().hashCode();
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:PerpetualCache.java


示例18: setCacheProperties

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private void setCacheProperties(Cache cache) {
  if (properties != null) {
    MetaObject metaCache = SystemMetaObject.forObject(cache);
    //用反射设置额外的property属性
    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 for cache: '" + name + "' of type " + type);
        }
      }
    }
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:41,代码来源:CacheBuilder.java


示例19: putObject

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
@Override
public void putObject(Object key, Object object) {
  if (object == null || object instanceof Serializable) {
      //先序列化,再委托被包装者putObject
    delegate.putObject(key, serialize((Serializable) object));
  } else {
    throw new CacheException("SharedCache failed to make a copy of a non-serializable object: " + object);
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:10,代码来源:SerializedCache.java


示例20: serialize

import org.apache.ibatis.cache.CacheException; //导入依赖的package包/类
private byte[] serialize(Serializable value) {
  try {
      //序列化核心就是ByteArrayOutputStream
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(value);
    oos.flush();
    oos.close();
    return bos.toByteArray();
  } catch (Exception e) {
    throw new CacheException("Error serializing object.  Cause: " + e, e);
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:14,代码来源:SerializedCache.java



注:本文中的org.apache.ibatis.cache.CacheException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MultiInstanceActivityBehavior类代码示例发布时间:2022-05-22
下一篇:
Java Vector2D类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap