蒙德里安 - 设置数据库架构定义
Mondrian - Set database schema definition
我正在与 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>
我有以下蒙德里安查询定义:
<%@ 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>
最后我自己找到了解决办法。
为了定义要使用的数据库模式,我将 属性 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,我添加了一个引用新 class:
的 dynResolver 属性
<jp:mondrianQuery id="query" dataSource="jdbc/DB" dynResolver="com.company.mondrian.filters.DynamicSchemaProcessor" catalogUri="/WEB-INF/queries/Cube.mondrian.xml">
我正在与 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>
我有以下蒙德里安查询定义:
<%@ 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>
最后我自己找到了解决办法。
为了定义要使用的数据库模式,我将 属性 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,我添加了一个引用新 class:
的 dynResolver 属性<jp:mondrianQuery id="query" dataSource="jdbc/DB" dynResolver="com.company.mondrian.filters.DynamicSchemaProcessor" catalogUri="/WEB-INF/queries/Cube.mondrian.xml">