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.IParameterResolver
SQLBaseComponent 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.pentaho.commons.connection.IPentahoConnectionreference to connection objectprotected booleanis set to false if using another IPreparedComponents connection vs ownstatic final Stringprotected Liststores the prepared parameters for later useprotected Stringstores the prepared query for later useFields inherited from class org.pentaho.platform.engine.services.solution.ComponentBase
COMPONENT_EXECUTE_FAIL, debug, MISSING_SESSION, UNKNOWN_COMPONENT_IDFields inherited from class org.pentaho.platform.engine.core.system.PentahoBase
EMPTYLOGID, loggingLevel, LOGID_MASK1, LOGID_MASK2, LOGID_SEPARATORFields inherited from interface org.pentaho.platform.api.engine.ILogger
ACTIVITY_LOG, DEBUG, ERROR, FATAL, INFO, INSTANCE_LOG, SESSION_LOG, SOLUTION_LOG, TRACE, UNKNOWN, WARNFields inherited from interface org.pentaho.platform.api.data.IPreparedComponent
PREPARE_LATER_INTER_PREFIX, PREPARE_LATER_PLACEHOLDER, PREPARE_LATER_PREFIX, PREPARED_COMPONENT_NAME, PREPARED_OUTPUT_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()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 booleandetermines 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.IPentahoConnectionpass 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.IPentahoConnectionattempt to aquire a connection.abstract org.apache.commons.logging.Logintprotected org.pentaho.commons.connection.IPentahoMetaDatagetMetadata(org.pentaho.commons.connection.IPentahoResultSet resultSet, boolean live) returns metadata based on the result set.getQuery()intbooleanabstract Stringorg.pentaho.commons.connection.IPentahoResultSetreturns 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 booleanexecutes the specified query template.voidsetMaxRows(int value) voidsetQueryTimeout(int timeInSec) voidsetReadOnly(boolean value) org.pentaho.commons.connection.IPentahoConnectionreturn this class's connection.booleanvalidates the action.abstract booleanprotected voidwaitFor(int millis) pause the thread a certain number of millisecondsMethods 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, validateMethods inherited from class org.pentaho.platform.engine.services.PentahoMessenger
debug, debug, error, error, error, fatal, fatal, getMessages, getUserString, info, info, setMessages, trace, trace, warn, warnMethods inherited from class org.pentaho.platform.engine.core.system.PentahoBase
genLogIdFromInfo, genLogIdFromInfo, genLogIdFromSession, getLoggingLevel, setLoggingLevel, setLogIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.pentaho.platform.api.engine.IAuditable
getId, getObjectNameMethods 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, validateMethods inherited from interface org.pentaho.platform.api.engine.ILogger
debug, debug, error, error, fatal, fatal, getLoggingLevel, info, info, setLoggingLevel, trace, trace, warn, warn
-
Field Details
-
PREPARE_PARAMETER_PREFIX
- See Also:
-
preparedQuery
stores the prepared query for later use -
preparedParameters
stores the prepared parameters for later use -
connectionOwner
protected boolean connectionOwneris set to false if using another IPreparedComponents connection vs own -
connection
protected org.pentaho.commons.connection.IPentahoConnection connectionreference to connection object
-
-
Constructor Details
-
SQLBaseComponent
public SQLBaseComponent()
-
-
Method Details
-
validateSystemSettings
public abstract boolean validateSystemSettings()- Specified by:
validateSystemSettingsin classorg.pentaho.platform.engine.services.solution.ComponentBase
-
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
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
called when in prepared-component mode, this method populates the preparedQuery string and preparedParameters object.- Parameters:
rawQuery-- Returns:
-
runQuery
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
-
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
-
setReadOnly
public void setReadOnly(boolean value) -
getReadOnly
public boolean getReadOnly()
-