1. 程式人生 > >Kettle執行完ETL後清空Mondrian快取

Kettle執行完ETL後清空Mondrian快取

如果資料發生變化,mondrian由於其cache的功能,查詢出來的資料並不是最新的,因此,可以在kettle執行完ETL任務以後清空mondrian快取。

做法是在ETL後連線Http client(核心物件-> 查詢 -> Http client),在其URL中填寫YourTomcatUrl/mondrian/testpage.jsp?query=flush

在tomcat裡的webapps\mondrian\WEB-INF\queries目錄下,新建一個flush.jsp 如下:

<%@ page session="true" contentType="text/html; charset=ISO-8859-1" %>
<%@ taglib uri="http://www.tonbeller.com/jpivot" prefix="jp" %>
<%@ taglib uri="http://www.tonbeller.com/wcf" prefix="wcf" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<%
java.util.Iterator<mondrian.rolap.RolapSchema> schemaIterator =  mondrian.rolap.RolapSchema.getRolapSchemas();
while(schemaIterator.hasNext()){
    mondrian.rolap.RolapSchema schema = schemaIterator.next();
    mondrian.olap.CacheControl cacheControl = schema.getInternalConnection().getCacheControl(null);
    
    for (mondrian.olap.Cube cube : schema.getCubes()) {
        cacheControl.flush(cacheControl.createMeasuresRegion(cube));
    }
}

String redirectURL = request.getHeader("Referer");
response.sendRedirect(redirectURL);        
%>