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 boolean
absolute(ResultSet rs, int position)
void
afterLast(ResultSet rs)
RowMetaAndData
callProcedure(String[] arg, String[] argdir, int[] argtype, String resultname, int resulttype)
void
cancelQuery()
Cancel the open/running queries on the database connectionvoid
cancelStatement(Statement statement)
Cancel an open/running SQL statementboolean
checkColumnExists(String columnname, String tablename)
Deprecated.Deprecated in favor of the smartercheckColumnExists(String, String, String)
boolean
checkColumnExists(String schemaname, String tablename, String columnname)
See if the column specified exists by reading the metadata first, execution last.boolean
checkColumnExistsByDbMeta(String schemaname, String tablename, String columnname)
boolean
checkIndexExists(String tableName, String[] idxFields)
Check if an index on certain fields in a table exists.boolean
checkIndexExists(String schemaName, String tableName, String[] idxFields)
Check if an index on certain fields in a table exists.boolean
checkSequenceExists(String sequenceName)
Check whether the sequence exists, Oracle only!boolean
checkSequenceExists(String schemaName, String sequenceName)
Check whether the sequence exists, Oracle only!boolean
checkTableExists(String tablename)
Deprecated.Deprecated in favor ofcheckTableExists(String, String)
boolean
checkTableExists(String schema, String tablename)
See if the table specified exists.boolean
checkTableExistsByDbMeta(String schema, String tablename)
Deprecated.Deprecated in favor ofcheckTableExists(String, String)
void
cleanupLogRecords(LogTableCoreInterface logTable, String transJobName)
void
clearBatch(PreparedStatement preparedStatement)
void
clearInsertBatch()
Deprecated.void
close()
void
closeConnectionOnly()
Only for unique connections usage, typically you use disconnect() to disconnect() from the database.void
closeInsert()
void
closeLookup()
void
closePreparedStatement(PreparedStatement ps)
void
closeProcedureStatement()
void
closeQuery(ResultSet res)
void
closeUpdate()
void
commit()
Perform a commit the connection if this is supported by the databasevoid
commit(boolean force)
void
commitLog(boolean force, LogTableCoreInterface logTable)
This methods may be removed in future.void
commitLog(LogTableCoreInterface logTable)
This methods may be removed in future.void
connect()
Open the database connection.void
connect(String partitionId)
Open the database connection.void
connect(String group, String partitionId)
void
copyVariablesFrom(VariableSpace space)
Copy the variables from another space, without initializing with the defaults.int
countParameters(String sql)
static KettleDatabaseBatchException
createKettleDatabaseBatchException(String message, SQLException ex)
void
disconnect()
Disconnect from the database and close all open prepared statements.void
emptyAndCommit(PreparedStatement ps, boolean batch)
Close the passed prepared statement.void
emptyAndCommit(PreparedStatement ps, boolean batch, int batchCounter)
Close the prepared statement of the insert statement.String
environmentSubstitute(String aString)
Substitute the string using the current variable space.String[]
environmentSubstitute(String[] aString)
Replaces environment variables in an array of strings.boolean
equals(Object obj)
This implementation is NullPointerException subject, and may not follow fundamental equals contract.Result
execStatement(String sql)
Execute an SQL statement on the database connection (has to be open)Result
execStatement(String rawsql, RowMetaInterface params, Object[] data)
Result
execStatements(String script)
Execute a series of SQL statements, separated by ;Result
execStatements(String script, RowMetaInterface params, Object[] data)
Execute a series of SQL statements, separated by ;Result
execStatementsFromFile(String filename, boolean sendSinglestatement)
Execute an SQL statement inside a file on the database connection (has to be open)void
executeAndClearBatch(PreparedStatement preparedStatement)
String
fieldSubstitute(String aString, RowMetaInterface rowMeta, Object[] rowData)
Substitutes field values inaString
.void
first(ResultSet rs)
String
getAlterTableStatement(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon)
boolean
getBooleanValueOfVariable(String variableName, boolean defaultValue)
This method returns a boolean for the new variable check boxes.String[]
getCatalogs()
Connection
getConnection()
String
getConnectionGroup()
String
getContainerObjectId()
Gets the execution container (Carte/DI server/BI Server) object id.int
getCopy()
String
getCreateIndexStatement(String tablename, String indexname, String[] idxFields, boolean tk, boolean unique, boolean bitmap, boolean semiColon)
String
getCreateIndexStatement(String schemaname, String tablename, String indexname, String[] idxFields, boolean tk, boolean unique, boolean bitmap, boolean semiColon)
String
getCreateSequenceStatement(String sequence, long startAt, long incrementBy, long maxValue, boolean semiColon)
String
getCreateSequenceStatement(String schemaName, String sequence, long startAt, long incrementBy, long maxValue, boolean semiColon)
String
getCreateSequenceStatement(String sequence, String startAt, String incrementBy, String maxValue, boolean semiColon)
String
getCreateSequenceStatement(String schemaName, String sequenceName, String startAt, String incrementBy, String maxValue, boolean semiColon)
String
getCreateTableStatement(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon)
Generates SQLDatabaseMeta
getDatabaseMeta()
DatabaseMetaData
getDatabaseMetaData()
DataSource
getDataSource(String partitionId)
String
getDDL(String tablename, RowMetaInterface fields)
String
getDDL(String tablename, RowMetaInterface fields, String tk, boolean useAutoinc, String pk)
String
getDDL(String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk, boolean semicolon)
String
getDDLCreationTable(String tableName, RowMetaInterface fields)
Return SQL CREATION statement for a TableString
getDDLTruncateTable(String schema, String tablename)
Return SQL TRUNCATE statement for a TableString
getFilename()
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)RowMetaAndData
getGeneratedKeys(PreparedStatement ps)
String
getInsertStatement(String schemaName, String tableName, RowMetaInterface fields)
String
getInsertStatement(String tableName, RowMetaInterface fields)
Object[]
getLastLogDate(String logtable, String name, boolean job, LogStatus status)
String
getLogChannelId()
Gets the log channel id.LogLevel
getLogLevel()
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)
RowMeta
getMetaFromRow(Object[] row, ResultSetMetaData md)
Long
getNextSequenceValue(String sequenceName, String keyfield)
Long
getNextSequenceValue(String schemaName, String sequenceName, String keyfield)
Long
getNextValue(Hashtable<String,Counter> counters, String tableName, String valKey)
Long
getNextValue(Hashtable<String,Counter> counters, String schemaName, String tableName, String valKey)
int
getNrExecutedCommits()
String
getObjectCopy()
Gets a string identifying a copy in a series of steps.ObjectId
getObjectId()
Gets the object id in a repository.String
getObjectName()
Gets the object name.ObjectRevision
getObjectRevision()
Gets the objects revision in a repository.LoggingObjectType
getObjectType()
Gets the object type.RowMetaAndData
getOneRow(String sql)
Execute a query and return at most one row from the resultsetRowMetaAndData
getOneRow(String sql, RowMetaInterface param, Object[] data)
int
getOpened()
String
getOwnerName()
RowMetaInterface
getParameterMetaData(String sql, RowMetaInterface inform, Object[] data)
RowMetaInterface
getParameterMetaData(PreparedStatement ps)
LoggingObjectInterface
getParent()
Gets the parent.Object
getParentObject()
VariableSpace
getParentVariableSpace()
Get the parent of the variable space.String
getPartitionId()
PreparedStatement
getPrepStatementInsert()
PreparedStatement
getPrepStatementLookup()
PreparedStatement
getPrepStatementUpdate()
String[]
getPrimaryKeyColumnNames(String tablename)
Return primary key column names ...String[]
getProcedures()
RowMetaInterface
getQueryFields(String sql, boolean param)
RowMetaInterface
getQueryFields(String sql, boolean param, RowMetaInterface inform, Object[] data)
RowMetaInterface
getQueryFieldsFallback(String sql, boolean param, RowMetaInterface inform, Object[] data)
RowMetaInterface
getQueryFieldsFromDatabaseMetaData()
RowMetaInterface
getQueryFieldsFromPreparedStatement(String sql)
Date
getRegistrationDate()
StubRepositoryDirectory
getRepositoryDirectory()
Gets the repository directory.RowMetaInterface
getReturnRowMeta()
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 connectionString
getSQLOutput(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)
RowMetaInterface
getTableFields(String tablename)
Returns a RowMeta describing the fields of a table expression.RowMetaInterface
getTableFieldsMeta(String schemaName, String tableName)
Returns a RowMeta describing the fields of a table.RowMetaInterface
getTableFieldsMetaByDbMeta(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()
boolean
getUseBatchInsert(boolean batch)
String
getVariable(String variableName)
Get the value of a variable.String
getVariable(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)
void
initializeConnectionDataSource(String partitionId)
void
initializeVariablesFrom(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()).void
injectVariables(Map<String,String> prop)
Inject variables.void
insertFinished(boolean batch)
void
insertFinished(PreparedStatement ps, boolean batch)
Deprecated.use emptyAndCommit() instead (pass in the number of rows left in the batch)void
insertRow()
void
insertRow(boolean batch)
void
insertRow(String schemaName, String tableName, RowMetaInterface fields, Object[] data)
void
insertRow(String tableName, RowMetaInterface fields, Object[] data)
void
insertRow(PreparedStatement ps)
boolean
insertRow(PreparedStatement ps, boolean batch)
Insert a row into the database using a prepared statement that has all values set.boolean
insertRow(PreparedStatement ps, boolean batch, boolean handleCommit)
Insert a row into the database using a prepared statement that has all values set.boolean
isAutoCommit()
boolean
isForcingSeparateLogging()
boolean
isGatheringMetrics()
Gets the boolean value of whether or not this object is gathering kettle metrics during execution.boolean
isSystemTable(String tableName)
String[]
listVariables()
List the variables (not the values) that are currently in the variable space.void
lockTables(String[] tableNames)
Lock a tables in the database for write operationsvoid
normalConnect(String partitionId)
Open the database connection.ResultSet
openQuery(String sql)
ResultSet
openQuery(String sql, RowMetaInterface params, Object[] data)
Open a query on the database with a set of parameters stored in a Kettle RowResultSet
openQuery(String sql, RowMetaInterface params, Object[] data, int fetchMode)
ResultSet
openQuery(String sql, RowMetaInterface params, Object[] data, int fetchMode, boolean lazyConversion)
ResultSet
openQuery(PreparedStatement ps, RowMetaInterface params, Object[] data)
boolean
prepareDelete(String table, String[] codes, String[] condition)
Prepare a delete statement by giving it the tablename, fields and conditions to work with.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.void
prepareInsert(RowMetaInterface rowMeta, String tableName)
Prepare inserting values into a table, using the fields & values in a Rowvoid
prepareInsert(RowMetaInterface rowMeta, String schemaName, String tableName)
Prepare inserting values into a table, using the fields & values in a RowPreparedStatement
prepareSQL(String sql)
Prepare a statement to be executed on the database.PreparedStatement
prepareSQL(String sql, boolean returnKeys)
Prepare a statement to be executed on the database.boolean
prepareUpdate(String table, String[] codes, String[] condition, String[] sets)
boolean
prepareUpdate(String schemaName, String tableName, String[] codes, String[] condition, String[] sets)
void
printSQLException(SQLException ex)
boolean
relative(ResultSet rs, int rows)
void
releaseSavepoint(Savepoint savepoint)
void
rollback()
void
rollback(boolean force)
void
rollback(Savepoint savepoint)
void
setAutoCommit()
void
setAutoCommit(boolean useAutoCommit)
void
setCommit(int commitSize)
Specify after how many rows a commit needs to occur when inserting or updating values.void
setCommitSize(int size)
void
setConnection(Connection connection)
Allows for the injection of a "life" connection, generated by a piece of software outside of Kettle.void
setConnectionGroup(String connectionGroup)
void
setContainerObjectId(String containerObjectId)
void
setCopy(int copy)
void
setForcingSeparateLogging(boolean forcingSeparateLogging)
This option will force the create of a separate logging channel even if the logging concerns identical objects with identical names.void
setGatheringMetrics(boolean gatheringMetrics)
Enable of disable kettle metrics gathering during executionvoid
setLogLevel(LogLevel logLevel)
void
setLookup(String table, String[] codes, String[] condition, String[] gets, String[] rename, String orderby)
void
setLookup(String tableName, String[] codes, String[] condition, String[] gets, String[] rename, String orderby, boolean checkForMultipleResults)
void
setLookup(String schema, String table, String[] codes, String[] condition, String[] gets, String[] rename, String orderby)
void
setLookup(String schemaName, String tableName, String[] codes, String[] condition, String[] gets, String[] rename, String orderby, boolean checkForMultipleResults)
void
setNrExecutedCommits(int nrExecutedCommits)
void
setOpened(int opened)
void
setOwnerName(String name)
void
setParentVariableSpace(VariableSpace parent)
Set the parent variable spacevoid
setPartitionId(String partitionId)
void
setProcLookup(String proc, String[] arg, String[] argdir, int[] argtype, String returnvalue, int returntype)
void
setProcValues(RowMetaInterface rowMeta, Object[] data, int[] argnrs, String[] argdir, boolean result)
void
setQueryLimit(int rows)
Set the maximum number of records to retrieve from a query.Savepoint
setSavepoint()
Savepoint
setSavepoint(String savePointName)
void
setValue(PreparedStatement ps, ValueMetaInterface v, Object object, int pos)
void
setValues(RowMetaInterface rowMeta, Object[] data)
void
setValues(RowMetaInterface rowMeta, Object[] data, PreparedStatement ps)
void
setValues(RowMetaInterface rowMeta, Object[] data, PreparedStatement ps, int ignoreThisValueIndex)
Sets the values of the preparedStatement pstmt.void
setValues(RowMetaAndData row)
void
setValues(RowMetaAndData row, PreparedStatement ps)
void
setValuesInsert(RowMetaInterface rowMeta, Object[] data)
void
setValuesInsert(RowMetaAndData row)
void
setValuesLookup(RowMetaInterface rowMeta, Object[] data)
void
setValuesUpdate(RowMetaInterface rowMeta, Object[] data)
void
setVariable(String variableName, String variableValue)
Sets a variable in the Kettle Variables list.void
shareVariablesWith(VariableSpace space)
Share a variable space from another variable space.String
toString()
void
truncateTable(String tablename)
void
truncateTable(String schema, String tablename)
void
unlockTables(String[] tableNames)
Unlock certain tables in the database for write operationsvoid
updateRow()
void
writeLogRecord(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 onDatabaseMeta
equality.
-
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
-
connect
public void connect() throws KettleDatabaseException
Open 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
closeConnectionOnly
public void closeConnectionOnly() throws KettleDatabaseException
Only 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 KettleDatabaseException
Cancel 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 KettleDatabaseException
Perform 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 KettleDatabaseException
This 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:
SQLException
KettleDatabaseException
-
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:VariableSpace
Copy the variables from another space, without initializing with the defaults. This does not affect any parent relationship.- Specified by:
copyVariablesFrom
in interfaceVariableSpace
- Parameters:
space
- the space to copy the variables from.
-
environmentSubstitute
public String environmentSubstitute(String aString)
Description copied from interface:VariableSpace
Substitute the string using the current variable space.- Specified by:
environmentSubstitute
in interfaceVariableSpace
- Parameters:
aString
- The string to substitute.- Returns:
- The substituted string.
-
environmentSubstitute
public String[] environmentSubstitute(String[] aString)
Description copied from interface:VariableSpace
Replaces environment variables in an array of strings. See also: environmentSubstitute(String string)- Specified by:
environmentSubstitute
in 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:VariableSpace
Substitutes 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:
fieldSubstitute
in 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:VariableSpace
Get the parent of the variable space.- Specified by:
getParentVariableSpace
in interfaceVariableSpace
- Returns:
- the parent.
-
setParentVariableSpace
public void setParentVariableSpace(VariableSpace parent)
Description copied from interface:VariableSpace
Set the parent variable space- Specified by:
setParentVariableSpace
in interfaceVariableSpace
- Parameters:
parent
- The parent variable space to set
-
getVariable
public String getVariable(String variableName, String defaultValue)
Description copied from interface:VariableSpace
Get the value of a variable with a default in case the variable is not found.- Specified by:
getVariable
in 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:VariableSpace
Get the value of a variable.- Specified by:
getVariable
in 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:VariableSpace
This 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:
getBooleanValueOfVariable
in 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:VariableSpace
Initialize 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:
initializeVariablesFrom
in interfaceVariableSpace
- Parameters:
parent
- the parent to start from, or null if root.
-
listVariables
public String[] listVariables()
Description copied from interface:VariableSpace
List the variables (not the values) that are currently in the variable space.- Specified by:
listVariables
in interfaceVariableSpace
- Returns:
- Array of String variable names.
-
setVariable
public void setVariable(String variableName, String variableValue)
Description copied from interface:VariableSpace
Sets a variable in the Kettle Variables list.- Specified by:
setVariable
in 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:VariableSpace
Share a variable space from another variable space. This means that the object should take over the space used as argument.- Specified by:
shareVariablesWith
in interfaceVariableSpace
- Parameters:
space
- Variable space to be shared.
-
injectVariables
public void injectVariables(Map<String,String> prop)
Description copied from interface:VariableSpace
Inject 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:
injectVariables
in 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:LoggingObjectInterface
Gets the filename.- Specified by:
getFilename
in interfaceLoggingObjectInterface
- Returns:
- the filename
-
getLogChannelId
public String getLogChannelId()
Description copied from interface:LoggingObjectInterface
Gets the log channel id.- Specified by:
getLogChannelId
in interfaceLoggingObjectInterface
- Returns:
- the log channel id
-
getObjectName
public String getObjectName()
Description copied from interface:LoggingObjectInterface
Gets the object name.- Specified by:
getObjectName
in interfaceLoggingObjectInterface
- Returns:
- the name
-
getObjectCopy
public String getObjectCopy()
Description copied from interface:LoggingObjectInterface
Gets a string identifying a copy in a series of steps.- Specified by:
getObjectCopy
in interfaceLoggingObjectInterface
- Returns:
- A string identifying a copy in a series of steps.
-
getObjectId
public ObjectId getObjectId()
Description copied from interface:LoggingObjectInterface
Gets the object id in a repository.- Specified by:
getObjectId
in interfaceLoggingObjectInterface
- Returns:
- the objectId in a repository
-
getObjectRevision
public ObjectRevision getObjectRevision()
Description copied from interface:LoggingObjectInterface
Gets the objects revision in a repository.- Specified by:
getObjectRevision
in interfaceLoggingObjectInterface
- Returns:
- the object revision in a repository
-
getObjectType
public LoggingObjectType getObjectType()
Description copied from interface:LoggingObjectInterface
Gets the object type.- Specified by:
getObjectType
in interfaceLoggingObjectInterface
- Returns:
- the objectType
-
getParent
public LoggingObjectInterface getParent()
Description copied from interface:LoggingObjectInterface
Gets the parent.- Specified by:
getParent
in interfaceLoggingObjectInterface
- Returns:
- the parent
-
getRepositoryDirectory
public RepositoryDirectory getRepositoryDirectory()
Description copied from interface:LoggingObjectInterface
Gets the repository directory.- Specified by:
getRepositoryDirectory
in interfaceLoggingObjectInterface
- Returns:
- the repositoryDirectory
-
getLogLevel
public LogLevel getLogLevel()
Description copied from interface:LoggingObjectInterface
Gets the logging level of the log channel of this logging object.- Specified by:
getLogLevel
in 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:LoggingObjectInterface
Gets 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:
getContainerObjectId
in 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:
getRegistrationDate
in 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:LoggingObjectInterface
Gets the boolean value of whether or not this object is gathering kettle metrics during execution.- Specified by:
isGatheringMetrics
in interfaceLoggingObjectInterface
- Returns:
- true if this logging object is gathering kettle metrics during execution
-
setGatheringMetrics
public void setGatheringMetrics(boolean gatheringMetrics)
Description copied from interface:LoggingObjectInterface
Enable of disable kettle metrics gathering during execution- Specified by:
setGatheringMetrics
in interfaceLoggingObjectInterface
- Parameters:
gatheringMetrics
- set to true to enable metrics gathering during execution.
-
isForcingSeparateLogging
public boolean isForcingSeparateLogging()
- Specified by:
isForcingSeparateLogging
in interfaceLoggingObjectInterface
- Returns:
- True if the logging is forcibly separated out from even identical objects.
-
setForcingSeparateLogging
public void setForcingSeparateLogging(boolean forcingSeparateLogging)
Description copied from interface:LoggingObjectInterface
This option will force the create of a separate logging channel even if the logging concerns identical objects with identical names.- Specified by:
setForcingSeparateLogging
in interfaceLoggingObjectInterface
- Parameters:
forcingSeparateLogging
- Set to true to force separate logging
-
setOwnerName
public void setOwnerName(String name)
-
getOwnerName
public String getOwnerName()
-
-