提交 3d40aad2 authored 作者: Thomas Mueller's avatar Thomas Mueller

The build converts the javadocs to a resource.

上级 25d38fde
org.h2.tools.Backup=Creates a backup of a database.
org.h2.tools.Backup.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-file <filename>] The target file name (default\: backup.zip)\n[-dir <dir>] The source directory (default\: .)\n[-db <database>] Source database; not required if there is only one\n[-quiet] Do not print progress information
org.h2.tools.ChangeFileEncryption=Allows changing the database file encryption password or algorithm.\nThis tool can not be used to change a password of a user.
org.h2.tools.ChangeFileEncryption.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-cipher type] The encryption type (AES or XTEA)\n[-dir <dir>] The database directory (default\: .)\n[-db <database>] Database name (all databases if not set)\n[-decrypt <pwd>] The decryption password (if not set\: not yet encrypted)\n[-encrypt <pwd>] The encryption password (if not set\: do not encrypt)\n[-quiet] Do not print progress information
org.h2.tools.ConvertTraceFile=Converts a .trace.db file to a SQL script and Java source code.\nSQL statement statistics are listed as well.
org.h2.tools.ConvertTraceFile.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-traceFile <file>] The trace file name (default\: test.trace.db)\n[-script <file>] The script file name (default\: test.sql)\n[-javaClass <file>] The Java directory and class file name (default\: Test)
org.h2.tools.CreateCluster=Creates a cluster from a standalone database.\nCopies a database to another location if required.
org.h2.tools.CreateCluster.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-urlSource <url>] The database URL of the source database (jdbc\:h2\:...)\n[-urlTarget <url>] The database URL of the target database (jdbc\:h2\:...)\n[-user <user>] The user name (default\: sa)\n[-password <pwd>] The password\n[-serverList <list>] The comma separated list of host names or IP addresses
org.h2.tools.DeleteDbFiles=Deletes all files belonging to a database.\nThe database must be closed before calling this tool.
org.h2.tools.DeleteDbFiles.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-dir <dir>] The directory (default\: .)\n[-db <database>] The database name\n[-quiet] Do not print progress information
org.h2.tools.Recover=Helps recovering a corrupted database.
org.h2.tools.Recover.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-dir <dir>] The directory (default\: .)\n[-db <database>] The database name (all databases if not set)\n[-trace] Print additional trace information
org.h2.tools.Restore=Restores a H2 database by extracting the database files from a .zip file.
org.h2.tools.Restore.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-file <filename>] The source file name (default\: backup.zip)\n[-dir <dir>] The target directory (default\: .)\n[-db <database>] The target database name (as stored if not set)\n[-quiet] Do not print progress information
org.h2.tools.RunScript=Runs a SQL script against a database.
org.h2.tools.RunScript.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-url <url>] The database URL (jdbc\:...)\n[-user <user>] The user name (default\: sa)\n[-password <pwd>] The password\n[-script <file>] The script file to run (default\: backup.sql)\n[-driver <class>] The JDBC driver class to use (not required in most cases)\n[-showResults] Show the statements and the results of queries\n[-checkResults] Check if the query results match the expected results\n[-options ...] A list of options (only for embedded H2, see RUNSCRIPT)
org.h2.tools.Script=Creates a SQL script file by extracting the schema and data of a database.
org.h2.tools.Script.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-url <url>] The database URL (jdbc\:...)\n[-user <user>] The user name (default\: sa)\n[-password <pwd>] The password\n[-script <file>] The target script file name (default\: backup.sql)\n[-options ...] A list of options (only for embedded H2, see RUNSCRIPT)\n[-quiet] Do not print progress information
...@@ -24,34 +24,28 @@ import org.h2.util.IOUtils; ...@@ -24,34 +24,28 @@ import org.h2.util.IOUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
/** /**
* Backs up a H2 database by creating a .zip file from the database files. * Creates a backup of a database.
* @h2.resource
*/ */
public class Backup extends Tool { public class Backup extends Tool {
private void showUsage() {
out.println("Creates a backup of a database.");
out.println("java "+getClass().getName() + "\n" +
" [-file <filename>] The target file name (default: backup.zip)\n" +
" [-dir <dir>] Source directory (default: .)\n" +
" [-db <database>] Source database name\n" +
" [-quiet] Do not print progress information");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. * Options are case sensitive. Supported options are:
* The options must be split into strings like this: "-db", "test",... * <table>
* Options are case sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) * <tr><td>[-file &lt;filename&gt;]</td>
* </li><li>-file filename (the default is backup.zip) * <td>The target file name (default: backup.zip)</td></tr>
* </li><li>-dir database directory (the default is the current directory) * <tr><td>[-dir &lt;dir&gt;]</td>
* </li><li>-db database name (not required if there is only one database) * <td>The source directory (default: .)</td></tr>
* </li><li>-quiet does not print progress information * <tr><td>[-db &lt;database&gt;]</td>
* </li></ul> * <td>Source database; not required if there is only one</td></tr>
* <tr><td>[-quiet]</td>
* <td>Do not print progress information</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new Backup().run(args); new Backup().run(args);
......
...@@ -17,9 +17,10 @@ import org.h2.util.FileUtils; ...@@ -17,9 +17,10 @@ import org.h2.util.FileUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
/** /**
* A tools to change, remove or set a file password of a database without * Allows changing the database file encryption password or algorithm.
* opening it. The encryption algorithm can be changed as well. It can not be * <br />
* used to change a password of a user. * This tool can not be used to change a password of a user.
* @h2.resource
*/ */
public class ChangeFileEncryption extends Tool { public class ChangeFileEncryption extends Tool {
...@@ -28,34 +29,27 @@ public class ChangeFileEncryption extends Tool { ...@@ -28,34 +29,27 @@ public class ChangeFileEncryption extends Tool {
private byte[] decrypt; private byte[] decrypt;
private byte[] encrypt; private byte[] encrypt;
private void showUsage() {
out.println("Allows changing the database file encryption password or algorithm.");
out.println("java "+getClass().getName() + "\n" +
" -cipher <type> AES or XTEA\n" +
" [-dir <dir>] The database directory (default: .)\n" +
" [-db <database>] The database name (default: all databases)\n" +
" [-decrypt <pwd>] The decryption password (default: the database is not yet encrypted)\n" +
" [-encrypt <pwd>] The encryption password (default: the database should not be encrypted)\n" +
" [-quiet] Do not print progress information");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. * Options are case sensitive. Supported options are:
* The options must be split into strings like this: "-db", "test",... * <table>
* Options are case sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) * <tr><td>[-cipher type]</td>
* </li><li>-dir database directory (the default is the current directory) * <td>The encryption type (AES or XTEA)</td></tr>
* </li><li>-db database name (all databases if no name is specified) * <tr><td>[-dir &lt;dir&gt;]</td>
* </li><li>-cipher type (AES or XTEA) * <td>The database directory (default: .)</td></tr>
* </li><li>-decrypt password (null if the database is not encrypted) * <tr><td>[-db &lt;database&gt;]</td>
* </li><li>-encrypt password (null if the database should not be encrypted) * <td>Database name (all databases if not set)</td></tr>
* </li><li>-quiet does not print progress information * <tr><td>[-decrypt &lt;pwd&gt;]</td>
* </li></ul> * <td>The decryption password (if not set: not yet encrypted)</td></tr>
* <tr><td>[-encrypt &lt;pwd&gt;]</td>
* <td>The encryption password (if not set: do not encrypt)</td></tr>
* <tr><td>[-quiet]</td>
* <td>Do not print progress information</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new ChangeFileEncryption().run(args); new ChangeFileEncryption().run(args);
......
...@@ -21,8 +21,10 @@ import org.h2.util.StringUtils; ...@@ -21,8 +21,10 @@ import org.h2.util.StringUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
/** /**
* Convert a trace file to a java class. * Converts a .trace.db file to a SQL script and Java source code.
* This is required because the find command truncates lines. * <br />
* SQL statement statistics are listed as well.
* @h2.resource
*/ */
public class ConvertTraceFile extends Tool { public class ConvertTraceFile extends Tool {
...@@ -54,28 +56,21 @@ public class ConvertTraceFile extends Tool { ...@@ -54,28 +56,21 @@ public class ConvertTraceFile extends Tool {
} }
} }
private void showUsage() {
out.println("Converts a .trace.db file to a SQL script and Java source code.");
out.println("java "+getClass().getName() + "\n" +
" [-traceFile <file>] The trace file name (default: test.trace.db)\n" +
" [-script <file>] The script file name (default: test.sql)\n" +
" [-javaClass <file>] The Java directory and class file name (default: Test)");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. The options must be split into * Options are case sensitive. Supported options are:
* strings like this: "-traceFile", "test.trace.db",... Options are case * <table>
* sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) </li> * <tr><td>[-traceFile &lt;file&gt;]</td>
* <li>-traceFile filename (the default is test.trace.db) </li> * <td>The trace file name (default: test.trace.db)</td></tr>
* <li>-script filename (the default is test.sql) </li> * <tr><td>[-script &lt;file&gt;]</td>
* <li>-javaClass className (the default is Test) </li> * <td>The script file name (default: test.sql)</td></tr>
* </ul> * <tr><td>[-javaClass &lt;file&gt;]</td>
* <td>The Java directory and class file name (default: Test)</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws Exception
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new ConvertTraceFile().run(args); new ConvertTraceFile().run(args);
......
...@@ -16,38 +16,32 @@ import org.h2.util.JdbcUtils; ...@@ -16,38 +16,32 @@ import org.h2.util.JdbcUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
/** /**
* Tool to create a database cluster. This will copy a database to another * Creates a cluster from a standalone database.
* location if required, and modify the cluster setting. * <br />
* Copies a database to another location if required.
* @h2.resource
*/ */
public class CreateCluster extends Tool { public class CreateCluster extends Tool {
private void showUsage() {
out.println("Creates a cluster from a standalone database.");
out.println("java "+getClass().getName() + "\n" +
" -urlSource <url> The database URL of the source database (jdbc:h2:...)\n" +
" -urlTarget <url> The database URL of the target database (jdbc:h2:...)\n" +
" -user <user> The user name\n" +
" [-password <pwd>] The password\n" +
" -serverList <list> The comma separated list of host names or IP addresses");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. The options must be split into * Options are case sensitive. Supported options are:
* strings like this: "-urlSource", "jdbc:h2:test",... Options are case * <table>
* sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) </li> * <tr><td>[-urlSource &lt;url&gt;]</td>
* <li>-urlSource jdbc:h2:... (the database URL of the source database) * <td>The database URL of the source database (jdbc:h2:...)</td></tr>
* </li> * <tr><td>[-urlTarget &lt;url&gt;]</td>
* <li>-urlTarget jdbc:h2:... (the database URL of the target database) * <td>The database URL of the target database (jdbc:h2:...)</td></tr>
* </li><li>-user (the user name) * <tr><td>[-user &lt;user&gt;]</td>
* </li><li>-password (the password) * <td>The user name (default: sa)</td></tr>
* </li><li>-serverList (the server list) * <tr><td>[-password &lt;pwd&gt;]</td>
* </li></ul> * <td>The password</td></tr>
* <tr><td>[-serverList &lt;list&gt;]</td>
* <td>The comma separated list of host names or IP addresses</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new CreateCluster().run(args); new CreateCluster().run(args);
...@@ -56,7 +50,7 @@ public class CreateCluster extends Tool { ...@@ -56,7 +50,7 @@ public class CreateCluster extends Tool {
public void run(String[] args) throws SQLException { public void run(String[] args) throws SQLException {
String urlSource = null; String urlSource = null;
String urlTarget = null; String urlTarget = null;
String user = null; String user = "sa";
String password = ""; String password = "";
String serverList = null; String serverList = null;
for (int i = 0; args != null && i < args.length; i++) { for (int i = 0; args != null && i < args.length; i++) {
......
...@@ -16,33 +16,28 @@ import org.h2.util.FileUtils; ...@@ -16,33 +16,28 @@ import org.h2.util.FileUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
/** /**
* Delete the database files. The database must be closed before calling this * Deletes all files belonging to a database.
* tool. * <br />
* The database must be closed before calling this tool.
* @h2.resource
*/ */
public class DeleteDbFiles extends Tool { public class DeleteDbFiles extends Tool {
private void showUsage() {
out.println("Deletes all files belonging to a database.");
out.println("java "+getClass().getName() + "\n" +
" [-dir <dir>] The directory (default: .)\n" +
" [-db <database>] The database name\n" +
" [-quiet] Do not print progress information");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. * Options are case sensitive. Supported options are:
* The options must be split into strings like this: "-db", "test",... * <table>
* Options are case sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) * <tr><td>[-dir &lt;dir&gt;]</td>
* </li><li>-dir database directory (the default is the current directory) * <td>The directory (default: .)</td></tr>
* </li><li>-db database name (all databases if no name is specified) * <tr><td>[-db &lt;database&gt;]</td>
* </li><li>-quiet does not print progress information * <td>The database name</td></tr>
* </li></ul> * <tr><td>[-quiet]</td>
* <td>Do not print progress information</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new DeleteDbFiles().run(args); new DeleteDbFiles().run(args);
......
...@@ -58,12 +58,8 @@ import org.h2.value.Value; ...@@ -58,12 +58,8 @@ import org.h2.value.Value;
import org.h2.value.ValueLob; import org.h2.value.ValueLob;
/** /**
* Dumps the contents of a database file to a human readable text file. This * Helps recovering a corrupted database.
* text file can be used to recover most of the data. This tool does not open * @h2.resource
* the database and can be used even if the database files are corrupted. A
* database can get corrupted if there is a bug in the database engine or file
* system software, or if an application writes into the database file that
* doesn't understand the the file format, or if there is a hardware problem.
*/ */
public class Recover extends Tool implements DataHandler { public class Recover extends Tool implements DataHandler {
...@@ -80,33 +76,37 @@ public class Recover extends Tool implements DataHandler { ...@@ -80,33 +76,37 @@ public class Recover extends Tool implements DataHandler {
private HashMap tableMap; private HashMap tableMap;
private boolean remove; private boolean remove;
private void showUsage() {
out.println("Helps recovering a corrupted database.");
out.println("java "+getClass().getName() + "\n" +
" [-dir <dir>] The directory (default: .)\n" +
" [-db <database>] The database name\n" +
" [-trace] Print additional trace information");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. * Options are case sensitive. Supported options are:
* The options must be split into strings like this: "-db", "test",... * <table>
* Options are case sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) * <tr><td>[-dir &lt;dir&gt;]</td>
* </li><li>-dir database directory (the default is the current directory) * <td>The directory (default: .)</td></tr>
* </li><li>-db database name (all databases if no name is specified) * <tr><td>[-db &lt;database&gt;]</td>
* </li><li>-trace (print additional trace information while processing) * <td>The database name (all databases if not set)</td></tr>
* </li></ul> * <tr><td>[-trace]</td>
* <td>Print additional trace information</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new Recover().run(args); new Recover().run(args);
} }
/**
* Dumps the contents of a database file to a human readable text file. This
* text file can be used to recover most of the data. This tool does not
* open the database and can be used even if the database files are
* corrupted. A database can get corrupted if there is a bug in the database
* engine or file system software, or if an application writes into the
* database file that doesn't understand the the file format, or if there is
* a hardware problem.
*
* @param args the command line arguments
*/
public void run(String[] args) throws SQLException { public void run(String[] args) throws SQLException {
String dir = "."; String dir = ".";
String db = null; String db = null;
......
...@@ -22,31 +22,27 @@ import org.h2.util.Tool; ...@@ -22,31 +22,27 @@ import org.h2.util.Tool;
/** /**
* Restores a H2 database by extracting the database files from a .zip file. * Restores a H2 database by extracting the database files from a .zip file.
* @h2.resource
*/ */
public class Restore extends Tool { public class Restore extends Tool {
private void showUsage() {
out.println("Restores a database backup.");
out.println("java "+getClass().getName() + "\n" +
" [-file <filename>] The source file name (default: backup.zip)\n" +
" [-dir <dir>] Target directory (default: .)\n" +
" [-db <database>] Target database name");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. * Options are case sensitive. Supported options are:
* The options must be split into strings like this: "-db", "test",... * <table>
* Options are case sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) * <tr><td>[-file &lt;filename&gt;]</td>
* </li><li>-file filename (the default is backup.zip) * <td>The source file name (default: backup.zip)</td></tr>
* </li><li>-dir database directory (the default is the current directory) * <tr><td>[-dir &lt;dir&gt;]</td>
* </li><li>-db database name (as stored in the backup if no name is specified) * <td>The target directory (default: .)</td></tr>
* </li></ul> * <tr><td>[-db &lt;database&gt;]</td>
* <td>The target database name (as stored if not set)</td></tr>
* <tr><td>[-quiet]</td>
* <td>Do not print progress information</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new Restore().run(args); new Restore().run(args);
......
...@@ -30,70 +30,65 @@ import org.h2.util.StringUtils; ...@@ -30,70 +30,65 @@ import org.h2.util.StringUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
/** /**
* Executes the contents of a SQL script file against a database. * Runs a SQL script against a database.
* This tool is usually used to create a database from script. * @h2.resource
* It can also be used to analyze performance problems by running
* the tool using Java profiler settings such as:
* <pre>
* java -Xrunhprof:cpu=samples ...
* </pre>
*/ */
public class RunScript extends Tool { public class RunScript extends Tool {
private boolean showResults; private boolean showResults;
private boolean checkResults; private boolean checkResults;
private void showUsage() { /**
out.println("Runs a SQL script."); * Options are case sensitive. Supported options are:
out.println("java "+getClass().getName() + "\n" + * <table>
" -url <url> The database URL\n" + * <tr><td>[-help] or [-?]</td>
" -user <user> The user name\n" + * <td>Print the list of options</td></tr>
" [-password <pwd>] The password\n" + * <tr><td>[-url &lt;url&gt;]</td>
" [-script <file>] The script file to run (default: backup.sql)\n" + * <td>The database URL (jdbc:...)</td></tr>
" [-driver <class>] The JDBC driver class to use (not required in most cases)\n" + * <tr><td>[-user &lt;user&gt;]</td>
" [-showResults] Show the statements and the results of queries\n" + * <td>The user name (default: sa)</td></tr>
" [-checkResults] Check if the query results match the expected results\n" + * <tr><td>[-password &lt;pwd&gt;]</td>
" [-options ...] A list of options (only for embedded H2, see RUNSCRIPT)"); * <td>The password</td></tr>
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html"); * <tr><td>[-script &lt;file&gt;]</td>
* <td>The script file to run (default: backup.sql)</td></tr>
* <tr><td>[-driver &lt;class&gt;]</td>
* <td>The JDBC driver class to use (not required in most cases)</td></tr>
* <tr><td>[-showResults]</td>
* <td>Show the statements and the results of queries</td></tr>
* <tr><td>[-checkResults]</td>
* <td>Check if the query results match the expected results</td></tr>
* <tr><td>[-options ...]</td>
* <td>A list of options (only for embedded H2, see RUNSCRIPT)</td></tr>
* </table>
* @h2.resource
*
* @param args the command line arguments
*/
public static void main(String[] args) throws SQLException {
new RunScript().run(args);
} }
/** /**
* The command line interface for this tool. The options must be split into * Executes the contents of a SQL script file against a database.
* strings like this: "-user", "sa",... Options are case sensitive. The * This tool is usually used to create a database from script.
* following options are supported: * It can also be used to analyze performance problems by running
* <ul> * the tool using Java profiler settings such as:
* <li>-help or -? (print the list of options) </li> * <pre>
* <li>-url jdbc:h2:... (database URL) </li> * java -Xrunhprof:cpu=samples,depth=16 ...
* <li>-user username </li> * </pre>
* <li>-password password </li>
* <li>-script filename (default file name is backup.sql) </li>
* <li>-driver driver (the JDBC driver class name; not required for most
* databases) </li>
* <li>-showResults (show the statements and the results of queries)</li>
* <li>-checkResults (check if the query results match the expected results</li>
* <li>-options (to specify a list of options for the RUNSCRIPT command;
* only for H2 and only when using the embedded mode)</li>
* </ul>
* To include local files when using remote databases, use the special * To include local files when using remote databases, use the special
* syntax: * syntax:
*
* <pre> * <pre>
* &#064;INCLUDE fileName * &#064;INCLUDE fileName
* </pre> * </pre>
*
* This syntax is only supported by this tool. Embedded RUNSCRIPT SQL * This syntax is only supported by this tool. Embedded RUNSCRIPT SQL
* statements will be executed by the database. * statements will be executed by the database.
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException {
new RunScript().run(args);
}
public void run(String[] args) throws SQLException { public void run(String[] args) throws SQLException {
String url = null; String url = null;
String user = null; String user = "sa";
String password = ""; String password = "";
String script = "backup.sql"; String script = "backup.sql";
String options = null; String options = null;
......
...@@ -22,36 +22,31 @@ import org.h2.util.Tool; ...@@ -22,36 +22,31 @@ import org.h2.util.Tool;
/** /**
* Creates a SQL script file by extracting the schema and data of a database. * Creates a SQL script file by extracting the schema and data of a database.
* @h2.resource
*/ */
public class Script extends Tool { public class Script extends Tool {
private void showUsage() {
out.println("Allows converting a database to a SQL script.");
out.println("java "+getClass().getName() + "\n" +
" -url <url> The database URL\n" +
" -user <user> The user name\n" +
" [-password <pwd>] The password\n" +
" [-script <file>] The script file to run (default: backup.sql)\n" +
" [-quiet] Do not print progress information\n" +
" [-options ...] The list of options (only for H2 embedded mode)");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/** /**
* The command line interface for this tool. * Options are case sensitive. Supported options are:
* The options must be split into strings like this: "-user", "sa",... * <table>
* Options are case sensitive. The following options are supported: * <tr><td>[-help] or [-?]</td>
* <ul> * <td>Print the list of options</td></tr>
* <li>-help or -? (print the list of options) * <tr><td>[-url &lt;url&gt;]</td>
* </li><li>-url jdbc:h2:... (database URL) * <td>The database URL (jdbc:...)</td></tr>
* </li><li>-user username * <tr><td>[-user &lt;user&gt;]</td>
* </li><li>-password password * <td>The user name (default: sa)</td></tr>
* </li><li>-script filename (default file name is backup.sql) * <tr><td>[-password &lt;pwd&gt;]</td>
* </li><li>-options to specify a list of options (only for H2) * <td>The password</td></tr>
* </li></ul> * <tr><td>[-script &lt;file&gt;]</td>
* <td>The target script file name (default: backup.sql)</td></tr>
* <tr><td>[-options ...]</td>
* <td>A list of options (only for embedded H2, see RUNSCRIPT)</td></tr>
* <tr><td>[-quiet]</td>
* <td>Do not print progress information</td></tr>
* </table>
* @h2.resource
* *
* @param args the command line arguments * @param args the command line arguments
* @throws SQLException
*/ */
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
new Script().run(args); new Script().run(args);
...@@ -59,7 +54,7 @@ public class Script extends Tool { ...@@ -59,7 +54,7 @@ public class Script extends Tool {
public void run(String[] args) throws SQLException { public void run(String[] args) throws SQLException {
String url = null; String url = null;
String user = null; String user = "sa";
String password = ""; String password = "";
String file = "backup.sql"; String file = "backup.sql";
String options1 = null, options2 = null; String options1 = null, options2 = null;
...@@ -99,7 +94,7 @@ public class Script extends Tool { ...@@ -99,7 +94,7 @@ public class Script extends Tool {
return; return;
} }
} }
if (url == null || user == null || file == null) { if (url == null) {
showUsage(); showUsage();
return; return;
} }
......
...@@ -6,8 +6,15 @@ ...@@ -6,8 +6,15 @@
*/ */
package org.h2.util; package org.h2.util;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
...@@ -87,4 +94,29 @@ public class SortedProperties extends Properties { ...@@ -87,4 +94,29 @@ public class SortedProperties extends Properties {
return prop; return prop;
} }
/**
* Store a properties file. The header and the date is not written.
*
* @param fileName the target file name
*/
public synchronized void store(String fileName) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
store(out, null);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
LineNumberReader r = new LineNumberReader(reader);
FileWriter w = new FileWriter(fileName);
PrintWriter writer = new PrintWriter(new BufferedWriter(w));
while (true) {
String line = r.readLine();
if (line == null) {
break;
}
if (!line.startsWith("#")) {
writer.println(line);
}
}
writer.close();
}
} }
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
*/ */
package org.h2.util; package org.h2.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Properties;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
/** /**
...@@ -22,6 +24,8 @@ public abstract class Tool { ...@@ -22,6 +24,8 @@ public abstract class Tool {
*/ */
protected PrintStream out = System.out; protected PrintStream out = System.out;
private Properties resources;
/** /**
* Sets the standard output stream. * Sets the standard output stream.
* *
...@@ -57,6 +61,30 @@ public abstract class Tool { ...@@ -57,6 +61,30 @@ public abstract class Tool {
out.println(buff.toString()); out.println(buff.toString());
} }
/**
* Print the usage of the tool. This method reads the description from the
* resource file.
*/
protected void showUsage() {
if (resources == null) {
resources = new Properties();
String resourceName = "/org/h2/res/javadoc.properties";
try {
byte[] buff = Resources.get(resourceName);
if (buff != null) {
resources.load(new ByteArrayInputStream(buff));
}
} catch (IOException e) {
out.println("Cannot load " + resourceName);
}
}
String className = getClass().getName();
out.println(resources.get(className));
out.println("Usage: java "+getClass().getName() + " <options>");
out.println(resources.get(className + ".main"));
out.println("See also http://h2database.com/javadoc/" + className.replace('.', '/') + ".html");
}
/** /**
* Read an argument and check if it is true (1), false (-1), or not (0). * Read an argument and check if it is true (1), false (-1), or not (0).
* This method is used for compatibility with older versions only. * This method is used for compatibility with older versions only.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论