提交 79304ac8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Make methods static if possible.

上级 c5e2da62
......@@ -132,7 +132,7 @@ public class Set extends Prepared {
}
case SetTypes.COMPRESS_LOB: {
session.getUser().checkAdmin();
int algo = CompressTool.getInstance().getCompressAlgorithm(stringValue);
int algo = CompressTool.getCompressAlgorithm(stringValue);
database.setLobCompressionAlgorithm(algo == Compressor.NO ? null : stringValue);
addOrUpdateSetting(name, stringValue, 0);
break;
......
......@@ -59,7 +59,7 @@ implements XAConnection, XAResource
org.h2.Driver.load();
}
JdbcXAConnection(JdbcDataSourceFactory factory, int id, JdbcConnection physicalConn) throws SQLException {
JdbcXAConnection(JdbcDataSourceFactory factory, int id, JdbcConnection physicalConn) {
this.factory = factory;
setTrace(factory.getTrace(), TraceObject.XA_DATA_SOURCE, id);
this.physicalConn = physicalConn;
......
......@@ -117,7 +117,7 @@ public class FileStoreInputStream extends InputStream {
page.read(buff, 0, remainingInBuffer);
page.reset();
page.checkCapacity(uncompressed);
compress.expand(buff, page.getBytes(), 0);
CompressTool.expand(buff, page.getBytes(), 0);
remainingInBuffer = uncompressed;
}
if (alwaysClose) {
......
......@@ -69,7 +69,6 @@ public class CompressTool {
* @param in the byte array with the original data
* @param algorithm the algorithm (LZF, DEFLATE)
* @return the compressed data
* @throws SQLException if a error occurs
*/
public byte[] compress(byte[] in, String algorithm) {
int len = in.length;
......@@ -84,10 +83,7 @@ public class CompressTool {
return out;
}
/**
* INTERNAL
*/
public int compress(byte[] in, int len, Compressor compress, byte[] out) {
private static int compress(byte[] in, int len, Compressor compress, byte[] out) {
int newLen = 0;
out[0] = (byte) compress.getAlgorithm();
int start = 1 + writeVariableInt(out, 1, len);
......@@ -105,7 +101,6 @@ public class CompressTool {
*
* @param in the byte array with the compressed data
* @return the uncompressed data
* @throws SQLException if a error occurs
*/
public byte[] expand(byte[] in) {
int algorithm = in[0];
......@@ -124,7 +119,7 @@ public class CompressTool {
/**
* INTERNAL
*/
public void expand(byte[] in, byte[] out, int outPos) {
public static void expand(byte[] in, byte[] out, int outPos) {
int algorithm = in[0];
Compressor compress = getCompressor(algorithm);
try {
......@@ -230,7 +225,7 @@ public class CompressTool {
}
}
private Compressor getCompressor(String algorithm) {
private static Compressor getCompressor(String algorithm) {
if (algorithm == null) {
algorithm = "LZF";
}
......@@ -249,7 +244,7 @@ public class CompressTool {
/**
* INTERNAL
*/
public int getCompressAlgorithm(String algorithm) {
public static int getCompressAlgorithm(String algorithm) {
algorithm = StringUtils.toUpperEnglish(algorithm);
if ("NO".equals(algorithm)) {
return Compressor.NO;
......
......@@ -108,7 +108,7 @@ public class CreateScriptFile {
try {
OutputStream out;
if (cipher != null) {
byte[] key = new SHA256().getKeyPasswordHash("script", password.toCharArray());
byte[] key = SHA256.getKeyPasswordHash("script", password.toCharArray());
IOUtils.delete(fileName);
FileStore store = FileStore.open(null, fileName, "rw", cipher, key);
store.init();
......@@ -142,7 +142,7 @@ public class CreateScriptFile {
try {
InputStream in;
if (cipher != null) {
byte[] key = new SHA256().getKeyPasswordHash("script", password.toCharArray());
byte[] key = SHA256.getKeyPasswordHash("script", password.toCharArray());
FileStore store = FileStore.open(null, fileName, "rw", cipher, key);
store.init();
in = new FileStoreInputStream(store, null, compressionAlgorithm != null, false);
......
......@@ -28,14 +28,14 @@ public class InitDatabaseFromJar {
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
new InitDatabaseFromJar().createScript();
createScript();
new InitDatabaseFromJar().initDb();
}
/**
* Create a script from a new database.
*/
private void createScript() throws Exception {
private static void createScript() throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
Statement stat = conn.createStatement();
......
......@@ -322,8 +322,7 @@ java org.h2.test.TestAll timer
private static void run(String... args) throws Exception {
SelfDestructor.startCountdown(3 * 60);
long time = System.currentTimeMillis();
TestAll test = new TestAll();
test.printSystemInfo();
printSystemInfo();
System.setProperty("h2.maxMemoryRowsDistinct", "128");
System.setProperty("h2.check2", "true");
......@@ -366,6 +365,7 @@ kill a test:
kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
*/
TestAll test = new TestAll();
if (args.length > 0) {
if ("reopen".equals(args[0])) {
System.setProperty("h2.delayWrongPasswordMin", "0");
......@@ -775,7 +775,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
return buff.toString();
}
private void appendIf(StringBuilder buff, boolean flag, String text) {
private static void appendIf(StringBuilder buff, boolean flag, String text) {
if (flag) {
buff.append(text);
buff.append(' ');
......
......@@ -304,14 +304,14 @@ public abstract class TestBase {
return "jdbc:h2:" + url;
}
private String addOption(String url, String option, String value) {
private static String addOption(String url, String option, String value) {
if (url.indexOf(";" + option + "=") < 0) {
url += ";" + option + "=" + value;
}
return url;
}
private Connection getConnectionInternal(String url, String user, String password) throws SQLException {
private static Connection getConnectionInternal(String url, String user, String password) throws SQLException {
org.h2.Driver.load();
// url += ";DEFAULT_TABLE_TYPE=1";
// Class.forName("org.hsqldb.jdbcDriver");
......@@ -974,18 +974,6 @@ public abstract class TestBase {
assertResultSet(true, rs, data);
}
/**
* Check if a result set contains the expected data.
* The sort order is not significant
*
* @param rs the result set
* @param data the expected data
* @throws AssertionError if there is a mismatch
*/
// void assertResultSetUnordered(ResultSet rs, String[][] data) {
// assertResultSet(false, rs, data);
// }
/**
* Check if a result set contains the expected data.
*
......@@ -1037,7 +1025,7 @@ public abstract class TestBase {
}
}
private boolean testRow(String[] a, String[] b, int len) {
private static boolean testRow(String[] a, String[] b, int len) {
for (int i = 0; i < len; i++) {
String sa = a[i];
String sb = b[i];
......@@ -1054,7 +1042,7 @@ public abstract class TestBase {
return true;
}
private String[] getData(ResultSet rs, int len) throws SQLException {
private static String[] getData(ResultSet rs, int len) throws SQLException {
String[] data = new String[len];
for (int i = 0; i < len; i++) {
data[i] = rs.getString(i + 1);
......@@ -1064,7 +1052,7 @@ public abstract class TestBase {
return data;
}
private String formatRow(String[] row) {
private static String formatRow(String[] row) {
String sb = "";
for (String r : row) {
sb += "{" + r + "}";
......
......@@ -47,12 +47,12 @@ public class TestPerformance {
new TestPerformance().test(args);
}
private Connection getResultConnection() throws SQLException {
private static Connection getResultConnection() throws SQLException {
org.h2.Driver.load();
return DriverManager.getConnection("jdbc:h2:data/results");
}
private void openResults() throws SQLException {
private static void openResults() throws SQLException {
Connection conn = null;
Statement stat = null;
try {
......@@ -236,13 +236,13 @@ public class TestPerformance {
}
}
private void runDatabase(Database db, ArrayList<Bench> tests, int size) throws Exception {
private static void runDatabase(Database db, ArrayList<Bench> tests, int size) throws Exception {
for (Bench bench : tests) {
runTest(db, bench, size);
}
}
private void runTest(Database db, Bench bench, int size) throws Exception {
private static void runTest(Database db, Bench bench, int size) throws Exception {
bench.init(db, size);
bench.runTest();
}
......
......@@ -108,7 +108,7 @@ public class Profile extends Thread {
}
}
private void closeSilently(Reader reader) {
private static void closeSilently(Reader reader) {
if (reader != null) {
try {
reader.close();
......@@ -118,7 +118,7 @@ public class Profile extends Thread {
}
}
private void closeSilently(Writer writer) {
private static void closeSilently(Writer writer) {
if (writer != null) {
try {
writer.close();
......@@ -244,11 +244,11 @@ public class Profile extends Thread {
}
}
private void print(String s) {
private static void print(String s) {
System.out.println(s);
}
private void printLine(char c) {
private static void printLine(char c) {
for (int i = 0; i < 60; i++) {
System.out.print(c);
}
......
......@@ -78,7 +78,7 @@ public class TaskProcess {
}
}
private void copyInThread(final InputStream in, final OutputStream out) {
private static void copyInThread(final InputStream in, final OutputStream out) {
new Task() {
public void call() throws IOException {
while (true) {
......
......@@ -247,7 +247,7 @@ public class TestCsv extends TestBase {
IOUtils.delete(getBaseDir() + "/test.csv");
}
private String randomData(Random random) {
private static String randomData(Random random) {
if (random.nextInt(10) == 1) {
return null;
}
......
......@@ -650,7 +650,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
* @param conn the connection
* @return the result set
*/
public static ResultSet nullResultSet(Connection conn) throws SQLException {
public static ResultSet nullResultSet(Connection conn) {
return null;
}
......
......@@ -247,7 +247,7 @@ public class TestLinkedTable extends TestBase {
cb.close();
}
private void testLinkOtherSchema() throws SQLException {
private static void testLinkOtherSchema() throws SQLException {
org.h2.Driver.load();
Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
Connection cb = DriverManager.getConnection("jdbc:h2:mem:two", "sa", "sa");
......@@ -289,7 +289,7 @@ public class TestLinkedTable extends TestBase {
conn2.close();
}
private void testLinkDrop() throws SQLException {
private static void testLinkDrop() throws SQLException {
org.h2.Driver.load();
Connection connA = DriverManager.getConnection("jdbc:h2:mem:a");
Statement statA = connA.createStatement();
......
......@@ -235,7 +235,7 @@ public class TestLob extends TestBase {
}
}
private void testAddLobRestart() throws SQLException {
private static void testAddLobRestart() throws SQLException {
DeleteDbFiles.execute("memFS:", "lob", true);
Connection conn = org.h2.Driver.load().connect("jdbc:h2:memFS:lob", null);
Statement stat = conn.createStatement();
......@@ -320,7 +320,7 @@ public class TestLob extends TestBase {
conn.close();
}
private void collectAndWait() {
private static void collectAndWait() {
for (int i = 0; i < 3; i++) {
System.gc();
}
......@@ -1020,11 +1020,11 @@ public class TestLob extends TestBase {
conn.close();
}
private Reader getRandomReader(int len, int seed) {
private static Reader getRandomReader(int len, int seed) {
return new CharArrayReader(getRandomChars(len, seed));
}
private char[] getRandomChars(int len, int seed) {
private static char[] getRandomChars(int len, int seed) {
Random random = new Random(seed);
char[] buff = new char[len];
for (int i = 0; i < len; i++) {
......@@ -1039,7 +1039,7 @@ public class TestLob extends TestBase {
return buff;
}
private InputStream getRandomStream(int len, int seed) {
private static InputStream getRandomStream(int len, int seed) {
Random random = new Random(seed);
byte[] buff = new byte[len];
random.nextBytes(buff);
......
......@@ -199,7 +199,7 @@ public class TestScript extends TestBase {
write("");
}
private void setParameter(PreparedStatement prep, int i, String param) throws SQLException {
private static void setParameter(PreparedStatement prep, int i, String param) throws SQLException {
if (param.equalsIgnoreCase("null")) {
param = null;
}
......@@ -255,7 +255,7 @@ public class TestScript extends TestBase {
return 0;
}
private String formatString(String s) {
private static String formatString(String s) {
if (s == null) {
return "null";
}
......@@ -311,7 +311,7 @@ public class TestScript extends TestBase {
writeResult(sql, (ordered ? "rows (ordered): " : "rows: ") + i, null);
}
private String format(String[] row, int[] max) {
private static String format(String[] row, int[] max) {
int length = max.length;
StringBuilder buff = new StringBuilder();
for (int i = 0; i < length; i++) {
......@@ -376,7 +376,7 @@ public class TestScript extends TestBase {
out.println(s);
}
private void sort(String[] a) {
private static void sort(String[] a) {
for (int i = 1, j, len = a.length; i < len; i++) {
String t = a[i];
for (j = i - 1; j >= 0 && t.compareTo(a[j]) < 0; j--) {
......
......@@ -125,7 +125,7 @@ public class TestSequence extends TestBase {
conn.close();
}
private long getNext(Statement stat) throws SQLException {
private static long getNext(Statement stat) throws SQLException {
ResultSet rs = stat.executeQuery("call next value for testSequence");
rs.next();
long value = rs.getLong(1);
......
......@@ -194,7 +194,7 @@ public class TestTempTables extends TestBase {
stat.execute("drop table test");
}
private void testConstraints(Connection conn1, Connection conn2) throws SQLException {
private static void testConstraints(Connection conn1, Connection conn2) throws SQLException {
Statement s1 = conn1.createStatement(), s2 = conn2.createStatement();
s1.execute("create local temporary table test(id int unique)");
s2.execute("create local temporary table test(id int unique)");
......@@ -204,7 +204,7 @@ public class TestTempTables extends TestBase {
s2.execute("drop table test");
}
private void testIndexes(Connection conn1, Connection conn2) throws SQLException {
private static void testIndexes(Connection conn1, Connection conn2) throws SQLException {
conn1.createStatement().executeUpdate("create local temporary table test(id int)");
conn1.createStatement().executeUpdate("create index idx_id on test(id)");
conn2.createStatement().executeUpdate("create local temporary table test(id int)");
......
......@@ -143,11 +143,10 @@ public class TestPreparedStatement extends TestBase {
stat.execute("DROP TABLE TEST");
}
private String getString(int i) {
private static String getString(int i) {
return new String(new char[100000]).replace('\0', (char) ('0' + i));
}
private void testExecuteErrorTwice(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("CREATE TABLE BAD AS SELECT A");
try {
......@@ -301,7 +300,7 @@ public class TestPreparedStatement extends TestBase {
assertFalse(rs.next());
}
private void testCoalesce(Connection conn) throws SQLException {
private static void testCoalesce(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.executeUpdate("create table test(tm timestamp)");
stat.executeUpdate("insert into test values(current_timestamp)");
......
......@@ -60,7 +60,7 @@ public class TestConnectionPool extends TestBase {
cp.dispose();
}
private void testWrongUrl() throws SQLException {
private void testWrongUrl() {
JdbcConnectionPool cp = JdbcConnectionPool.create("jdbc:wrong:url", "", "");
try {
cp.getConnection();
......
......@@ -100,7 +100,7 @@ public class TestXASimple extends TestBase {
JdbcUtils.closeSilently(xa);
}
private void shutdown(JdbcDataSource ds) throws SQLException {
private static void shutdown(JdbcDataSource ds) throws SQLException {
Connection conn = ds.getConnection();
conn.createStatement().execute("shutdown immediately");
JdbcUtils.closeSilently(conn);
......
......@@ -87,10 +87,6 @@ public class Test {
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
new Test().test(args);
}
private void test(String... args) throws Exception {
int port = 9099;
String connect = "192.168.0.3";
boolean file = false;
......@@ -106,7 +102,7 @@ public class Test {
test(connect, port, file);
}
private void test(String connect, int port, boolean file) throws Exception {
private static void test(String connect, int port, boolean file) throws Exception {
Socket socket = new Socket(connect, port);
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
System.out.println("Connected to " + socket.toString());
......@@ -117,7 +113,7 @@ public class Test {
}
}
private void testFile(DataOutputStream out) throws IOException {
private static void testFile(DataOutputStream out) throws IOException {
File file = new File("test.txt");
if (file.exists()) {
file.delete();
......@@ -142,7 +138,7 @@ public class Test {
write.close();
}
private void testDatabases(DataOutputStream out) throws Exception {
private static void testDatabases(DataOutputStream out) throws Exception {
Test[] dbs = {
new Test("org.h2.Driver", "jdbc:h2:test1", "sa", "", true),
new Test("org.h2.Driver", "jdbc:h2:test2", "sa", "", false),
......
......@@ -63,10 +63,6 @@ public class TestRecover {
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
new TestRecover().runTest();
}
private void runTest() throws Exception {
System.out.println("URL=" + URL);
System.out.println("backup...");
new File(TEST_DIRECTORY).mkdirs();
......@@ -174,14 +170,14 @@ public class TestRecover {
}
}
private void testLoop() throws Exception {
private static void testLoop() throws Exception {
Random random = new SecureRandom();
while (true) {
runOneTest(random.nextInt());
}
}
private Connection openConnection() throws Exception {
private static Connection openConnection() throws Exception {
Class.forName(DRIVER);
Connection conn = DriverManager.getConnection(URL, "sa", "sa");
Statement stat = conn.createStatement();
......@@ -194,7 +190,7 @@ public class TestRecover {
return conn;
}
private void closeConnection(Connection conn) {
private static void closeConnection(Connection conn) {
try {
conn.close();
} catch (SQLException e) {
......@@ -215,7 +211,7 @@ public class TestRecover {
}
}
private void runOneTest(int i) throws Exception {
private static void runOneTest(int i) throws Exception {
Random random = new Random(i);
Connection conn = openConnection();
PreparedStatement prepInsert = null;
......@@ -309,7 +305,7 @@ public class TestRecover {
}
}
private boolean testConsistency() {
private static boolean testConsistency() {
FileOutputStream out = null;
PrintWriter p = null;
try {
......@@ -347,7 +343,7 @@ public class TestRecover {
}
}
private void test(Connection conn, String order) throws Exception {
private static void test(Connection conn, String order) throws Exception {
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT * FROM TEST " + order);
int max = 0;
......
......@@ -100,7 +100,7 @@ public class TestRowLocks extends TestBase {
c2.close();
}
private String getSingleValue(Statement stat, String sql) throws SQLException {
private static String getSingleValue(Statement stat, String sql) throws SQLException {
ResultSet rs = stat.executeQuery(sql);
return rs.next() ? rs.getString(1) : null;
}
......
......@@ -99,7 +99,7 @@ public class TestCrashAPI extends TestBase implements Runnable {
}
}
private void recoverAll() throws SQLException {
private static void recoverAll() throws SQLException {
org.h2.Driver.load();
File[] files = new File("temp/backup").listFiles();
Arrays.sort(files, new Comparator<File>() {
......
......@@ -275,7 +275,7 @@ public class TestJoin extends TestBase {
}
}
private String readResult(ResultSet rs) throws SQLException {
private static String readResult(ResultSet rs) throws SQLException {
StringBuilder b = new StringBuilder();
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
......
......@@ -264,7 +264,7 @@ public class TestKillRestartMulti extends TestBase {
}
}
private void testConsistent(Connection conn) throws SQLException {
private static void testConsistent(Connection conn) throws SQLException {
for (int i = 0; i < 20; i++) {
Statement stat = conn.createStatement();
try {
......
......@@ -217,7 +217,7 @@ public class TestNestedJoins extends TestBase {
}
}
private String getResult(ResultSet rs) throws SQLException {
private static String getResult(ResultSet rs) throws SQLException {
ArrayList<String> list = New.arrayList();
while (rs.next()) {
StringBuilder buff = new StringBuilder();
......@@ -569,7 +569,7 @@ public class TestNestedJoins extends TestBase {
deleteDb("nestedJoins");
}
private String cleanRemarks(String sql) throws SQLException {
private static String cleanRemarks(String sql) {
ScriptReader r = new ScriptReader(new StringReader(sql));
r.setSkipRemarks(true);
sql = r.readStatement();
......
......@@ -184,7 +184,7 @@ public class TestOuterJoins extends TestBase {
buff.append(")");
}
private void appendRandomCondition(Random random, StringBuilder buff, int max) {
private static void appendRandomCondition(Random random, StringBuilder buff, int max) {
if (max > 0 && random.nextInt(4) == 0) {
return;
}
......@@ -230,7 +230,7 @@ public class TestOuterJoins extends TestBase {
}
}
private void appendRandomValueOrColumn(Random random, StringBuilder buff, int max) {
private static void appendRandomValueOrColumn(Random random, StringBuilder buff, int max) {
if (random.nextBoolean()) {
buff.append(random.nextInt(8) - 2);
} else {
......@@ -269,7 +269,7 @@ public class TestOuterJoins extends TestBase {
}
}
private String getResult(ResultSet rs) throws SQLException {
private static String getResult(ResultSet rs) throws SQLException {
ArrayList<String> list = New.arrayList();
while (rs.next()) {
StringBuilder buff = new StringBuilder();
......@@ -561,7 +561,7 @@ public class TestOuterJoins extends TestBase {
deleteDb("nestedJoins");
}
private String cleanRemarks(String sql) throws SQLException {
private static String cleanRemarks(String sql) {
ScriptReader r = new ScriptReader(new StringReader(sql));
r.setSkipRemarks(true);
sql = r.readStatement();
......
......@@ -195,7 +195,7 @@ public class TestPowerOffFs2 extends TestBase {
}
}
private void testConsistent(Connection conn) throws SQLException {
private static void testConsistent(Connection conn) throws SQLException {
for (int i = 0; i < 20; i++) {
Statement stat = conn.createStatement();
try {
......
......@@ -188,7 +188,7 @@ public class TestRandomCompare extends TestBase {
}
}
private void appendRandomValue(Random random, StringBuilder buff) {
private static void appendRandomValue(Random random, StringBuilder buff) {
switch (random.nextInt(7)) {
case 0:
buff.append("null");
......@@ -238,7 +238,7 @@ public class TestRandomCompare extends TestBase {
}
}
private String getResult(ResultSet rs) throws SQLException {
private static String getResult(ResultSet rs) throws SQLException {
ArrayList<String> list = New.arrayList();
while (rs.next()) {
StringBuilder buff = new StringBuilder();
......
......@@ -88,7 +88,7 @@ public class TestThreads extends TestBase implements Runnable {
conn.close();
}
private void insertRows(Connection conn, String tableName, int len) throws SQLException {
private static void insertRows(Connection conn, String tableName, int len) throws SQLException {
PreparedStatement prep = conn.prepareStatement("INSERT INTO " + tableName + " VALUES(?, 'Hi')");
for (int i = 0; i < len; i++) {
prep.setInt(1, i);
......@@ -96,7 +96,7 @@ public class TestThreads extends TestBase implements Runnable {
}
}
private void checkTable(Connection conn, String tableName) throws SQLException {
private static void checkTable(Connection conn, String tableName) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM " + tableName + " ORDER BY ID");
while (rs.next()) {
......
......@@ -154,7 +154,7 @@ public class Expression {
return list[i];
}
private String getColumnName(String alias, Column column) {
private static String getColumnName(String alias, Column column) {
if (alias == null) {
return column.getName();
}
......
......@@ -86,7 +86,7 @@ public class TestMultiOrder extends TestMultiThread {
prep.execute();
}
private String getString(int id) {
private static String getString(int id) {
StringBuilder buff = new StringBuilder();
Random rnd = new Random(id);
int len = rnd.nextInt(40);
......@@ -101,19 +101,19 @@ public class TestMultiOrder extends TestMultiThread {
return buff.toString();
}
private synchronized int getNextCustomerId() {
private static synchronized int getNextCustomerId() {
return customerCount++;
}
private synchronized int increaseOrders() {
private static synchronized int increaseOrders() {
return orderCount++;
}
private synchronized int increaseOrderLines(int count) {
private static synchronized int increaseOrderLines(int count) {
return orderLineCount += count;
}
private int getCustomerCount() {
private static int getCustomerCount() {
return customerCount;
}
......
......@@ -28,7 +28,7 @@ public class TestTempTableCrash {
new TestTempTableCrash().test();
}
private void test() throws Exception {
public void test() throws Exception {
Connection conn;
Statement stat;
......
......@@ -28,7 +28,7 @@ public class TestUndoLogLarge {
new TestUndoLogLarge().test();
}
private void test() throws SQLException {
public void test() throws SQLException {
DeleteDbFiles.execute("data", "test", true);
Connection conn = DriverManager.getConnection("jdbc:h2:data/test");
Statement stat = conn.createStatement();
......@@ -50,4 +50,5 @@ public class TestUndoLogLarge {
conn.rollback();
conn.close();
}
}
......@@ -30,7 +30,7 @@ public class TestUndoLogMemory {
// new TestUndoLogMemory().test(1000, "space(100000)");
}
private void test(int count, String defaultValue) throws SQLException {
public void test(int count, String defaultValue) throws SQLException {
// -Xmx1m -XX:+HeapDumpOnOutOfMemoryError
DeleteDbFiles.execute("data", "test", true);
......@@ -74,4 +74,5 @@ public class TestUndoLogMemory {
System.out.println("close---");
conn.close();
}
}
......@@ -68,7 +68,7 @@ class Arg {
return obj;
}
private String quote(Class<?> valueClass, Object value) {
private static String quote(Class<?> valueClass, Object value) {
if (value == null) {
return null;
} else if (valueClass == String.class) {
......
......@@ -118,7 +118,7 @@ public class TestCache extends TestBase implements CacheWriter {
conn.close();
}
private int getReadCount(Statement stat) throws Exception {
private static int getReadCount(Statement stat) throws Exception {
ResultSet rs;
rs = stat.executeQuery("select value from information_schema.settings where name = 'info.FILE_READ'");
rs.next();
......
......@@ -243,7 +243,7 @@ public class TestCompress extends TestBase {
assertEquals(buff.length, test.length);
assertEquals(buff, test);
Arrays.fill(test, (byte) 0);
utils.expand(out, test, 0);
CompressTool.expand(out, test, 0);
assertEquals(buff, test);
}
for (String a : new String[] { null, "LZF", "DEFLATE", "ZIP", "GZIP" }) {
......
......@@ -67,7 +67,7 @@ public class TestDataPage extends TestBase implements DataHandler {
testAll();
}
private void testPerformance() {
private static void testPerformance() {
Data data = Data.create(null, 1024);
for (int j = 0; j < 4; j++) {
long time = System.currentTimeMillis();
......
......@@ -39,7 +39,7 @@ public class TestDate extends TestBase {
testCurrentTimeZone();
}
private void testCurrentTimeZone() {
private static void testCurrentTimeZone() {
for (int year = 1970; year < 2050; year += 3) {
for (int month = 1; month <= 12; month++) {
for (int day = 1; day < 29; day++) {
......@@ -51,7 +51,7 @@ public class TestDate extends TestBase {
}
}
private void test(int year, int month, int day, int hour) {
private static void test(int year, int month, int day, int hour) {
DateTimeUtils.parseDateTime(year + "-" + month + "-" + day + " " + hour + ":00:00", Value.TIMESTAMP, ErrorCode.TIMESTAMP_CONSTANT_2);
}
......
......@@ -39,7 +39,7 @@ public class TestIntArray extends TestBase {
assertEquals(5, array.get(2));
}
private void testInit() {
private static void testInit() {
IntArray array = new IntArray(new int[0]);
array.add(10);
}
......@@ -81,7 +81,7 @@ public class TestIntArray extends TestBase {
}
}
private int[] add(int[] array, int i, int value) {
private static int[] add(int[] array, int i, int value) {
int[] a2 = new int[array.length + 1];
System.arraycopy(array, 0, a2, 0, array.length);
if (i < array.length) {
......@@ -92,15 +92,15 @@ public class TestIntArray extends TestBase {
return array;
}
private int[] add(int[] array, int value) {
private static int[] add(int[] array, int value) {
return add(array, array.length, value);
}
private int get(int[] array, int i) {
private static int get(int[] array, int i) {
return array[i];
}
private int[] remove(int[] array, int i) {
private static int[] remove(int[] array, int i) {
int[] a2 = new int[array.length - 1];
System.arraycopy(array, 0, a2, 0, i);
if (i < a2.length) {
......
......@@ -132,12 +132,12 @@ public class TestOldVersion extends TestBase {
m.invoke(serverOld);
}
private ClassLoader getClassLoader(String jarFile) throws Exception {
private static ClassLoader getClassLoader(String jarFile) throws Exception {
URL[] urls = { new URL(jarFile) };
return new URLClassLoader(urls, null);
}
private Driver getDriver(ClassLoader cl) throws Exception {
private static Driver getDriver(ClassLoader cl) throws Exception {
Class<?> driverClass;
try {
driverClass = cl.loadClass("org.h2.Driver");
......
......@@ -794,7 +794,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
event("setProgress " + state + " " + name + " " + x + " " + max);
}
private void event(String s) {
private static void event(String s) {
eventBuffer.append(s).append(';');
}
......
......@@ -59,7 +59,7 @@ public class TestScriptReader extends TestBase {
}
}
private String randomStatement(Random random) {
private static String randomStatement(Random random) {
StringBuilder buff = new StringBuilder();
int len = random.nextInt(5);
for (int i = 0; i < len; i++) {
......
......@@ -37,35 +37,33 @@ public class TestSecurity extends TestBase {
testXTEA();
}
private void testConnectWithHash() throws SQLException {
private static void testConnectWithHash() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "sa");
String pwd = StringUtils.convertBytesToString(new SHA256().getKeyPasswordHash("SA", "sa".toCharArray()));
String pwd = StringUtils.convertBytesToString(SHA256.getKeyPasswordHash("SA", "sa".toCharArray()));
Connection conn2 = DriverManager.getConnection("jdbc:h2:mem:test;PASSWORD_HASH=TRUE", "sa", pwd);
conn.close();
conn2.close();
}
private void testSHA() {
SHA256 sha = new SHA256();
testOneSHA(sha);
testOneSHA();
}
private String getHashString(SHA256 sha, byte[] data) {
byte[] result = sha.getHash(data, true);
private String getHashString(byte[] data) {
byte[] result = SHA256.getHash(data, true);
if (data.length > 0) {
assertEquals(0, data[0]);
}
return StringUtils.convertBytesToString(result);
}
private void testOneSHA(SHA256 sha) {
private void testOneSHA() {
assertEquals("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
getHashString(sha, new byte[] {}));
getHashString(new byte[] {}));
assertEquals("68aa2e2ee5dff96e3355e6c7ee373e3d6a4e17f75f9518d843709c0c9bc3e3d4",
getHashString(sha, new byte[] { 0x19 }));
getHashString(new byte[] { 0x19 }));
assertEquals("175ee69b02ba9b58e2b0a5fd13819cea573f3940a94f825128cf4209beabb4e8",
getHashString(
sha,
new byte[] { (byte) 0xe3, (byte) 0xd7, 0x25, 0x70, (byte) 0xdc, (byte) 0xdd, 0x78, 0x7c, (byte) 0xe3,
(byte) 0x88, 0x7a, (byte) 0xb2, (byte) 0xcd, 0x68, 0x46, 0x52 }));
checkSHA256("", "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855");
......@@ -81,12 +79,11 @@ public class TestSecurity extends TestBase {
}
private void checkSHA256(String message, String expected) {
SHA256 sha = new SHA256();
String hash = StringUtils.convertBytesToString(sha.getHash(message.getBytes(), true)).toUpperCase();
String hash = StringUtils.convertBytesToString(SHA256.getHash(message.getBytes(), true)).toUpperCase();
assertEquals(expected, hash);
}
private void testXTEA() {
private static void testXTEA() {
byte[] test = new byte[4096];
BlockCipher xtea = CipherFactory.getBlockCipher("XTEA");
xtea.setKey("abcdefghijklmnop".getBytes());
......
......@@ -36,7 +36,7 @@ public class TestStreams extends TestBase {
testLZFStreamClose();
}
private byte[] getRandomBytes(Random random) {
private static byte[] getRandomBytes(Random random) {
int[] sizes = { 0, 1, random.nextInt(1000), random.nextInt(100000), random.nextInt(1000000) };
int size = sizes[random.nextInt(sizes.length)];
byte[] buffer = new byte[size];
......
......@@ -33,7 +33,7 @@ public class TestTraceSystem extends TestBase {
testAdapter();
}
private void testAdapter() {
private static void testAdapter() {
TraceSystem ts = new TraceSystem(null);
ts.setLevelFile(TraceSystem.ADAPTER);
ts.getTrace("test").info("test");
......
......@@ -94,7 +94,7 @@ public class TestValueMemory extends TestBase implements DataHandler {
long first = Utils.getMemoryUsed();
ArrayList<Value> list = new ArrayList<Value>();
long memory = 0;
for (int i = 0; memory < 1000000; i++) {
while (memory < 1000000) {
Value v = create(type);
memory += v.getMemory() + Constants.MEMORY_POINTER;
list.add(v);
......
......@@ -6,7 +6,6 @@
*/
package org.h2.test.utils;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.math.BigDecimal;
import java.math.BigInteger;
......@@ -26,7 +25,7 @@ public class MemoryFootprint {
*
* @param a ignored
*/
public static void main(String... a) throws IOException {
public static void main(String... a) {
// System.getProperties().store(System.out, "");
print("Object", new Object());
print("Timestamp", new java.sql.Timestamp(0));
......
......@@ -548,7 +548,7 @@ public class BuildBase {
}
in.close();
} catch (IOException e) {
throw new RuntimeException("Error downloading", e);
throw new RuntimeException("Error downloading " + fileURL + " to " + target, e);
}
byte[] data = buff.toByteArray();
String got = getSHA1(data);
......
......@@ -537,7 +537,7 @@ public class PgTcpRedirect {
* @param buffer the byte array
* @param len the length
*/
synchronized static void printData(byte[] buffer, int len) {
static synchronized void printData(byte[] buffer, int len) {
if (DEBUG) {
System.out.print(" ");
for (int i = 0; i < len; i++) {
......
......@@ -66,7 +66,7 @@ public class SQLStatement {
}
}
private void setValue(PreparedStatement prep, int parameterIndex, Object x) {
private static void setValue(PreparedStatement prep, int parameterIndex, Object x) {
try {
prep.setObject(parameterIndex, x);
} catch (SQLException e) {
......
......@@ -152,7 +152,7 @@ class TableDefinition<T> {
}
}
private String getDataType(Field field) {
private static String getDataType(Field field) {
Class<?> fieldClass = field.getType();
if (fieldClass == Integer.class) {
return "INT";
......
......@@ -38,7 +38,7 @@ public class ClassReader {
private int nextPc;
private Map<String, Object> fieldMap = new HashMap<String, Object>();
private void debug(String s) {
private static void debug(String s) {
if (DEBUG) {
System.out.println(s);
}
......
......@@ -157,7 +157,7 @@ public class JavaParser {
}
}
private String cleanPackageName(String name) {
private static String cleanPackageName(String name) {
if (name.startsWith("org.h2.java.lang") || name.startsWith("org.h2.java.io")) {
return name.substring("org.h2.".length());
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论