summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlzhang2011-09-27 05:14:14 (EDT)
committer xgu2011-09-27 05:14:14 (EDT)
commit3eda780182ee5a7ef3a316f7ff8d8211e0ad1c84 (patch)
treec868916656a4f55df60845aab0ada3e3e3144646
parentb6a893f00fcab247f00f39cfc2487df934cc60a2 (diff)
downloadorg.eclipse.birt-3eda780182ee5a7ef3a316f7ff8d8211e0ad1c84.zip
org.eclipse.birt-3eda780182ee5a7ef3a316f7ff8d8211e0ad1c84.tar.gz
org.eclipse.birt-3eda780182ee5a7ef3a316f7ff8d8211e0ad1c84.tar.bz2
Checkin: Add Support for MDX function
"YearToDate,QuarterToDate,PreviousNPeriod"
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java57
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/QuarterToDateFunction.java80
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java20
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/YearToDateFunction.java76
4 files changed, 228 insertions, 5 deletions
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java
new file mode 100644
index 0000000..20c0dcb
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java
@@ -0,0 +1,57 @@
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+public class PreviousNPeriodsFunction extends AbstractMDX implements IParallelPeriod
+{
+ private String levelName;
+ private int offset;
+
+ public PreviousNPeriodsFunction( String levelName, int offset )
+ {
+ this.levelName = levelName;
+ this.offset = offset;
+ }
+
+ public String getLevelName( )
+ {
+ return levelName;
+ }
+
+ public int getOffset()
+ {
+ return offset;
+ }
+
+ public TimeMember getResult( TimeMember member )
+ {
+ String[] levels = member.getLevelType( );
+ int[] values = member.getMemberValue( );
+
+ Calendar cal = new GregorianCalendar( );
+ translateToCal( cal, levels, values );
+
+ if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
+ cal.add( Calendar.YEAR, -offset );
+ else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_QUARTER ) )
+ cal.add( Calendar.MONTH, -offset * 3 );
+ else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_MONTH ) )
+ cal.add( Calendar.MONTH, -offset );
+ else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
+ cal.add( Calendar.WEEK_OF_MONTH, -offset );
+ else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
+ cal.add( Calendar.WEEK_OF_YEAR, -offset );
+ else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH ) )
+ cal.add( Calendar.DAY_OF_MONTH, -offset );
+ else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR ) )
+ cal.add( Calendar.DAY_OF_YEAR, -offset );
+ else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) )
+ cal.add( Calendar.DAY_OF_WEEK, -offset );
+
+ int[] newValues = getValueFromCal( cal, levels );
+
+ TimeMember newMember = new TimeMember( newValues, levels );
+ return newMember;
+ }
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/QuarterToDateFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/QuarterToDateFunction.java
new file mode 100644
index 0000000..7ed94ed
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/QuarterToDateFunction.java
@@ -0,0 +1,80 @@
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+public class QuarterToDateFunction extends AbstractMDX implements IPeriodsFunction
+{
+
+ public List<TimeMember> getResult( TimeMember member )
+ {
+ String[] levels = member.getLevelType( );
+ int[] values = member.getMemberValue( );
+
+ Calendar cal = new GregorianCalendar();
+ String calculateUnit = this.translateToCal( cal, levels, values ) ;
+
+ List<TimeMember> list = new ArrayList<TimeMember>( );
+
+ if ( calculateUnit.equals( QUARTER ) )
+ {
+ TimeMember newMember = new TimeMember( values, levels );
+ list.add( newMember );
+ }
+ else if ( calculateUnit.equals( MONTH ) )
+ {
+ int month = cal.get( Calendar.MONTH ) + 1;
+ int quarter = cal.get( Calendar.MONTH ) / 3 + 1;
+ int startMonth = quarter * 3 - 2;
+ TimeMember newMember = null;
+ for ( int i = startMonth; i <= month; i++ )
+ {
+ int[] newValues = getValueFromCal( cal, levels );
+ newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ cal.add( Calendar.MONTH, -1 );
+ }
+ }
+ else if ( calculateUnit.equals( WEEK ) )
+ {
+ int weekOfYear = cal.get( Calendar.WEEK_OF_YEAR );
+ int quarter = cal.get( Calendar.MONTH ) / 3 + 1;
+ int startMonth = quarter * 3 - 2;
+
+ Calendar startCal = (Calendar)cal.clone( );
+ startCal.set( Calendar.MONTH, startMonth-1 );
+ startCal.set( Calendar.DAY_OF_MONTH, 1 );
+ int starWeek = startCal.get( Calendar.WEEK_OF_YEAR );
+ TimeMember newMember = null;
+ for ( int i = starWeek; i <= weekOfYear; i++ )
+ {
+ int[] newValues = getValueFromCal( cal, levels );
+ newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ cal.add( Calendar.WEEK_OF_YEAR, -1 );
+ }
+ }
+ else if ( calculateUnit.equals( DAY ) )
+ {
+ int dayOfYear = cal.get( Calendar.DAY_OF_YEAR );
+ int quarter = cal.get( Calendar.MONTH ) / 3 + 1;
+ int startMonth = quarter * 3 - 2;
+ Calendar startCal = (Calendar)cal.clone( );
+ startCal.set( Calendar.MONTH, startMonth-1 );
+ startCal.set( Calendar.DAY_OF_MONTH, 1 );
+ int startDay = startCal.get( Calendar.DAY_OF_YEAR );
+ TimeMember newMember = null;
+ for ( int i = startDay; i <= dayOfYear; i++ )
+ {
+ int[] newValues = getValueFromCal( cal, levels );
+ newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ cal.add( Calendar.DAY_OF_YEAR, -1 );
+ }
+ }
+
+ return list;
+ }
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java
index e759c19..d784378 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java
@@ -2,18 +2,28 @@ package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
public class TimeFunctionFactory
{
- public static IPeriodsFunction createPeriodsToDateFunction( String levelTYpe )
+ public static IPeriodsFunction createPeriodsToDateFunction( String levelType )
{
+ if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
+ return new YearToDateFunction( );
+ else if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_QUARTER ) )
+ return new QuarterToDateFunction( );
+ else if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_MONTH ) )
+ return new MonthToDateFunction( );
+ else if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
+ return new WeekToDateFunciton( );
+ else if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
+ return new WeekToDateFunciton( );
return null;
}
- public static IPeriodsFunction createTrailingFunction( String levelTYpe, int Offset )
+ public static IPeriodsFunction createTrailingFunction( String levelType, int Offset )
{
- return new TrailingFunction(levelTYpe, Offset);
+ return new TrailingFunction( levelType, Offset );
}
- public static IParallelPeriod createParallelPeriodFunction( String levelTYpe, int Offset )
+ public static IParallelPeriod createParallelPeriodFunction( String levelType, int Offset )
{
- return null;
+ return new PreviousNPeriodsFunction( levelType, Offset );
}
}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/YearToDateFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/YearToDateFunction.java
new file mode 100644
index 0000000..1a0c97f
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/YearToDateFunction.java
@@ -0,0 +1,76 @@
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+
+public class YearToDateFunction extends AbstractMDX implements IPeriodsFunction
+{
+ public List<TimeMember> getResult( TimeMember member )
+ {
+ String[] levels = member.getLevelType( );
+ int[] values = member.getMemberValue( );
+
+ Calendar cal = new GregorianCalendar();
+ String calculateUnit = this.translateToCal( cal, levels, values ) ;
+
+ List<TimeMember> list = new ArrayList<TimeMember>( );
+ if ( calculateUnit.equals( YEAR ) )
+ {
+ TimeMember newMember = new TimeMember( values, levels );
+ list.add( newMember );
+ }
+ else if ( calculateUnit.equals( QUARTER ) )
+ {
+ int quarter = cal.get( Calendar.MONTH ) / 3 + 1;
+ TimeMember newMember = null;
+ for ( int i = 1; i <= quarter; i++ )
+ {
+ int[] newValues = getValueFromCal( cal, levels );
+ newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ cal.add( Calendar.MONTH, -3 );
+ }
+ }
+ else if ( calculateUnit.equals( MONTH ) )
+ {
+ int month = cal.get( Calendar.MONTH )+1;
+ TimeMember newMember = null;
+ for( int i=1; i<=month ; i++)
+ {
+ int[] newValues = getValueFromCal( cal,levels);
+ newMember = new TimeMember(newValues,levels);
+ list.add( newMember );
+ cal.add( Calendar.MONTH, -1 );
+ }
+ }
+ else if ( calculateUnit.equals( WEEK ) )
+ {
+ int weekOfYear = cal.get( Calendar.WEEK_OF_YEAR );
+ TimeMember newMember = null;
+ for ( int i = 1; i <= weekOfYear; i++ )
+ {
+ int[] newValues = getValueFromCal( cal, levels );
+ newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ cal.add( Calendar.WEEK_OF_YEAR, -1 );
+ }
+ }
+ else if ( calculateUnit.equals( DAY ) )
+ {
+ int dayOfYear = cal.get( Calendar.DAY_OF_YEAR );
+ TimeMember newMember = null;
+ for ( int i = 1; i <= dayOfYear; i++ )
+ {
+ int[] newValues = getValueFromCal( cal, levels );
+ newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ cal.add( Calendar.DAY_OF_YEAR, -1 );
+ }
+ }
+
+ return list;
+ }
+}