提交 f188e9dc authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 9ac5a876
...@@ -726,8 +726,9 @@ public class MetaTable extends Table { ...@@ -726,8 +726,9 @@ public class MetaTable extends Table {
break; break;
} }
case HELP: { case HELP: {
String resource = "/org/h2/res/help.csv";
try { try {
byte[] data = Resources.get("/org/h2/res/help.csv"); byte[] data = Resources.get(resource);
Reader reader = new InputStreamReader(new ByteArrayInputStream(data)); Reader reader = new InputStreamReader(new ByteArrayInputStream(data));
ResultSet rs = Csv.getInstance().read(reader, null); ResultSet rs = Csv.getInstance().read(reader, null);
for(int i=0; rs.next(); i++) { for(int i=0; rs.next(); i++) {
...@@ -741,7 +742,7 @@ public class MetaTable extends Table { ...@@ -741,7 +742,7 @@ public class MetaTable extends Table {
}); });
} }
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, resource);
} }
break; break;
} }
......
...@@ -80,8 +80,10 @@ public class Backup { ...@@ -80,8 +80,10 @@ public class Backup {
*/ */
public static void execute(String zipFileName, String directory, String db, boolean quiet) throws SQLException { public static void execute(String zipFileName, String directory, String db, boolean quiet) throws SQLException {
ArrayList list = FileLister.getDatabaseFiles(directory, db, true); ArrayList list = FileLister.getDatabaseFiles(directory, db, true);
if (list.size() == 0 && !quiet) { if (list.size() == 0) {
if(!quiet) {
System.out.println("No database files found"); System.out.println("No database files found");
}
return; return;
} }
File file = new File(zipFileName); File file = new File(zipFileName);
...@@ -111,7 +113,7 @@ public class Backup { ...@@ -111,7 +113,7 @@ public class Backup {
zipOut.closeEntry(); zipOut.closeEntry();
zipOut.close(); zipOut.close();
} catch(IOException e) { } catch(IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, zipFileName);
} finally { } finally {
IOUtils.closeSilently(out); IOUtils.closeSilently(out);
} }
......
...@@ -177,7 +177,7 @@ public class ChangePassword { ...@@ -177,7 +177,7 @@ public class ChangePassword {
in.close(); in.close();
out.close(); out.close();
} catch(IOException e) { } catch(IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
FileUtils.delete(fileName); FileUtils.delete(fileName);
FileUtils.rename(temp, fileName); FileUtils.rename(temp, fileName);
......
...@@ -263,7 +263,7 @@ public class CompressTool { ...@@ -263,7 +263,7 @@ public class CompressTool {
} }
return out; return out;
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
} }
...@@ -295,7 +295,7 @@ public class CompressTool { ...@@ -295,7 +295,7 @@ public class CompressTool {
} }
return in; return in;
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
} }
......
...@@ -61,7 +61,7 @@ public class ConvertTraceFile { ...@@ -61,7 +61,7 @@ public class ConvertTraceFile {
try { try {
convertFile(traceFile, javaClass, script); convertFile(traceFile, javaClass, script);
} catch(IOException e) { } catch(IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, traceFile);
} }
} }
......
...@@ -9,7 +9,6 @@ import java.sql.Connection; ...@@ -9,7 +9,6 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.h2.message.Message;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
/** /**
...@@ -87,17 +86,20 @@ public class CreateCluster { ...@@ -87,17 +86,20 @@ public class CreateCluster {
Statement stat = null; Statement stat = null;
try { try {
org.h2.Driver.load(); org.h2.Driver.load();
// use cluster='' so connecting is possible even if the cluster is enabled // use cluster='' so connecting is possible even if the cluster is enabled
conn = DriverManager.getConnection(urlSource + ";CLUSTER=''", user, password); conn = DriverManager.getConnection(urlSource + ";CLUSTER=''", user, password);
conn.close(); conn.close();
boolean exists;
try { try {
conn = DriverManager.getConnection(urlTarget + ";IFEXISTS=TRUE", user, password); conn = DriverManager.getConnection(urlTarget + ";IFEXISTS=TRUE", user, password);
conn.close(); conn.close();
throw new Exception("Target database must not yet exist. Please delete it first"); exists = true;
} catch(SQLException e) { } catch(SQLException e) {
// database does not exists - ok // database does not exists - ok
exists = false;
}
if(exists) {
throw new SQLException("Target database must not yet exist. Please delete it first");
} }
// TODO cluster: need to open the database in exclusive mode, so that other applications // TODO cluster: need to open the database in exclusive mode, so that other applications
...@@ -116,8 +118,6 @@ public class CreateCluster { ...@@ -116,8 +118,6 @@ public class CreateCluster {
conn = DriverManager.getConnection(urlTarget, user, password); conn = DriverManager.getConnection(urlTarget, user, password);
stat = conn.createStatement(); stat = conn.createStatement();
stat.executeUpdate("SET CLUSTER '" + serverlist + "'"); stat.executeUpdate("SET CLUSTER '" + serverlist + "'");
} catch(Exception e) {
throw Message.convert(e);
} finally { } finally {
JdbcUtils.closeSilently(conn); JdbcUtils.closeSilently(conn);
JdbcUtils.closeSilently(stat); JdbcUtils.closeSilently(stat);
......
...@@ -158,7 +158,7 @@ public class Restore { ...@@ -158,7 +158,7 @@ public class Restore {
zipIn.closeEntry(); zipIn.closeEntry();
zipIn.close(); zipIn.close();
} catch(IOException e) { } catch(IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, zipFileName);
} finally { } finally {
IOUtils.closeSilently(in); IOUtils.closeSilently(in);
} }
......
...@@ -232,8 +232,6 @@ public class RunScript { ...@@ -232,8 +232,6 @@ public class RunScript {
stat = conn.createStatement(); stat = conn.createStatement();
String sql = "RUNSCRIPT FROM '" + fileName + "' " + options; String sql = "RUNSCRIPT FROM '" + fileName + "' " + options;
stat.execute(sql); stat.execute(sql);
} catch (Exception e) {
throw Message.convert(e);
} finally { } finally {
JdbcUtils.closeSilently(stat); JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn); JdbcUtils.closeSilently(conn);
...@@ -264,8 +262,8 @@ public class RunScript { ...@@ -264,8 +262,8 @@ public class RunScript {
} finally { } finally {
conn.close(); conn.close();
} }
} catch (Exception e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, fileName);
} }
} }
......
...@@ -6,6 +6,7 @@ package org.h2.tools; ...@@ -6,6 +6,7 @@ package org.h2.tools;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
...@@ -110,8 +111,6 @@ public class Script { ...@@ -110,8 +111,6 @@ public class Script {
stat = conn.createStatement(); stat = conn.createStatement();
String sql = "SCRIPT " + options1 + " TO '" + fileName + "' " + options2; String sql = "SCRIPT " + options1 + " TO '" + fileName + "' " + options2;
stat.execute(sql); stat.execute(sql);
} catch(Exception e) {
throw Message.convert(e);
} finally { } finally {
JdbcUtils.closeSilently(stat); JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn); JdbcUtils.closeSilently(conn);
...@@ -143,8 +142,8 @@ public class Script { ...@@ -143,8 +142,8 @@ public class Script {
writer.println(s + ";"); writer.println(s + ";");
} }
writer.close(); writer.close();
} catch(Exception e) { } catch(IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, fileName);
} finally { } finally {
JdbcUtils.closeSilently(stat); JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn); JdbcUtils.closeSilently(conn);
......
...@@ -94,11 +94,12 @@ public class FileUtils { ...@@ -94,11 +94,12 @@ public class FileUtils {
} }
private static void freeMemoryAndFinalize() { private static void freeMemoryAndFinalize() {
long mem = Runtime.getRuntime().freeMemory(); Runtime rt = Runtime.getRuntime();
long mem = rt.freeMemory();
for(int i=0; i<16; i++) { for(int i=0; i<16; i++) {
System.gc(); rt.gc();
long now = Runtime.getRuntime().freeMemory(); long now = rt.freeMemory();
Runtime.getRuntime().runFinalization(); rt.runFinalization();
if(now == mem) { if(now == mem) {
break; break;
} }
...@@ -124,7 +125,7 @@ public class FileUtils { ...@@ -124,7 +125,7 @@ public class FileUtils {
if(newFile.exists()) { if(newFile.exists()) {
throw Message.getSQLException(Message.FILE_RENAME_FAILED_2, new String[]{oldName, newName}, null); throw Message.getSQLException(Message.FILE_RENAME_FAILED_2, new String[]{oldName, newName}, null);
} }
for(int i=0; i<16; i++) { for(int i=0; i<Constants.MAX_FILE_RETRY; i++) {
boolean ok = oldFile.renameTo(newFile); boolean ok = oldFile.renameTo(newFile);
if(ok) { if(ok) {
return; return;
...@@ -175,7 +176,7 @@ public class FileUtils { ...@@ -175,7 +176,7 @@ public class FileUtils {
return; return;
} }
File dir = new File(parent); File dir = new File(parent);
for(int i=0; i<16; i++) { for(int i=0; i<Constants.MAX_FILE_RETRY; i++) {
if(dir.exists() || dir.mkdirs()) { if(dir.exists() || dir.mkdirs()) {
return; return;
} }
...@@ -195,7 +196,7 @@ public class FileUtils { ...@@ -195,7 +196,7 @@ public class FileUtils {
return true; return true;
} }
File file = new File(fileName); File file = new File(fileName);
for(int i=0; i<8; i++) { for(int i=0; i<Constants.MAX_FILE_RETRY; i++) {
try { try {
return file.createNewFile(); return file.createNewFile();
} catch (IOException e) { } catch (IOException e) {
...@@ -216,7 +217,7 @@ public class FileUtils { ...@@ -216,7 +217,7 @@ public class FileUtils {
} }
File file = new File(fileName); File file = new File(fileName);
if(file.exists()) { if(file.exists()) {
for(int i=0; i<16; i++) { for(int i=0; i<Constants.MAX_FILE_RETRY; i++) {
boolean ok = file.delete(); boolean ok = file.delete();
if(ok) { if(ok) {
return; return;
...@@ -233,7 +234,7 @@ public class FileUtils { ...@@ -233,7 +234,7 @@ public class FileUtils {
} }
try { try {
// sleep at most 256 ms // sleep at most 256 ms
long sleep = (long)i * (long)i; long sleep = Math.min(256, i * i);
Thread.sleep(sleep); Thread.sleep(sleep);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore // ignore
...@@ -267,7 +268,7 @@ public class FileUtils { ...@@ -267,7 +268,7 @@ public class FileUtils {
try { try {
return f.getCanonicalPath(); return f.getCanonicalPath();
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, fileName);
} }
} }
...@@ -350,7 +351,6 @@ public class FileUtils { ...@@ -350,7 +351,6 @@ public class FileUtils {
} }
public static String[] listFiles(String path) throws SQLException { public static String[] listFiles(String path) throws SQLException {
//System.out.println("listFiles: " + path);
if(isInMemory(path)) { if(isInMemory(path)) {
String[] list = new String[memoryFiles.size()]; String[] list = new String[memoryFiles.size()];
MemoryFile[] l = new MemoryFile[memoryFiles.size()]; MemoryFile[] l = new MemoryFile[memoryFiles.size()];
...@@ -372,7 +372,7 @@ public class FileUtils { ...@@ -372,7 +372,7 @@ public class FileUtils {
} }
return list; return list;
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, path);
} }
// try { // try {
...@@ -399,6 +399,9 @@ public class FileUtils { ...@@ -399,6 +399,9 @@ public class FileUtils {
} }
public static void copy(String original, String copy) throws SQLException { public static void copy(String original, String copy) throws SQLException {
int todoTestDidNotClose;
//System.out.println("###COPY### " + original + " " + copy);
//new Error("").printStackTrace();
FileOutputStream out = null; FileOutputStream out = null;
FileInputStream in = null; FileInputStream in = null;
try { try {
...@@ -413,9 +416,10 @@ public class FileUtils { ...@@ -413,9 +416,10 @@ public class FileUtils {
out.write(buffer, 0, len); out.write(buffer, 0, len);
} }
} catch(IOException e) { } catch(IOException e) {
throw Message.convertIOException(e, "original: " + original + " copy: " + copy);
} finally {
IOUtils.closeSilently(in); IOUtils.closeSilently(in);
IOUtils.closeSilently(out); IOUtils.closeSilently(out);
throw Message.convert(e);
} }
} }
......
...@@ -52,7 +52,7 @@ public class NetUtils { ...@@ -52,7 +52,7 @@ public class NetUtils {
} catch(BindException be) { } catch(BindException be) {
throw Message.getSQLException(Message.EXCEPTION_OPENING_PORT_1, new String[]{""+port}, be); throw Message.getSQLException(Message.EXCEPTION_OPENING_PORT_1, new String[]{""+port}, be);
} catch(IOException e) { } catch(IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, "port: " + port + " ssl: " + ssl);
} }
} }
......
...@@ -15,6 +15,8 @@ public class RandomUtils { ...@@ -15,6 +15,8 @@ public class RandomUtils {
static { static {
try { try {
secureRandom = SecureRandom.getInstance("SHA1PRNG"); secureRandom = SecureRandom.getInstance("SHA1PRNG");
byte[] seed = secureRandom.generateSeed(64);
secureRandom.setSeed(seed);
random = new Random(secureRandom.nextLong()); random = new Random(secureRandom.nextLong());
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
// random is null if the algorithm is not found // random is null if the algorithm is not found
......
...@@ -25,7 +25,7 @@ public class ScriptReader { ...@@ -25,7 +25,7 @@ public class ScriptReader {
try { try {
return reader.read(); return reader.read();
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
} }
......
...@@ -613,7 +613,7 @@ public class DataType { ...@@ -613,7 +613,7 @@ public class DataType {
} else if(x instanceof Timestamp) { } else if(x instanceof Timestamp) {
return ValueTimestamp.get((Timestamp)x); return ValueTimestamp.get((Timestamp)x);
} else if(x instanceof java.util.Date) { } else if(x instanceof java.util.Date) {
return ValueDate.get(new Date(((java.util.Date)x).getTime())); return ValueTimestamp.get(new Timestamp(((java.util.Date)x).getTime()));
} else if(x instanceof java.io.Reader) { } else if(x instanceof java.io.Reader) {
return ValueLob.createClob((java.io.Reader)x, -1, session.getDataHandler()); return ValueLob.createClob((java.io.Reader)x, -1, session.getDataHandler());
} else if(x instanceof java.sql.Clob) { } else if(x instanceof java.sql.Clob) {
......
...@@ -134,7 +134,7 @@ public class ValueLob extends Value { ...@@ -134,7 +134,7 @@ public class ValueLob extends Value {
lob.createFromReader(buff, len, in, remaining, handler); lob.createFromReader(buff, len, in, remaining, handler);
return lob; return lob;
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
} }
...@@ -172,7 +172,7 @@ public class ValueLob extends Value { ...@@ -172,7 +172,7 @@ public class ValueLob extends Value {
out.close(); out.close();
} }
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
} }
...@@ -267,7 +267,7 @@ public class ValueLob extends Value { ...@@ -267,7 +267,7 @@ public class ValueLob extends Value {
lob.createFromStream(buff, len, in, remaining, handler); lob.createFromStream(buff, len, in, remaining, handler);
return lob; return lob;
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
} }
...@@ -317,7 +317,7 @@ public class ValueLob extends Value { ...@@ -317,7 +317,7 @@ public class ValueLob extends Value {
out.close(); out.close();
} }
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, null);
} }
} }
...@@ -434,7 +434,7 @@ public class ValueLob extends Value { ...@@ -434,7 +434,7 @@ public class ValueLob extends Value {
return ByteUtils.convertBytesToString(buff); return ByteUtils.convertBytesToString(buff);
} }
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, fileName);
} }
} }
...@@ -450,18 +450,23 @@ public class ValueLob extends Value { ...@@ -450,18 +450,23 @@ public class ValueLob extends Value {
try { try {
return IOUtils.readBytesAndClose(getInputStream(), Integer.MAX_VALUE); return IOUtils.readBytesAndClose(getInputStream(), Integer.MAX_VALUE);
} catch (IOException e) { } catch (IOException e) {
throw Message.convert(e); throw Message.convertIOException(e, fileName);
} }
} }
public int hashCode() { public int hashCode() {
if (hash == 0) { if (hash == 0) {
if(precision > 4096) {
int todoTestThis;
return (int)(precision ^ (precision >> 32));
} else {
try { try {
hash = ByteUtils.getByteArrayHash(getBytes()); hash = ByteUtils.getByteArrayHash(getBytes());
} catch(SQLException e) { } catch(SQLException e) {
// TODO hash code for lob: should not ignore exception // TODO hash code for lob: should not ignore exception
} }
} }
}
return hash; return hash;
} }
......
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.value; package org.h2.value;
import java.sql.SQLException; import java.sql.SQLException;
......
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.samples; package org.h2.samples;
import java.io.*; import java.io.*;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论