001 /* 002 // This software is subject to the terms of the Common Public License 003 // Agreement, available at the following URL: 004 // http://www.opensource.org/licenses/cpl.html. 005 // Copyright (C) 2007-2007 Julian Hyde 006 // All Rights Reserved. 007 // You must accept the terms of that agreement to use this software. 008 */ 009 package mondrian.olap4j; 010 011 import mondrian.olap.Property; 012 import mondrian.rolap.*; 013 import org.olap4j.metadata.Datatype; 014 import org.olap4j.metadata.Measure; 015 016 /** 017 * Implementation of {@link org.olap4j.metadata.Measure} 018 * for the Mondrian OLAP engine, 019 * as a wrapper around a mondrian 020 * {@link mondrian.rolap.RolapStoredMeasure}. 021 * 022 * @author jhyde 023 * @version $Id: //open/mondrian/src/main/mondrian/olap4j/MondrianOlap4jMeasure.java#3 $ 024 * @since Dec 10, 2007 025 */ 026 public class MondrianOlap4jMeasure 027 extends MondrianOlap4jMember 028 implements Measure 029 { 030 MondrianOlap4jMeasure( 031 MondrianOlap4jSchema olap4jSchema, 032 RolapMeasure measure) 033 { 034 super(olap4jSchema, measure); 035 } 036 037 public String toString() { 038 return getUniqueName(); 039 } 040 041 public Aggregator getAggregator() { 042 if (!(member instanceof RolapStoredMeasure)) { 043 return Aggregator.UNKNOWN; 044 } 045 final RolapAggregator aggregator = 046 ((RolapStoredMeasure) member).getAggregator(); 047 if (aggregator == RolapAggregator.Avg) { 048 return Aggregator.AVG; 049 } else if (aggregator == RolapAggregator.Count) { 050 return Aggregator.COUNT; 051 } else if (aggregator == RolapAggregator.DistinctCount) { 052 return Aggregator.UNKNOWN; 053 } else if (aggregator == RolapAggregator.Max) { 054 return Aggregator.MAX; 055 } else if (aggregator == RolapAggregator.Min) { 056 return Aggregator.MIN; 057 } else if (aggregator == RolapAggregator.Sum) { 058 return Aggregator.SUM; 059 } else { 060 return Aggregator.UNKNOWN; 061 } 062 } 063 064 public Datatype getDatatype() { 065 final String datatype = 066 (String) member.getPropertyValue(Property.DATATYPE.getName()); 067 if (datatype != null) { 068 if (datatype.equals("Integer")) { 069 return Datatype.INTEGER; 070 } else if (datatype.equals("Numeric")) { 071 return Datatype.DOUBLE; 072 } 073 } 074 return Datatype.STRING; 075 } 076 077 public boolean isVisible() { 078 return (Boolean) member.getPropertyValue(Property.VISIBLE.getName()); 079 } 080 } 081 082 // End MondrianOlap4jMeasure.java