use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.
the class OlapServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// Stub /etc/mondrian
mondrianFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "mondrian";
stubGetFolder(repository, mondrianFolderPath);
// Stub /etc/olap-servers
olapFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "olap-servers";
stubGetFolder(repository, olapFolderPath);
// Create a session as admin.
session = new StandaloneSession("admin");
doReturn(aggManager).when(server).getAggregationManager();
doReturn(cacheControl).when(aggManager).getCacheControl(any(RolapConnection.class), any(PrintWriter.class));
// Create the olap service. Make sure to override hasAccess with the
// mock version.
olapService = spy(new OlapServiceImpl(repository, server) {
public boolean hasAccess(String path, EnumSet<RepositoryFilePermission> perms, IPentahoSession session) {
return accessMock.hasAccess(path, perms, session);
}
@Override
protected XmlaHandler.XmlaExtra getXmlaExtra(final OlapConnection connection) throws SQLException {
return mockXmlaExtra;
}
});
}
use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.
the class OlapServiceImplTest method flushSingleSchemaCache.
@Test
public void flushSingleSchemaCache() throws Exception {
OlapConnection connection = mock(OlapConnection.class);
doReturn(connection).when(olapService).getConnection("schemaX", session);
RolapConnection rc = mock(RolapConnection.class);
doReturn(rc).when(connection).unwrap(RolapConnection.class);
doReturn(cacheControl).when(rc).getCacheControl(any(PrintWriter.class));
RolapSchema schema = mock(RolapSchema.class);
doReturn(schema).when(rc).getSchema();
olapService.flush(session, "schemaX");
verify(cacheControl, times(1)).flushSchema(schema);
}
use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.
the class OlapServiceImplTest method testFlushProceedsOnException.
@Test
public void testFlushProceedsOnException() throws Exception {
stubHostedServer();
final Properties properties = new Properties();
properties.put(RolapConnectionProperties.Locale.name(), getLocale().toString());
OlapConnection conn = mock(OlapConnection.class);
when(server.getConnection("Pentaho", "myHostedServer", null, properties)).thenReturn(conn);
when(conn.isWrapperFor(any(Class.class))).thenReturn(true);
final RolapConnection rolapConn = mock(RolapConnection.class);
when(conn.unwrap(any(Class.class))).thenReturn(rolapConn);
when(rolapConn.getCacheControl(any(PrintWriter.class))).thenThrow(new RuntimeException("something happend"));
try {
olapService.flushAll(session);
} catch (IOlapServiceException e) {
fail("Exception shouldn't have made it this far.");
}
}
use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.
the class OlapServiceImpl method flushRemoteCatalogs.
/**
* Flushes all remote catalogs accessible to session.
* Unlike Hosted Catalogs, remote catalogs need to be
* flushed individually since they each may be running
* in separate instances.
*/
private void flushRemoteCatalogs(IPentahoSession session) throws SQLException {
for (String name : getRemoteCatalogNames(session)) {
OlapConnection connection = null;
try {
connection = getConnection(name, session);
XmlaHandler.XmlaExtra xmlaExtra = getXmlaExtra(connection);
if (xmlaExtra != null) {
xmlaExtra.flushSchemaCache(connection);
}
} catch (Exception e) {
LOG.warn(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0019_FAILED_TO_FLUSH", name), e);
} finally {
if (connection != null) {
connection.close();
}
}
}
}
use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.
the class OlapServiceImpl method addCatalogToCache.
/**
* Adds a catalog and its children to the cache.
* Do not use directly. This must be called with a write lock
* on the cache.
*
* @param catalogName The name of the catalog to load in cache.
*/
private void addCatalogToCache(IPentahoSession session, String catalogName) {
final IOlapService.Catalog catalog = new Catalog(catalogName, new ArrayList<IOlapService.Schema>());
OlapConnection connection = null;
try {
connection = getConnection(catalogName, session);
for (org.olap4j.metadata.Schema schema4j : connection.getOlapSchemas()) {
connection.setSchema(schema4j.getName());
final IOlapService.Schema schema = new Schema(schema4j.getName(), catalog, new ArrayList<IOlapService.Cube>(), new ArrayList<String>(connection.getAvailableRoleNames()));
for (org.olap4j.metadata.Cube cube4j : schema4j.getCubes()) {
schema.cubes.add(new IOlapService.Cube(cube4j.getName(), cube4j.getCaption(), schema));
}
catalog.schemas.add(schema);
}
// We're done.
getCache(session).add(catalog);
} catch (OlapException e) {
LOG.warn("Failed to initialize the olap connection cache for catalog " + catalogName, e);
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn("Failed to gracefully close an olap connection to catalog " + catalogName, e);
}
}
}
Aggregations