Class SQLConnection
- java.lang.Object
-
- org.pentaho.platform.plugin.services.connections.sql.SQLConnection
-
- All Implemented Interfaces:
org.pentaho.commons.connection.ILimitableConnection,org.pentaho.commons.connection.IPentahoConnection,org.pentaho.platform.engine.core.system.IPentahoLoggingConnection
public class SQLConnection extends Object implements org.pentaho.platform.engine.core.system.IPentahoLoggingConnection, org.pentaho.commons.connection.ILimitableConnection
- Author:
- wseyler TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
-
-
Field Summary
Fields Modifier and Type Field Description static intCONCUR_READONLYstatic intCONCUR_UPDATABLEprotected ConnectionnativeConnectionstatic intRESULTSET_FORWARDONLYstatic intRESULTSET_SCROLLABLE-
Fields inherited from interface org.pentaho.commons.connection.IPentahoConnection
CLASSNAME_KEY, CONNECTION, CONNECTION_NAME, DRIVER_KEY, HQL_DATASOURCE, JNDI_NAME_KEY, KEYS, LOCATION_KEY, MDX_DATASOURCE, MDX_OLAP4J_DATASOURCE, NONE_DATASOURCE, PASSWORD_KEY, PROVIDER, QUERY_KEY, SQL_DATASOURCE, USERNAME_KEY, XML_DATASOURCE
-
-
Constructor Summary
Constructors Constructor Description SQLConnection()SQLConnection(String driverName, String location, String userName, String password, org.pentaho.platform.api.engine.ILogger logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ConnectioncaptureConnection(Connection connection)Allow wrapping/proxying of the native SQL connection by a subclass.voidclearWarnings()voidclose()booleanconnect(Properties props)protected voidenhanceConnection(Connection connection)Allows the native SQL Connection to be enhanced in a subclass.protected voidenhanceStatement(Statement statement)Allows the native SQL Statement to be enhanced by a subclass.intexecute(String query)intexecute(String query, int scrollType, int concur)org.pentaho.commons.connection.IPentahoResultSetexecuteQuery(String query)Executes the specified query.org.pentaho.commons.connection.IPentahoResultSetexecuteQuery(String query, int scrollType, int concur)Executes the specified query with the defined parametersStringgetDatasourceType()return datasource type SQLintgetFetchSize()StringgetLastQuery()intgetMaxRows()ConnectiongetNativeConnection()intgetQueryTimeout()Returns the query timeout value (in seconds)booleangetReadOnly()Returns the state of the readonly flagorg.pentaho.commons.connection.IPentahoResultSetgetResultSet()protected voidinit(String driverName, String location, String userName, String password)booleaninitialized()protected voidinitWithJNDI(String jndiName)booleanisClosed()booleanisFallBackToNonscrollableOnError()booleanisForcedForwardOnly()booleanisReadOnly()org.pentaho.commons.connection.IPentahoResultSetprepareAndExecuteQuery(String query, List parameters)org.pentaho.commons.connection.IPentahoResultSetprepareAndExecuteQuery(String query, List parameters, int scrollType, int concur)booleanpreparedQueriesSupported()voidsetFallBackToNonscrollableOnError(boolean fallBackToNonscrollableOnError)voidsetFetchSize(int fetchSize)voidsetForcedForwardOnly(boolean forcedForwardOnly)voidsetLogger(org.pentaho.platform.api.engine.ILogger logger)voidsetMaxRows(int maxRows)voidsetProperties(Properties props)voidsetQueryTimeout(int timeInSec)Sets the valid of the timeout (in seconds)voidsetReadOnly(boolean value)Sets the connection object to readonly.protected voidsetStatementLimitations(Statement stmt)The purpose of this method is to set limitations such as fetchSize and maxrows on the provided statement.protected voidunEnhanceConnection(Connection connection)Allows enhancements to the native SQL Connection to be removed in a subclass.
-
-
-
Field Detail
-
nativeConnection
protected Connection nativeConnection
-
RESULTSET_SCROLLABLE
public static final int RESULTSET_SCROLLABLE
- See Also:
- Constant Field Values
-
RESULTSET_FORWARDONLY
public static final int RESULTSET_FORWARDONLY
- See Also:
- Constant Field Values
-
CONCUR_READONLY
public static final int CONCUR_READONLY
- See Also:
- Constant Field Values
-
CONCUR_UPDATABLE
public static final int CONCUR_UPDATABLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
setLogger
public void setLogger(org.pentaho.platform.api.engine.ILogger logger)
- Specified by:
setLoggerin interfaceorg.pentaho.platform.engine.core.system.IPentahoLoggingConnection
-
setProperties
public void setProperties(Properties props)
- Specified by:
setPropertiesin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
setQueryTimeout
public void setQueryTimeout(int timeInSec)
Sets the valid of the timeout (in seconds)- Specified by:
setQueryTimeoutin interfaceorg.pentaho.commons.connection.ILimitableConnection
-
setReadOnly
public void setReadOnly(boolean value)
Sets the connection object to readonly.- Parameters:
value-
-
getQueryTimeout
public int getQueryTimeout()
Returns the query timeout value (in seconds)
-
initialized
public boolean initialized()
- Specified by:
initializedin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
getDatasourceType
public String getDatasourceType()
return datasource type SQL- Specified by:
getDatasourceTypein interfaceorg.pentaho.commons.connection.IPentahoConnection- Returns:
- datasource type
-
initWithJNDI
protected void initWithJNDI(String jndiName)
-
enhanceConnection
protected void enhanceConnection(Connection connection) throws SQLException
Allows the native SQL Connection to be enhanced in a subclass. Best used when a connection needs to be enhanced with an "effective user"- Parameters:
connection-- Throws:
SQLException
-
unEnhanceConnection
protected void unEnhanceConnection(Connection connection) throws SQLException
Allows enhancements to the native SQL Connection to be removed in a subclass. Best used when a connection needs to be enhanced with an "effective user"- Parameters:
connection-- Throws:
SQLException
-
captureConnection
protected Connection captureConnection(Connection connection) throws SQLException
Allow wrapping/proxying of the native SQL connection by a subclass. Best used when a connection needs to be be enhanced or proxied for Single Signon or possibly tenanting.- Parameters:
connection-- Returns:
- Throws:
SQLException
-
enhanceStatement
protected void enhanceStatement(Statement statement) throws SQLException
Allows the native SQL Statement to be enhanced by a subclass. Examples may be to allow additional information like a user to be bound to the statement.- Parameters:
statement-- Throws:
SQLException
-
close
public void close()
- Specified by:
closein interfaceorg.pentaho.commons.connection.IPentahoConnection
-
getLastQuery
public String getLastQuery()
- Specified by:
getLastQueryin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
executeQuery
public org.pentaho.commons.connection.IPentahoResultSet executeQuery(String query) throws SQLException, InterruptedException, org.pentaho.platform.api.engine.PentahoSystemException
Executes the specified query.- Specified by:
executeQueryin interfaceorg.pentaho.commons.connection.IPentahoConnection- Parameters:
query- the query to execute- Returns:
- the resultset from the query
- Throws:
SQLException- indicates an error running the queryInterruptedException- indicates that the query took longer than the allowed timeout valueorg.pentaho.platform.api.engine.PentahoSystemException
-
executeQuery
public org.pentaho.commons.connection.IPentahoResultSet executeQuery(String query, int scrollType, int concur) throws SQLException, InterruptedException, org.pentaho.platform.api.engine.PentahoSystemException
Executes the specified query with the defined parameters- Parameters:
query- the query to be executedscrollType-concur-- Returns:
- the result set of data for the query
- Throws:
SQLException- indicates an error running the queryInterruptedException- indicates the query took longer than allowable by the query timeoutorg.pentaho.platform.api.engine.PentahoSystemException
-
prepareAndExecuteQuery
public org.pentaho.commons.connection.IPentahoResultSet prepareAndExecuteQuery(String query, List parameters) throws SQLException
- Specified by:
prepareAndExecuteQueryin interfaceorg.pentaho.commons.connection.IPentahoConnection- Throws:
SQLException
-
setStatementLimitations
protected void setStatementLimitations(Statement stmt) throws SQLException
The purpose of this method is to set limitations such as fetchSize and maxrows on the provided statement. If the JDBC driver does not support the setting and throws an Exception, we will re-throw iff the limit was explicitly set.- Parameters:
stmt- Either a Statement or PreparedStatement- Throws:
SQLException- , UnsupportedOperationException
-
prepareAndExecuteQuery
public org.pentaho.commons.connection.IPentahoResultSet prepareAndExecuteQuery(String query, List parameters, int scrollType, int concur) throws SQLException
- Throws:
SQLException
-
preparedQueriesSupported
public boolean preparedQueriesSupported()
- Specified by:
preparedQueriesSupportedin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
clearWarnings
public void clearWarnings()
- Specified by:
clearWarningsin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
getResultSet
public org.pentaho.commons.connection.IPentahoResultSet getResultSet()
- Specified by:
getResultSetin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
connect
public boolean connect(Properties props)
- Specified by:
connectin interfaceorg.pentaho.commons.connection.IPentahoConnection
-
execute
public int execute(String query) throws SQLException
- Throws:
SQLException
-
execute
public int execute(String query, int scrollType, int concur) throws SQLException
- Throws:
SQLException
-
getNativeConnection
public Connection getNativeConnection()
- Returns:
- Returns the nativeConnection.
-
getFetchSize
public int getFetchSize()
- Returns:
- Returns the fetchSize.
-
setFetchSize
public void setFetchSize(int fetchSize)
- Specified by:
setFetchSizein interfaceorg.pentaho.commons.connection.IPentahoConnection- Parameters:
fetchSize- The fetchSize to set.
-
getMaxRows
public int getMaxRows()
- Returns:
- Returns the maxRows.
-
setMaxRows
public void setMaxRows(int maxRows)
- Specified by:
setMaxRowsin interfaceorg.pentaho.commons.connection.ILimitableConnection- Specified by:
setMaxRowsin interfaceorg.pentaho.commons.connection.IPentahoConnection- Parameters:
maxRows- The maxRows to set.
-
getReadOnly
public boolean getReadOnly()
Returns the state of the readonly flag- Returns:
- true if the connection is set to readonly
-
setFallBackToNonscrollableOnError
public void setFallBackToNonscrollableOnError(boolean fallBackToNonscrollableOnError)
-
isFallBackToNonscrollableOnError
public boolean isFallBackToNonscrollableOnError()
-
isForcedForwardOnly
public boolean isForcedForwardOnly()
-
setForcedForwardOnly
public void setForcedForwardOnly(boolean forcedForwardOnly)
-
-