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

--no commit message

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