gpt4 book ai didi

java - Mondrian - 设置数据库模式定义

转载 作者:行者123 更新时间:2023-12-02 03:11:12 26 4
gpt4 key购买 nike

我正在与 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>

最佳答案

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

为了定义要使用的数据库模式,我将属性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">

关于java - Mondrian - 设置数据库模式定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41026593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com