Skip to content

Commit

Permalink
MONDRIAN: Move writeback APIs (Scenario etc.) to olap4j.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 13070]
  • Loading branch information
julianhyde committed Sep 29, 2009
1 parent f07f92c commit eee6414
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 258 deletions.
2 changes: 1 addition & 1 deletion ivy.xml
Expand Up @@ -55,7 +55,7 @@
<dependency org="javax.servlet" name="jsp-api" rev="2.0"/>
<dependency org="javax.servlet" name="servlet-api" rev="2.4"/>
<dependency org="log4j" name="log4j" rev="1.2.9"/>
<dependency org="org.olap4j" name="olap4j" rev="0.9.7.241"
<dependency org="org.olap4j" name="olap4j" rev="0.9.7.277"
conf="default->default" changing="true">
<artifact name="olap4j"/>
<artifact name="olap4j" type="source" ext="jar"
Expand Down
99 changes: 9 additions & 90 deletions src/main/mondrian/olap/Cell.java
Expand Up @@ -13,6 +13,9 @@

package mondrian.olap;

import org.olap4j.Scenario;
import org.olap4j.AllocationPolicy;

import java.util.List;

/**
Expand Down Expand Up @@ -128,102 +131,18 @@ public interface Cell {
Member getContextMember(Dimension dimension);

/**
* Sets the value of a cell.
*
* <p>The connection must have an active scenario; see
* {@link Connection#setScenario(Scenario)}.
* Helper method to implement {@link org.olap4j.Cell#setValue}.
*
* @param value Cell value
* @param scenario Scenario
* @param newValue New value
* @param allocationPolicy Allocation policy
* @param allocationArgs Allocation policy arguments
* @param allocationArgs Arguments for allocation policy
*/
void setValue(
Object value,
Scenario scenario,
Object newValue,
AllocationPolicy allocationPolicy,
Object... allocationArgs);

/**
* TODO: document; move to olap4j
*/
enum AllocationPolicy {
/**
* Every atomic cell that contributes to the updated cell will be
* assigned an equal value that is:
*
* <blockquote>
* &lt;atomic cell value&gt; =
* &lt;value&gt; / Count(atomic cells contained in &lt;tuple&gt;)
* </blockquote>
*/
EQUAL_ALLOCATION,

/**
* Every atomic cell that contributes to the updated cell will be
* changed according to:
*
* <blockquote>
* &lt;atomic cell value&gt; = &lt;atomic cell value&gt; +
* (&lt;value&gt; - &lt;existing value&gt;) /
* Count(atomic cells contained in &lt;tuple&gt;)
* </blockquote>
*/
EQUAL_INCREMENT,

/**
* Every atomic cell that contributes to the updated cell will be
* assigned an equal value that is:
*
* <blockquote>
* &lt;atomic cell value&gt; =
* &lt;value&gt; * &lt;weight value expression&gt;
* </blockquote>
*
* <p>Takes an optional argument, {@code weight_value_expression}.
* If {@code weight_value_expression} is not provided, the following
* expression is assigned to it by default:
*
* <blockquote>
* &lt;weight value expression&gt; =
* &lt;atomic cell value&gt; / &lt;existing value&gt;
* <blockquote>
*
* <p>The value of {@code weight value expression} should be expressed
* as a value between 0 and 1. This value specifies the ratio of the
* allocated value you want to assign to the atomic cells that are
* affected by the allocation. It is the client application programmer's
* responsibilffity to create expressions whose rollup aggregate values
* will equal the allocated value of the expression.
*/
WEIGHTED_ALLOCATION,

/**
* Every atomic cell that contributes to the updated cell will be
* changed according to:
*
* <blockquote>
* &lt;atomic cell value&gt; = &lt;atomic cell value&gt; +
* (&lt;value&gt; - &lt;existing value&gt;) *
* &lt;weight value expression&gt;
* </blockquote>
*
* <p>Takes an optional argument, {@code weight_value_expression}.
* If {@code weight_value_expression} is not provided, the following
* expression is assigned to it by default:
*
* <blockquote>
* &lt;weight value expression&gt; =
* &lt;atomic cell value&gt; / &lt;existing value&gt;
* <blockquote>
*
* <p>The value of {@code weight value expression} should be expressed
* as a value between 0 and 1. This value specifies the ratio of the
* allocated value you want to assign to the atomic cells that are
* affected by the allocation. It is the client application programmer's
* responsibility to create expressions whose rollup aggregate values
* will equal the allocated value of the expression.
*/
WEIGHTED_INCREMENT,
}
}

