Class SQLBaseComponent
- java.lang.Object
-
- org.pentaho.platform.engine.core.system.PentahoBase
-
- org.pentaho.platform.engine.services.PentahoMessenger
-
- org.pentaho.platform.engine.services.solution.ComponentBase
-
- org.pentaho.platform.plugin.action.sql.SQLBaseComponent
-
- All Implemented Interfaces:
Serializable,org.pentaho.commons.connection.IDisposable,org.pentaho.platform.api.data.IDataComponent,org.pentaho.platform.api.data.IPreparedComponent,org.pentaho.platform.api.engine.IAuditable,org.pentaho.platform.api.engine.IComponent,org.pentaho.platform.api.engine.ILogger,org.pentaho.platform.api.engine.IParameterResolver
- Direct Known Subclasses:
SQLLookupRule
public abstract class SQLBaseComponent extends org.pentaho.platform.engine.services.solution.ComponentBase implements org.pentaho.platform.api.data.IDataComponent, org.pentaho.platform.api.data.IPreparedComponent, org.pentaho.platform.api.engine.IParameterResolverSQLBaseComponent is the base class for SQLExecute and SQLLookupRule. it does the majority of work when interacting with Pentaho's BI Platform, including implementing the necessary component features. It also implements IDataComponent and IPreparedComponent.- See Also:
SQLExecute,SQLLookupRule, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected org.pentaho.commons.connection.IPentahoConnectionconnectionreference to connection objectprotected booleanconnectionOwneris set to false if using another IPreparedComponents connection vs ownstatic StringPREPARE_PARAMETER_PREFIXprotected ListpreparedParametersstores the prepared parameters for later useprotected StringpreparedQuerystores the prepared query for later use-
Fields inherited from class org.pentaho.platform.engine.services.solution.ComponentBase
COMPONENT_EXECUTE_FAIL, debug, MISSING_SESSION, UNKNOWN_COMPONENT_ID
-
Fields inherited from class org.pentaho.platform.engine.core.system.PentahoBase
EMPTYLOGID, loggingLevel, LOGID_MASK1, LOGID_MASK2, LOGID_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description SQLBaseComponent()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddispose()dispose of the resultset, and if the owner, dispose of the connection.voiddone()nothing to do in done call from runtime context.org.pentaho.commons.connection.IPentahoResultSetdoQuery(SQLConnection sqlConnection, String query, boolean forwardOnlyResultset)protected booleanexecuteAction()determines state of component, and executes accordingly.org.pentaho.commons.connection.IPentahoResultSetexecutePrepared(Map preparedParams)executes a prepared method that returns a result set executePrepared looks up any "PREPARELATER" params in the preparedParams map.protected org.pentaho.commons.connection.IPentahoConnectiongetConnection()pass through to getConnection(defaultConnection)protected org.pentaho.commons.connection.IPentahoConnectiongetConnection(org.pentaho.commons.connection.IPentahoConnection defaultConnection)This method retrieves a connection based on the components inputs.org.pentaho.commons.connection.IPentahoConnectiongetDatasourceConnection()attempt to aquire a connection.abstract org.apache.commons.logging.LoggetLogger()intgetMaxRows()protected org.pentaho.commons.connection.IPentahoMetaDatagetMetadata(org.pentaho.commons.connection.IPentahoResultSet resultSet, boolean live)returns metadata based on the result set.StringgetQuery()intgetQueryTimeout()booleangetReadOnly()abstract StringgetResultOutputName()org.pentaho.commons.connection.IPentahoResultSetgetResultSet()returns the result set objectbooleaninit()nothing is done in the init functionprotected booleanprepareQuery(String rawQuery)called when in prepared-component mode, this method populates the preparedQuery string and preparedParameters object.intresolveParameter(String template, String parameter, Matcher parameterMatcher, int copyStart, StringBuffer results)This method is called when TemplateUtil.applyTemplate() encounters a parameter.protected booleanrunQuery(String rawQuery, boolean live)executes the specified query template.voidsetMaxRows(int value)voidsetQueryTimeout(int timeInSec)voidsetReadOnly(boolean value)org.pentaho.commons.connection.IPentahoConnectionshareConnection()return this class's connection.booleanvalidateAction()validates the action.abstract booleanvalidateSystemSettings()protected voidwaitFor(int millis)pause the thread a certain number of milliseconds-
Methods inherited from class org.pentaho.platform.engine.services.solution.ComponentBase
addTempParameter, addTempParameterObject, applyInputsToFormat, audit, createFeedbackParameter, createFeedbackParameter, createFeedbackParameter, createFeedbackParameter, createFeedbackParameter, createFeedbackParameter, createFeedbackParameter, createNewInstance, execute, feedbackAllowed, getActionDefinition, getActionName, getActionTitle, getComponentDefinition, getComponentDefinition, getContentOutputItem, getDefaultOutputStream, getFeedbackOutputStream, getId, getInitFailMessage, getInitOk, getInputBooleanValue, getInputLongValue, getInputNames, getInputParameter, getInputStream, getInputStringValue, getInputStringValue, getInputValue, getInstanceId, getLogId, getObjectName, getOutputContentItem, getOutputContentItem, getOutputItem, getOutputItem, getOutputNames, getOutputPreference, getProcessId, getResource, getResourceAsString, getResourceDataSource, getResourceInputStream, getResourceNames, getRuntimeContext, getSession, getSetting, getSolutionName, getSolutionPath, getStringSetting, inputMissingError, isDefinedInput, isDefinedOutput, isDefinedResource, isPromptPending, outputMissingError, promptNeeded, promptNow, resourceComponentSettingError, resourceMissingError, saveSetting, setActionDefinition, setActionName, setComponentDefinition, setComponentDefinitionMap, setFeedbackMimeType, setInstanceId, setOutputMimeType, setOutputMimeType, setOutputValue, setProcessId, setRuntimeContext, setSession, validate
-
Methods inherited from class org.pentaho.platform.engine.services.PentahoMessenger
debug, debug, error, error, error, fatal, fatal, getMessages, getUserString, info, info, setMessages, trace, trace, warn, warn
-
Methods inherited from class org.pentaho.platform.engine.core.system.PentahoBase
genLogIdFromInfo, genLogIdFromInfo, genLogIdFromSession, getLoggingLevel, setLoggingLevel, setLogId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.pentaho.platform.api.engine.IComponent
execute, getActionDefinition, getActionName, getComponentDefinition, getInstanceId, getMessages, getProcessId, getRuntimeContext, getSession, setActionDefinition, setActionName, setComponentDefinition, setComponentDefinitionMap, setInstanceId, setMessages, setProcessId, setRuntimeContext, setSession, validate
-
-
-
-
Field Detail
-
PREPARE_PARAMETER_PREFIX
public static final String PREPARE_PARAMETER_PREFIX
- See Also:
- Constant Field Values
-
preparedQuery
protected String preparedQuery
stores the prepared query for later use
-
preparedParameters
protected List preparedParameters
stores the prepared parameters for later use
-
connectionOwner
protected boolean connectionOwner
is set to false if using another IPreparedComponents connection vs own
-
connection
protected org.pentaho.commons.connection.IPentahoConnection connection
reference to connection object
-
-
Method Detail
-
validateSystemSettings
public abstract boolean validateSystemSettings()
- Specified by:
validateSystemSettingsin classorg.pentaho.platform.engine.services.solution.ComponentBase
-
getResultOutputName
public abstract String getResultOutputName()
-
getLogger
public abstract org.apache.commons.logging.Log getLogger()
- Specified by:
getLoggerin classorg.pentaho.platform.engine.core.system.PentahoBase
-
getResultSet
public org.pentaho.commons.connection.IPentahoResultSet getResultSet()
returns the result set object- Specified by:
getResultSetin interfaceorg.pentaho.platform.api.data.IDataComponent- Returns:
- pentaho result set
-
validateAction
public boolean validateAction()
validates the action. checks to verify inputs are available to execute - verify query is available - verify connection is available, via jndi, connection string, or prepared component - verify output is specified- Specified by:
validateActionin classorg.pentaho.platform.engine.services.solution.ComponentBase
-
done
public void done()
nothing to do in done call from runtime context.- Specified by:
donein interfaceorg.pentaho.platform.api.engine.IComponent- Specified by:
donein classorg.pentaho.platform.engine.services.solution.ComponentBase
-
executeAction
protected boolean executeAction()
determines state of component, and executes accordingly. various inputs that impact the state include: live - returns a live result set vs. an in memory copy transform - transform a result set based on additional inputs prepared_component - if available, use existing connection from prepared component max_rows - sets the number of rows that should be returned in result sets The specified output also impacts the state of the execution. If prepared_component is defined as an output, setup the query but delay execution.- Specified by:
executeActionin classorg.pentaho.platform.engine.services.solution.ComponentBase
-
getMetadata
protected org.pentaho.commons.connection.IPentahoMetaData getMetadata(org.pentaho.commons.connection.IPentahoResultSet resultSet, boolean live)returns metadata based on the result set. if not live, create an in memory version- Parameters:
resultSet- result set object to find metadatalive- if false, create an in memory version- Returns:
- metadata object
-
executePrepared
public org.pentaho.commons.connection.IPentahoResultSet executePrepared(Map preparedParams)
executes a prepared method that returns a result set executePrepared looks up any "PREPARELATER" params in the preparedParams map.- Specified by:
executePreparedin interfaceorg.pentaho.platform.api.data.IPreparedComponent- Parameters:
preparedParams- a map of possible parameters.- Returns:
- result set
-
prepareQuery
protected boolean prepareQuery(String rawQuery)
called when in prepared-component mode, this method populates the preparedQuery string and preparedParameters object.- Parameters:
rawQuery-- Returns:
-
runQuery
protected boolean runQuery(String rawQuery, boolean live)
executes the specified query template. The query template is first formatted and then executed. If live, the original result set is made available as an output. If not live, the result set is converted into memory and the connection and live result set are closed.- Parameters:
rawQuery- query templatelive- returns original result set if true, memory result set if false- Returns:
- true if successful
-
doQuery
public org.pentaho.commons.connection.IPentahoResultSet doQuery(SQLConnection sqlConnection, String query, boolean forwardOnlyResultset) throws Exception
- Throws:
Exception
-
dispose
public void dispose()
dispose of the resultset, and if the owner, dispose of the connection.- Specified by:
disposein interfaceorg.pentaho.platform.api.data.IDataComponent- Specified by:
disposein interfaceorg.pentaho.commons.connection.IDisposable- Specified by:
disposein interfaceorg.pentaho.platform.api.data.IPreparedComponent
-
resolveParameter
public int resolveParameter(String template, String parameter, Matcher parameterMatcher, int copyStart, StringBuffer results)
This method is called when TemplateUtil.applyTemplate() encounters a parameter. TemplateUtil.applyTemplate is called when someone makes a call to applyInputsToFormat() In this class it is called in the above "runQuery()" method.- Specified by:
resolveParameterin interfaceorg.pentaho.platform.api.engine.IParameterResolver- Overrides:
resolveParameterin classorg.pentaho.platform.engine.services.solution.ComponentBase- Parameters:
template- the source stringparameter- the parameter valueparameterMatcher- the regex parameter matchercopyStart- the start of the copyresults- the output result- Returns:
- the next copystart
-
getDatasourceConnection
public org.pentaho.commons.connection.IPentahoConnection getDatasourceConnection()
attempt to aquire a connection. if connection isn't available, wait a certain period of time before trying again.- Returns:
- connection
-
waitFor
protected void waitFor(int millis)
pause the thread a certain number of milliseconds- Parameters:
millis- time to sleep
-
shareConnection
public org.pentaho.commons.connection.IPentahoConnection shareConnection()
return this class's connection. This implements the IPreparedComponent interface, which may share its connection with others.- Specified by:
shareConnectionin interfaceorg.pentaho.platform.api.data.IPreparedComponent- Returns:
- connection object
-
getConnection
protected org.pentaho.commons.connection.IPentahoConnection getConnection()
pass through to getConnection(defaultConnection)- Returns:
- connection
-
getConnection
protected org.pentaho.commons.connection.IPentahoConnection getConnection(org.pentaho.commons.connection.IPentahoConnection defaultConnection)
This method retrieves a connection based on the components inputs.- Parameters:
defaultConnection- a default connection to use if no other is available- Returns:
- new connection object
-
init
public boolean init()
nothing is done in the init function- Specified by:
initin interfaceorg.pentaho.platform.api.engine.IComponent- Specified by:
initin classorg.pentaho.platform.engine.services.solution.ComponentBase- Returns:
- true always
-
getQueryTimeout
public int getQueryTimeout()
-
setQueryTimeout
public void setQueryTimeout(int timeInSec)
-
getMaxRows
public int getMaxRows()
-
setMaxRows
public void setMaxRows(int value)
-
getQuery
public String getQuery()
-
setReadOnly
public void setReadOnly(boolean value)
-
getReadOnly
public boolean getReadOnly()
-
-