public abstract class ScriptRunner
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
ScriptRunner.ScriptType
Script type
|
| Modifier and Type | Field and Description |
|---|---|
protected Dialect |
dialect
The target database dialect
|
private static java.util.regex.Pattern |
JDBC
Pattern for the JDBC URL parsing
|
protected static CentralLogger |
LOG
Logger
|
protected java.util.Map<java.lang.String,java.lang.String> |
placeholders
Map for placeholder values
|
protected java.util.List<java.lang.String> |
scripts
Scripts to be run
|
protected ScriptRunner.ScriptType |
scriptType
Script type
|
protected boolean |
usePlaceholders
If placeholders should be used
|
| Constructor and Description |
|---|
ScriptRunner(Dialect dialect)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.util.List<java.lang.String> |
addScriptPath(java.util.List<java.lang.String> scriptNames)
Add script path to script names
|
protected void |
applyDDLScripts(java.sql.Connection conn) |
protected java.lang.String |
applyPlaceholders(java.sql.Connection conn,
java.lang.String source)
Substitutes variables as placeholders within a SQL string by values.
|
protected void |
applySchema(java.sql.Connection conn)
Apply SQL scripts using connection
|
protected void |
applyScripts(java.sql.Connection conn,
ScriptSplitter splitter)
Apply SQL scripts using connection
|
protected abstract void |
applyUdfScripts(java.sql.Connection conn)
Apply SQL scripts.
|
static void |
createMissingUdfs(Database db)
Check for missing UDFs and create them.
|
protected abstract void |
createMissingUdfs(java.lang.String dbname,
java.lang.String url,
java.lang.String adm,
java.lang.String pwd)
Check for missing UDFs and create them.
|
protected java.util.List<java.lang.String> |
defaultUdfScripts()
Provide a list of default UDF scripts
|
protected void |
execute(java.sql.Connection conn,
java.lang.String sql)
Execute an SQL statement.
|
static void |
main(java.lang.String... args)
Runner main method.
|
protected java.util.List<java.lang.String> |
makeScripts(java.util.List<java.lang.String> scriptNames)
Make full script files names from script names
|
protected void |
parseCmdLine(java.lang.String[] args)
Parse command line arguments.
|
private java.lang.String |
readLine(java.io.Reader r)
Read the next line from the source Reader.
|
private void |
runScript(java.sql.Connection conn,
java.io.Reader script)
Run UDFs SQL script against the database.
|
private void |
runScript(java.sql.Connection conn,
java.io.Reader script,
ScriptSplitter splitter)
Run UDFs SQL script against the database.
|
boolean |
supportsUdfScripts()
Check if UDFs are created with script
|
protected static final CentralLogger LOG
private static final java.util.regex.Pattern JDBC
protected java.util.Map<java.lang.String,java.lang.String> placeholders
protected boolean usePlaceholders
protected final Dialect dialect
protected java.util.List<java.lang.String> scripts
protected ScriptRunner.ScriptType scriptType
public ScriptRunner(Dialect dialect)
dialect - the target database dialectpublic static void main(java.lang.String... args)
throws java.lang.Exception
args - Command line arguments, as follows: [<db url>, <user>, <password>, <command>].java.lang.Exception - On error.protected void parseCmdLine(java.lang.String[] args)
args - command line arguments;public boolean supportsUdfScripts()
true if UDFs are created with scriptprotected java.util.List<java.lang.String> defaultUdfScripts()
protected void applyDDLScripts(java.sql.Connection conn)
throws java.sql.SQLException,
java.io.IOException
java.sql.SQLExceptionjava.io.IOExceptionprotected java.lang.String applyPlaceholders(java.sql.Connection conn,
java.lang.String source)
conn - Database connection.source - The SQL statement to be executed.protected abstract void applyUdfScripts(java.sql.Connection conn)
throws java.sql.SQLException,
java.io.IOException
conn - Database connection.java.sql.SQLException - on SQL error.java.io.IOException - on script reading error.protected abstract void createMissingUdfs(java.lang.String dbname,
java.lang.String url,
java.lang.String adm,
java.lang.String pwd)
throws java.sql.SQLException,
PersistenceException
dbname - Database name.url - Database JDBC URL.adm - Admin login.pwd - Admin password.java.sql.SQLException - on SQL error.PersistenceException - on script reading error.public static void createMissingUdfs(Database db) throws java.sql.SQLException, PersistenceException
db - Database.java.sql.SQLException - on SQL error.PersistenceException - on script reading error.protected java.util.List<java.lang.String> addScriptPath(java.util.List<java.lang.String> scriptNames)
scriptNames - original script namesprotected java.util.List<java.lang.String> makeScripts(java.util.List<java.lang.String> scriptNames)
scriptNames - original script namesprotected void applyScripts(java.sql.Connection conn,
ScriptSplitter splitter)
throws java.io.IOException,
java.sql.SQLException
conn - connectionsplitter - script splitterjava.io.IOException - on I/O errorjava.sql.SQLException - on database errorprotected void applySchema(java.sql.Connection conn)
throws java.io.IOException,
java.sql.SQLException
conn - connectionjava.io.IOException - on I/O errorjava.sql.SQLException - on database errorprivate void runScript(java.sql.Connection conn,
java.io.Reader script,
ScriptSplitter splitter)
throws java.io.IOException,
java.sql.SQLException
conn - The database connection.script - The reader for the script.java.io.IOException - In I/O error.java.sql.SQLException - In database error.private void runScript(java.sql.Connection conn,
java.io.Reader script)
throws java.io.IOException,
java.sql.SQLException
conn - The database connection.script - The reader for the script.java.io.IOException - In I/O error.java.sql.SQLException - In database error.protected void execute(java.sql.Connection conn,
java.lang.String sql)
throws java.sql.SQLException
conn - The database connection.sql - The SQL statement to be executed.java.sql.SQLException - On error.private java.lang.String readLine(java.io.Reader r)
throws java.io.IOException
r - The reader for the source file.null if EOF.java.io.IOException - In the event of an I/O error.