public Handler(Query query, Form form) throws ResourceException { this.query = query; this.queryString = form.getQueryString(); for (QueryParameter p : query.getParameters()) { String name = p.getName(); String svalue = form.getFirstValue(name, true); switch (p.getType()) { case DATE: parameters.put(p, readParameterValue(Date.class, p, svalue)); break; case NUMBER: parameters.put(p, readParameterValue(BigDecimal.class, p, svalue)); break; case STRING: parameters.put(p, readParameterValue(String.class, p, svalue)); break; case CLOB: case BLOB: throw new ClientErrorException( Status.CLIENT_ERROR_BAD_REQUEST, String.format("LOBs are not supported as parameters: %s", name)); } } if (log.isDebugEnabled()) { for (QueryParameter qp : parameters.keySet()) { log.debug(qp.toString(parameters.get(qp))); } } }
public void setCached(C data) { if (query.isCacheable()) { Cache cache = ccf.get(query); if (cache != null) { cache.put(new Element(getId(), data)); if (query.getHitCount() > 0 && !query.isEternal()) { CacheStats cs = getCacheStats(); ccf.createCacheJob(this, cs.getExpTime()); } if (log.isDebugEnabled()) { log.debug(String.format("Element %s put into %s cache", getId(), query.getQid())); } } } }
@SuppressWarnings("unchecked") public C getCached() { if (query.isCacheable()) { Cache cache = ccf.get(query); if (cache == null) { if (log.isDebugEnabled()) { log.debug(String.format("Cache for %s not found", this)); } } else { if (log.isDebugEnabled()) { log.debug(String.format("Cache for %s found", this)); } if (cache.isKeyInCache(getId())) { Element el = cache.get(getId()); boolean expired = (el == null || el.isExpired()); if (log.isDebugEnabled()) { log.debug( String.format( "Element %d found in %s cache (expired = %s)", getId(), query.getQid(), expired)); } if (el != null && !expired) { return (C) el.getObjectValue(); } } else { if (log.isDebugEnabled()) { log.debug(String.format("Element %d not found in %s cache", getId(), query.getQid())); } } } } return (C) null; }
public CacheStats getCacheStats() { CacheStats cs = new CacheStats(); if (query.isCacheable()) { Cache cache = ccf.get(query); if (cache != null) { if (cache.isKeyInCache(getId())) { Element el = cache.get(getId()); cs.setExpired(el == null || el.isExpired()); if (el != null && !cs.isExpired()) { cs.setLastUpdate(el.getLastUpdateTime()); cs.setExpTime(el.getExpirationTime()); cs.setHitCount(el.getHitCount()); } } } } return cs; }