public void openQuery() throws Exception { Class.forName( olap4jDriver ); OlapConnection connection = null; if ( Utils.isEmpty( username ) && Utils.isEmpty( password ) ) { connection = (OlapConnection) DriverManager.getConnection( olap4jUrl ); } else { connection = (OlapConnection) DriverManager.getConnection( olap4jUrl, username, password ); } OlapWrapper wrapper = connection; olapConnection = wrapper.unwrap( OlapConnection.class ); try { if ( !Utils.isEmpty( catalogName ) ) { olapConnection.setCatalog( catalogName ); } } catch ( SQLException e ) { throw new OlapException( "Error setting catalog for MDX statement: '" + catalogName + "'" ); } OlapStatement stmt = olapConnection.createStatement(); if ( !Utils.isEmpty( mdx ) ) { CellSet tmp = stmt.executeOlapQuery( mdx ); result = tmp; } else { throw new Exception( "Error executing empty MDX query" ); } }
/** * Executes a query and processes the result using a callback. * * @param queryString MDX query text */ public <T> T runQuery(String queryString, Util.Functor1<T, CellSet> f) { long start = System.currentTimeMillis(); OlapConnection connection = null; OlapStatement statement = null; CellSet cellSet = null; try { connection = getOlapConnection(); statement = connection.createStatement(); debug("CmdRunner.runQuery: AFTER createStatement"); start = System.currentTimeMillis(); cellSet = statement.executeOlapQuery(queryString); return f.apply(cellSet); } catch (SQLException e) { throw new RuntimeException(e); } finally { queryTime = (System.currentTimeMillis() - start); totalQueryTime += queryTime; debug("CmdRunner.runQuery: BOTTOM"); Util.close(cellSet, statement, connection); } }
connection = getConnection(request, Collections.<String, String>emptyMap()); statement = connection.createStatement(); resultSet = getExtra(connection).executeDrillthrough(
/** * @param connection * @param mdx * @return * @throws OlapException */ protected CellSet executeMdx(OlapConnection connection, String mdx) throws OlapException { if (logger.isDebugEnabled()) { logger.debug(mdx); } Date start = new Date(System.currentTimeMillis()); OlapStatement stmt = connection.createStatement(); CellSet result = stmt.executeOlapQuery(mdx); long duration = System.currentTimeMillis() - start.getTime(); if (logger.isInfoEnabled()) { logger.info(String.format("Query execution time : %d ms", duration)); } fireQueryExecuted(start, duration, mdx); return result; }
@Override public void execute() throws TranslatorException { try { stmt = this.connection.createStatement(); cellSet = stmt.executeOlapQuery(mdxQuery); CellSetAxis rowAxis = this.cellSet.getAxes().get(Axis.ROWS.axisOrdinal()); rowPositionIterator = rowAxis.iterator(); columnsAxis = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal()); colWidth = rowAxis.getAxisMetaData().getHierarchies().size() + this.columnsAxis.getPositions().size(); } catch (SQLException e) { throw new TranslatorException(e); } }
Statement stmt = getConnection().createStatement(); result = stmt.executeQuery(mdx); } catch (SQLException e) {