Skip to content

Commit

Permalink
merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
pstoellberger committed Aug 12, 2013
2 parents e65544a + 670f52a commit f09bd79
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 221 deletions.
6 changes: 5 additions & 1 deletion saiku-bi-platform-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@
<id>pentaho-third-party</id>
<url>http://repo.pentaho.org/artifactory/third-party/</url>
</repository>

<repository>
<id>alabs-repo</id>
<name>alabs repository</name>
<url>http://repo.analytical-labs.com/repo/</url>
</repository>
<repository>
<id>ibiblio</id>
<url>http://ibiblio.org/maven2/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class MdxQuery implements IQuery {

private static final Logger log = LoggerFactory.getLogger(MdxQuery.class);

private Properties properties = new Properties();
private String mdx;
private SaikuCube cube;
Expand All @@ -56,14 +56,14 @@ public class MdxQuery implements IQuery {
private Scenario scenario;
private CellSet cellset;
private OlapStatement statement;

public MdxQuery(OlapConnection con, SaikuCube cube, String name, String mdx) {
this.cube = cube;
this.connection = con;
this.name = name;
this.mdx = mdx;
}

public String getName() {
return name;
}
Expand All @@ -87,60 +87,69 @@ public SaikuCube getSaikuCube() {
return cube;
}

public String getMdx() {
return mdx;
}
public void setMdx(String mdx) {
this.mdx = mdx;
}
public String getMdx() {
return mdx;
}

public void setMdx(String mdx) {
this.mdx = mdx;
}

public void resetQuery() {
this.mdx = "";
}
public void setProperties(Properties props) {
this.properties.putAll(props);
}
public Properties getProperties() {
Properties props = new Properties(this.properties);
props.put(QueryProperties.KEY_IS_DRILLTHROUGH, isDrillThroughEnabled().toString());
props.put("org.saiku.connection.scenario", Boolean.toString(false));
try {
props.put("org.saiku.query.explain", Boolean.toString(connection.isWrapperFor(RolapConnection.class)));
} catch (Exception e) {
props.put("org.saiku.query.explain", Boolean.toString(false));
}
return props;
}
public String toXml() {
QuerySerializer qs = new QuerySerializer(this);
return qs.createXML();
}
public Boolean isDrillThroughEnabled() {
try {
Cube cube = getCube();
return (cube != null && cube.isDrillThroughEnabled());
} catch (Exception e) {
e.printStackTrace();
};
return false;
}

public void setProperties(Properties props) {
this.properties.putAll(props);
}

public Properties getProperties() {
Properties props = this.properties;
props.put(QueryProperties.KEY_IS_DRILLTHROUGH, isDrillThroughEnabled().toString());
props.put("org.saiku.connection.scenario", Boolean.toString(false));
try {
props.put("org.saiku.query.explain", Boolean.toString(connection.isWrapperFor(RolapConnection.class)));
} catch (Exception e) {
props.put("org.saiku.query.explain", Boolean.toString(false));
}
return props;
}

public String toXml() {
QuerySerializer qs = new QuerySerializer(this);
return qs.createXML();
}

public Boolean isDrillThroughEnabled() {
try {
Cube cube = getCube();
return (cube != null && cube.isDrillThroughEnabled());
} catch (Exception e) {
e.printStackTrace();
};
return false;
}

public CellSet execute() throws Exception {
OlapConnection con = connection;
con.setCatalog(getSaikuCube().getCatalogName());
OlapStatement stmt = con.createStatement();
this.statement = stmt;
CellSet cs = stmt.executeOlapQuery(mdx);
if (statement != null) {
statement.close();
try {
if (statement != null) {
statement.close();
statement = null;
}

OlapConnection con = connection;
con.setCatalog(getSaikuCube().getCatalogName());
OlapStatement stmt = con.createStatement();
this.statement = stmt;
CellSet cs = stmt.executeOlapQuery(mdx);

return cs;
} finally {
if (statement != null) {
statement.close();
statement = null;
}
}
this.statement = null;
return cs;
}

public QueryType getType() {
Expand All @@ -164,47 +173,49 @@ public QueryAxis getAxis(String name) throws SaikuOlapException {
}

public Cube getCube() {
final MdxParserFactory parserFactory =
connection.getParserFactory();
MdxParser mdxParser =
parserFactory.createMdxParser(connection);
MdxValidator mdxValidator =
parserFactory.createMdxValidator(connection);

String mdx = getMdx();
try {

if (mdx != null && mdx.length() > 0 && mdx.toUpperCase().contains("FROM")) {
SelectNode select =
mdxParser.parseSelect(getMdx());
select = mdxValidator.validateSelect(select);
CubeType cubeType = (CubeType) select.getFrom().getType();
return cubeType.getCube();
}
} catch (Exception e) {
log.debug("Parsing MDX to get the Cube failed. Using fallback scenario.", e);
}
try {
// ok seems like we failed to get the cube, lets try it differently
if (connection != null && mdx != null && mdx.length() > 0) {
for (Database db : connection.getOlapDatabases()) {
Catalog cat = db.getCatalogs().get(cube.getCatalogName());
if (cat != null) {
for (Schema schema : cat.getSchemas()) {
for (Cube cub : schema.getCubes()) {
if (cub.getName().equals(cube.getName()) || cub.getUniqueName().equals(cube.getName())) {
return cub;
}
}
}
}
}
}
} catch (OlapException e) {
e.printStackTrace();
final MdxParserFactory parserFactory =
connection.getParserFactory();
MdxParser mdxParser =
parserFactory.createMdxParser(connection);
MdxValidator mdxValidator =
parserFactory.createMdxValidator(connection);

String mdx = getMdx();
try {

if (mdx != null && mdx.length() > 0 && mdx.toUpperCase().contains("FROM")) {
SelectNode select =
mdxParser.parseSelect(getMdx());
select = mdxValidator.validateSelect(select);
CubeType cubeType = (CubeType) select.getFrom().getType();
return cubeType.getCube();
}
} catch (Exception e) {
log.debug("Parsing MDX to get the Cube failed. Using fallback scenario.", e);
} finally {
mdxValidator = null;
}
try {
// ok seems like we failed to get the cube, lets try it differently
if (connection != null && mdx != null && mdx.length() > 0) {
for (Database db : connection.getOlapDatabases()) {
Catalog cat = db.getCatalogs().get(cube.getCatalogName());
if (cat != null) {
for (Schema schema : cat.getSchemas()) {
for (Cube cub : schema.getCubes()) {
if (cub.getName().equals(cube.getName()) || cub.getUniqueName().equals(cube.getName())) {
return cub;
}
}
}
}
}
}
} catch (OlapException e) {
e.printStackTrace();
}


return null;
}

Expand All @@ -231,15 +242,15 @@ public void resetAxisSelections(QueryAxis axis) {
public void clearAllQuerySelections() {
throw new UnsupportedOperationException();
}

public void clearAxis(String axisName) throws SaikuOlapException {
throw new UnsupportedOperationException();
}

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

public Scenario getScenario() {
return scenario;
}
Expand All @@ -257,7 +268,7 @@ public void removeTag() {

public void storeCellset(CellSet cs) {
this.cellset = cs;

}

public CellSet getCellset() {
Expand All @@ -266,13 +277,13 @@ public CellSet getCellset() {

public void setStatement(OlapStatement os) {
this.statement = os;

}

public OlapStatement getStatement() {
return this.statement;
}

public void cancel() throws Exception {
if (this.statement != null && !this.statement.isClosed()) {
statement.close();
Expand Down
Loading

0 comments on commit f09bd79

Please sign in to comment.