提交 4b0fe6a5 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 f89dd431
......@@ -161,6 +161,7 @@
<fileset dir="src/docsrc" includes="index.html"/>
<fileset dir="src/docsrc" includes="html/**/*" excludes="**/*.jsp" />
</copy>
<java classname="org.h2.tools.code.CheckPackageHtml" classpath="bin"/>
<java classname="org.h2.tools.code.CheckTextFiles" classpath="bin"/>
<java classname="org.h2.tools.doc.GenerateDoc" classpath="bin">
<arg line="-in src/docsrc/html -out docs/html"/>
......@@ -259,8 +260,9 @@
<target name="javadocImpl" depends="javadoc">
<mkdir dir="docs/javadocImpl"/>
<javadoc
sourcepath="src/main"
sourcepath="src/main;src/test;src/tools"
packagenames="org.h2.*"
excludepackagenames="org.h2.tools.doclet"
classpath="${path.lucene.jar};${path.servlet.jar}"
destDir="docs/javadocImpl"
/>
......
......@@ -3904,7 +3904,10 @@ public class Parser {
private ScriptCommand parseScript() throws SQLException {
ScriptCommand command = new ScriptCommand(session);
boolean data = true, passwords = true, settings = true, dropTables = false;
boolean data = true, passwords = true, settings = true, dropTables = false, simple = false;
if (readIf("SIMPLE")) {
simple = true;
}
if (readIf("NODATA")) {
data = false;
}
......@@ -3925,6 +3928,7 @@ public class Parser {
command.setPasswords(passwords);
command.setSettings(settings);
command.setDrop(dropTables);
command.setSimple(simple);
if (readIf("TO")) {
command.setFileName(readString());
if (readIf("COMPRESSION")) {
......
......@@ -66,6 +66,7 @@ public class ScriptCommand extends ScriptBase {
private boolean data;
private boolean settings;
private boolean drop;
private boolean simple;
private LocalResult result;
private byte[] lineSeparator;
private byte[] buffer;
......@@ -242,11 +243,20 @@ public class ScriptCommand extends ScriptBase {
}
buff.append(Parser.quoteIdentifier(columns[j].getName()));
}
buff.append(") VALUES(");
buff.append(") VALUES");
if (!simple) {
buff.append('\n');
}
buff.append('(');
String ins = buff.toString();
buff = null;
while (cursor.next()) {
Row row = cursor.get();
buff = new StringBuffer(ins);
if (buff == null) {
buff = new StringBuffer(ins);
} else {
buff.append(",\n(");
}
for (int j = 0; j < row.getColumnCount(); j++) {
if (j > 0) {
buff.append(", ");
......@@ -268,6 +278,12 @@ public class ScriptCommand extends ScriptBase {
}
}
buff.append(")");
if (simple || buff.length() > Constants.IO_BUFFER_SIZE) {
add(buff.toString(), true);
buff = null;
}
}
if (buff != null) {
add(buff.toString(), true);
}
}
......@@ -479,4 +495,8 @@ public class ScriptCommand extends ScriptBase {
}
}
public void setSimple(boolean simple) {
this.simple = simple;
}
}
......@@ -103,12 +103,13 @@ RUNSCRIPT FROM 'backup'
"
"Commands (DML)","SCRIPT","
SCRIPT [NODATA] [NOPASSWORDS] [NOSETTINGS] [DROP] [BLOCKSIZE blockSizeInt]
SCRIPT [SIMPLE] [NODATA] [NOPASSWORDS] [NOSETTINGS] [DROP] [BLOCKSIZE blockSizeInt]
[TO fileNameString
[COMPRESSION {DEFLATE|LZF|ZIP|GZIP}]
[CIPHER cipher PASSWORD string]]
","
Creates a SQL script with or without the insert statements.
The simple format does not use multi-row insert statements.
If no file name is specified, the script is returned as a result set.
This command can be used to create a backup of the database.
If the DROP option is specified, drop statements are created for tables, views, and sequences.
......
......@@ -6,6 +6,7 @@ package org.h2.samples;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.tools.Script;
......@@ -18,6 +19,7 @@ import org.h2.tools.RunScript;
* using this script.
*/
public class Compact {
public static void main(String[] args) throws Exception {
DeleteDbFiles.execute("data", "test", true);
Class.forName("org.h2.Driver");
......@@ -26,14 +28,20 @@ public class Compact {
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');");
conn.close();
System.out.println("Compacting...");
compact("data", "test", "sa", "");
System.out.println("Done.");
}
public static void compact(String dir, String dbName, String user, String password) throws Exception {
/**
* Utility method to compact a database.
*
* @param dir the directory
* @param dbName the database name
* @param user the user name
* @param password the password
*/
public static void compact(String dir, String dbName, String user, String password) throws SQLException {
String url = "jdbc:h2:" + dir + "/" + dbName;
String file = "data/test.sql";
Script.execute(url, user, password, file);
......
......@@ -6,6 +6,7 @@ package org.h2.samples;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import org.h2.tools.Csv;
......@@ -17,12 +18,16 @@ import org.h2.tools.SimpleResultSet;
* how to use the tool to read such files.
*/
public class CsvSample {
public static void main(String[] args) throws Exception {
public static void main(String[] args) throws SQLException {
CsvSample.write();
CsvSample.read();
}
static void write() throws Exception {
/**
* Write a CSV file.
*/
static void write() throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 255, 0);
rs.addColumn("EMAIL", Types.VARCHAR, 255, 0);
......@@ -32,7 +37,10 @@ public class CsvSample {
Csv.getInstance().write("data/test.csv", rs, null);
}
static void read() throws Exception {
/**
* Read a CSV file.
*/
static void read() throws SQLException {
ResultSet rs = Csv.getInstance().read("data/test.csv", null, null);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
......
......@@ -35,18 +35,37 @@ public class FileFunctions {
conn.close();
}
/**
* Read a String from a file. The default encoding for this platform is used.
*
* @param fileName the file name
* @return the text
*/
public static String readTextFile(String fileName) throws IOException {
byte[] buff = readFile(fileName);
String s = new String(buff);
return s;
}
/**
* Read a String from a file using the specified encoding.
*
* @param fileName the file name
* @param encoding the encoding
* @return the text
*/
public static String readTextFileWithEncoding(String fileName, String encoding) throws IOException {
byte[] buff = readFile(fileName);
String s = new String(buff, encoding);
return s;
}
/**
* Read a file into a byte array.
*
* @param fileName the file name
* @return the byte array
*/
public static byte[] readFile(String fileName) throws IOException {
RandomAccessFile file = new RandomAccessFile(fileName, "r");
try {
......
......@@ -37,14 +37,32 @@ public class Function {
conn.close();
}
/**
* Check if a value is a prime number.
*
* @param value the value
* @return true if it is a prime number
*/
public static boolean isPrime(int value) {
return new BigInteger(String.valueOf(value)).isProbablePrime(100);
}
/**
* Execute a query.
*
* @param conn the connection
* @param sql the SQL statement
* @return the result set
*/
public static ResultSet query(Connection conn, String sql) throws SQLException {
return conn.createStatement().executeQuery(sql);
}
/**
* Creates a simple result set with one row.
*
* @return the result set
*/
public static ResultSet simpleResultSet() throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ID", Types.INTEGER, 10, 0);
......
......@@ -74,8 +74,13 @@ public class FunctionMultiReturn {
}
/**
* Convert polar coordinates to cartesian coordinates.
* The function may be called twice, once to retrieve the result columns (with null parameters),
* and the second time to return the data.
*
* @param r the distance from the point 0/0
* @param alpha the angle
* @return a result set with two columns: x and y
*/
public static ResultSet polar2Cartesian(Double r, Double alpha) throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
......@@ -90,8 +95,13 @@ public class FunctionMultiReturn {
}
/**
* Convert polar coordinates to cartesian coordinates.
* The function may be called twice, once to retrieve the result columns (with null parameters),
* and the second time to return the data.
*
* @param r the distance from the point 0/0
* @param alpha the angle
* @return an array two values: x and y
*/
public static Object[] polar2CartesianArray(Double r, Double alpha) throws SQLException {
double x = r.doubleValue() * Math.cos(alpha.doubleValue());
......@@ -99,6 +109,15 @@ public class FunctionMultiReturn {
return new Object[]{new Double(x), new Double(y)};
}
/**
* Convert a set of polar coordinates to cartesian coordinates.
* The function may be called twice, once to retrieve the result columns (with null parameters),
* and the second time to return the data.
*
* @param conn the connection
* @param query the query
* @return a result set with the coodinates
*/
public static ResultSet polar2CartesianSet(Connection conn, String query) throws SQLException {
SimpleResultSet result = new SimpleResultSet();
result.addColumn("R", Types.DOUBLE, 0, 0);
......
......@@ -23,6 +23,9 @@ public class InitDatabaseFromJar {
new InitDatabaseFromJar().initDb();
}
/**
* Create a script from a new database.
*/
private void createScript() throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
......@@ -33,6 +36,9 @@ public class InitDatabaseFromJar {
conn.close();
}
/**
* Initialize a database from a SQL script file.
*/
void initDb() throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
......
......@@ -16,6 +16,7 @@ import org.h2.tools.Server;
* the server mode supports remote connections.
*/
public class MixedMode {
public static void main(String[] args) throws Exception {
// start the server, allows to access the database remotly
......
......@@ -21,6 +21,7 @@ import org.h2.util.StringUtils;
* from a simple SQL script. A textual representation of the data is created as well.
*/
public class Newsfeed {
public static void main(String[] args) throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:", "sa", "");
......@@ -42,6 +43,12 @@ public class Newsfeed {
conn.close();
}
/**
* Convert HTML text to plain text.
*
* @param html the html text
* @return the plain text
*/
private static String convertHtml2Text(String html) {
String s = html;
s = StringUtils.replaceAll(s, "<b>", "");
......
......@@ -38,6 +38,14 @@ public class SQLInjection {
// "jdbc:derby:test3;create=true", "sa", "sa");
}
/**
* Run the test against the specified database.
*
* @param driver the JDBC driver name
* @param url the database URL
* @param user the user name
* @param password the password
*/
void run(String driver, String url, String user, String password) throws Exception {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
......@@ -106,6 +114,9 @@ public class SQLInjection {
conn.close();
}
/**
* Simulate a login using an insecure method.
*/
void loginByNameInsecure() throws Exception {
System.out.println("Insecure Systems Inc. - login");
String name = input("Name?");
......@@ -119,6 +130,15 @@ public class SQLInjection {
}
}
/**
* Utility method to get a user record given the user name and password.
* This method is secure.
*
* @param conn the database connection
* @param userName the user name
* @param password the password
* @return a result set with the user record if the password matches
*/
public static ResultSet getUser(Connection conn, String userName, String password) throws Exception {
PreparedStatement prep = conn.prepareStatement(
"SELECT * FROM USERS WHERE NAME=? AND PASSWORD=?");
......@@ -127,6 +147,15 @@ public class SQLInjection {
return prep.executeQuery();
}
/**
* Utility method to change a password of a user.
* This method is secure, except that the old password is not checked.
*
* @param conn the database connection
* @param userName the user name
* @param password the password
* @return the new password
*/
public static String changePassword(Connection conn, String userName, String password) throws Exception {
PreparedStatement prep = conn.prepareStatement(
"UPDATE USERS SET PASSWORD=? WHERE NAME=?");
......@@ -136,6 +165,10 @@ public class SQLInjection {
return password;
}
/**
* Simulate a login using an insecure method.
* A stored procedure is used here.
*/
void loginStoredProcedureInsecure() throws Exception {
System.out.println("Insecure Systems Inc. - login using a stored procedure");
stat.execute("CREATE ALIAS IF NOT EXISTS " +
......@@ -153,6 +186,9 @@ public class SQLInjection {
}
}
/**
* Simulate a login using a secure method.
*/
void loginByNameSecure() throws Exception {
System.out.println("Secure Systems Inc. - login using placeholders");
String name = input("Name?");
......@@ -170,6 +206,9 @@ public class SQLInjection {
}
}
/**
* Sample code to limit access only to specific rows.
*/
void limitRowAccess() throws Exception {
System.out.println("Secure Systems Inc. - limit row access");
stat.execute("DROP TABLE IF EXISTS SESSION_USER");
......@@ -185,6 +224,9 @@ public class SQLInjection {
}
}
/**
* Simulate a login using an insecure method.
*/
void loginByIdInsecure() throws Exception {
System.out.println("Half Secure Systems Inc. - login by id");
String id = input("User ID?");
......@@ -205,6 +247,9 @@ public class SQLInjection {
}
}
/**
* Simulate a login using a secure method.
*/
void loginByIdSecure() throws Exception {
System.out.println("Secure Systems Inc. - login by id");
String id = input("User ID?");
......@@ -226,6 +271,12 @@ public class SQLInjection {
}
}
/**
* List active items.
* The method uses the hard coded value '1', and therefore the database
* can not verify if the SQL statement was constructed with user
* input or not.
*/
void listActiveItems() throws Exception {
System.out.println("Half Secure Systems Inc. - list active items");
ResultSet rs = stat.executeQuery(
......@@ -235,6 +286,11 @@ public class SQLInjection {
}
}
/**
* List active items.
* The method uses a constant, and therefore the database
* knows it does not contain user input.
*/
void listActiveItemsUsingConstants() throws Exception {
System.out.println("Secure Systems Inc. - list active items");
ResultSet rs = stat.executeQuery(
......@@ -244,6 +300,11 @@ public class SQLInjection {
}
}
/**
* List items using a specified sort order.
* The method is not secure as user input is used to construct the
* SQL statement.
*/
void listItemsSortedInsecure() throws Exception {
System.out.println("Insecure Systems Inc. - list items");
String order = input("order (id, name)?");
......@@ -258,6 +319,11 @@ public class SQLInjection {
}
}
/**
* List items using a specified sort order.
* The method is secure as the user input is validated before use.
* However the database has no chance to verify this.
*/
void listItemsSortedSecure() throws Exception {
System.out.println("Secure Systems Inc. - list items");
String order = input("order (id, name)?");
......@@ -275,6 +341,10 @@ public class SQLInjection {
}
}
/**
* List items using a specified sort order.
* The method is secure as a parameterized statement is used.
*/
void listItemsSortedSecureParam() throws Exception {
System.out.println("Secure Systems Inc. - list items");
String order = input("order (1, 2, -1, -2)?");
......@@ -291,6 +361,11 @@ public class SQLInjection {
}
}
/**
* This method creates a one way hash from the password
* (using a random salt), and stores this information instead of the
* password.
*/
void storePasswordHashWithSalt() throws Exception {
System.out.println("Very Secure Systems Inc. - login");
stat.execute("DROP TABLE IF EXISTS USERS2");
......@@ -322,10 +397,15 @@ public class SQLInjection {
stat.execute("SET ALLOW_LITERALS ALL");
}
/**
* Utility method to get user input from the command line.
*
* @param prompt the prompt
* @return the user input
*/
String input(String prompt) throws Exception {
System.out.print(prompt);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
return reader.readLine();
return new BufferedReader(new InputStreamReader(System.in)).readLine();
}
}
......@@ -16,6 +16,7 @@ import java.util.Properties;
* (both database passwords, and account passwords).
*/
public class SecurePassword {
public static void main(String[] argv) throws Exception {
Class.forName("org.h2.Driver");
......
......@@ -22,6 +22,9 @@ public class ShowProgress implements DatabaseEventListener {
private long last, start;
/**
* Create a new instance of this class, and start the timer.
*/
public ShowProgress() {
start = last = System.currentTimeMillis();
}
......@@ -30,6 +33,9 @@ public class ShowProgress implements DatabaseEventListener {
new ShowProgress().test();
}
/**
* Run the progress test.
*/
void test() throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:test;LOG=2", "sa", "");
......@@ -69,15 +75,34 @@ public class ShowProgress implements DatabaseEventListener {
}
/**
* This method is called by the database if disk space is low.
*
* @param stillAvailable the number of bytes still available
*/
public void diskSpaceIsLow(long stillAvailable) throws SQLException {
System.out.println("diskSpaceIsLow stillAvailable="+stillAvailable);
}
/**
* This method is called if an exception occurs in the database.
*
* @param e the exception
* @param sql the SQL statement
*/
public void exceptionThrown(SQLException e, String sql) {
System.out.println("Error executing " + sql);
e.printStackTrace();
}
/**
* This method is called when opening the database to notify about the progress.
*
* @param state the current state
* @param name the object name (depends on the state)
* @param current the current progress
* @param max the 100% mark
*/
public void setProgress(int state, String name, int current, int max) {
long time = System.currentTimeMillis();
if (time < last + 5000) {
......@@ -104,14 +129,25 @@ public class ShowProgress implements DatabaseEventListener {
+ (time - start) + " ms");
}
/**
* This method is called when the database is closed.
*/
public void closingDatabase() {
System.out.println("Closing the database");
}
/**
* This method is called just after creating the instance.
*
* @param url the database URL
*/
public void init(String url) {
System.out.println("Initializing the event listener for database " + url);
}
/**
* This method is called when the database is open.
*/
public void opened() {
}
......
......@@ -9,6 +9,7 @@ package org.h2.samples;
* if it is running.
*/
public class ShutdownServer {
public static void main(String[] args) throws Exception {
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094", "", false);
}
......
......@@ -42,12 +42,33 @@ public class TriggerSample {
conn.close();
}
/**
* This class is a simple trigger implementation.
*/
public static class MyTrigger implements Trigger {
/**
* Initializes the trigger.
*
* @param conn a connection to the database
* @param schemaName the name of the schema
* @param triggerName the name of the trigger used in the CREATE TRIGGER statement
* @param tableName the name of the table
* @param before whether the fire method is called before or after the operation is performed
* @param type the operation type: INSERT, UPDATE, or DELETE
*/
public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) {
// System.out.println("Initializing trigger " + triggerName + " for table " + tableName);
}
/**
* This method is called for each triggered action.
*
* @param conn a connection to the database
* @param oldRow the old row, or null if no old row is available (for INSERT)
* @param newRow the new row, or null if no new row is available (for DELETE)
* @throws SQLException if the operation must be undone
*/
public void fire(Connection conn,
Object[] oldRow, Object[] newRow)
throws SQLException {
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Standalone sample applications.
</body></html>
\ No newline at end of file
......@@ -113,11 +113,6 @@ import org.h2.util.StringUtils;
*/
public class TestAll {
// Snippets to run test code:
// java -cp .;%H2DRIVERS% org.h2.test.TestAll
// java -Xrunhprof:cpu=samples,depth=8 org.h2.test.TestAll
// java -Xrunhprof:heap=sites,depth=8 org.h2.test.TestAll
/*
Random test:
......@@ -154,9 +149,19 @@ java org.h2.test.TestAll timer
/*
add tests with select distinct type (code coverage)
(code coverage: limit, sample-size)
add tests with select distinct type
staging.trace.db.gz
allow queries as well in batch updates
CALL syntax should probably work for regular executeUpdate as well.
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/callablestatement.html#1000220
documentation: package.html
-Djboss.bind.address=<ip_address>
-Dh2.bindAddress=...
documentation: package.html: write test (enforce one package.html where there is a .java file)
write to the db file what version was used to create a database
......@@ -296,7 +301,8 @@ Features of H2
} else if ("all".equals(args[0])) {
test.testEverything();
} else if ("codeCoverage".equals(args[0])) {
test.testCodeCoverage();
test.codeCoverage = true;
test.runTests();
} else if ("multiThread".equals(args[0])) {
new TestMulti().runTest(test);
} else if ("halt".equals(args[0])) {
......@@ -310,49 +316,10 @@ Features of H2
System.out.println("done (" + (System.currentTimeMillis() - time) + " ms)");
}
void runTests() throws Exception {
// TODO test set lock_mode=0, 1; max_trace_file_size; modes; collation; assert
// TODO test shutdown immediately
// smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
// logMode = 1; traceLevelFile = throttle = 0;
// deleteIndex = textStorage = true;
// cipher = null;
// codeCoverage = true;
// memory = true;
// new TestSpeed().runTest(this);
// new TestSpeed().runTest(this);
// new TestSpeed().runTest(this);
// new TestSpeed().runTest(this);
// smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
// traceLevelFile = throttle = 0;
// big = true;
// memory = false;
//
testQuick();
testCombination();
}
void testCodeCoverage() throws Exception {
this.codeCoverage = true;
runTests();
}
void testQuick() throws Exception {
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
traceLevelFile = throttle = 0;
logMode = 1;
cipher = null;
testAll();
}
void testEverything() throws Exception {
/**
* Run all tests in all possible combinations.
*/
private void testEverything() throws Exception {
for (int c = 0; c < 3; c++) {
if (c == 0) {
cipher = null;
......@@ -373,20 +340,30 @@ Features of H2
for (logMode = 0; logMode < 3; logMode++) {
traceLevelFile = logMode;
TestBase.printTime("cipher:" + cipher +" a:" +a+" logMode:"+logMode);
testAll();
test();
}
}
}
}
void testCombination() throws Exception {
/**
* Run the tests with a number of different settings.
*/
private void runTests() throws Exception {
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
traceLevelFile = throttle = 0;
logMode = 1;
cipher = null;
test();
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
traceLevelFile = throttle = 0;
logMode = 1;
cipher = null;
mvcc = false;
cache2Q = false;
testAll();
test();
diskUndo = false;
smallLog = false;
......@@ -401,7 +378,7 @@ Features of H2
cipher = null;
mvcc = false;
cache2Q = false;
testAll();
test();
big = false;
smallLog = false;
......@@ -418,7 +395,7 @@ Features of H2
cipher = null;
mvcc = false;
cache2Q = false;
testAll();
test();
diskUndo = true;
smallLog = false;
......@@ -433,7 +410,7 @@ Features of H2
cipher = "XTEA";
mvcc = false;
cache2Q = false;
testAll();
test();
diskUndo = false;
big = true;
......@@ -451,7 +428,7 @@ Features of H2
cipher = null;
mvcc = false;
cache2Q = false;
testAll();
test();
big = true;
smallLog = true;
......@@ -468,7 +445,7 @@ Features of H2
cipher = null;
mvcc = false;
cache2Q = true;
testAll();
test();
big = true;
smallLog = false;
......@@ -485,7 +462,7 @@ Features of H2
cipher = "AES";
mvcc = false;
cache2Q = false;
testAll();
test();
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
traceLevelFile = throttle = 0;
......@@ -493,48 +470,16 @@ Features of H2
cipher = null;
mvcc = true;
cache2Q = false;
testAll();
test();
memory = true;
testAll();
test();
}
void testAll() throws Exception {
DeleteDbFiles.execute(TestBase.baseDir, null, true);
testDatabase();
testUnit();
DeleteDbFiles.execute(TestBase.baseDir, null, true);
}
void testUnit() {
new TestBitField().runTest(this);
new TestCompress().runTest(this);
new TestDataPage().runTest(this);
new TestDate().runTest(this);
new TestExit().runTest(this);
new TestFile().runTest(this);
new TestFileLock().runTest(this);
new TestFtp().runTest(this);
new TestFileSystem().runTest(this);
new TestIntArray().runTest(this);
new TestIntIntHashMap().runTest(this);
new TestMultiThreadedKernel().runTest(this);
new TestOverflow().runTest(this);
new TestPattern().runTest(this);
new TestReader().runTest(this);
new TestSampleApps().runTest(this);
new TestScriptReader().runTest(this);
new TestSecurity().runTest(this);
new TestStreams().runTest(this);
new TestStringCache().runTest(this);
new TestStringUtils().runTest(this);
new TestTools().runTest(this);
new TestValue().runTest(this);
new TestValueHashMap().runTest(this);
}
void testDatabase() throws Exception {
/**
* Run all tests with the current settings.
*/
private void test() throws Exception {
System.out.println("test big:"+big+" net:"+networked+" cipher:"+cipher+" memory:"+memory+" log:"+logMode+" diskResult:"+diskResult + " mvcc:" + mvcc);
beforeTest();
......@@ -611,10 +556,37 @@ Features of H2
new TestRandomSQL().runTest(this);
new TestKillRestart().runTest(this);
// unit
new TestBitField().runTest(this);
new TestCompress().runTest(this);
new TestDataPage().runTest(this);
new TestDate().runTest(this);
new TestExit().runTest(this);
new TestFile().runTest(this);
new TestFileLock().runTest(this);
new TestFtp().runTest(this);
new TestFileSystem().runTest(this);
new TestIntArray().runTest(this);
new TestIntIntHashMap().runTest(this);
new TestMultiThreadedKernel().runTest(this);
new TestOverflow().runTest(this);
new TestPattern().runTest(this);
new TestReader().runTest(this);
new TestSampleApps().runTest(this);
new TestScriptReader().runTest(this);
new TestSecurity().runTest(this);
new TestStreams().runTest(this);
new TestStringCache().runTest(this);
new TestStringUtils().runTest(this);
new TestTools().runTest(this);
new TestValue().runTest(this);
new TestValueHashMap().runTest(this);
afterTest();
}
public void beforeTest() throws SQLException {
DeleteDbFiles.execute(TestBase.baseDir, null, true);
FileSystemDisk.getInstance().deleteRecursive("trace.db");
if (networked) {
TcpServer.logInternalErrors = true;
......@@ -634,6 +606,7 @@ Features of H2
if (networked && server != null) {
server.stop();
}
DeleteDbFiles.execute(TestBase.baseDir, null, true);
}
private void printSystem() {
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
The implementation of the benchmark application.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A standalone code coverage tool.
</body></html>
\ No newline at end of file
......@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Tests if prepared statements are re-compiled when required.
*/
public class TestAutoRecompile extends TestBase {
public void test() throws Exception {
......
......@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
import org.h2.tools.Restore;
/**
* Test for the BACKUP SQL statement.
*/
public class TestBackup extends TestBase {
public void test() throws Exception {
......
......@@ -13,6 +13,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Test for batch updates.
*/
public class TestBatchUpdates extends TestBase {
static final String COFFEE_UPDATE = "UPDATE TEST SET PRICE=PRICE*20 WHERE TYPE_ID=?";
......
......@@ -12,6 +12,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
import org.h2.util.MemoryUtils;
/**
* Test for big databases.
*/
public class TestBigDb extends TestBase {
public void test() throws Exception {
......
......@@ -13,6 +13,9 @@ import java.util.ArrayList;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
/**
* Test for big result sets.
*/
public class TestBigResult extends TestBase {
public void test() throws Exception {
if (config.memory) {
......
......@@ -18,6 +18,9 @@ import java.util.Random;
import org.h2.test.TestBase;
/**
* Various test cases.
*/
public class TestCases extends TestBase {
public void test() throws Exception {
......
......@@ -9,6 +9,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Tests the CHECKPOINT SQL statement.
*/
public class TestCheckpoint extends TestBase {
public void test() throws Exception {
......
......@@ -16,6 +16,9 @@ import org.h2.tools.CreateCluster;
import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Server;
/**
* Test for the cluster feature.
*/
public class TestCluster extends TestBase {
public void test() throws Exception {
......@@ -41,7 +44,7 @@ public class TestCluster extends TestBase {
prep.setString(2, "Data" + i);
prep.executeUpdate();
}
check(conn, len);
check(conn, len);
conn.close();
CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget",
......@@ -77,21 +80,21 @@ public class TestCluster extends TestBase {
stat = conn.createStatement();
check(conn, len);
conn.close();
// disable the cluster
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9091/test;CLUSTER=''", "sa", "");
conn.close();
n1.stop();
// re-create the cluster
DeleteDbFiles.main(new String[] { "-dir", baseDir + "/node2", "-quiet" });
CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget",
"jdbc:h2:file:" + baseDir + "/node2/test", "-user", "sa", "-serverlist",
"localhost:9091,localhost:9092" });
"localhost:9091,localhost:9092" });
n1 = org.h2.tools.Server.createTcpServer(
new String[] { "-tcpPort", "9091", "-baseDir", baseDir + "/node1" }).start();
n2 = org.h2.tools.Server.createTcpServer(
new String[] { "-tcpPort", "9092", "-baseDir", baseDir + "/node2" }).start();
new String[] { "-tcpPort", "9092", "-baseDir", baseDir + "/node2" }).start();
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9091,localhost:9092/test", "sa", "");
stat = conn.createStatement();
......
......@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Tests the compatibility with other databases.
*/
public class TestCompatibility extends TestBase {
private Connection conn;
......
......@@ -20,6 +20,9 @@ import org.h2.tools.Csv;
import org.h2.util.IOUtils;
import org.h2.util.StringUtils;
/**
* CSVREAD and CSVWRITE tests.
*/
public class TestCsv extends TestBase {
public void test() throws Exception {
......
......@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Test for the exclusive mode.
*/
public class TestExclusive extends TestBase {
public void test() throws Exception {
......
......@@ -12,6 +12,9 @@ import java.util.StringTokenizer;
import org.h2.test.TestBase;
/**
* Fulltext search tests.
*/
public class TestFullText extends TestBase {
public void test() throws Exception {
......
......@@ -20,6 +20,9 @@ import org.h2.api.AggregateFunction;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
/**
* Tests for user defined functions and aggregates.
*/
public class TestFunctions extends TestBase {
private Statement stat;
......@@ -28,9 +31,9 @@ public class TestFunctions extends TestBase {
testAggregate();
testFunctions();
}
public static class MedianString implements AggregateFunction {
private ArrayList list = new ArrayList();
public void add(Object value) throws SQLException {
......@@ -47,9 +50,9 @@ public class TestFunctions extends TestBase {
public void init(Connection conn) throws SQLException {
}
}
private void testAggregate() throws Exception {
deleteDb("functions");
Connection conn = getConnection("functions");
......@@ -60,11 +63,11 @@ public class TestFunctions extends TestBase {
rs.next();
check("5", rs.getString(1));
conn.close();
if (config.memory) {
return;
}
conn = getConnection("functions");
stat = conn.createStatement();
rs = stat.executeQuery("SELECT MEDIAN(X) FROM SYSTEM_RANGE(1, 9)");
......@@ -85,7 +88,7 @@ public class TestFunctions extends TestBase {
stat.execute("DROP AGGREGATE IF EXISTS MEDIAN");
conn.close();
}
private void testFunctions() throws Exception {
deleteDb("functions");
Connection conn = getConnection("functions");
......
......@@ -13,6 +13,9 @@ import java.util.Random;
import org.h2.result.SortOrder;
import org.h2.test.TestBase;
/**
* Index tests.
*/
public class TestIndex extends TestBase {
Connection conn;
......@@ -30,7 +33,7 @@ public class TestIndex extends TestBase {
public void test() throws Exception {
testDescIndex();
if (config.networked && config.big) {
return;
}
......@@ -70,7 +73,7 @@ public class TestIndex extends TestBase {
conn.close();
}
void testDescIndex() throws Exception {
if (config.memory) {
return;
......
......@@ -15,6 +15,9 @@ import java.sql.Timestamp;
import org.h2.test.TestBase;
/**
* Tests the linked table feature (CREATE LINKED TABLE).
*/
public class TestLinkedTable extends TestBase {
public void test() throws Exception {
......@@ -26,7 +29,7 @@ public class TestLinkedTable extends TestBase {
testLinkTable();
testLinkTwoTables();
}
// this is not a bug, it is the documented behavior
// private void testLinkAutoAdd() throws Exception {
// Class.forName("org.h2.Driver");
......@@ -42,7 +45,7 @@ public class TestLinkedTable extends TestBase {
// ca.close();
// cb.close();
// }
private void testLinkOtherSchema() throws Exception {
Class.forName("org.h2.Driver");
Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
......@@ -59,7 +62,7 @@ public class TestLinkedTable extends TestBase {
ca.close();
cb.close();
}
private void testLinkTwoTables() throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
......@@ -131,7 +134,7 @@ public class TestLinkedTable extends TestBase {
stat2.executeUpdate("UPDATE TEST_LINK_DI SET ID=ID+1");
stat2.executeUpdate("UPDATE TEST_LINK_U SET NAME=NAME || ID");
ResultSet rs;
rs = stat2.executeQuery("SELECT * FROM TEST_LINK_DI ORDER BY ID");
rs.next();
check(rs.getInt(1), 2);
......@@ -140,7 +143,7 @@ public class TestLinkedTable extends TestBase {
check(rs.getInt(1), 3);
check(rs.getString(2), "World3");
checkFalse(rs.next());
rs = stat2.executeQuery("SELECT * FROM TEST_LINK_U ORDER BY ID");
rs.next();
check(rs.getInt(1), 2);
......
......@@ -14,6 +14,9 @@ import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase;
import org.h2.util.JdbcUtils;
/**
* Tests the DatabaseEventListener.
*/
public class TestListener extends TestBase implements DatabaseEventListener {
private long last, start;
......@@ -85,7 +88,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
if (url.toUpperCase().indexOf("CIPHER") >= 0) {
return;
}
Connection conn = null;
Connection conn = null;
try {
conn = DriverManager.getConnection(url, getUser(), getPassword());
conn.createStatement().execute("DROP TABLE TEST2");
......@@ -105,7 +108,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
if (url.toUpperCase().indexOf("CIPHER") >= 0) {
return;
}
Connection conn = null;
Connection conn = null;
try {
conn = DriverManager.getConnection(url, getUser(), getPassword());
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS TEST2(ID INT)");
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
......@@ -26,9 +26,8 @@ import org.h2.util.IOUtils;
import org.h2.util.StringUtils;
/**
* @author Thomas
* Tests LOB and CLOB data types.
*/
public class TestLob extends TestBase {
public void test() throws Exception {
......
......@@ -6,6 +6,9 @@ package org.h2.test.db;
import java.io.Serializable;
/**
* A utility class for TestLob.
*/
class TestLobObject implements Serializable {
private static final long serialVersionUID = 904356179316518715L;
String data;
......
......@@ -13,6 +13,9 @@ import java.util.ArrayList;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
/**
* Tests the database transaction log file.
*/
public class TestLogFile extends TestBase {
private Connection conn;
......
......@@ -12,6 +12,9 @@ import java.util.Random;
import org.h2.test.TestBase;
/**
* Tests the memory usage of the cache.
*/
public class TestMemoryUsage extends TestBase {
private Connection conn;
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
......@@ -13,9 +13,8 @@ import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase;
/**
* @author Thomas
* Multi-connection tests.
*/
public class TestMultiConn extends TestBase implements DatabaseEventListener {
public void test() throws Exception {
......@@ -175,8 +174,8 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
public void init(String url) {
}
public void opened() {
}
}
}
......@@ -13,6 +13,9 @@ import java.util.Random;
import org.h2.test.TestBase;
import org.h2.tools.MultiDimension;
/**
* Tests the multi-dimension index tool.
*/
public class TestMultiDimension extends TestBase {
public void test() throws Exception {
......
......@@ -13,6 +13,9 @@ import java.util.Random;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
/**
* Multi-threaded tests.
*/
public class TestMultiThread extends TestBase implements Runnable {
private boolean stop;
......
......@@ -15,6 +15,9 @@ import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase;
import org.h2.tools.Restore;
/**
* Tests opening and closing a database.
*/
public class TestOpenClose extends TestBase implements DatabaseEventListener {
int nextId = 10;
......@@ -171,8 +174,8 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
public void init(String url) {
}
public void opened() {
}
}
}
......@@ -15,12 +15,16 @@ import java.util.TreeSet;
import org.h2.test.TestBase;
/**
* Test various optimizations (query cache, optimization for MIN(..), and MAX(..)).
*/
public class TestOptimizations extends TestBase {
public void test() throws Exception {
if (config.networked) {
return;
}
testDistinctOptimization();
testQueryCacheTimestamp();
testQueryCacheSpeed();
testQueryCache(true);
......@@ -30,6 +34,45 @@ public class TestOptimizations extends TestBase {
testMinMaxCountOptimization(false);
}
private void testDistinctOptimization() throws Exception {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR, TYPE INT)");
stat.execute("CREATE INDEX IDX_TEST_TYPE ON TEST(TYPE)");
Random random = new Random(1);
int len = getSize(10000, 100000);
int[] groupCount = new int[10];
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)");
for (int i = 0; i < len; i++) {
prep.setInt(1, i);
prep.setString(2, "Hello World");
int type = random.nextInt(10);
groupCount[type]++;
prep.setInt(3, type);
prep.execute();
}
ResultSet rs;
rs = stat.executeQuery("SELECT TYPE, COUNT(*) FROM TEST GROUP BY TYPE ORDER BY TYPE");
for (int i = 0; rs.next(); i++) {
check(i, rs.getInt(1));
check(groupCount[i], rs.getInt(2));
}
checkFalse(rs.next());
rs = stat.executeQuery("SELECT DISTINCT TYPE FROM TEST ORDER BY TYPE");
for (int i = 0; rs.next(); i++) {
check(i, rs.getInt(1));
}
checkFalse(rs.next());
stat.execute("ANALYZE");
rs = stat.executeQuery("SELECT DISTINCT TYPE FROM TEST ORDER BY TYPE");
for (int i = 0; rs.next(); i++) {
check(i, rs.getInt(1));
}
checkFalse(rs.next());
conn.close();
}
private void testQueryCacheTimestamp() throws Exception {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
......
......@@ -21,6 +21,9 @@ import org.h2.test.TestBase;
import org.h2.util.FileUtils;
import org.h2.util.JdbcUtils;
/**
* Tests simulated power off conditions.
*/
public class TestPowerOff extends TestBase {
private String dbName = "powerOff";
......
......@@ -14,6 +14,9 @@ import java.util.ArrayList;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
/**
* Test for the read-only database feature.
*/
public class TestReadOnly extends TestBase {
public void test() throws Exception {
......
......@@ -12,16 +12,19 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Access rights tests.
*/
public class TestRights extends TestBase {
private Statement stat;
public void test() throws Exception {
// testLowerCaseUser();
testSchemaRenameUser();
testAccessRights();
}
// public void testLowerCaseUser() throws Exception {
// Documentation: For compatibility, only unquoted or uppercase user names are allowed.
// deleteDb("rights");
......@@ -68,7 +71,7 @@ public class TestRights extends TestBase {
stat.execute("drop user test1");
conn.close();
}
public void testAccessRights() throws Exception {
if (config.memory) {
return;
......
......@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.api.Trigger;
import org.h2.test.TestBase;
/**
* Tests the RUNSCRIPT SQL statement.
*/
public class TestRunscript extends TestBase implements Trigger {
public void test() throws Exception {
......
......@@ -12,6 +12,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Tests the ALLOW_LITERALS feature (protection against SQL injection).
*/
public class TestSQLInjection extends TestBase {
Connection conn;
......
......@@ -23,6 +23,9 @@ import org.h2.test.TestAll;
import org.h2.test.TestBase;
import org.h2.util.StringUtils;
/**
* This test runs a SQL script file and compares the output with the expected output.
*/
public class TestScript extends TestBase {
private boolean failFast;
......
......@@ -14,6 +14,9 @@ import java.sql.SQLException;
import org.h2.test.TestBase;
import org.h2.util.ScriptReader;
/**
* This test runs a simple SQL script file and compares the output with the expected output.
*/
public class TestScriptSimple extends TestBase {
private Connection conn;
......
......@@ -10,13 +10,16 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Tests the sequence feature of this database.
*/
public class TestSequence extends TestBase {
public void test() throws Exception {
testCache();
testTwo();
}
private void testCache() throws Exception {
if (config.memory) {
return;
......@@ -41,7 +44,7 @@ public class TestSequence extends TestBase {
checkFalse(rs.next());
conn.close();
}
private void testTwo() throws Exception {
deleteDb("sequence");
Connection conn = getConnection("sequence");
......
......@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Tests the meta data tables information_schema.locks and sessions.
*/
public class TestSessionsLocks extends TestBase {
public void test() throws Exception {
......
......@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Tests if disk space is reused after deleting many rows.
*/
public class TestSpaceReuse extends TestBase {
public void test() throws Exception {
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
......@@ -11,9 +11,8 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* @author Thomas
* Various small performance tests.
*/
public class TestSpeed extends TestBase {
// java -cp .;..\..\hsqldb\lib\hsqldb.jar -Xrunhprof:heap=sites,depth=6
......@@ -59,7 +58,7 @@ public class TestSpeed extends TestBase {
long time = System.currentTimeMillis();
// for(int i=1; i<8000; i*=2) {
// stat.execute("INSERT INTO TEST_A SELECT ID+"+i+", NAME FROM TEST_A");
//
//
// // stat.execute("INSERT INTO TEST_A VALUES("+i+", 'Hello')");
// }
// for(int i=0; i<4; i++) {
......@@ -71,7 +70,7 @@ public class TestSpeed extends TestBase {
// }
// System.out.println(System.currentTimeMillis()-time);
//
//
// stat.execute("CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME
// VARCHAR(255))");
// for(int i=0; i<80000; i++) {
......@@ -82,7 +81,7 @@ public class TestSpeed extends TestBase {
// System.exit(0);
// int testParser;
// java -Xrunhprof:cpu=samples,depth=8 -cp . org.h2.test.TestAll
//
//
// stat.execute("CREATE TABLE TEST(ID INT)");
// stat.execute("INSERT INTO TEST VALUES(1)");
// ResultSet rs = stat.executeQuery("SELECT ID OTHER_ID FROM TEST");
......
......@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Temporary table tests.
*/
public class TestTempTables extends TestBase {
public void test() throws Exception {
......
......@@ -15,6 +15,9 @@ import java.util.Vector;
import org.h2.test.TestBase;
/**
* Transactional tests, including transaction isolation tests, and tests related to savepoints.
*/
public class TestTransaction extends TestBase {
public void test() throws Exception {
......@@ -22,9 +25,9 @@ public class TestTransaction extends TestBase {
testSavepoint();
testIsolation();
}
private void testReferential() throws Exception {
deleteDb("transaction");
deleteDb("transaction");
Connection c1 = getConnection("transaction");
c1.setAutoCommit(false);
Statement s1 = c1.createStatement();
......@@ -43,7 +46,7 @@ public class TestTransaction extends TestBase {
checkNotGeneralException(e);
}
c2.commit();
c1.rollback();
c1.rollback();
c1.close();
c2.close();
}
......
......@@ -15,9 +15,8 @@ import org.h2.api.Trigger;
import org.h2.test.TestBase;
/**
* @author Thomas
* Tests for trigger and constraints.
*/
public class TestTriggersConstraints extends TestBase implements Trigger {
private static boolean mustNotCallTrigger;
......
......@@ -11,6 +11,9 @@ import java.util.ArrayList;
import org.h2.test.TestBase;
/**
* Tests for the two-phase-commit feature.
*/
public class TestTwoPhaseCommit extends TestBase {
public void test() throws Exception {
if (config.memory || config.networked || config.logMode == 0) {
......
......@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Test for views.
*/
public class TestView extends TestBase {
public void test() throws Exception {
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Database tests. Most tests are on the SQL level.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
JDBC API tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Tests related to distributed transactions.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Multi version concurrency tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
High level test classes.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Multi version concurrency tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
This package contains server tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Synthetic tests using random operations or statements.
</body></html>
\ No newline at end of file
......@@ -993,7 +993,7 @@ script nopasswords nosettings blocksize 10;
> DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB;
> DROP ALIAS IF EXISTS SYSTEM_COMBINE_CLOB;
> DROP TABLE IF EXISTS SYSTEM_LOB_STREAM;
> INSERT INTO PUBLIC.TEST(ID, DATA) VALUES(1, SYSTEM_COMBINE_CLOB(0));
> INSERT INTO PUBLIC.TEST(ID, DATA) VALUES (1, SYSTEM_COMBINE_CLOB(0));
> INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 0, 'abc ', NULL);
> INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 1, ' ', NULL);
> INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 2, ' ', NULL);
......@@ -2862,7 +2862,7 @@ script NOPASSWORDS NOSETTINGS drop;
> CREATE PRIMARY KEY ON PUBLIC.TEST(I);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> DROP TABLE IF EXISTS PUBLIC.TEST;
> INSERT INTO PUBLIC.TEST(I, NAME, Y) VALUES(1, 'Hello', 2);
> INSERT INTO PUBLIC.TEST(I, NAME, Y) VALUES (1, 'Hello', 2);
> rows: 8
INSERT INTO TEST(i, name) VALUES(2, 'World');
......@@ -3888,7 +3888,7 @@ insert into test values(1, '', '');
insert into test values(2, 'Cafe', X'cafe');
> update count: 1
script nopasswords nosettings;
script simple nopasswords nosettings;
> SCRIPT
> -------------------------------------------------------------------------------
> -- 3 = SELECT COUNT(*) FROM PUBLIC.TEST;
......@@ -4422,7 +4422,7 @@ SELECT * FROM TEST_SEQ ORDER BY ID;
> 20 20
> rows (ordered): 4
SCRIPT NOPASSWORDS NOSETTINGS;
SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.TEST;
......@@ -4464,7 +4464,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
> CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, CREATEDATE VARCHAR(255) DEFAULT '2001-01-01' NOT NULL, MODIFY_DATE TIMESTAMP );
> CREATE PRIMARY KEY ON PUBLIC.TEST(ID);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.TEST(ID, CREATEDATE, MODIFY_DATE) VALUES(1, '2001-01-01', NULL);
> INSERT INTO PUBLIC.TEST(ID, CREATEDATE, MODIFY_DATE) VALUES (1, '2001-01-01', NULL);
> rows: 5
ALTER TABLE TEST ADD NAME VARCHAR(255) NULL BEFORE CREATEDATE;
......@@ -4477,7 +4477,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
> CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, NAME VARCHAR(255), CREATEDATE VARCHAR(255) DEFAULT '2001-01-01' NOT NULL, MODIFY_DATE TIMESTAMP );
> CREATE PRIMARY KEY ON PUBLIC.TEST(ID);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.TEST(ID, NAME, CREATEDATE, MODIFY_DATE) VALUES(1, NULL, '2001-01-01', NULL);
> INSERT INTO PUBLIC.TEST(ID, NAME, CREATEDATE, MODIFY_DATE) VALUES (1, NULL, '2001-01-01', NULL);
> rows: 5
UPDATE TEST SET NAME = 'Hi';
......@@ -6044,7 +6044,7 @@ CAST(XT AS TIMESTAMP) D2TS, CAST(XD AS TIMESTAMP) D2TS FROM TEST;
> null null null null null null null
> rows: 4
SCRIPT NOPASSWORDS NOSETTINGS;
SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT
> ----------------------------------------------------------------------------------------------------------------------------------
> -- 4 = SELECT COUNT(*) FROM PUBLIC.TEST;
......@@ -7146,7 +7146,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
> CREATE PRIMARY KEY ON PUBLIC.A_TEST(A_INT);
> CREATE PRIMARY KEY ON PUBLIC.B_TEST(B_INT);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.B_TEST(B_INT, B_VARCHAR) VALUES(-1, 'XX');
> INSERT INTO PUBLIC.B_TEST(B_INT, B_VARCHAR) VALUES (-1, 'XX');
> rows: 14
DROP TABLE A_TEST;
......@@ -7231,7 +7231,7 @@ SELECT * FROM CHILD;
> 201 null null Johann
> rows: 4
SCRIPT NOPASSWORDS NOSETTINGS;
SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.FAMILY;
......@@ -7256,7 +7256,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
ALTER TABLE CHILD DROP CONSTRAINT PARENT_CHILD;
> ok
SCRIPT NOPASSWORDS NOSETTINGS;
SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT
> --------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.FAMILY;
......@@ -7568,12 +7568,12 @@ INSERT INTO TEST VALUES(2, STRINGDECODE('abcsond\344rzeich\344 ') || char(22222)
script nopasswords nosettings;
> SCRIPT
> ------------------------------------------------------------------------------------------------------------------------------------------------------------
> -------------------------------------------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.TEST;
> CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, NAME VARCHAR(255) );
> CREATE PRIMARY KEY ON PUBLIC.TEST(ID);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.TEST(ID, NAME) VALUES(2, STRINGDECODE('abcsond\u00e4rzeich\u00e4 \u56ce \u00f6\u00e4\u00fc\u00d6\u00c4\u00dc\u00e9\u00e8\u00e0\u00f1!'));
> INSERT INTO PUBLIC.TEST(ID, NAME) VALUES (2, STRINGDECODE('abcsond\u00e4rzeich\u00e4 \u56ce \u00f6\u00e4\u00fc\u00d6\u00c4\u00dc\u00e9\u00e8\u00e0\u00f1!'));
> rows: 5
call STRINGENCODE(STRINGDECODE('abcsond\344rzeich\344 \u56ce \366\344\374\326\304\334\351\350\340\361!'));
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A player to interpret and execute Java statements in a trace file.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Unit tests that don't start the database (in most cases).
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Security tools.
</body></html>
\ No newline at end of file
package org.h2.tools.code;
import java.io.File;
/**
* This tool checks that for each .java file there is a package.html file.
*/
public class CheckPackageHtml {
private boolean hasError;
public static void main(String[] args) throws Exception {
new CheckPackageHtml().run();
}
void run() throws Exception {
String baseDir = "src";
check(new File(baseDir));
if (hasError) {
throw new Exception("Errors found");
}
}
private int check(File file) throws Exception {
String name = file.getName();
if (file.isDirectory()) {
if (name.equals("CVS") || name.equals(".svn")) {
return 0;
}
File[] list = file.listFiles();
boolean foundPackageHtml = false, foundJava = false;
for (int i = 0; i < list.length; i++) {
int type = check(list[i]);
if (type == 1) {
foundJava = true;
} else if (type == 2) {
foundPackageHtml = true;
}
}
if (foundJava && !foundPackageHtml) {
System.out.println("No package.html file, but a Java file found at: " + file.getAbsolutePath());
hasError = true;
}
} else {
if (name.endsWith(".java")) {
return 1;
} else if (name.equals("package.html")) {
return 2;
}
}
return 0;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Source code checking classes.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Tools to build the documentation.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A Javadoc doclet to build nicer and smaller API Javadoc HTML files.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Internationalization tools.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A Javadoc indexing mechanism.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A tool to redirect and interpret PostgreSQL network protocol packets.
</body></html>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论