001 package railo.runtime.tag; 002 003 import org.apache.oro.text.regex.MalformedPatternException; 004 005 import railo.commons.lang.StringUtil; 006 import railo.runtime.exp.ApplicationException; 007 import railo.runtime.exp.PageException; 008 import railo.runtime.ext.tag.TagImpl; 009 import railo.runtime.op.Caster; 010 import railo.runtime.query.QueryCacheFilter; 011 import railo.runtime.query.QueryCacheFilterImpl; 012 import railo.runtime.query.QueryCacheFilterUDF; 013 import railo.runtime.query.QueryCacheSupport; 014 import railo.runtime.type.UDF; 015 016 /** 017 * Flushes the query cache 018 * 019 * 020 * 021 **/ 022 public final class ObjectCache extends TagImpl { 023 024 /** Clears queries from the cache in the Application scope. */ 025 private String action="clear"; 026 private QueryCacheFilter filter; 027 private String result="cfObjectCache"; 028 029 /** set the value action 030 * Clears queries from the cache in the Application scope. 031 * @param action value to set 032 **/ 033 public void setAction(String action) { 034 this.action=action; 035 } 036 public void setResult(String result) { 037 this.result=result; 038 } 039 040 public void setFilter(Object filter) throws PageException { 041 this.filter=createFilter(filter, false); 042 } 043 044 public void setFilter(String filter) throws PageException { 045 this.filter=createFilter(filter, false); 046 } 047 048 public void setFilterignorecase(String filter) throws PageException { 049 this.filter=createFilter(filter, true); 050 } 051 052 053 054 public static QueryCacheFilter createFilter(Object filter,boolean ignoreCase) throws PageException { 055 if(filter instanceof UDF) 056 return createFilter((UDF)filter); 057 return createFilter(Caster.toString(filter),ignoreCase); 058 } 059 060 061 public static QueryCacheFilter createFilter(UDF filter) throws PageException { 062 return new QueryCacheFilterUDF(filter); 063 } 064 065 public static QueryCacheFilter createFilter(String pattern,boolean ignoreCase) throws PageException { 066 if(!StringUtil.isEmpty(pattern,true)) { 067 try { 068 return new QueryCacheFilterImpl(pattern,ignoreCase); 069 } catch (MalformedPatternException e) { 070 throw Caster.toPageException(e); 071 } 072 } 073 return null; 074 } 075 076 077 078 079 080 081 082 /** 083 * @see javax.servlet.jsp.tagext.Tag#doStartTag() 084 */ 085 public int doStartTag() throws PageException { 086 _doStartTag(); 087 return SKIP_BODY; 088 } 089 public void _doStartTag() throws PageException { 090 QueryCacheSupport qc = ((QueryCacheSupport)pageContext.getQueryCache()); 091 if(action.equalsIgnoreCase("clear")) { 092 if(filter==null) 093 qc.clear(); 094 else 095 qc.clear(filter); 096 } 097 else if(action.equalsIgnoreCase("size")) { 098 pageContext.setVariable(result, Caster.toDouble(qc.size())); 099 } 100 else throw new ApplicationException("attribute action has a invalid value ["+action+"], valid is only [clear,size]"); 101 102 103 104 } 105 106 /** 107 * @see javax.servlet.jsp.tagext.Tag#doEndTag() 108 */ 109 public int doEndTag() { 110 return EVAL_PAGE; 111 } 112 113 /** 114 * @see javax.servlet.jsp.tagext.Tag#release() 115 */ 116 public void release() { 117 super.release(); 118 action="clear"; 119 result="cfObjectCache"; 120 filter=null; 121 } 122 }