Mondrian - 设置数据库模式定义

时间:2016-12-07 20:17:45

标签: java database mondrian

我和mondrian一起工​​作,我有一些工作正常的代码定义。 现在我想在我的代码上设置一个不同的数据库模式,mondrian将从中获取查询结果,但我无法找到这样做的地方。

蒙德里安立方体的定义如下:

<Schema name="Cubo">
  <Cube name="PERM_PD" cache="true" enabled="true">
    <Table name="FACT_PERM_PD">
    </Table>
    <Dimension foreignKey="STE_ID" highCardinality="false" name="ESTADO">
      <Hierarchy name="ESTADO" hasAll="true" allMemberName="Todos" primaryKey="STE_ID">
        <Table name="OLAP_ESTADO">
        </Table>
        <Level name="ESTADO.STE_NAME" table="OLAP_ESTADO" column="STE_NAME" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension foreignKey="TIPO_ID" highCardinality="false" name="TIPO_DOCUMENTO">
      <Hierarchy name="TIPO_DOCUMENTO" hasAll="true" allMemberName="Todos" primaryKey="TIPO_ID">
        <Table name="OLAP_TIPO_DOCUMENTO">
        </Table>
        <Level name="TIPO_DOCUMENTO.TIPO_NAME" table="OLAP_TIPO_DOCUMENTO" column="TIPO_NAME" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension highCardinality="false" name="FECHA">
      <Hierarchy name="FECHA" hasAll="true" allMemberName="Todos">
        <Level name="DATE.YEAR" column="YEAR" type="Numeric" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
        </Level>
        <Level name="DATE.MONTH" column="MONTH" type="Numeric" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
        </Level>
        <Level name="DATE.DAY" column="DAY" type="Numeric" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
        </Level>
        <Level name="DATE.HOUR" column="HOUR" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension foreignKey="TEMA_ID" highCardinality="false" name="TEMA">
      <Hierarchy name="TEMA" hasAll="true" allMemberName="Todos" primaryKey="TEMA_ID">
        <Table name="OLAP_TEMA">
        </Table>
        <Level name="TEMA.TEMA_NAME" table="OLAP_TEMA" column="TEMA_NAME" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension highCardinality="false" name="DOC">
      <Hierarchy name="DOC" hasAll="true" allMemberName="Todos">
        <Level name="DOC_ID" column="DCMT_ID" type="Numeric" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>        
    <Measure name="TIEMPO TOTAL" column="UNIDAD_TIME" datatype="Integer" formatString="#.##0" aggregator="sum">
    </Measure>
    <Measure name="DIAS" column="UNIDAD_TIME" datatype="Numeric" formatString="#,###.####" aggregator="avg">
    </Measure>
  </Cube> 
</Schema>

我有以下mondrian查询定义:

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

<% String iUrl = request.getParameter("iUrl");
String docLink = "../" + iUrl + "/AbrirDocServlet?id={0}";%>

<jp:mondrianQuery id="query01" dataSource="jdbc/olapDB" catalogUri="/WEB-INF/queries/Cubo.mondrian.xml">
select NON EMPTY {[Measures].[DIAS]} ON COLUMNS,
  NON EMPTY {([TIPO_DOCUMENTO.TIPO_DOCUMENTO].[Todos], [TEMA.TEMA].[Todos], [DEPENDENCIA.DEPENDENCIA].[Todos], [FECHA.FECHA].[Todos], [DOC.DOC].[Todos])} ON ROWS from [PERM]
<jp:clickable urlPattern="<%=docLink%>" uniqueName="[DOC.DOC]"/>
</jp:mondrianQuery>

1 个答案:

答案 0 :(得分:2)

最后我自己找到了解决方案。

要定义要使用的数据库模式,我将属性 schema 添加到标记 Table ,如下所示:

<Table name="TABLE_NAME" schema="%SCHEMA%">

然后动态更改模式名称我覆盖FilterDynamicSchemaProcessor的过滤器函数:

public class DynamicSchemaProcessor extends FilterDynamicSchemaProcessor {

    @Override
    protected String filter(final String schemaUrl, final Util.PropertyList connectInfo, final InputStream stream) throws java.lang.Exception {
        String originalSchema = super.filter(schemaUrl, connectInfo, stream);       
        return originalSchema.replace("%SCHEMA%", schema);
    }
}

要将此自定义过滤器设置为我的mondrianQuery,我添加了一个引用新类的dynResolver属性:

<jp:mondrianQuery id="query" dataSource="jdbc/DB" dynResolver="com.company.mondrian.filters.DynamicSchemaProcessor" catalogUri="/WEB-INF/queries/Cube.mondrian.xml">