saiku中多cube排序问题

时间:2023-03-08 17:24:16
saiku中多cube排序问题

如题,一个schema中如果有多个cube(常有),那cube之间是如何排序显示的?

我们看一下OlapMetaExplorer.java文件的getConnection方法,其中有一行

Collections.sort(cubes, new SaikuCubeCaptionComparator());

这个就是为cubes排序的,而他的排序规则是SaikuCubeCaptionComparator,看一下SaikuCubeCaptionComparator的代码:

public class SaikuCubeCaptionComparator implements Comparator<SaikuCube> {

  public int compare( SaikuCube o1, SaikuCube o2 ) {
if ( o1.getCaption() == null || o2.getCaption() == null ) {
return 0;
}
return o1.getCaption().compareTo( o2.getCaption() );
}
}

其中java.lang.String.compareTo() 方法比较两个字符串的字典。比较是基于字符串中的每个字符的Unicode值,这就不符合我想要的效果

所以我修改了OlapMetaExplorer.java文件的getConnection方法:

//                            Collections.sort(cubes, new SaikuCubeCaptionComparator());
Collections.sort(cubes);

这样一来所有的cube就会name属性的按照首字母顺序来排序,之后我再修改所有cube的name属性(因为页面显示的时候显示的是caption属性的值,name属性可以任意修改):

<Cube name="1APPAZLTJ" caption="%{cube.name.APPAZLTJ}" visible="true" cache="false" enabled="true">

<Cube name="2YHZCSLTJ" caption="%{cube.name.YHZCSLTJ}" visible="true" cache="false" enabled="true">

<Cube name="3YHZXZLFX(NIAN)" caption="%{cube.name.YHZXZLFX(NIAN)}" visible="true" cache="false" enabled="true">

这样就可以按照我想要的顺序来显示了