Class Database
- java.lang.Object
-
- org.pentaho.di.core.database.Database
-
- All Implemented Interfaces:
Closeable,AutoCloseable,LoggingObjectInterface,LoggingObjectLifecycleInterface,VariableSpace
public class Database extends Object implements VariableSpace, LoggingObjectInterface, Closeable
Database handles the process of connecting to, reading from, writing to and updating databases. The database specific parameters are defined in DatabaseInfo.- Since:
- 05-04-2003
- Author:
- Matt
-
-
Constructor Summary
Constructors Constructor Description Database(DatabaseMeta databaseMeta)Deprecated.Please specify the parent object so that we can see which object is initiating a database connectionDatabase(LoggingObjectInterface parentObject, DatabaseMeta databaseMeta)Construct a new Database Connection
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanabsolute(ResultSet rs, int position)voidafterLast(ResultSet rs)RowMetaAndDatacallProcedure(String[] arg, String[] argdir, int[] argtype, String resultname, int resulttype)voidcancelQuery()Cancel the open/running queries on the database connectionvoidcancelStatement(Statement statement)Cancel an open/running SQL statementbooleancheckColumnExists(String columnname, String tablename)Deprecated.Deprecated in favor of the smartercheckColumnExists(String, String, String)booleancheckColumnExists(String schemaname, String tablename, String columnname)See if the column specified exists by reading the metadata first, execution last.booleancheckColumnExistsByDbMeta(String schemaname, String tablename, String columnname)booleancheckIndexExists(String tableName, String[] idxFields)Check if an index on certain fields in a table exists.booleancheckIndexExists(String schemaName, String tableName, String[] idxFields)Check if an index on certain fields in a table exists.booleancheckSequenceExists(String sequenceName)Check whether the sequence exists, Oracle only!booleancheckSequenceExists(String schemaName, String sequenceName)Check whether the sequence exists, Oracle only!booleancheckTableExists(String tablename)Deprecated.Deprecated in favor ofcheckTableExists(String, String)booleancheckTableExists(String schema, String tablename)See if the table specified exists.booleancheckTableExistsByDbMeta(String schema, String tablename)Deprecated.Deprecated in favor ofcheckTableExists(String, String)voidcleanupLogRecords(LogTableCoreInterface logTable, String transJobName)voidclearBatch(PreparedStatement preparedStatement)voidclearInsertBatch()Deprecated.voidclose()voidcloseConnectionOnly()Only for unique connections usage, typically you use disconnect() to disconnect() from the database.voidcloseInsert()voidcloseLookup()voidclosePreparedStatement(PreparedStatement ps)voidcloseProcedureStatement()voidcloseQuery(ResultSet res)voidcloseUpdate()voidcommit()Perform a commit the connection if this is supported by the databasevoidcommit(boolean force)voidcommitLog(boolean force, LogTableCoreInterface logTable)This methods may be removed in future.voidcommitLog(LogTableCoreInterface logTable)This methods may be removed in future.voidconnect()Open the database connection.voidconnect(String partitionId)Open the database connection.voidconnect(String group, String partitionId)voidcopyVariablesFrom(VariableSpace space)Copy the variables from another space, without initializing with the defaults.intcountParameters(String sql)static KettleDatabaseBatchExceptioncreateKettleDatabaseBatchException(String message, SQLException ex)voiddisconnect()Disconnect from the database and close all open prepared statements.voidemptyAndCommit(PreparedStatement ps, boolean batch)Close the passed prepared statement.voidemptyAndCommit(PreparedStatement ps, boolean batch, int batchCounter)Close the prepared statement of the insert statement.StringenvironmentSubstitute(String aString)Substitute the string using the current variable space.String[]environmentSubstitute(String[] aString)Replaces environment variables in an array of strings.booleanequals(Object obj)This implementation is NullPointerException subject, and may not follow fundamental equals contract.ResultexecStatement(String sql)Execute an SQL statement on the database connection (has to be open)ResultexecStatement(String rawsql, RowMetaInterface params, Object[] data)ResultexecStatements(String script)Execute a series of SQL statements, separated by ;ResultexecStatements(String script, RowMetaInterface params, Object[] data)Execute a series of SQL statements, separated by ;ResultexecStatementsFromFile(String filename, boolean sendSinglestatement)Execute an SQL statement inside a file on the database connection (has to be open)voidexecuteAndClearBatch(PreparedStatement preparedStatement)StringfieldSubstitute(String aString, RowMetaInterface rowMeta, Object[] rowData)Substitutes field values inaString.voidfirst(ResultSet rs)StringgetAlterTableStatement(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon)booleangetBooleanValueOfVariable(String variableName, boolean defaultValue)This method returns a boolean for the new variable check boxes.String[]getCatalogs()ConnectiongetConnection()StringgetConnectionGroup()StringgetContainerObjectId()Gets the execution container (Carte/DI server/BI Server) object id.intgetCopy()StringgetCreateIndexStatement(String tablename, String indexname, String[] idxFields, boolean tk, boolean unique, boolean bitmap, boolean semiColon)StringgetCreateIndexStatement(String schemaname, String tablename, String indexname, String[] idxFields, boolean tk, boolean unique, boolean bitmap, boolean semiColon)StringgetCreateSequenceStatement(String sequence, long startAt, long incrementBy, long maxValue, boolean semiColon)StringgetCreateSequenceStatement(String schemaName, String sequence, long startAt, long incrementBy, long maxValue, boolean semiColon)StringgetCreateSequenceStatement(String sequence, String startAt, String incrementBy, String maxValue, boolean semiColon)StringgetCreateSequenceStatement(String schemaName, String sequenceName, String startAt, String incrementBy, String maxValue, boolean semiColon)StringgetCreateTableStatement(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon)Generates SQLDatabaseMetagetDatabaseMeta()DatabaseMetaDatagetDatabaseMetaData()DataSourcegetDataSource(String partitionId)StringgetDDL(String tablename, RowMetaInterface fields)StringgetDDL(String tablename, RowMetaInterface fields, String tk, boolean useAutoinc, String pk)StringgetDDL(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon)StringgetDDLCreationTable(String tableName, RowMetaInterface fields)Return SQL CREATION statement for a TableStringgetDDLTruncateTable(String schema, String tablename)Return SQL TRUNCATE statement for a TableStringgetFilename()Gets the filename.List<Object[]>getFirstRows(String tableName, int limit)List<Object[]>getFirstRows(String tableName, int limit, ProgressMonitorListener monitor)Get the first rows from a table (for preview)RowMetaAndDatagetGeneratedKeys(PreparedStatement ps)StringgetInsertStatement(String schemaName, String tableName, RowMetaInterface fields)StringgetInsertStatement(String tableName, RowMetaInterface fields)Object[]getLastLogDate(String logtable, String name, boolean job, LogStatus status)StringgetLogChannelId()Gets the log channel id.LogLevelgetLogLevel()Gets the logging level of the log channel of this logging object.Object[]getLookup()Object[]getLookup(boolean failOnMultipleResults)Object[]getLookup(boolean failOnMultipleResults, boolean lazyConversion)Object[]getLookup(PreparedStatement ps)Object[]getLookup(PreparedStatement ps, boolean failOnMultipleResults)Object[]getLookup(PreparedStatement ps, boolean failOnMultipleResults, boolean lazyConversion)RowMetagetMetaFromRow(Object[] row, ResultSetMetaData md)LonggetNextSequenceValue(String sequenceName, String keyfield)LonggetNextSequenceValue(String schemaName, String sequenceName, String keyfield)LonggetNextValue(Hashtable<String,Counter> counters, String tableName, String valKey)LonggetNextValue(Hashtable<String,Counter> counters, String schemaName, String tableName, String valKey)intgetNrExecutedCommits()StringgetObjectCopy()Gets a string identifying a copy in a series of steps.ObjectIdgetObjectId()Gets the object id in a repository.StringgetObjectName()Gets the object name.ObjectRevisiongetObjectRevision()Gets the objects revision in a repository.LoggingObjectTypegetObjectType()Gets the object type.RowMetaAndDatagetOneRow(String sql)Execute a query and return at most one row from the resultsetRowMetaAndDatagetOneRow(String sql, RowMetaInterface param, Object[] data)intgetOpened()StringgetOwnerName()RowMetaInterfacegetParameterMetaData(String sql, RowMetaInterface inform, Object[] data)RowMetaInterfacegetParameterMetaData(PreparedStatement ps)LoggingObjectInterfacegetParent()Gets the parent.ObjectgetParentObject()VariableSpacegetParentVariableSpace()Get the parent of the variable space.StringgetPartitionId()PreparedStatementgetPrepStatementInsert()PreparedStatementgetPrepStatementLookup()PreparedStatementgetPrepStatementUpdate()String[]getPrimaryKeyColumnNames(String tablename)Return primary key column names ...String[]getProcedures()RowMetaInterfacegetQueryFields(String sql, boolean param)RowMetaInterfacegetQueryFields(String sql, boolean param, RowMetaInterface inform, Object[] data)RowMetaInterfacegetQueryFieldsFallback(String sql, boolean param, RowMetaInterface inform, Object[] data)RowMetaInterfacegetQueryFieldsFromDatabaseMetaData()RowMetaInterfacegetQueryFieldsFromPreparedStatement(String sql)DategetRegistrationDate()StubRepositoryDirectorygetRepositoryDirectory()Gets the repository directory.RowMetaInterfacegetReturnRowMeta()Object[]getRow(ResultSet rs)Get a row from the resultset.Object[]getRow(ResultSet rs, boolean lazyConversion)Get a row from the resultset.Object[]getRow(ResultSet rs, ResultSetMetaData dummy, RowMetaInterface rowInfo)Get a row from the resultset.List<Object[]>getRows(String sql, int limit)Reads the result of an SQL query into an ArrayListList<Object[]>getRows(String sql, int limit, ProgressMonitorListener monitor)Reads the result of an SQL query into an ArrayListList<Object[]>getRows(String sql, RowMetaInterface params, Object[] data, int fetchMode, boolean lazyConversion, int limit, ProgressMonitorListener monitor)Reads the result of an SQL query into an ArrayList.List<Object[]>getRows(ResultSet rset, int limit, ProgressMonitorListener monitor)Reads the result of a ResultSet into an ArrayListString[]getSchemas()String[]getSequences()Return all sequence names from connectionStringgetSQLOutput(String schemaName, String tableName, RowMetaInterface fields, Object[] r, String dateFormat)Return SQL statement (INSERT INTO TableName ...Map<String,Collection<String>>getSynonymMap()Map<String,Collection<String>>getSynonymMap(String schemanamein)String[]getSynonyms()String[]getSynonyms(boolean includeSchema)String[]getSynonyms(String schemanamein, boolean includeSchema)RowMetaInterfacegetTableFields(String tablename)Returns a RowMeta describing the fields of a table expression.RowMetaInterfacegetTableFieldsMeta(String schemaName, String tableName)Returns a RowMeta describing the fields of a table.RowMetaInterfacegetTableFieldsMetaByDbMeta(String schemaName, String tableName)Map<String,Collection<String>>getTableMap()Map<String,Collection<String>>getTableMap(String schemanamein)Map<String,Collection<String>>getTableMap(String schemanamein, Map<String,String> props)String[]getTablenames()String[]getTablenames(boolean includeSchema)String[]getTablenames(String schemanamein, boolean includeSchema)String[]getTablenames(String schemanamein, boolean includeSchema, Map<String,String> props)String[]getTableTypes()booleangetUseBatchInsert(boolean batch)StringgetVariable(String variableName)Get the value of a variable.StringgetVariable(String variableName, String defaultValue)Get the value of a variable with a default in case the variable is not found.Map<String,Collection<String>>getViewMap()Map<String,Collection<String>>getViewMap(String schemanamein)String[]getViews()String[]getViews(boolean includeSchema)String[]getViews(String schemanamein, boolean includeSchema)voidinitializeConnectionDataSource(String partitionId)voidinitializeVariablesFrom(VariableSpace parent)Initialize variable space using the defaults, copy over the variables from the parent (using copyVariablesFrom()), after this the "injected" variables should be inserted (injectVariables()).voidinjectVariables(Map<String,String> prop)Inject variables.voidinsertFinished(boolean batch)voidinsertFinished(PreparedStatement ps, boolean batch)Deprecated.use emptyAndCommit() instead (pass in the number of rows left in the batch)voidinsertRow()voidinsertRow(boolean batch)voidinsertRow(String schemaName, String tableName, RowMetaInterface fields, Object[] data)voidinsertRow(String tableName, RowMetaInterface fields, Object[] data)voidinsertRow(PreparedStatement ps)booleaninsertRow(PreparedStatement ps, boolean batch)Insert a row into the database using a prepared statement that has all values set.booleaninsertRow(PreparedStatement ps, boolean batch, boolean handleCommit)Insert a row into the database using a prepared statement that has all values set.booleanisAutoCommit()booleanisForcingSeparateLogging()booleanisGatheringMetrics()Gets the boolean value of whether or not this object is gathering kettle metrics during execution.booleanisLoggingObjectInUse()booleanisSystemTable(String tableName)String[]listVariables()List the variables (not the values) that are currently in the variable space.voidlockTables(String[] tableNames)Lock a tables in the database for write operationsvoidnormalConnect(String partitionId)Open the database connection.ResultSetopenQuery(String sql)ResultSetopenQuery(String sql, RowMetaInterface params, Object[] data)Open a query on the database with a set of parameters stored in a Kettle RowResultSetopenQuery(String sql, RowMetaInterface params, Object[] data, int fetchMode)ResultSetopenQuery(String sql, RowMetaInterface params, Object[] data, int fetchMode, boolean lazyConversion)ResultSetopenQuery(PreparedStatement ps, RowMetaInterface params, Object[] data)booleanprepareDelete(String table, String[] codes, String[] condition)Prepare a delete statement by giving it the tablename, fields and conditions to work with.booleanprepareDelete(String schemaName, String tableName, String[] codes, String[] condition)Prepare a delete statement by giving it the tablename, fields and conditions to work with.voidprepareInsert(RowMetaInterface rowMeta, String tableName)Prepare inserting values into a table, using the fields & values in a RowvoidprepareInsert(RowMetaInterface rowMeta, String schemaName, String tableName)Prepare inserting values into a table, using the fields & values in a RowPreparedStatementprepareSQL(String sql)Prepare a statement to be executed on the database.PreparedStatementprepareSQL(String sql, boolean returnKeys)Prepare a statement to be executed on the database.booleanprepareUpdate(String table, String[] codes, String[] condition, String[] sets)booleanprepareUpdate(String schemaName, String tableName, String[] codes, String[] condition, String[] sets)voidprintSQLException(SQLException ex)booleanrelative(ResultSet rs, int rows)voidreleaseSavepoint(Savepoint savepoint)voidrollback()voidrollback(boolean force)voidrollback(Savepoint savepoint)voidsetAutoCommit()voidsetAutoCommit(boolean useAutoCommit)voidsetCommit(int commitSize)Specify after how many rows a commit needs to occur when inserting or updating values.voidsetCommitSize(int size)voidsetConnection(Connection connection)Allows for the injection of a "life" connection, generated by a piece of software outside of Kettle.voidsetConnectionGroup(String connectionGroup)voidsetContainerObjectId(String containerObjectId)voidsetCopy(int copy)voidsetForcingSeparateLogging(boolean forcingSeparateLogging)This option will force the create of a separate logging channel even if the logging concerns identical objects with identical names.voidsetGatheringMetrics(boolean gatheringMetrics)Enable of disable kettle metrics gathering during executionvoidsetLoggingObjectInUse(boolean inUse)voidsetLogLevel(LogLevel logLevel)voidsetLookup(String table, String[] codes, String[] condition, String[] gets, String[] rename, String orderby)voidsetLookup(String tableName, String[] codes, String[] condition, String[] gets, String[] rename, String orderby, boolean checkForMultipleResults)voidsetLookup(String schema, String table, String[] codes, String[] condition, String[] gets, String[] rename, String orderby)voidsetLookup(String schemaName, String tableName, String[] codes, String[] condition, String[] gets, String[] rename, String orderby, boolean checkForMultipleResults)voidsetNrExecutedCommits(int nrExecutedCommits)voidsetOpened(int opened)voidsetOwnerName(String name)voidsetParentVariableSpace(VariableSpace parent)Set the parent variable spacevoidsetPartitionId(String partitionId)voidsetProcLookup(String proc, String[] arg, String[] argdir, int[] argtype, String returnvalue, int returntype)voidsetProcValues(RowMetaInterface rowMeta, Object[] data, int[] argnrs, String[] argdir, boolean result)voidsetQueryLimit(int rows)Set the maximum number of records to retrieve from a query.SavepointsetSavepoint()SavepointsetSavepoint(String savePointName)voidsetValue(PreparedStatement ps, ValueMetaInterface v, Object object, int pos)voidsetValues(RowMetaInterface rowMeta, Object[] data)voidsetValues(RowMetaInterface rowMeta, Object[] data, PreparedStatement ps)voidsetValues(RowMetaInterface rowMeta, Object[] data, PreparedStatement ps, int ignoreThisValueIndex)Sets the values of the preparedStatement pstmt.voidsetValues(RowMetaAndData row)voidsetValues(RowMetaAndData row, PreparedStatement ps)voidsetValuesInsert(RowMetaInterface rowMeta, Object[] data)voidsetValuesInsert(RowMetaAndData row)voidsetValuesLookup(RowMetaInterface rowMeta, Object[] data)voidsetValuesUpdate(RowMetaInterface rowMeta, Object[] data)voidsetVariable(String variableName, String variableValue)Sets a variable in the Kettle Variables list.voidshareVariablesWith(VariableSpace space)Share a variable space from another variable space.StringtoString()voidtruncateTable(String tablename)voidtruncateTable(String schema, String tablename)voidunlockTables(String[] tableNames)Unlock certain tables in the database for write operationsvoidupdateRow()voidwriteLogRecord(LogTableCoreInterface logTable, LogStatus status, Object subject, Object parent)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.pentaho.di.core.logging.LoggingObjectLifecycleInterface
callAfterLog, callBeforeLog
-
Methods inherited from interface org.pentaho.di.core.variables.VariableSpace
environmentSubstitute
-
-
-
-
Constructor Detail
-
Database
@Deprecated public Database(DatabaseMeta databaseMeta)
Deprecated.Please specify the parent object so that we can see which object is initiating a database connectionConstruct a new Database Connection- Parameters:
databaseMeta- The Database Connection Info to construct the connection with.
-
Database
public Database(LoggingObjectInterface parentObject, DatabaseMeta databaseMeta)
Construct a new Database Connection- Parameters:
databaseMeta- The Database Connection Info to construct the connection with.
-
-
Method Detail
-
equals
public boolean equals(Object obj)
This implementation is NullPointerException subject, and may not follow fundamental equals contract. Databases equality is based onDatabaseMetaequality.
-
setConnection
public void setConnection(Connection connection)
Allows for the injection of a "life" connection, generated by a piece of software outside of Kettle.- Parameters:
connection-
-
getConnection
public Connection getConnection()
- Returns:
- Returns the connection.
-
setQueryLimit
public void setQueryLimit(int rows)
Set the maximum number of records to retrieve from a query.- Parameters:
rows-
-
getPrepStatementInsert
public PreparedStatement getPrepStatementInsert()
- Returns:
- Returns the prepStatementInsert.
-
getPrepStatementLookup
public PreparedStatement getPrepStatementLookup()
- Returns:
- Returns the prepStatementLookup.
-
getPrepStatementUpdate
public PreparedStatement getPrepStatementUpdate()
- Returns:
- Returns the prepStatementUpdate.
-
getDataSource
public DataSource getDataSource(String partitionId) throws KettleDatabaseException
- Returns:
- Returns the dataSource.
- Throws:
KettleDatabaseException
-
isLoggingObjectInUse
public boolean isLoggingObjectInUse()
- Specified by:
isLoggingObjectInUsein interfaceLoggingObjectInterface
-
setLoggingObjectInUse
public void setLoggingObjectInUse(boolean inUse)
-
connect
public void connect() throws KettleDatabaseExceptionOpen the database connection.- Throws:
KettleDatabaseException- if something went wrong.
-
connect
public void connect(String partitionId) throws KettleDatabaseException
Open the database connection.- Parameters:
partitionId- the partition ID in the cluster to connect to.- Throws:
KettleDatabaseException- if something went wrong.
-
connect
public void connect(String group, String partitionId) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
normalConnect
public void normalConnect(String partitionId) throws KettleDatabaseException
Open the database connection. The algorithm is:- If
databaseMeta.getAccessType()returnsDatabaseMeta.TYPE_ACCESS_JNDI, then the connection's datasource is looked up in JNDI - If
databaseMeta.isUsingConnectionPool(), then the connection's datasource is looked up in the pool - otherwise, the connection is established via DriverManager
- Parameters:
partitionId- the partition ID in the cluster to connect to.- Throws:
KettleDatabaseException- if something went wrong.
- If
-
initializeConnectionDataSource
public void initializeConnectionDataSource(String partitionId) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
disconnect
public void disconnect()
Disconnect from the database and close all open prepared statements.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
closeConnectionOnly
public void closeConnectionOnly() throws KettleDatabaseExceptionOnly for unique connections usage, typically you use disconnect() to disconnect() from the database.- Throws:
KettleDatabaseException- in case there is an error during connection close.
-
cancelQuery
public void cancelQuery() throws KettleDatabaseExceptionCancel the open/running queries on the database connection- Throws:
KettleDatabaseException
-
cancelStatement
public void cancelStatement(Statement statement) throws KettleDatabaseException
Cancel an open/running SQL statement- Parameters:
statement- the statement to cancel- Throws:
KettleDatabaseException
-
setCommit
public void setCommit(int commitSize)
Specify after how many rows a commit needs to occur when inserting or updating values.- Parameters:
commitSize- The number of rows to wait before doing a commit on the connection.
-
setAutoCommit
public void setAutoCommit()
-
setCommitSize
public void setCommitSize(int size)
-
setAutoCommit
public void setAutoCommit(boolean useAutoCommit) throws KettleDatabaseException- Throws:
KettleDatabaseException
-
commit
public void commit() throws KettleDatabaseExceptionPerform a commit the connection if this is supported by the database- Throws:
KettleDatabaseException
-
commit
public void commit(boolean force) throws KettleDatabaseException- Throws:
KettleDatabaseException
-
commitLog
public void commitLog(LogTableCoreInterface logTable) throws KettleDatabaseException
This methods may be removed in future.- Parameters:
logTable-- Throws:
KettleDatabaseException
-
commitLog
public void commitLog(boolean force, LogTableCoreInterface logTable) throws KettleDatabaseExceptionThis methods may be removed in future.- Parameters:
force-logTable-- Throws:
KettleDatabaseException
-
rollback
public void rollback() throws KettleDatabaseException- Throws:
KettleDatabaseException
-
rollback
public void rollback(boolean force) throws KettleDatabaseException- Throws:
KettleDatabaseException
-
prepareInsert
public void prepareInsert(RowMetaInterface rowMeta, String tableName) throws KettleDatabaseException
Prepare inserting values into a table, using the fields & values in a Row- Parameters:
rowMeta- The row metadata to determine which values need to be insertedtableName- The name of the table in which we want to insert rows- Throws:
KettleDatabaseException- if something went wrong.
-
prepareInsert
public void prepareInsert(RowMetaInterface rowMeta, String schemaName, String tableName) throws KettleDatabaseException
Prepare inserting values into a table, using the fields & values in a Row- Parameters:
rowMeta- The metadata row to determine which values need to be insertedschemaName- The name of the schema in which we want to insert rowstableName- The name of the table in which we want to insert rows- Throws:
KettleDatabaseException- if something went wrong.
-
prepareSQL
public PreparedStatement prepareSQL(String sql) throws KettleDatabaseException
Prepare a statement to be executed on the database. (does not return generated keys)- Parameters:
sql- The SQL to be prepared- Returns:
- The PreparedStatement object.
- Throws:
KettleDatabaseException
-
prepareSQL
public PreparedStatement prepareSQL(String sql, boolean returnKeys) throws KettleDatabaseException
Prepare a statement to be executed on the database.- Parameters:
sql- The SQL to be preparedreturnKeys- set to true if you want to return generated keys from an insert statement- Returns:
- The PreparedStatement object.
- Throws:
KettleDatabaseException
-
closeLookup
public void closeLookup() throws KettleDatabaseException- Throws:
KettleDatabaseException
-
closePreparedStatement
public void closePreparedStatement(PreparedStatement ps) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
closeInsert
public void closeInsert() throws KettleDatabaseException- Throws:
KettleDatabaseException
-
closeUpdate
public void closeUpdate() throws KettleDatabaseException- Throws:
KettleDatabaseException
-
setValues
public void setValues(RowMetaInterface rowMeta, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValues
public void setValues(RowMetaAndData row) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValuesInsert
public void setValuesInsert(RowMetaInterface rowMeta, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValuesInsert
public void setValuesInsert(RowMetaAndData row) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValuesUpdate
public void setValuesUpdate(RowMetaInterface rowMeta, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValuesLookup
public void setValuesLookup(RowMetaInterface rowMeta, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setProcValues
public void setProcValues(RowMetaInterface rowMeta, Object[] data, int[] argnrs, String[] argdir, boolean result) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValue
public void setValue(PreparedStatement ps, ValueMetaInterface v, Object object, int pos) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValues
public void setValues(RowMetaAndData row, PreparedStatement ps) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValues
public void setValues(RowMetaInterface rowMeta, Object[] data, PreparedStatement ps) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setValues
public void setValues(RowMetaInterface rowMeta, Object[] data, PreparedStatement ps, int ignoreThisValueIndex) throws KettleDatabaseException
Sets the values of the preparedStatement pstmt.- Parameters:
rowMeta-data-- Throws:
KettleDatabaseException
-
getGeneratedKeys
public RowMetaAndData getGeneratedKeys(PreparedStatement ps) throws KettleDatabaseException
- Parameters:
ps- The prepared insert statement to use- Returns:
- The generated keys in auto-increment fields
- Throws:
KettleDatabaseException- in case something goes wrong retrieving the keys.
-
getNextSequenceValue
public Long getNextSequenceValue(String sequenceName, String keyfield) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getNextSequenceValue
public Long getNextSequenceValue(String schemaName, String sequenceName, String keyfield) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
insertRow
public void insertRow(String tableName, RowMetaInterface fields, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
insertRow
public void insertRow(String schemaName, String tableName, RowMetaInterface fields, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getInsertStatement
public String getInsertStatement(String tableName, RowMetaInterface fields)
-
getInsertStatement
public String getInsertStatement(String schemaName, String tableName, RowMetaInterface fields)
-
insertRow
public void insertRow() throws KettleDatabaseException- Throws:
KettleDatabaseException
-
insertRow
public void insertRow(boolean batch) throws KettleDatabaseException- Throws:
KettleDatabaseException
-
updateRow
public void updateRow() throws KettleDatabaseException- Throws:
KettleDatabaseException
-
insertRow
public void insertRow(PreparedStatement ps) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
insertRow
public boolean insertRow(PreparedStatement ps, boolean batch) throws KettleDatabaseException
Insert a row into the database using a prepared statement that has all values set.- Parameters:
ps- The prepared statementbatch- True if you want to use batch inserts (size = commit size)- Returns:
- true if the rows are safe: if batch of rows was sent to the database OR if a commit was done.
- Throws:
KettleDatabaseException
-
getUseBatchInsert
public boolean getUseBatchInsert(boolean batch) throws KettleDatabaseException- Throws:
KettleDatabaseException
-
insertRow
public boolean insertRow(PreparedStatement ps, boolean batch, boolean handleCommit) throws KettleDatabaseException
Insert a row into the database using a prepared statement that has all values set.- Parameters:
ps- The prepared statementbatch- True if you want to use batch inserts (size = commit size)handleCommit- True if you want to handle the commit here after the commit size (False e.g. in case the step handles this, see TableOutput)- Returns:
- true if the rows are safe: if batch of rows was sent to the database OR if a commit was done.
- Throws:
KettleDatabaseException
-
clearInsertBatch
@Deprecated public void clearInsertBatch() throws KettleDatabaseException
Deprecated.Clears batch of insert prepared statement- Throws:
KettleDatabaseException
-
clearBatch
public void clearBatch(PreparedStatement preparedStatement) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
executeAndClearBatch
public void executeAndClearBatch(PreparedStatement preparedStatement) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
insertFinished
public void insertFinished(boolean batch) throws KettleDatabaseException- Throws:
KettleDatabaseException
-
emptyAndCommit
public void emptyAndCommit(PreparedStatement ps, boolean batch) throws KettleDatabaseException
Close the passed prepared statement. This object's "written" property is passed to the method that does the execute and commit.- Parameters:
ps-batch-- Throws:
KettleDatabaseException
-
emptyAndCommit
public void emptyAndCommit(PreparedStatement ps, boolean batch, int batchCounter) throws KettleDatabaseException
Close the prepared statement of the insert statement.- Parameters:
ps- The prepared statement to empty and close.batch- true if you are using batch processingbatchCounter- The number of rows on the batch queue- Throws:
KettleDatabaseException
-
createKettleDatabaseBatchException
public static KettleDatabaseBatchException createKettleDatabaseBatchException(String message, SQLException ex)
-
insertFinished
@Deprecated public void insertFinished(PreparedStatement ps, boolean batch) throws KettleDatabaseException
Deprecated.use emptyAndCommit() instead (pass in the number of rows left in the batch)Close the prepared statement of the insert statement.- Parameters:
ps- The prepared statement to empty and close.batch- true if you are using batch processing (typically true for this method)- Throws:
KettleDatabaseException
-
execStatement
public Result execStatement(String sql) throws KettleDatabaseException
Execute an SQL statement on the database connection (has to be open)- Parameters:
sql- The SQL to execute- Returns:
- a Result object indicating the number of lines read, deleted, inserted, updated, ...
- Throws:
KettleDatabaseException- in case anything goes wrong.
-
execStatement
public Result execStatement(String rawsql, RowMetaInterface params, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
execStatements
public Result execStatements(String script) throws KettleDatabaseException
Execute a series of SQL statements, separated by ; We are already connected... Multiple statements have to be split into parts We use the ";" to separate statements... We keep the results in Result object from Jobs- Parameters:
script- The SQL script to be execute- Returns:
- A result with counts of the number or records updates, inserted, deleted or read.
- Throws:
KettleDatabaseException- In case an error occurs
-
execStatements
public Result execStatements(String script, RowMetaInterface params, Object[] data) throws KettleDatabaseException
Execute a series of SQL statements, separated by ; We are already connected... Multiple statements have to be split into parts We use the ";" to separate statements... We keep the results in Result object from Jobs- Parameters:
script- The SQL script to be executeparams- Parameters Metadata- Parameters value- Returns:
- A result with counts of the number or records updates, inserted, deleted or read.
- Throws:
KettleDatabaseException- In case an error occurs
-
openQuery
public ResultSet openQuery(String sql) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
openQuery
public ResultSet openQuery(String sql, RowMetaInterface params, Object[] data) throws KettleDatabaseException
Open a query on the database with a set of parameters stored in a Kettle Row- Parameters:
sql- The SQL to launch with question marks (?) as placeholders for the parametersparams- The parameters or null if no parameters are used.- Returns:
- A JDBC ResultSet
- Throws:
KettleDatabaseException- when something goes wrong with the query.
-
openQuery
public ResultSet openQuery(String sql, RowMetaInterface params, Object[] data, int fetchMode) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
openQuery
public ResultSet openQuery(String sql, RowMetaInterface params, Object[] data, int fetchMode, boolean lazyConversion) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
openQuery
public ResultSet openQuery(PreparedStatement ps, RowMetaInterface params, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTableFields
public RowMetaInterface getTableFields(String tablename) throws KettleDatabaseException
Returns a RowMeta describing the fields of a table expression.Note that this implementation makes use of a SQL statement in order to populate the ValueMeta object in the RowMeta it returns. This is sometimes necessary when the caller needs the ValueMeta values to be properly casted.
In cases where a simple list of columns is required, it is preferable to use
getTableFieldsMeta(String, String). This other method will not use a SQL query and will populate whatever information it can using @linkDatabaseMetaData.getColumns(String, String, String, String).- Parameters:
tablename- This is the properly quoted, and schema prefixed table name.- Throws:
KettleDatabaseException
-
getQueryFields
public RowMetaInterface getQueryFields(String sql, boolean param) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
checkTableExists
@Deprecated public boolean checkTableExists(String tablename) throws KettleDatabaseException
Deprecated.Deprecated in favor ofcheckTableExists(String, String)See if the table specified exists by reading- Parameters:
tablename- The name of the table to check.
This is supposed to be the properly quoted name of the table or the complete schema-table name combination.- Returns:
- true if the table exists, false if it doesn't.
- Throws:
KettleDatabaseException
-
checkTableExists
public boolean checkTableExists(String schema, String tablename) throws KettleDatabaseException
See if the table specified exists.This is a smarter implementation of
checkTableExists(String)where metadata is used first and we only use statements when absolutely necessary.Contrary to previous versions of similar duplicated methods, this implementation does not require quoted identifiers.
- Parameters:
tablename- The unquoted name of the table to check.
This is NOT the properly quoted name of the table or the complete schema-table name combination.schema- The unquoted name of the schema.- Returns:
- true if the table exists, false if it doesn't.
- Throws:
KettleDatabaseException
-
checkTableExistsByDbMeta
@Deprecated public boolean checkTableExistsByDbMeta(String schema, String tablename) throws KettleDatabaseException
Deprecated.Deprecated in favor ofcheckTableExists(String, String)See if the table specified exists by getting db metadata.- Parameters:
tablename- The name of the table to check.
This is supposed to be the properly quoted name of the table or the complete schema-table name combination.- Returns:
- true if the table exists, false if it doesn't.
- Throws:
KettleDatabaseException
-
checkColumnExists
public boolean checkColumnExists(String schemaname, String tablename, String columnname) throws KettleDatabaseException
See if the column specified exists by reading the metadata first, execution last.This is a smarter implementation of
checkTableExists(String)where metadata is used first and we only use statements when absolutely necessary.Contrary to previous versions of similar duplicated methods, this implementation does not require quoted identifiers.
- Parameters:
schemaname- The name of the schema to check.tablename- The name of the table to check.columnname- The name of the column to check.- Returns:
- true if the table exists, false if it doesn't.
- Throws:
KettleDatabaseException
-
checkColumnExistsByDbMeta
public boolean checkColumnExistsByDbMeta(String schemaname, String tablename, String columnname) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
checkColumnExists
@Deprecated public boolean checkColumnExists(String columnname, String tablename) throws KettleDatabaseException
Deprecated.Deprecated in favor of the smartercheckColumnExists(String, String, String)See if the column specified exists by reading- Parameters:
columnname- The name of the column to check.tablename- The name of the table to check.
This is supposed to be the properly quoted name of the table or the complete schema-table name combination.- Returns:
- true if the table exists, false if it doesn't.
- Throws:
KettleDatabaseException
-
checkSequenceExists
public boolean checkSequenceExists(String sequenceName) throws KettleDatabaseException
Check whether the sequence exists, Oracle only!- Parameters:
sequenceName- The name of the sequence- Returns:
- true if the sequence exists.
- Throws:
KettleDatabaseException
-
checkSequenceExists
public boolean checkSequenceExists(String schemaName, String sequenceName) throws KettleDatabaseException
Check whether the sequence exists, Oracle only!- Parameters:
sequenceName- The name of the sequence- Returns:
- true if the sequence exists.
- Throws:
KettleDatabaseException
-
checkIndexExists
public boolean checkIndexExists(String tableName, String[] idxFields) throws KettleDatabaseException
Check if an index on certain fields in a table exists.- Parameters:
tableName- The table on which the index is checkedidxFields- The fields on which the indexe is checked- Returns:
- True if the index exists
- Throws:
KettleDatabaseException
-
checkIndexExists
public boolean checkIndexExists(String schemaName, String tableName, String[] idxFields) throws KettleDatabaseException
Check if an index on certain fields in a table exists.- Parameters:
tableName- The table on which the index is checkedidxFields- The fields on which the indexe is checked- Returns:
- True if the index exists
- Throws:
KettleDatabaseException
-
getCreateIndexStatement
public String getCreateIndexStatement(String tablename, String indexname, String[] idxFields, boolean tk, boolean unique, boolean bitmap, boolean semiColon)
-
getCreateIndexStatement
public String getCreateIndexStatement(String schemaname, String tablename, String indexname, String[] idxFields, boolean tk, boolean unique, boolean bitmap, boolean semiColon)
-
getCreateSequenceStatement
public String getCreateSequenceStatement(String sequence, long startAt, long incrementBy, long maxValue, boolean semiColon)
-
getCreateSequenceStatement
public String getCreateSequenceStatement(String sequence, String startAt, String incrementBy, String maxValue, boolean semiColon)
-
getCreateSequenceStatement
public String getCreateSequenceStatement(String schemaName, String sequence, long startAt, long incrementBy, long maxValue, boolean semiColon)
-
getCreateSequenceStatement
public String getCreateSequenceStatement(String schemaName, String sequenceName, String startAt, String incrementBy, String maxValue, boolean semiColon)
-
getTableFieldsMeta
public RowMetaInterface getTableFieldsMeta(String schemaName, String tableName) throws KettleDatabaseException
Returns a RowMeta describing the fields of a table.This is a lighter implementation of
getTableFields(String)where metadata is used first and we only use statements when absolutely necessary.Note that the ValueMeta returned here will not contain any actual values and as such, this method should be used whenever a simple list of columns is required, and we're not planning on looking at the actual data.
Contrary to previous versions of similar duplicated methods, this implementation does not require quoted identifiers.
- Parameters:
schemaName- The unquoted schema name. Can be null.tableName- The unquoted table name. Cannot be null.- Throws:
KettleDatabaseException
-
getTableFieldsMetaByDbMeta
public RowMetaInterface getTableFieldsMetaByDbMeta(String schemaName, String tableName) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getQueryFields
public RowMetaInterface getQueryFields(String sql, boolean param, RowMetaInterface inform, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getQueryFieldsFromPreparedStatement
public RowMetaInterface getQueryFieldsFromPreparedStatement(String sql) throws Exception
- Throws:
Exception
-
getQueryFieldsFromDatabaseMetaData
public RowMetaInterface getQueryFieldsFromDatabaseMetaData() throws Exception
- Throws:
Exception
-
getQueryFieldsFallback
public RowMetaInterface getQueryFieldsFallback(String sql, boolean param, RowMetaInterface inform, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
closeQuery
public void closeQuery(ResultSet res) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
absolute
public boolean absolute(ResultSet rs, int position) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
relative
public boolean relative(ResultSet rs, int rows) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
afterLast
public void afterLast(ResultSet rs) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
first
public void first(ResultSet rs) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getRow
public Object[] getRow(ResultSet rs) throws KettleDatabaseException
Get a row from the resultset. Do not use lazy conversion- Parameters:
rs- The resultset to get the row from- Returns:
- one row or null if no row was found on the resultset or if an error occurred.
- Throws:
KettleDatabaseException
-
getRow
public Object[] getRow(ResultSet rs, boolean lazyConversion) throws KettleDatabaseException
Get a row from the resultset.- Parameters:
rs- The resultset to get the row fromlazyConversion- set to true if strings need to have lazy conversion enabled- Returns:
- one row or null if no row was found on the resultset or if an error occurred.
- Throws:
KettleDatabaseException
-
getRow
public Object[] getRow(ResultSet rs, ResultSetMetaData dummy, RowMetaInterface rowInfo) throws KettleDatabaseException
Get a row from the resultset.- Parameters:
rs- The resultset to get the row from- Returns:
- one row or null if no row was found on the resultset or if an error occurred.
- Throws:
KettleDatabaseException
-
printSQLException
public void printSQLException(SQLException ex)
-
setLookup
public void setLookup(String table, String[] codes, String[] condition, String[] gets, String[] rename, String orderby) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setLookup
public void setLookup(String schema, String table, String[] codes, String[] condition, String[] gets, String[] rename, String orderby) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setLookup
public void setLookup(String tableName, String[] codes, String[] condition, String[] gets, String[] rename, String orderby, boolean checkForMultipleResults) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setLookup
public void setLookup(String schemaName, String tableName, String[] codes, String[] condition, String[] gets, String[] rename, String orderby, boolean checkForMultipleResults) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
prepareUpdate
public boolean prepareUpdate(String table, String[] codes, String[] condition, String[] sets)
-
prepareUpdate
public boolean prepareUpdate(String schemaName, String tableName, String[] codes, String[] condition, String[] sets)
-
prepareDelete
public boolean prepareDelete(String table, String[] codes, String[] condition)
Prepare a delete statement by giving it the tablename, fields and conditions to work with.- Parameters:
table- The table-name to delete incodes-condition-- Returns:
- true when everything went OK, false when something went wrong.
-
prepareDelete
public boolean prepareDelete(String schemaName, String tableName, String[] codes, String[] condition)
Prepare a delete statement by giving it the tablename, fields and conditions to work with.- Parameters:
schemaName- the schema-name to delete intableName- The table-name to delete incodes-condition-- Returns:
- true when everything went OK, false when something went wrong.
-
setProcLookup
public void setProcLookup(String proc, String[] arg, String[] argdir, int[] argtype, String returnvalue, int returntype) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getLookup
public Object[] getLookup() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getLookup
public Object[] getLookup(boolean failOnMultipleResults) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getLookup
public Object[] getLookup(boolean failOnMultipleResults, boolean lazyConversion) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getLookup
public Object[] getLookup(PreparedStatement ps) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getLookup
public Object[] getLookup(PreparedStatement ps, boolean failOnMultipleResults) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getLookup
public Object[] getLookup(PreparedStatement ps, boolean failOnMultipleResults, boolean lazyConversion) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getDatabaseMetaData
public DatabaseMetaData getDatabaseMetaData() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getDDL
public String getDDL(String tablename, RowMetaInterface fields) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getDDL
public String getDDL(String tablename, RowMetaInterface fields, String tk, boolean useAutoinc, String pk) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getDDL
public String getDDL(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getCreateTableStatement
public String getCreateTableStatement(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon)
Generates SQL- Parameters:
tableName- the table name or schema/table combination: this needs to be quoted properly in advance.fields- the fieldstk- the name of the technical key fielduseAutoinc- true if we need to use auto-increment fields for a primary keypk- the name of the primary/technical key fieldsemicolon- append semicolon to the statement- Returns:
- the SQL needed to create the specified table and fields.
-
getAlterTableStatement
public String getAlterTableStatement(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
truncateTable
public void truncateTable(String tablename) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
truncateTable
public void truncateTable(String schema, String tablename) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getOneRow
public RowMetaAndData getOneRow(String sql) throws KettleDatabaseException
Execute a query and return at most one row from the resultset- Parameters:
sql- The SQL for the query- Returns:
- one Row with data or null if nothing was found.
- Throws:
KettleDatabaseException
-
getMetaFromRow
public RowMeta getMetaFromRow(Object[] row, ResultSetMetaData md) throws SQLException, KettleDatabaseException
- Throws:
SQLExceptionKettleDatabaseException
-
getOneRow
public RowMetaAndData getOneRow(String sql, RowMetaInterface param, Object[] data) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getParameterMetaData
public RowMetaInterface getParameterMetaData(PreparedStatement ps)
-
countParameters
public int countParameters(String sql)
-
getParameterMetaData
public RowMetaInterface getParameterMetaData(String sql, RowMetaInterface inform, Object[] data)
-
writeLogRecord
public void writeLogRecord(LogTableCoreInterface logTable, LogStatus status, Object subject, Object parent) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
cleanupLogRecords
public void cleanupLogRecords(LogTableCoreInterface logTable, String transJobName) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getLastLogDate
public Object[] getLastLogDate(String logtable, String name, boolean job, LogStatus status) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getNextValue
public Long getNextValue(Hashtable<String,Counter> counters, String tableName, String valKey) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getNextValue
public Long getNextValue(Hashtable<String,Counter> counters, String schemaName, String tableName, String valKey) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
isSystemTable
public boolean isSystemTable(String tableName)
-
getRows
public List<Object[]> getRows(String sql, int limit) throws KettleDatabaseException
Reads the result of an SQL query into an ArrayList- Parameters:
sql- The SQL to launchlimit- <=0 means unlimited, otherwise this specifies the maximum number of rows read.- Returns:
- An ArrayList of rows.
- Throws:
KettleDatabaseException- if something goes wrong.
-
getRows
public List<Object[]> getRows(String sql, int limit, ProgressMonitorListener monitor) throws KettleDatabaseException
Reads the result of an SQL query into an ArrayList- Parameters:
sql- The SQL to launchlimit- <=0 means unlimited, otherwise this specifies the maximum number of rows read.monitor- The progress monitor to update while getting the rows.- Returns:
- An ArrayList of rows.
- Throws:
KettleDatabaseException- if something goes wrong.
-
getRows
public List<Object[]> getRows(String sql, RowMetaInterface params, Object[] data, int fetchMode, boolean lazyConversion, int limit, ProgressMonitorListener monitor) throws KettleDatabaseException
Reads the result of an SQL query into an ArrayList.- Parameters:
sql- The SQL to launchparams- The types of any parameters to be passed to the querydata- The values of any parameters to be passed to the queryfetchMode- The fetch mode for the query (ResultSet.FETCH_FORWARD, e.g.)lazyConversion- Whether to perform lazy conversion of the valueslimit- <=0 means unlimited, otherwise this specifies the maximum number of rows read.monitor- The progress monitor to update while getting the rows.- Returns:
- An ArrayList of rows.
- Throws:
KettleDatabaseException- if something goes wrong.
-
getRows
public List<Object[]> getRows(ResultSet rset, int limit, ProgressMonitorListener monitor) throws KettleDatabaseException
Reads the result of a ResultSet into an ArrayList- Parameters:
rset- the ResultSet to read outlimit- <=0 means unlimited, otherwise this specifies the maximum number of rows read.monitor- The progress monitor to update while getting the rows.- Returns:
- An ArrayList of rows.
- Throws:
KettleDatabaseException- if something goes wrong.
-
getFirstRows
public List<Object[]> getFirstRows(String tableName, int limit) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getFirstRows
public List<Object[]> getFirstRows(String tableName, int limit, ProgressMonitorListener monitor) throws KettleDatabaseException
Get the first rows from a table (for preview)- Parameters:
tableName- The table name (or schema/table combination): this needs to be quoted properlylimit- limit <=0 means unlimited, otherwise this specifies the maximum number of rows read.monitor- The progress monitor to update while getting the rows.- Returns:
- An ArrayList of rows.
- Throws:
KettleDatabaseException- in case something goes wrong
-
getReturnRowMeta
public RowMetaInterface getReturnRowMeta()
-
getTableTypes
public String[] getTableTypes() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTablenames
public String[] getTablenames() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTablenames
public String[] getTablenames(boolean includeSchema) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTablenames
public String[] getTablenames(String schemanamein, boolean includeSchema) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTablenames
public String[] getTablenames(String schemanamein, boolean includeSchema, Map<String,String> props) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTableMap
public Map<String,Collection<String>> getTableMap() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTableMap
public Map<String,Collection<String>> getTableMap(String schemanamein) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getTableMap
public Map<String,Collection<String>> getTableMap(String schemanamein, Map<String,String> props) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getViews
public String[] getViews() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getViews
public String[] getViews(boolean includeSchema) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getViews
public String[] getViews(String schemanamein, boolean includeSchema) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getViewMap
public Map<String,Collection<String>> getViewMap() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getViewMap
public Map<String,Collection<String>> getViewMap(String schemanamein) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getSynonyms
public String[] getSynonyms() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getSynonyms
public String[] getSynonyms(boolean includeSchema) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getSynonyms
public String[] getSynonyms(String schemanamein, boolean includeSchema) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getSynonymMap
public Map<String,Collection<String>> getSynonymMap() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getSynonymMap
public Map<String,Collection<String>> getSynonymMap(String schemanamein) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getSchemas
public String[] getSchemas() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getCatalogs
public String[] getCatalogs() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getProcedures
public String[] getProcedures() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
isAutoCommit
public boolean isAutoCommit()
-
getDatabaseMeta
public DatabaseMeta getDatabaseMeta()
- Returns:
- Returns the databaseMeta.
-
lockTables
public void lockTables(String[] tableNames) throws KettleDatabaseException
Lock a tables in the database for write operations- Parameters:
tableNames- The tables to lock. These need to be the appropriately quoted fully qualified (schema+table) names.- Throws:
KettleDatabaseException
-
unlockTables
public void unlockTables(String[] tableNames) throws KettleDatabaseException
Unlock certain tables in the database for write operations- Parameters:
tableNames- The tables to unlock- Throws:
KettleDatabaseException
-
getOpened
public int getOpened()
- Returns:
- the opened
-
setOpened
public void setOpened(int opened)
- Parameters:
opened- the opened to set
-
getConnectionGroup
public String getConnectionGroup()
- Returns:
- the connectionGroup
-
setConnectionGroup
public void setConnectionGroup(String connectionGroup)
- Parameters:
connectionGroup- the connectionGroup to set
-
getPartitionId
public String getPartitionId()
- Returns:
- the partitionId
-
setPartitionId
public void setPartitionId(String partitionId)
- Parameters:
partitionId- the partitionId to set
-
getCopy
public int getCopy()
- Returns:
- the copy
-
setCopy
public void setCopy(int copy)
- Parameters:
copy- the copy to set
-
copyVariablesFrom
public void copyVariablesFrom(VariableSpace space)
Description copied from interface:VariableSpaceCopy the variables from another space, without initializing with the defaults. This does not affect any parent relationship.- Specified by:
copyVariablesFromin interfaceVariableSpace- Parameters:
space- the space to copy the variables from.
-
environmentSubstitute
public String environmentSubstitute(String aString)
Description copied from interface:VariableSpaceSubstitute the string using the current variable space.- Specified by:
environmentSubstitutein interfaceVariableSpace- Parameters:
aString- The string to substitute.- Returns:
- The substituted string.
-
environmentSubstitute
public String[] environmentSubstitute(String[] aString)
Description copied from interface:VariableSpaceReplaces environment variables in an array of strings. See also: environmentSubstitute(String string)- Specified by:
environmentSubstitutein interfaceVariableSpace- Parameters:
aString- The array of strings that wants its variables to be replaced.- Returns:
- the array with the environment variables replaced.
-
fieldSubstitute
public String fieldSubstitute(String aString, RowMetaInterface rowMeta, Object[] rowData) throws KettleValueException
Description copied from interface:VariableSpaceSubstitutes field values inaString. Field values are of the form "?{}". The values are retrieved from the specified row. Please note that the getString() method is used to convert to a String, for all values in the row. - Specified by:
fieldSubstitutein interfaceVariableSpace- Parameters:
aString- the string on which to apply the substitution.rowMeta- The row metadata to use.rowData- The row data to use- Returns:
- the string with the substitution applied.
- Throws:
KettleValueException- In case there is a String conversion error
-
getParentVariableSpace
public VariableSpace getParentVariableSpace()
Description copied from interface:VariableSpaceGet the parent of the variable space.- Specified by:
getParentVariableSpacein interfaceVariableSpace- Returns:
- the parent.
-
setParentVariableSpace
public void setParentVariableSpace(VariableSpace parent)
Description copied from interface:VariableSpaceSet the parent variable space- Specified by:
setParentVariableSpacein interfaceVariableSpace- Parameters:
parent- The parent variable space to set
-
getVariable
public String getVariable(String variableName, String defaultValue)
Description copied from interface:VariableSpaceGet the value of a variable with a default in case the variable is not found.- Specified by:
getVariablein interfaceVariableSpace- Parameters:
variableName- The name of the variabledefaultValue- The default value in case the variable could not be found- Returns:
- the String value of a variable
-
getVariable
public String getVariable(String variableName)
Description copied from interface:VariableSpaceGet the value of a variable.- Specified by:
getVariablein interfaceVariableSpace- Parameters:
variableName- The name of the variable- Returns:
- the String value of a variable or null in case the variable could not be found.
-
getBooleanValueOfVariable
public boolean getBooleanValueOfVariable(String variableName, boolean defaultValue)
Description copied from interface:VariableSpaceThis method returns a boolean for the new variable check boxes. If the variable name is not set or the variable name is not specified, this method simply returns the default value. If not, it convert the variable value to a boolean. "Y", "YES" and "TRUE" all convert to true. (case insensitive)- Specified by:
getBooleanValueOfVariablein interfaceVariableSpace- Parameters:
variableName- The variable to look up.defaultValue- The default value to return.- Returns:
- See Also:
static method ValueMeta.convertStringToBoolean()
-
initializeVariablesFrom
public void initializeVariablesFrom(VariableSpace parent)
Description copied from interface:VariableSpaceInitialize variable space using the defaults, copy over the variables from the parent (using copyVariablesFrom()), after this the "injected" variables should be inserted (injectVariables()). The parent is set as parent variable space.- Specified by:
initializeVariablesFromin interfaceVariableSpace- Parameters:
parent- the parent to start from, or null if root.
-
listVariables
public String[] listVariables()
Description copied from interface:VariableSpaceList the variables (not the values) that are currently in the variable space.- Specified by:
listVariablesin interfaceVariableSpace- Returns:
- Array of String variable names.
-
setVariable
public void setVariable(String variableName, String variableValue)
Description copied from interface:VariableSpaceSets a variable in the Kettle Variables list.- Specified by:
setVariablein interfaceVariableSpace- Parameters:
variableName- The name of the variable to setvariableValue- The value of the variable to set. If the variableValue is null, the variable is cleared from the list.
-
shareVariablesWith
public void shareVariablesWith(VariableSpace space)
Description copied from interface:VariableSpaceShare a variable space from another variable space. This means that the object should take over the space used as argument.- Specified by:
shareVariablesWithin interfaceVariableSpace- Parameters:
space- Variable space to be shared.
-
injectVariables
public void injectVariables(Map<String,String> prop)
Description copied from interface:VariableSpaceInject variables. The behaviour should be that the properties object will be stored and at the time the VariableSpace is initialized (or upon calling this method if the space is already initialized). After injecting the link of the properties object should be removed.- Specified by:
injectVariablesin interfaceVariableSpace- Parameters:
prop- Properties object containing key-value pairs.
-
callProcedure
public RowMetaAndData callProcedure(String[] arg, String[] argdir, int[] argtype, String resultname, int resulttype) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
closeProcedureStatement
public void closeProcedureStatement() throws KettleDatabaseException- Throws:
KettleDatabaseException
-
getDDLCreationTable
public String getDDLCreationTable(String tableName, RowMetaInterface fields) throws KettleDatabaseException
Return SQL CREATION statement for a Table- Parameters:
tableName- The table to create- Throws:
KettleDatabaseException
-
getDDLTruncateTable
public String getDDLTruncateTable(String schema, String tablename) throws KettleDatabaseException
Return SQL TRUNCATE statement for a Table- Parameters:
schema- The schematablename- The table to create- Throws:
KettleDatabaseException
-
getSQLOutput
public String getSQLOutput(String schemaName, String tableName, RowMetaInterface fields, Object[] r, String dateFormat) throws KettleDatabaseException
Return SQL statement (INSERT INTO TableName ...- Parameters:
schemaName- tableName The schematableName-fields-dateFormat- date format of field- Throws:
KettleDatabaseException
-
setSavepoint
public Savepoint setSavepoint() throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
setSavepoint
public Savepoint setSavepoint(String savePointName) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
releaseSavepoint
public void releaseSavepoint(Savepoint savepoint) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
rollback
public void rollback(Savepoint savepoint) throws KettleDatabaseException
- Throws:
KettleDatabaseException
-
getParentObject
public Object getParentObject()
-
getPrimaryKeyColumnNames
public String[] getPrimaryKeyColumnNames(String tablename) throws KettleDatabaseException
Return primary key column names ...- Parameters:
tablename-- Throws:
KettleDatabaseException
-
getSequences
public String[] getSequences() throws KettleDatabaseException
Return all sequence names from connection- Returns:
- The sequences name list.
- Throws:
KettleDatabaseException
-
getFilename
public String getFilename()
Description copied from interface:LoggingObjectInterfaceGets the filename.- Specified by:
getFilenamein interfaceLoggingObjectInterface- Returns:
- the filename
-
getLogChannelId
public String getLogChannelId()
Description copied from interface:LoggingObjectInterfaceGets the log channel id.- Specified by:
getLogChannelIdin interfaceLoggingObjectInterface- Returns:
- the log channel id
-
getObjectName
public String getObjectName()
Description copied from interface:LoggingObjectInterfaceGets the object name.- Specified by:
getObjectNamein interfaceLoggingObjectInterface- Returns:
- the name
-
getObjectCopy
public String getObjectCopy()
Description copied from interface:LoggingObjectInterfaceGets a string identifying a copy in a series of steps.- Specified by:
getObjectCopyin interfaceLoggingObjectInterface- Returns:
- A string identifying a copy in a series of steps.
-
getObjectId
public ObjectId getObjectId()
Description copied from interface:LoggingObjectInterfaceGets the object id in a repository.- Specified by:
getObjectIdin interfaceLoggingObjectInterface- Returns:
- the objectId in a repository
-
getObjectRevision
public ObjectRevision getObjectRevision()
Description copied from interface:LoggingObjectInterfaceGets the objects revision in a repository.- Specified by:
getObjectRevisionin interfaceLoggingObjectInterface- Returns:
- the object revision in a repository
-
getObjectType
public LoggingObjectType getObjectType()
Description copied from interface:LoggingObjectInterfaceGets the object type.- Specified by:
getObjectTypein interfaceLoggingObjectInterface- Returns:
- the objectType
-
getParent
public LoggingObjectInterface getParent()
Description copied from interface:LoggingObjectInterfaceGets the parent.- Specified by:
getParentin interfaceLoggingObjectInterface- Returns:
- the parent
-
getRepositoryDirectory
public RepositoryDirectory getRepositoryDirectory()
Description copied from interface:LoggingObjectInterfaceGets the repository directory.- Specified by:
getRepositoryDirectoryin interfaceLoggingObjectInterface- Returns:
- the repositoryDirectory
-
getLogLevel
public LogLevel getLogLevel()
Description copied from interface:LoggingObjectInterfaceGets the logging level of the log channel of this logging object.- Specified by:
getLogLevelin interfaceLoggingObjectInterface- Returns:
- The logging level of the log channel of this logging object.
-
setLogLevel
public void setLogLevel(LogLevel logLevel)
-
getContainerObjectId
public String getContainerObjectId()
Description copied from interface:LoggingObjectInterfaceGets the execution container (Carte/DI server/BI Server) object id. We use this to see to which copy of the job/trans hierarchy this object belongs. If it is null, we assume that we are running a single copy in Spoon/Pan/Kitchen.- Specified by:
getContainerObjectIdin interfaceLoggingObjectInterface- Returns:
- the carteObjectId
-
setContainerObjectId
public void setContainerObjectId(String containerObjectId)
- Parameters:
containerObjectId- the execution container Object id to set
-
getRegistrationDate
public Date getRegistrationDate()
Stub- Specified by:
getRegistrationDatein interfaceLoggingObjectInterface- Returns:
- The registration date of this logging object. Null if it's not registered.
-
getNrExecutedCommits
public int getNrExecutedCommits()
- Returns:
- the nrExecutedCommits
-
setNrExecutedCommits
public void setNrExecutedCommits(int nrExecutedCommits)
- Parameters:
nrExecutedCommits- the nrExecutedCommits to set
-
execStatementsFromFile
public Result execStatementsFromFile(String filename, boolean sendSinglestatement) throws KettleException
Execute an SQL statement inside a file on the database connection (has to be open)- Parameters:
filename- The file that contains SQL to execute- Returns:
- a Result object indicating the number of lines read, deleted, inserted, updated, ...
- Throws:
KettleDatabaseException- in case anything goes wrong.KettleException
-
isGatheringMetrics
public boolean isGatheringMetrics()
Description copied from interface:LoggingObjectInterfaceGets the boolean value of whether or not this object is gathering kettle metrics during execution.- Specified by:
isGatheringMetricsin interfaceLoggingObjectInterface- Returns:
- true if this logging object is gathering kettle metrics during execution
-
setGatheringMetrics
public void setGatheringMetrics(boolean gatheringMetrics)
Description copied from interface:LoggingObjectInterfaceEnable of disable kettle metrics gathering during execution- Specified by:
setGatheringMetricsin interfaceLoggingObjectInterface- Parameters:
gatheringMetrics- set to true to enable metrics gathering during execution.
-
isForcingSeparateLogging
public boolean isForcingSeparateLogging()
- Specified by:
isForcingSeparateLoggingin interfaceLoggingObjectInterface- Returns:
- True if the logging is forcibly separated out from even identical objects.
-
setForcingSeparateLogging
public void setForcingSeparateLogging(boolean forcingSeparateLogging)
Description copied from interface:LoggingObjectInterfaceThis option will force the create of a separate logging channel even if the logging concerns identical objects with identical names.- Specified by:
setForcingSeparateLoggingin interfaceLoggingObjectInterface- Parameters:
forcingSeparateLogging- Set to true to force separate logging
-
setOwnerName
public void setOwnerName(String name)
-
getOwnerName
public String getOwnerName()
-
-