// End Cell.java
38 changes: 0 additions & 38 deletions src/main/mondrian/olap/Connection.java
Expand Up @@ -123,44 +123,6 @@ public interface Connection {
* @return Data source
*/
DataSource getDataSource();

/**
* Creates a Scenario.
*
* <p>It does not become the active scenario for the current connection.
* To do this, call {@link #setScenario(Scenario)}.
*
* @see #setScenario
*
* @return a new Scenario
*/
Scenario createScenario();

/**
* Sets the active Scenario of this connection.
*
* <p>After setting a scenario, the client may call
* {@link Cell#setValue} to change the value of cells returned
* from queries. The value of those cells is changed. This operation is
* referred to as 'writeback', and is used to perform 'what if' analysis,
* such as budgeting. See {@link mondrian.olap.Scenario} for more details.
*
* <p>If {@code scenario} is null, the connection will have no active
* scenario, and writeback is not allowed.
*
* <p>Scenarios are created using {@link #createScenario()}.
*
* @param scenario Scenario
*/
void setScenario(Scenario scenario);

/**
* Returns this connection's active Scenario, or null if there is no
* active Scenario.
*
* @return Active scenario, or null
*/
Scenario getScenario();
}

// End Connection.java
43 changes: 0 additions & 43 deletions src/main/mondrian/olap/Scenario.java

This file was deleted.

35 changes: 29 additions & 6 deletions src/main/mondrian/olap4j/MondrianOlap4jCell.java
Expand Up @@ -9,14 +9,11 @@
*/
package mondrian.olap4j;

import org.olap4j.Cell;
import org.olap4j.CellSet;
import org.olap4j.OlapException;
import org.olap4j.*;
import org.olap4j.metadata.Property;

import javax.sql.DataSource;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Proxy;

Expand All @@ -35,6 +32,13 @@ class MondrianOlap4jCell implements Cell {
private final MondrianOlap4jCellSet olap4jCellSet;
private final mondrian.olap.Cell cell;

/**
* Creates a MondrianOlap4jCell.
*
* @param coordinates Coordinates
* @param olap4jCellSet Cell set
* @param cell Cell in native Mondrian representation
*/
MondrianOlap4jCell(
int[] coordinates,
MondrianOlap4jCellSet olap4jCellSet,
Expand Down Expand Up @@ -139,12 +143,27 @@ public ResultSet drillThrough() throws OlapException {
}
}

public void setValue(
Object newValue,
AllocationPolicy allocationPolicy,
Object... allocationArgs)
{
Scenario scenario =
olap4jCellSet.olap4jStatement.olap4jConnection.getScenario();
cell.setValue(scenario, newValue, allocationPolicy, allocationArgs);
}

// must be public for reflection to work
public static class MyDelegatingInvocationHandler
extends DelegatingInvocationHandler
{
private final ResultSet resultSet;

/**
* Creates a MyDelegatingInvocationHandler.
*
* @param resultSet Result set
*/
MyDelegatingInvocationHandler(ResultSet resultSet) {
this.resultSet = resultSet;
}
Expand All @@ -153,7 +172,11 @@ protected Object getTarget() {
return resultSet;
}

// implement ResultSet.close()
/**
* Helper method to implement {@link java.sql.ResultSet#close()}.
*
* @throws SQLException on error
*/
public void close() throws SQLException {
resultSet.getStatement().getConnection().close();
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/mondrian/olap4j/MondrianOlap4jConnection.java
Expand Up @@ -11,7 +11,8 @@

import mondrian.mdx.*;
import mondrian.olap.*;
import mondrian.rolap.RolapMeasure;
import mondrian.rolap.*;

import org.olap4j.Axis;
import org.olap4j.Cell;
import org.olap4j.*;
Expand Down Expand Up @@ -76,6 +77,7 @@ abstract class MondrianOlap4jConnection implements OlapConnection {
private String roleName;
private boolean autoCommit;
private boolean readOnly;
private Scenario scenario;

/**
* Creates an Olap4j connection to Mondrian.
Expand Down Expand Up @@ -127,6 +129,18 @@ public OlapStatement createStatement() {
return new MondrianOlap4jStatement(this);
}

public ScenarioImpl createScenario() {
return ((RolapConnection) connection).createScenario();
}

public void setScenario(Scenario scenario) {
this.scenario = scenario;
}

public Scenario getScenario() {
return scenario;
}

public PreparedStatement prepareStatement(String sql) throws SQLException {
throw new UnsupportedOperationException();
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/mondrian/rolap/RolapCell.java
Expand Up @@ -17,6 +17,9 @@
import java.sql.*;
import java.util.*;

import org.olap4j.AllocationPolicy;
import org.olap4j.Scenario;

/**
* <code>RolapCell</code> implements {@link mondrian.olap.Cell} within a
* {@link RolapResult}.
Expand Down Expand Up @@ -233,6 +236,7 @@ public Member getContextMember(Dimension dimension) {
}

public void setValue(
Scenario scenario,
Object newValue,
AllocationPolicy allocationPolicy,
Object... allocationArgs)
Expand All @@ -242,7 +246,6 @@ public void setValue(
throw Util.newError(
"Allocation policy must not be null");
}
Scenario scenario = result.getQuery().getConnection().getScenario();
final RolapMember[] members = result.getCellMembers(pos);
for (int i = 0; i < members.length; i++) {
Member member = members[i];
Expand Down

0 comments on commit eee6414

Please sign in to comment.