use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.
the class MDXBaseComponentTest method testGetConnectionOrig_nullConnectionProps.
@Test
public void testGetConnectionOrig_nullConnectionProps() throws Exception {
doReturn(connAction).when(mdxBaseComponent).getActionDefinition();
when(connAction.getMdxConnectionString()).thenReturn(connectionStringAction);
when(connectionStringAction.getStringValue()).thenReturn("mdx:localhost:8080");
when(connAction.getConnectionProps()).thenReturn(actionInput);
when(actionInput.getValue()).thenReturn(null);
when(connAction.getConnection()).thenReturn(jdbcAction);
when(jdbcAction.getStringValue()).thenReturn("psql://localhost:5432");
when(connAction.getJndi()).thenReturn(jndiAction);
when(jndiAction.getStringValue()).thenReturn("jndi string");
when(connAction.getLocation()).thenReturn(locationAction);
when(locationAction.getStringValue()).thenReturn("location string");
when(connAction.getRole()).thenReturn(roleAction);
when(roleAction.getStringValue()).thenReturn("role string");
when(connAction.getCatalog()).thenReturn(catalog);
// when( catalog.getStringValue() ).thenReturn( "<catalog></catalog>" );
when(catalog.getStringValue()).thenReturn(null);
when(connAction.getCatalogResource()).thenReturn(catalogResource);
when(catalogResource.getName()).thenReturn("catalog name");
when(connAction.getUserId()).thenReturn(userAction);
when(connAction.getPassword()).thenReturn(userAction);
when(userAction.getStringValue()).thenReturn("user/pass");
PentahoSystem.registerObject(mdxConnection);
PentahoSystem.registerPrimaryObjectFactory(objFactory);
PentahoSessionHolder.setSession(session);
when(objFactory.get(any(Class.class), anyString(), any(IPentahoSession.class))).thenReturn(mdxConnection);
mdxBaseComponent.setRuntimeContext(runtimeContext);
when(runtimeContext.getResourceDefintion("catalog name")).thenReturn(catalogActionSeqRes);
when(catalogActionSeqRes.getSourceType()).thenReturn(IActionSequenceResource.URL_RESOURCE);
when(catalogActionSeqRes.getAddress()).thenReturn("sampledata");
when(connAction.getExtendedColumnNames()).thenReturn(ActionInputConstant.NULL_INPUT);
IPentahoConnection connectionOrig = mdxBaseComponent.getConnectionOrig();
assertNotNull(connectionOrig);
assertEquals(mdxConnection, connectionOrig);
}
use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.
the class MDXBaseComponent method getDatasourceConnection.
/**
* attempt to aquire a connection. if connection isn't available, wait a certain period of time before trying again.
*
* @return connection
*/
public IPentahoConnection getDatasourceConnection() {
IPentahoConnection con;
int[] timeouts = { 200, 500, 2000 };
for (int element : timeouts) {
try {
con = getConnection();
try {
con.clearWarnings();
} catch (Exception ex) {
// ignored
}
return con;
} catch (Exception ex) {
// ignored
}
waitFor(element);
}
con = getConnection();
try {
con.clearWarnings();
} catch (Exception ex) {
// ignore
}
return con;
}
use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.
the class MDXBaseComponent method executeAction.
@Override
protected boolean executeAction() {
boolean value = false;
/*
* This is the query part. You would need a connection to execute the query. The connection will either come in as
* an INPUT (prepared_component) or will be specified right there.
*
* So check if a prepared component exists, if not create a new connection. If connection is not null, proceed to
* work on the query part.
*
* In the query section you can either execute the query right away or prepare it to be used later by a sub report.
*/
try {
if (getActionDefinition() instanceof MdxQueryAction) {
MdxQueryAction queryAction = (MdxQueryAction) getActionDefinition();
// instead of creating our own.
if (queryAction.getMdxConnection() != ActionInputConstant.NULL_INPUT) {
if (queryAction.getMdxConnection().getValue() != null) {
connectionOwner = false;
IPreparedComponent component = (IPreparedComponent) queryAction.getMdxConnection().getValue();
IPentahoConnection conn = component.shareConnection();
if (conn.getDatasourceType() == IPentahoConnection.MDX_DATASOURCE) {
connection = conn;
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
getActionName()));
}
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
getActionName()));
}
} else {
dispose();
connection = getDatasourceConnection();
}
if (connection != null) {
String query = queryAction.getQuery().getStringValue();
if (queryAction.getOutputPreparedStatement() != null) {
// prepare the query for execution, but don't execute quite yet.
prepareQuery(query);
// set the output as self, which will be used later by another component.
setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
value = true;
} else {
value = runQuery(connection, query);
}
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0004_NO_CONNECTION_INFO", // $NON-NLS-1$
getActionName()));
}
} else if (getActionDefinition() instanceof MdxConnectionAction) {
dispose();
connection = getDatasourceConnection();
if (connection != null) {
setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
value = true;
}
} else {
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0004_VALIDATION_FAILED", // $NON-NLS-1$
getActionName()));
}
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
}
return value;
}
use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.
the class ReportWizardSpecComponent method getResultSet.
public IPentahoResultSet getResultSet(final ReportSpec reportSpec) throws Exception {
String jndiName = reportSpec.getReportSpecChoice().getJndiSource();
IPentahoConnection connection = null;
if (reportSpec.getIsMDX()) {
// did this ever work??
// $NON-NLS-1$
String connectStr = "";
IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
String dsName = datasourceService.getDSBoundName(jndiName);
if (dsName != null) {
// $NON-NLS-1$ //$NON-NLS-2$
connectStr = "dataSource=" + dsName + "; Catalog=mondrian";
} else {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
return null;
}
Properties props = new Properties();
props.setProperty(IPentahoConnection.CONNECTION, connectStr);
props.setProperty(IPentahoConnection.PROVIDER, reportSpec.getMondrianCubeDefinitionPath());
connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, props, getSession(), this);
} else {
connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, jndiName, getSession(), this);
}
String query = ReportParameterUtility.setupParametersForActionSequence(reportSpec.getQuery());
query = setupQueryParameters(query);
IPentahoResultSet res = connection.executeQuery(query);
return res;
}
use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.
the class JFreeReportGenerateDefinitionComponent method getResultSet.
public IPentahoResultSet getResultSet(final ReportSpec reportSpec) throws Exception {
String jndiName = reportSpec.getReportSpecChoice().getJndiSource();
IPentahoConnection connection = null;
if (reportSpec.getIsMDX()) {
// did this ever work??
// $NON-NLS-1$
String connectStr = "";
IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
String dsName = datasourceService.getDSBoundName(jndiName);
if (dsName != null) {
// $NON-NLS-1$ //$NON-NLS-2$
connectStr = "dataSource=" + dsName + "; Catalog=mondrian";
} else {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
return null;
}
Properties props = new Properties();
props.setProperty(IPentahoConnection.CONNECTION, connectStr);
props.setProperty(IPentahoConnection.PROVIDER, reportSpec.getMondrianCubeDefinitionPath());
connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, props, getSession(), this);
} else {
connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, jndiName, getSession(), this);
}
String query = ReportParameterUtility.setupParametersForActionSequence(reportSpec.getQuery());
query = setupQueryParameters(query);
IPentahoResultSet res = connection.executeQuery(query);
return res;
}
Aggregations