KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > mondrian > MondrianSqlAccess


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.mondrian;
14
15 import javax.sql.DataSource JavaDoc;
16
17 import mondrian.rolap.RolapMember;
18
19 import org.apache.log4j.Logger;
20
21 import com.tonbeller.jpivot.core.ExtensionSupport;
22 import com.tonbeller.jpivot.olap.model.Member;
23 import com.tonbeller.jpivot.olap.navi.ExpressionParser;
24 import com.tonbeller.jpivot.param.SqlAccess;
25 import com.tonbeller.wcf.param.SessionParam;
26
27 /**
28  * @author av
29  */

30 public class MondrianSqlAccess extends ExtensionSupport implements SqlAccess {
31   private static Logger logger = Logger.getLogger(MondrianSqlAccess.class);
32   
33   public DataSource JavaDoc getDataSource() {
34     MondrianModel mm = (MondrianModel) getModel();
35     return mm.getSqlDataSource();
36   }
37
38   public SessionParam createParameter(Member member, String JavaDoc paramName) {
39     MondrianMember mm = (MondrianMember) member;
40     RolapMember rm = (RolapMember) mm.getMonMember();
41     paramName = checkParamName(paramName, rm);
42     // All or calculated?
43
if (rm.getSqlKey() == null)
44       return null;
45     SessionParam p = new SessionParam();
46     p.setSqlValue(rm.getSqlKey());
47     p.setDisplayName(member.getLevel().getLabel());
48     p.setDisplayValue(member.getLabel());
49
50     ExpressionParser parser = (ExpressionParser) getModel().getExtension(ExpressionParser.ID);
51     if (parser != null)
52       p.setMdxValue(parser.unparse(member));
53
54     p.setName(paramName);
55     return p;
56   }
57
58   private String JavaDoc checkParamName(String JavaDoc paramName, RolapMember rm) {
59     if (paramName != null)
60       return paramName;
61     return MondrianUtil.defaultParamName(rm);
62   }
63
64   public SessionParam createParameter(Member member, String JavaDoc paramName, String JavaDoc propertyName) {
65     MondrianMember mm = (MondrianMember) member;
66     RolapMember rm = (RolapMember) mm.getMonMember();
67     paramName = checkParamName(paramName, rm);
68     // propertyValue may be null
69
Object JavaDoc propertyValue = rm.getPropertyValue(propertyName);
70     SessionParam p = new SessionParam();
71     p.setSqlValue(propertyValue);
72     p.setDisplayName(member.getLevel().getLabel());
73     p.setDisplayValue(member.getLabel());
74
75     ExpressionParser parser = (ExpressionParser) getModel().getExtension(ExpressionParser.ID);
76     if (parser != null)
77       p.setMdxValue(parser.unparse(member));
78     p.setName(paramName);
79     return p;
80   }
81
82 }
Popular Tags