Search in sources :

Example 1 with OlapConnection

use of org.olap4j.OlapConnection in project pentaho-kettle by pentaho.

the class OlapHelper method openQuery.

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");
    }
}
Also used : OlapStatement(org.olap4j.OlapStatement) OlapWrapper(org.olap4j.OlapWrapper) SQLException(java.sql.SQLException) OlapConnection(org.olap4j.OlapConnection) OlapException(org.olap4j.OlapException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) OlapException(org.olap4j.OlapException) CellSet(org.olap4j.CellSet)

Example 2 with OlapConnection

use of org.olap4j.OlapConnection in project mondrian by pentaho.

the class MondrianServerTest method testRepository.

/**
 * Tests a server that reads its repository from a file URL.
 */
public void testRepository() throws MalformedURLException, SQLException {
    final XmlaTestContext xmlaTestContext = new XmlaTestContext();
    final MondrianServer server = MondrianServer.createWithRepository(new UrlRepositoryContentFinder("inline:" + xmlaTestContext.getDataSourcesString()), null);
    final int id = server.getId();
    assertNotNull(id);
    OlapConnection connection = server.getConnection("FoodMart", "FoodMart", null);
    final NamedList<Catalog> catalogs = connection.getOlapCatalogs();
    assertEquals(1, catalogs.size());
    assertEquals("FoodMart", catalogs.get(0).getName());
    server.shutdown();
}
Also used : MondrianServer(mondrian.olap.MondrianServer) OlapConnection(org.olap4j.OlapConnection) UrlRepositoryContentFinder(mondrian.server.UrlRepositoryContentFinder) Catalog(org.olap4j.metadata.Catalog) XmlaTestContext(mondrian.xmla.test.XmlaTestContext)

Example 3 with OlapConnection

use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.

the class MondrianAbstractPlatformUserRoleMapper method getMondrianRolesFromCatalog.

/**
 * This method returns the role names as found in the Mondrian schema. The returned names must be ordered (sorted) or
 * code down-stream will not work.
 *
 * @param userSession
 *          Users' session
 * @param catalogName
 *          The name of the catalog
 * @return Array of role names from the schema file
 */
protected String[] getMondrianRolesFromCatalog(IPentahoSession userSession, String context) {
    String[] rtn = null;
    // Get the catalog service
    IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class);
    if (catalogService != null) {
        // Get the catalog by name
        MondrianCatalog catalog = catalogService.getCatalog(context, userSession);
        if (catalog != null) {
            // The roles are in the schema object
            MondrianSchema schema = catalog.getSchema();
            if (schema != null) {
                // Ask the schema for the role names array
                String[] roleNames = schema.getRoleNames();
                if ((roleNames != null) && (roleNames.length > 0)) {
                    // Return the roles from the schema
                    Arrays.sort(roleNames);
                    return roleNames;
                }
            }
        }
    }
    // Check with the IOlapService and try to get a list of roles there.
    IOlapService olapService = PentahoSystem.get(IOlapService.class);
    if (olapService != null) {
        MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(PentahoSystem.get(IUnifiedRepository.class));
        String serverName = null;
        for (String name : helper.getOlap4jServers()) {
            PropertyList props = Util.parseConnectString(helper.getOlap4jServerInfo(name).URL);
            if (props.get(RolapConnectionProperties.Catalog.name(), "").equals(context)) {
                serverName = name;
            }
        }
        if (serverName != null) {
            OlapConnection conn = null;
            try {
                // Use a null session for root access.
                conn = olapService.getConnection(serverName, null);
                List<String> roleList = conn.getAvailableRoleNames();
                String[] roleArray = roleList.toArray(new String[roleList.size()]);
                Arrays.sort(roleArray);
                return roleArray;
            } catch (OlapException e) {
                log.error("Failed to get a list of roles from olap connection " + context, e);
                throw new RuntimeException(e);
            } finally {
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        // OK to squash this one.
                        log.error("Failed to get a list of roles from olap connection " + context, e);
                    }
                }
            }
        }
    }
    // Sort the returned list of roles.
    return rtn;
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) SQLException(java.sql.SQLException) MondrianSchema(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema) OlapConnection(org.olap4j.OlapConnection) OlapException(org.olap4j.OlapException) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) PropertyList(mondrian.olap.Util.PropertyList) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 4 with OlapConnection

use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method flushCacheForCatalog.

private void flushCacheForCatalog(String catalogName, IPentahoSession pentahoSession) {
    IOlapService olapService = PentahoSystem.get(IOlapService.class, "IOlapService", pentahoSession);
    Connection unwrap = null;
    try {
        OlapConnection connection = olapService.getConnection(catalogName, pentahoSession);
        unwrap = connection.unwrap(Connection.class);
        unwrap.getCacheControl(null).flushSchema(unwrap.getSchema());
    } catch (Throwable e) {
        MondrianCatalogHelper.logger.warn(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0019_FAILED_TO_FLUSH", catalogName), e);
    } finally {
        if (unwrap != null) {
            unwrap.close();
        }
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) OlapConnection(org.olap4j.OlapConnection) OlapConnection(org.olap4j.OlapConnection) Connection(mondrian.olap.Connection)

Example 5 with OlapConnection

use of org.olap4j.OlapConnection in project teiid by teiid.

the class OlapExecutionFactory method unwrap.

private OlapConnection unwrap(Connection conn) throws TranslatorException {
    try {
        OlapWrapper wrapper = conn.unwrap(OlapWrapper.class);
        OlapConnection olapConn = wrapper.unwrap(OlapConnection.class);
        return olapConn;
    } catch (SQLException e) {
        throw new TranslatorException(e);
    }
}
Also used : OlapWrapper(org.olap4j.OlapWrapper) SQLException(java.sql.SQLException) OlapConnection(org.olap4j.OlapConnection) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

OlapConnection (org.olap4j.OlapConnection)22 SQLException (java.sql.SQLException)8 RolapConnection (mondrian.rolap.RolapConnection)5 OlapException (org.olap4j.OlapException)5 Properties (java.util.Properties)4 MondrianServer (mondrian.olap.MondrianServer)4 IOlapServiceException (org.pentaho.platform.plugin.action.olap.IOlapServiceException)4 PrintWriter (java.io.PrintWriter)3 Connection (java.sql.Connection)3 Test (org.junit.Test)3 OlapWrapper (org.olap4j.OlapWrapper)3 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)3 IOException (java.io.IOException)2 Connection (mondrian.olap.Connection)2 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)2 UrlRepositoryContentFinder (mondrian.server.UrlRepositoryContentFinder)2 XmlaHandler (mondrian.xmla.XmlaHandler)2 XmlaTestContext (mondrian.xmla.test.XmlaTestContext)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 OlapDataSource (org.olap4j.OlapDataSource)2