Tag - mondrian3

saiku2 mondrian3 OpenSource OpenBI    2017-07-19 23:28:23    838
首先需要下载mondrian-3.6.5.jar的源码或者使用反编译软件看到源码,我在网上没找到这个版本(由于我用反编译工具弄的,放到文件中会报错,所以就下载了源码,反正也好找),于是我拿了mondrian-3.7.0.0-752的源码下来,用着也正常

1、从中找到文件mondrian.olap.Util,找到方法readVirtualFileAsString
修改内容为如下(重点是红色内容):
        InputStream in = readVirtualFile(catalogUrl);
        try {
            return IOUtils.toString(in,"utf-8");    //-----------------此行为红色行
        } finally {
            IOUtils.closeQuietly(in);
        }
或者按照网上说的另外一种方式,整体替换为如下内容,也可以,不过下面的编码必须写你的schema文件的编码:
        try {
            final byte[] bytes = Util. readFully(in, 1024);
            final char[] chars = new char[bytes. length];
            for ( int i = 0; i < chars. length; i++) {
                chars[i] = ( char) bytes[i];
            }
            String str = new String(bytes,"utf-8").replace("\ufeff" , "" );//加replace("\ufeff", "")是为了过滤"UTF-8无BOM格式文件"的开头
            return str;
        } finally {
            if (in != null) {
                in.close();
            }
        }

2、再找到文件    mondrian.rolap.RolapSchema.lo

mondrian3 OpenSource OpenBI    2017-07-19 23:22:56    919

1、根据文档中,比较费解,没有看太懂(并且部分文档的方法无法使用):http://mondrian.pentaho.com/documentation/cache_control.php

 

2、本来打算使用文档中的另一个方法

但是最终发现我完全从外部调用,哪里获取RolapConnection呢,于是,此方法宣告失败

public boolean clearCache() throws Exception {
    if ( olapConnection.isWrapperFor( RolapConnection.class ) ) {
      System.out.println( "Clearing cache" );
      RolapConnection rcon = olapConnection.unwrap( RolapConnection.class );
      rcon.getCacheControl( null ).flushSchemaCache();
    }
    return true;
  }

 

3、经过努力,找到别人的方法,此方法可行,原文是

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));
    }
}

但是对于我用的版本不对应,会报无法转换为Iterator,然后做了稍微修改,如下

List<mondrian.rola