我应该使用什么来代替弃用的 mondrian.olap.Connection::execute?

What should I use instead of deprecated mondrian.olap.Connection::execute?

所以我想在 Java 1.8 中使用 Mondrian 3.14,所以我做了这样的事情:

String catalogFilePath = "<path>/mdx_schema.xml";
String connectUrl = "Provider=mondrian;" +
            "Jdbc=jdbc:postgresql://example.com:5432/database?user=user&password=pass;" +
            "JdbcDrivers=org.postgresql.Driver;" +
            "Catalog=file:" + catalogFilePath + ";";
Connection connection = DriverManager.getConnection(connectUrl, null);

String qs = "<query>";
Query q = connection.parseQuery(qs);
Result r = connection.execute(q);

但是,如 here 所述,Connection::execute 已弃用:

Deprecated. This method is deprecated and will be removed in mondrian-4.0. It operates by internally creating a statement. Better to use olap4j and explicitly create a statement.

那么,我应该在 olap 中使用什么来执行查询?

所以我实际上找到了答案 here :

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;

import org.olap4j.CellSet;
import org.olap4j.OlapConnection;
import org.olap4j.OlapStatement;
import org.olap4j.OlapWrapper;
import org.olap4j.layout.RectangularCellSetFormatter;
import java.sql.SQLException;

public static void main(String[] args) throws SQLException, ClassNotFoundException {
    Class.forName("mondrian.olap4j.MondrianOlap4jDriver");

    String catalogFilePath = "<path>/mdx_schema.xml";
    String connectUrl = "jdbc:mondrian:" +
    "Jdbc=jdbc:postgresql://example.com:5432/database?user=user&password=pass;" +
    "JdbcDrivers=org.postgresql.Driver;" +
    "Catalog=file:" + catalogFilePath + ";";

    Connection connection = DriverManager.getConnection(connectUrl);
    OlapWrapper wrapper = (OlapWrapper) connection;
    OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);
    OlapStatement statement = olapConnection.createStatement();

    String qs = "<query>";

    CellSet cellSet = statement.executeOlapQuery(qs);

    RectangularCellSetFormatter formatter = new RectangularCellSetFormatter(false);
    PrintWriter writer = new PrintWriter(System.out);
    formatter.format(cellSet, writer);
    writer.flush();

    connection.close();
}