Package org.apache.empire.db
Class DBSQLScript
java.lang.Object
org.apache.empire.db.DBSQLScript
- All Implemented Interfaces:
Iterable<String>,DBContextAware
DBSQLScript
This class is a collection of sql command strings.
The class is used for obtaining and executing DDL commands supplied by the database dbms (@see
This class is a collection of sql command strings.
The class is used for obtaining and executing DDL commands supplied by the database dbms (@see
DBMSHandler.getDDLScript(DDLActionType, DBObject, DBSQLScript))-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected final DBContextprotected ArrayList<DBSQLScript.SQLStmt> -
Constructor Summary
ConstructorsConstructorDescriptionDBSQLScript(DBContext context) DBSQLScript(DBContext context, String commandSeparator) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an delete statementvoidAdds an insert statementvoidAdds a statement to the script.voidAdds a statement to the script.final voidaddStmt(DBSQLBuilder sql) Adds a statement to the script.
The supplied StringBuilder will be reset to a length of 0voidAdds an update statementvoidclear()Clears the script by removing all statementsfinal intExecutes all SQL Statements one by one using the supplied dbms and connection.intexecuteAll(boolean ignoreErrors) Executes all SQL Statements one by one using the supplied dbms and connection.intExecutes all SQL Statements as a JDBC Batch Job.protected intexecuteStmt(DBMSHandler dbms, String sqlCmd, Object[] sqlParams, Connection conn) Executes a single statementReturns the current ContextintgetCount()Returns the number of statements in this scriptgetStmt(int i) Returns the statement command at the given indexObject[]getStmtParams(int i) Returns the statement command at the given indexfinal voidinsertStmt(int i, String stmt) Inserts an entry in the listvoidinsertStmt(int i, String stmt, Object[] params) Inserts an entry in the listiterator()Returns an iteratorprotected voidlogs a statement before executionvoidremoveStmt(int i) Removes a statement from the listfinal voidreplaceStmt(int i, String cmd) Replaces an entry in the listvoidreplaceStmt(int i, String cmd, Object[] params) Replaces an entry in the listtoString()Returns the sql script as a stringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
commandSeparator
-
sqlStmtList
-
context
-
-
Constructor Details
-
DBSQLScript
-
DBSQLScript
-
-
Method Details
-
getContext
Returns the current Context- Specified by:
getContextin interfaceDBContextAware- Returns:
- the database context
-
addStmt
Adds a statement to the script.- Parameters:
sql- the statement
-
addStmt
Adds a statement to the script.- Parameters:
sql- the statementparams- the statement parameters
-
addStmt
Adds a statement to the script.
The supplied StringBuilder will be reset to a length of 0- Parameters:
sql- the statement
-
addInsert
Adds an insert statement- Parameters:
cmd- the insert command
-
addUpdate
Adds an update statement- Parameters:
cmd- the insert command
-
addDelete
Adds an delete statement- Parameters:
cmd- the insert commandtable- the table to delete
-
getCount
public int getCount()Returns the number of statements in this script- Returns:
- number of statements in this script
-
getStmt
Returns the statement command at the given index- Parameters:
i- index of the statement to retrieve- Returns:
- the sql statement command
-
getStmtParams
Returns the statement command at the given index- Parameters:
i- index of the statement to retrieve- Returns:
- the sql statement params
-
insertStmt
Inserts an entry in the list- Parameters:
i- index of the statement to replacestmt- the new statement for this index, or NULL to remove the statementparams- the statement params
-
insertStmt
Inserts an entry in the list- Parameters:
i- index of the statement to replacestmt- the new statement for this index, or NULL to remove the statement
-
replaceStmt
Replaces an entry in the list- Parameters:
i- index of the statement to replacecmd- the new statement for this index, or NULL to remove the statementparams- the command params (optional)
-
replaceStmt
Replaces an entry in the list- Parameters:
i- index of the statement to replacecmd- the new statement for this index, or NULL to remove the statement
-
removeStmt
public void removeStmt(int i) Removes a statement from the list- Parameters:
i- index of the statement to replace
-
clear
public void clear()Clears the script by removing all statements -
executeAll
public int executeAll(boolean ignoreErrors) Executes all SQL Statements one by one using the supplied dbms and connection.- Parameters:
ignoreErrors- true if errors should be ignored- Returns:
- number of records affected
-
executeAll
public final int executeAll()Executes all SQL Statements one by one using the supplied dbms and connection.- Returns:
- number of records affected
-
executeBatch
public int executeBatch()Executes all SQL Statements as a JDBC Batch Job.- Returns:
- the total number of affected records
-
iterator
Returns an iterator -
toString
Returns the sql script as a string -
logStmt
logs a statement before execution- Parameters:
utils- the DBUilssqlCmd- the statementsqlParams- the paramscomment- flag indicating whether the command is a comment or not
-
executeStmt
protected int executeStmt(DBMSHandler dbms, String sqlCmd, Object[] sqlParams, Connection conn) throws SQLException Executes a single statement- Parameters:
dbms- the dbmssqlCmd- the sql statementsqlParams- the statement paramsconn- the connection- Returns:
- number of rows affected
- Throws:
SQLException
-