本文整理汇总了Java中org.olap4j.OlapStatement类的典型用法代码示例。如果您正苦于以下问题:Java OlapStatement类的具体用法?Java OlapStatement怎么用?Java OlapStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OlapStatement类属于org.olap4j包,在下文中一共展示了OlapStatement类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCannedProcedure
import org.olap4j.OlapStatement; //导入依赖的package包/类
@Test public void testCannedProcedure() throws Exception {
String ddl = "create foreign procedure proc(arg integer, arg1 date) returns table (x string) options (\"teiid_rel:native-query\" '$2 $1 something')";
String query = "exec proc(2, {d'1970-01-01'})";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "phy");
CommandBuilder commandBuilder = new CommandBuilder(tm);
Command obj = commandBuilder.getCommand(query);
OlapExecutionFactory oef = new OlapExecutionFactory();
Connection mock = Mockito.mock(java.sql.Connection.class);
OlapWrapper mock2 = Mockito.mock(OlapWrapper.class);
OlapConnection mock3 = Mockito.mock(OlapConnection.class);
OlapStatement mock4 = Mockito.mock(OlapStatement.class);
Mockito.stub(mock4.executeOlapQuery(Mockito.anyString())).toThrow(new TeiidRuntimeException());
Mockito.stub(mock3.createStatement()).toReturn(mock4);
Mockito.stub(mock2.unwrap(OlapConnection.class)).toReturn(mock3);
Mockito.stub(mock.unwrap(OlapWrapper.class)).toReturn(mock2);
ProcedureExecution pe = oef.createProcedureExecution((Call)obj, Mockito.mock(ExecutionContext.class), new RuntimeMetadataImpl(tm), mock);
try {
pe.execute();
fail();
} catch (TeiidRuntimeException e) {
Mockito.verify(mock4).executeOlapQuery("'1970-01-01' 2 something");
}
}
示例2: runQuery
import org.olap4j.OlapStatement; //导入依赖的package包/类
/**
* 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);
}
}
示例3: cancel
import org.olap4j.OlapStatement; //导入依赖的package包/类
@Override
public void cancel() throws TranslatorException {
try {
OlapStatement olapStatement = this.stmt;
if (olapStatement != null) {
olapStatement.cancel();
}
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
示例4: setStatementProfiling
import org.olap4j.OlapStatement; //导入依赖的package包/类
public void setStatementProfiling(
OlapStatement statement,
final PrintWriter pw)
{
((MondrianOlap4jStatement) statement).enableProfiling(
new ProfileHandler() {
public void explain(String plan, QueryTiming timing) {
pw.println(plan);
if (timing != null) {
pw.println(timing);
}
}
}
);
}
示例5: createStatement
import org.olap4j.OlapStatement; //导入依赖的package包/类
@Override
public OlapStatement createStatement() throws OlapException {
return new ServerOlapStatement(this);
}
示例6: ServerCellSet
import org.olap4j.OlapStatement; //导入依赖的package包/类
public ServerCellSet(OlapStatement olapStatement, Cube cube) {
this.olapStatement = olapStatement;
this.cube = cube;
}
示例7: getStatement
import org.olap4j.OlapStatement; //导入依赖的package包/类
@Override
public OlapStatement getStatement() throws SQLException {
return olapStatement;
}
示例8: createDatasource
import org.olap4j.OlapStatement; //导入依赖的package包/类
@Override
public JRDataSource createDatasource() throws JRException
{
Properties connectProps = new Properties();
connectProps.put(XMLA_SERVER, getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_URL));
connectProps.put(XMLA_CATALOG, getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_CATALOG));
connectProps.put(XMLA_DATA_SOURCE, getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_DATASOURCE));
connectProps.put(XMLA_USER, getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_USER));
connectProps.put(XMLA_PASSWORD, getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_PASSWORD));
connectProps.put(OLAP4J_DRIVER, OLAP4J_XMLA_DRIVER_CLASS);
connectProps.put(OLAP4J_URL_PREFIX, OLAP4J_XMLA_URL_PREFIX);
// load driver and Connection
rConnection = null;
try
{
Class.forName(OLAP4J_XMLA_DRIVER_CLASS);
rConnection = java.sql.DriverManager.getConnection(OLAP4J_XMLA_URL_PREFIX, connectProps);
}
catch (Throwable t)
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_CONNECTION_ERROR,
new Object[]{OLAP4J_XMLA_DRIVER_CLASS},
t);
}
OlapConnection connection = (OlapConnection) rConnection;
/*
MdxParserFactory pFactory = connection.getParserFactory();
MdxParser parser = pFactory.createMdxParser(connection);
SelectNode parsedObject = parser.parseSelect(getQueryString());
MdxValidator validator = pFactory.createMdxValidator(connection);
try {
validator.validateSelect(parsedObject);
} catch (OlapException e) {
throw new JRException("Invalid MDX query: " + getQueryString(), e);
}
*/
if (log.isDebugEnabled())
{
log.debug("running MDX: " + getQueryString());
}
CellSet result = null;
try
{
OlapStatement statement = connection.createStatement();
result = statement.executeOlapQuery(getQueryString());
}
catch (OlapException e)
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_EXECUTE_QUERY_ERROR,
new Object[]{getQueryString()},
e);
}
parseResult(result);
return new JROlapDataSource(dataset, xmlaResult);
}
示例9: createDatasource
import org.olap4j.OlapStatement; //导入依赖的package包/类
@Override
public JRDataSource createDatasource() throws JRException
{
JRDataSource dataSource = null;
Properties connectProps = new Properties();
connectProps.put(OLAP4J_JDBC_DRIVERS, getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_DRIVERS));
connectProps.put(OLAP4J_JDBC_URL, getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_URL));
connectProps.put(OLAP4J_JDBC_CATALOG, getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_CATALOG));
String user = (String) getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_USER);
if (user != null) {
connectProps.put(OLAP4J_JDBC_USER, user);
}
String password = (String) getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_PASSWORD);
if (password != null) {
connectProps.put(OLAP4J_JDBC_PASSWORD, password);
}
connectProps.put(OLAP4J_DRIVER, OLAP4J_MONDRIAN_DRIVER_CLASS);
connectProps.put(OLAP4J_URL_PREFIX, OLAP4J_MONDRIAN_URL_PREFIX);
// load driver and Connection
rConnection = null;
try
{
Class.forName(OLAP4J_MONDRIAN_DRIVER_CLASS);
rConnection = java.sql.DriverManager.getConnection(OLAP4J_MONDRIAN_URL_PREFIX, connectProps);
}
catch (Throwable t)
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_CONNECTION_ERROR,
new Object[]{OLAP4J_MONDRIAN_DRIVER_CLASS},
t);
}
OlapConnection connection = (OlapConnection) rConnection;
String queryStr = getQueryString();
if (connection != null && queryStr != null)
{
if (log.isDebugEnabled())
{
log.debug("MDX query: " + queryStr);
}
CellSet result = null;
try
{
OlapStatement statement = connection.createStatement();
result = statement.executeOlapQuery(getQueryString());
}
catch (OlapException e)
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_EXECUTE_QUERY_ERROR,
new Object[]{getQueryString()},
e);
}
if (log.isDebugEnabled())
{
OutputStream bos = new ByteArrayOutputStream();
CellSetFormatter formatter = new RectangularCellSetFormatter(true);
formatter.format(result, new PrintWriter(bos, true));
log.debug("Result:\n" + bos.toString());
}
dataSource = new Olap4jDataSource(dataset, result);
}
return dataSource;
}
示例10: createStatement
import org.olap4j.OlapStatement; //导入依赖的package包/类
public OlapStatement createStatement() {
return super.createStatement();
}
示例11: getResultSet
import org.olap4j.OlapStatement; //导入依赖的package包/类
/**
* 取CellSet
*
* @param connection
* @param mdx
* @return
* @throws OlapException
* @throws Exception
*/
public static CellSet getResultSet(OlapConnection connection, String mdx) throws OlapException, Exception {
OlapStatement olapStatement = connection.createStatement();
CellSet cellSet = olapStatement.executeOlapQuery(mdx);
return cellSet;
}