001 /* 002 // $Id: //open/mondrian/src/main/mondrian/rolap/RolapCalculatedMember.java#27 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2001-2002 Kana Software, Inc. 007 // Copyright (C) 2001-2007 Julian Hyde and others 008 // All Rights Reserved. 009 // You must accept the terms of that agreement to use this software. 010 // 011 // jhyde, 26 August, 2001 012 */ 013 014 package mondrian.rolap; 015 016 import mondrian.olap.*; 017 018 /** 019 * A <code>RolapCalculatedMember</code> is a member based upon a 020 * {@link Formula}. 021 * 022 * <p>It is created before the formula has been resolved; the formula is 023 * responsible for setting the "format_string" property. 024 * 025 * @author jhyde 026 * @since 26 August, 2001 027 * @version $Id: //open/mondrian/src/main/mondrian/rolap/RolapCalculatedMember.java#27 $ 028 */ 029 public class RolapCalculatedMember extends RolapMember { 030 private final Formula formula; 031 032 RolapCalculatedMember( 033 RolapMember parentMember, RolapLevel level, String name, 034 Formula formula) 035 { 036 // A calculated measure has MemberType.FORMULA because FORMULA 037 // overrides MEASURE. 038 super(parentMember, level, name, null, MemberType.FORMULA); 039 this.formula = formula; 040 } 041 042 // override RolapMember 043 public int getSolveOrder() { 044 final Number solveOrder = formula.getSolveOrder(); 045 return solveOrder == null ? 0 : solveOrder.intValue(); 046 } 047 048 public Object getPropertyValue(String propertyName, boolean matchCase) { 049 if (Util.equal(propertyName, Property.FORMULA.name, matchCase)) { 050 return formula; 051 } else if (Util.equal(propertyName, Property.CHILDREN_CARDINALITY.name, matchCase)) { 052 // Looking up children is unnecessary for calculated member. 053 // If do that, SQLException will be thrown. 054 return 0; 055 } else { 056 return super.getPropertyValue(propertyName, matchCase); 057 } 058 } 059 060 protected boolean computeCalculated(final MemberType memberType) { 061 return true; 062 } 063 064 public boolean isCalculatedInQuery() { 065 final String memberScope = 066 (String) getPropertyValue(Property.MEMBER_SCOPE.name); 067 return memberScope == null || 068 memberScope.equals("QUERY"); 069 } 070 071 public Exp getExpression() { 072 return formula.getExpression(); 073 } 074 075 public Formula getFormula() { 076 return formula; 077 } 078 } 079 080 081 // End RolapCalculatedMember.java