Skip to content

Commit

Permalink
Add PreparedOlapStatement.isSet(int) and .unset(int), and implement i…
Browse files Browse the repository at this point in the history
…n XMLA

driver. (These methods are implemented in the mondrian driver in eigenbase
change 13650.)

Add test for Member.getAncestorMembers().


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@314 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed May 29, 2010
1 parent d91ccf4 commit 24f806d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 17 deletions.
26 changes: 25 additions & 1 deletion src/org/olap4j/PreparedOlapStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2006-2008 Julian Hyde
// Copyright (C) 2006-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -94,6 +94,30 @@ public interface PreparedOlapStatement
*/
Cube getCube();

/**
* Returns whether the value of the designated parameter is set.
*
* <p>To set the value call one of the {@link #setInt setXxx} methods. To
* unset the value, call {@link #unset}.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @return whether the parameter's value has been set
* <code>ParameterMetaData.parameterNoNulls</code>,
* <code>ParameterMetaData.parameterNullable</code>, or
* <code>ParameterMetaData.parameterNullableUnknown</code>
* @exception java.sql.SQLException if a database access error occurs
*/
boolean isSet(int parameterIndex) throws SQLException;

/**
* Unsets the value of the designated parameter.
*
* @see #isSet(int)
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @exception java.sql.SQLException if a database access error occurs
*/
void unset(int parameterIndex) throws SQLException;
}

// End PreparedOlapStatement.java
12 changes: 11 additions & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2009 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -183,6 +183,14 @@ public void setBinaryStream(
getParameter(parameterIndex).setValue(x);
}

public void unset(int parameterIndex) throws SQLException {
getParameter(parameterIndex).unset();
}

public boolean isSet(int parameterIndex) throws SQLException {
return getParameter(parameterIndex).isSet();
}

public void clearParameters() throws SQLException {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -461,6 +469,8 @@ <T> T foo(XmlaOlap4jPreparedStatement.TypeHelper<T> helper, Type type) {
private interface Parameter {
String getName();
void setValue(Object o);
void unset();
boolean isSet();
}
}

Expand Down
64 changes: 49 additions & 15 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ public void testPreparedStatement() throws SQLException {
"MemberType<hierarchy=[Store]>",
olapType.toString());
break;
default:
throw Olap4jUtil.unexpected(method);
}
if (paramIndex != 1) {
fail("expected exception");
Expand All @@ -689,7 +691,7 @@ public void testPreparedStatement() throws SQLException {
assertEquals("Sales", metaData.getCube().getName());

String s = TestContext.toString(cellSet);
TestContext.assertEqualsVerbose(
final String expected =
"Axis #0:\n"
+ "{[Gender].[M]}\n"
+ "Axis #1:\n"
Expand All @@ -704,28 +706,44 @@ public void testPreparedStatement() throws SQLException {
+ "Row #0: 10,562\n"
+ "Row #0: 13,574\n"
+ "Row #0: 12,800\n"
+ "Row #0: 1,053\n",
s);
+ "Row #0: 1,053\n";
TestContext.assertEqualsVerbose(expected, s);

// Bind parameter and re-execute.
final List<Position> positions =
cellSet.getAxes().get(0).getPositions();
final Member member =
positions.get(positions.size() - 1).getMembers().get(0);
assertFalse(pstmt.isSet(1));

// parameter is 'set' even if value is null
pstmt.setObject(1, null);
assertTrue(pstmt.isSet(1));

pstmt.unset(1);
assertFalse(pstmt.isSet(1));

pstmt.setObject(1, member);
assertTrue(pstmt.isSet(1));
CellSet cellSet2 = pstmt.executeQuery();
assertIsClosed(cellSet, true);
assertIsClosed(cellSet2, false);
s = TestContext.toString(cellSet2);
TestContext.assertEqualsVerbose(
final String expected2 =
"Axis #0:\n"
+ "{[Gender].[M]}\n"
+ "Axis #1:\n"
+ "{[Store].[USA].[CA]}\n"
+ "{[Store].[USA].[CA].[San Francisco].[Store 14]}\n"
+ "Row #0: 37,989\n"
+ "Row #0: 1,053\n",
s);
+ "Row #0: 1,053\n";
TestContext.assertEqualsVerbose(expected2, s);

// Unset parameter and re-execute.
pstmt.unset(1);
cellSet = pstmt.executeQuery();
s = TestContext.toString(cellSet);
TestContext.assertEqualsVerbose(expected, s);

// Re-execute with a new MDX string.
CellSet cellSet3 = pstmt.executeOlapQuery(
Expand Down Expand Up @@ -1754,17 +1772,27 @@ public void testMetadata() throws Exception {
member.getLevel().getUniqueName());
assertEquals(Member.Type.REGULAR, member.getMemberType());

assertEquals(
"[Product].[Food].[Baked Goods]",
bread.getParentMember().getUniqueName());
final List<Member> list = bread.getAncestorMembers();
assertEquals(3, list.size());
assertEquals(
"[Product].[Food].[Baked Goods]", list.get(0).getUniqueName());
assertEquals("[Product].[Food]", list.get(1).getUniqueName());
assertEquals("[Product].[All Products]", list.get(2).getUniqueName());

assertEquals("Food", member.getCaption(null));

if (tester.getFlavor() != Tester.Flavor.XMLA) {
assertNull(member.getDescription(null));
assertEquals(1, member.getDepth());
assertEquals(-1, member.getSolveOrder());
assertFalse(member.isHidden());
assertNull(member.getDataMember());
assertFalse(member.isCalculatedInQuery());
assertNull(member.getDescription(null));
assertEquals(1, member.getDepth());
assertEquals(-1, member.getSolveOrder());
assertFalse(member.isHidden());
assertNull(member.getDataMember());
assertFalse(member.isCalculatedInQuery());
} else {
assertEquals("", member.getDescription(null));
assertEquals("", member.getDescription(null));
}

switch (tester.getFlavor()) {
Expand Down Expand Up @@ -1847,14 +1875,20 @@ public void testMetadata() throws Exception {
assertNotNull(measure.getName());
assertNotNull(measure.getAggregator());
assertTrue(measure.getDatatype() != null);
measureNameSet.add(measure.getName());
// mondrian's olap4j driver returns the invisible member
// [Measures].[Profit last Period]; the xmla driver does not,
// because XMLA by default does not return invisible measures.
if (measure.getName().equals("Profit last Period")) {
assertFalse(measure.isVisible());
} else {
measureNameSet.add(measure.getName());
}
}
assertEquals(
new HashSet<String>(
Arrays.asList(
"Unit Sales",
"Customer Count",
"Profit last Period",
"Profit",
"Profit Growth",
"Promotion Sales",
Expand Down

0 comments on commit 24f806d

Please sign in to comment.