Package com.jada.jpa.entity

Examples of com.jada.jpa.entity.Cache


    logger.info("Total number of cache entries removed = " + count);
  }
 
  public static Cache load(String siteId, Long cacheId) throws SecurityException, Exception {
      EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    Cache cache = (Cache) em.find(Cache.class, cacheId);
    if (!cache.getSiteId().equals(siteId)) {
      throw new SecurityException("");
    }
    return cache;
  }
View Full Code Here


    return cache;
  }
 
  public static void removeByKey(String siteId, String cacheKey) throws Exception {
      EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    Cache cache = loadByKey(siteId, cacheKey);
    if (cache != null) {
      em.remove(cache);
    }
  }
View Full Code Here

      Query query = em.createQuery(sql);
      query.setParameter("siteId", siteId);
      query.setParameter("cacheKey", cacheKey + "%");
      Iterator<?> iterator = query.getResultList().iterator();
      while (iterator.hasNext()) {
        Cache cache = (Cache) iterator.next();
        em.remove(cache);
      }
  }
View Full Code Here

        em.remove(cache);
      }
  }
 
  public static Cache loadByKey(String siteId, String cacheKey) throws SecurityException, Exception {
    Cache cache = null;
    try {
        EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
        String sql = "select cache " +
             "from   Cache cache " +
             "inner  join cache.site site " +
View Full Code Here

               "where  site.siteId = :siteId " +
               "and    cache.cacheKey = :cacheKey";
      Query query = em.createQuery(sql);
      query.setParameter("siteId", siteId);
      query.setParameter("cacheKey", cacheKey);
    Cache cache = null;
    try {
      cache = (Cache) query.getSingleResult();
    }
    catch (javax.persistence.NoResultException e) {}
      if (cache == null) {
        return null;
      }
      ByteArrayInputStream stream = new ByteArrayInputStream(cache.getCacheValue());
      ObjectInput in = new ObjectInputStream(stream);
      Object object = in.readObject();
      return object;
     
  }
View Full Code Here

               "where  site.siteId = :siteId " +
               "and    cache.cacheKey = :cacheKey";
      Query query = em.createQuery(sql);
      query.setParameter("siteId", siteId);
      query.setParameter("cacheKey", cacheKey);
    Cache cache = null;
    try {
      cache = (Cache) query.getSingleResult();
    }
    catch (javax.persistence.NoResultException e) {}
      if (cache == null) {
        return null;
      }
      return cache.getCacheText();
     
  }
View Full Code Here

     
  }
 
  public static void setCacheText(Site site, String cacheKey, char cacheTypeCode, String cacheValue) throws Exception {
      EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
      Cache cache = loadByKey(site.getSiteId(), cacheKey);
      boolean exist = true;
      if (cache == null) {
        cache = new Cache();
        exist = false;
        cache.setCacheTypeCode(cacheTypeCode);
        cache.setRecCreateBy(Constants.USERNAME_SYSTEM);
        cache.setRecCreateDatetime(new Date());
      }
      cache.setSite(site);
      cache.setCacheKey(cacheKey);
      cache.setCacheText(cacheValue);
    cache.setRecUpdateBy(Constants.USERNAME_SYSTEM);
    cache.setRecUpdateDatetime(new Date());
    if (!exist) {
      em.persist(cache);
    }
  }
View Full Code Here

      ObjectOutput out = new ObjectOutputStream(stream);
      out.writeObject(object);
      out.close();
      cacheValue = stream.toByteArray();
     
      Cache cache = loadByKey(site.getSiteId(), cacheKey);
      boolean exist = true;
      if (cache == null) {
        cache = new Cache();
        exist = false;
        cache.setCacheTypeCode(cacheTypeCode);
        cache.setRecCreateBy(Constants.USERNAME_SYSTEM);
        cache.setRecCreateDatetime(new Date());
      }
      cache.setSite(site);
      cache.setCacheKey(cacheKey);
      cache.setCacheValue(cacheValue);
    cache.setRecUpdateBy(Constants.USERNAME_SYSTEM);
    cache.setRecUpdateDatetime(new Date());
    if (!exist) {
      em.persist(cache);
    }
  }
View Full Code Here

    }
    cacheKey += id;
  }
 
  public void fail() throws SecurityException, Exception {
    Cache cache = CacheDAO.loadByKey(site.getSiteId(), cacheKey);
    int suspendCount = 0;
    if (cache != null) {
      String tokens[] = cache.getCacheText().split("\\|");
      suspendCount = Integer.parseInt(tokens[1]);
    }
   
    suspendCount++;
    String cacheText = (new Date()).getTime() + "|" + suspendCount;
View Full Code Here

  public void reset() throws Exception {
    CacheDAO.removeByKey(site.getSiteId(), cacheKey);
  }
 
  public boolean isSuspened() throws SecurityException, Exception {
    Cache cache = CacheDAO.loadByKey(site.getSiteId(), cacheKey);
    if (cache == null) {
      return false;
    }
   
    String tokens[] = cache.getCacheText().split("\\|");
    int suspendCount = Integer.parseInt(tokens[1]);
    if (suspendCount < Constants.ID_SUSPEND_COUNT) {
      return false;
    }
   
View Full Code Here

TOP

Related Classes of com.jada.jpa.entity.Cache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.