提交 7430fb79 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 5a766521
...@@ -37,7 +37,12 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch. ...@@ -37,7 +37,12 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<h3>Version 1.0 (Current)</h3> <h3>Version 1.0 (Current)</h3>
<h3>Version 1.0 / TODO (Build TODO)</h3><ul> <h3>Version 1.0 / TODO (Build TODO)</h3><ul>
<li>PreparedStatement.getMetaData is now implemented. <li>If large result sets (backed by a temporary file) where not closed, the file was not deleted.
Now, the default result set type is FETCH_FORWARD. This means temp files are deleted
automatically (without having to close the result set explicitly). But it also means
ResultSet.beforeFirst can only be called for scrollable result sets. To create a scrollable resut set,
use Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY).
</li><li>PreparedStatement.getMetaData is now implemented.
</li><li>Now PreparedStatement.setBigDecimal(..) can be called with an object of a derived class </li><li>Now PreparedStatement.setBigDecimal(..) can be called with an object of a derived class
if the system property h2.allowBigDecimalExtensions is set to true. if the system property h2.allowBigDecimalExtensions is set to true.
</li><li>The default database name in the documentation is now jdbc:h2:~/test. Like this, the database </li><li>The default database name in the documentation is now jdbc:h2:~/test. Like this, the database
......
...@@ -117,8 +117,7 @@ Welcome to H2, the free SQL database. The main feature of H2 are: ...@@ -117,8 +117,7 @@ Welcome to H2, the free SQL database. The main feature of H2 are:
to get informed about new releases. to get informed about new releases.
Your email address is only used in this context.<br /> Your email address is only used in this context.<br />
If you don't want a Google account, there is a manually maintained list as well: <br /> If you don't want a Google account, there is a manually maintained list as well: <br />
Email: <input type="email" name="email" size="30" onKeyDown="newsletter.spam.value='false';"/> Email: <input type="email" name="email" size="30"/>
<input type="hidden" name="spam" value="true" size="30"/>
<input type="hidden" name="text" value="subscribe"/> <input type="hidden" name="text" value="subscribe"/>
<input type="submit" value="Submit"/> <input type="submit" value="Submit"/>
</form> </form>
......
...@@ -3,15 +3,14 @@ Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http:/ ...@@ -3,15 +3,14 @@ Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http:/
Initial Developer: H2 Group Initial Developer: H2 Group
--> -->
<? <?
$spam2 = ("false" == $spam) ? "" : "SPAM";
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
$body = "Email: $email $body = "Email: $email
Message: Message:
$text $text
"; ";
$headers = 'From: newsletter@h2database.com' . "\r\n" . $headers = 'From: newsletter@h2database.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion(); 'X-Mailer: PHP/' . phpversion();S
mail("dbsupport@h2database.com", "[H2 Newsletter] $now $spam2", $body, $headers); mail("dbsupport@h2database.com", "[H2 Newsletter] $now", $body, $headers);
?> ?>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title> <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
H2 Database H2 Database
......
...@@ -3,7 +3,6 @@ Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http:/ ...@@ -3,7 +3,6 @@ Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http:/
Initial Developer: H2 Group Initial Developer: H2 Group
--> -->
<? <?
$spam2 = ("false" == $spam) ? "" : "SPAM";
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
$body = "Email: $email $body = "Email: $email
Message: Message:
...@@ -12,7 +11,7 @@ $text ...@@ -12,7 +11,7 @@ $text
$headers = 'From: feedback@h2database.com' . "\r\n" . $headers = 'From: feedback@h2database.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion(); 'X-Mailer: PHP/' . phpversion();
$headers = $headers =
mail("dbsupport@h2database.com", "[H2 Feedback] $now $spam2", $body, $headers); mail("dbsupport@h2database.com", "[H2 Feedback] $now", $body, $headers);
?> ?>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title> <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
H2 Database H2 Database
......
...@@ -103,10 +103,6 @@ public class Constants { ...@@ -103,10 +103,6 @@ public class Constants {
public static final int IO_BUFFER_SIZE = 4 * 1024; public static final int IO_BUFFER_SIZE = 4 * 1024;
public static final int IO_BUFFER_SIZE_COMPRESS = 128 * 1024; public static final int IO_BUFFER_SIZE_COMPRESS = 128 * 1024;
public static final int DEFAULT_CACHE_SIZE = 1 << 16;
public static final int CACHE_SIZE_INDEX_SHIFT = 3;
public static final int DEFAULT_CACHE_SIZE_INDEX = DEFAULT_CACHE_SIZE >> CACHE_SIZE_INDEX_SHIFT;
public static final int DEFAULT_CACHE_SIZE_LINEAR_INDEX = 1 << 8; public static final int DEFAULT_CACHE_SIZE_LINEAR_INDEX = 1 << 8;
public static final String SUFFIX_DB_FILE = ".db"; public static final String SUFFIX_DB_FILE = ".db";
...@@ -252,6 +248,9 @@ public class Constants { ...@@ -252,6 +248,9 @@ public class Constants {
public static final boolean INDEX_LOOKUP_NEW = getBooleanSetting("h2.indexLookupNew", true); public static final boolean INDEX_LOOKUP_NEW = getBooleanSetting("h2.indexLookupNew", true);
public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false); public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false);
public static final int DATASOURCE_TRACE_LEVEL = getIntSetting("h2.dataSourceTraceLevel", TraceSystem.ERROR); public static final int DATASOURCE_TRACE_LEVEL = getIntSetting("h2.dataSourceTraceLevel", TraceSystem.ERROR);
public static final int CACHE_SIZE_DEFAULT = getIntSetting("h2.cacheSizeDefault", (1 << 16));
public static final int CACHE_SIZE_INDEX_SHIFT = getIntSetting("h2.cacheSizeIndexShift", 3);
public static final int CACHE_SIZE_INDEX_DEFAULT = CACHE_SIZE_DEFAULT >> CACHE_SIZE_INDEX_SHIFT;
public static boolean getBooleanSetting(String name, boolean defaultValue) { public static boolean getBooleanSetting(String name, boolean defaultValue) {
String s = System.getProperty(name); String s = System.getProperty(name);
......
...@@ -312,11 +312,11 @@ public class Database implements DataHandler { ...@@ -312,11 +312,11 @@ public class Database implements DataHandler {
} }
private void openFileData() throws SQLException { private void openFileData() throws SQLException {
fileData = new DiskFile(this, databaseName+Constants.SUFFIX_DATA_FILE, accessModeData, true, true, Constants.DEFAULT_CACHE_SIZE); fileData = new DiskFile(this, databaseName+Constants.SUFFIX_DATA_FILE, accessModeData, true, true, Constants.CACHE_SIZE_DEFAULT);
} }
private void openFileIndex() throws SQLException { private void openFileIndex() throws SQLException {
fileIndex = new DiskFile(this, databaseName+Constants.SUFFIX_INDEX_FILE, accessModeData, false, logIndexChanges, Constants.DEFAULT_CACHE_SIZE_INDEX); fileIndex = new DiskFile(this, databaseName+Constants.SUFFIX_INDEX_FILE, accessModeData, false, logIndexChanges, Constants.CACHE_SIZE_INDEX_DEFAULT);
} }
public DataPage getDataPage() { public DataPage getDataPage() {
...@@ -519,7 +519,7 @@ public class Database implements DataHandler { ...@@ -519,7 +519,7 @@ public class Database implements DataHandler {
addDefaultSetting(SetTypes.DEFAULT_TABLE_TYPE, null, Constants.DEFAULT_TABLE_TYPE); addDefaultSetting(SetTypes.DEFAULT_TABLE_TYPE, null, Constants.DEFAULT_TABLE_TYPE);
addDefaultSetting(SetTypes.TRACE_LEVEL_FILE, null, traceSystem.getLevelFile()); addDefaultSetting(SetTypes.TRACE_LEVEL_FILE, null, traceSystem.getLevelFile());
addDefaultSetting(SetTypes.TRACE_LEVEL_SYSTEM_OUT, null, traceSystem.getLevelSystemOut()); addDefaultSetting(SetTypes.TRACE_LEVEL_SYSTEM_OUT, null, traceSystem.getLevelSystemOut());
addDefaultSetting(SetTypes.CACHE_SIZE, null, Constants.DEFAULT_CACHE_SIZE); addDefaultSetting(SetTypes.CACHE_SIZE, null, Constants.CACHE_SIZE_DEFAULT);
addDefaultSetting(SetTypes.CLUSTER, Constants.CLUSTERING_DISABLED, 0); addDefaultSetting(SetTypes.CLUSTER, Constants.CLUSTERING_DISABLED, 0);
addDefaultSetting(SetTypes.WRITE_DELAY, null, Constants.DEFAULT_WRITE_DELAY); addDefaultSetting(SetTypes.WRITE_DELAY, null, Constants.DEFAULT_WRITE_DELAY);
removeUnusedStorages(); removeUnusedStorages();
......
...@@ -1233,7 +1233,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -1233,7 +1233,7 @@ public class JdbcConnection extends TraceObject implements Connection {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id); debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id);
debugCodeCall("executeQuery", "CALL IDENTITY()"); debugCodeCall("executeQuery", "CALL IDENTITY()");
} }
ResultSet rs = new JdbcResultSet(session, this, statement, result, id, false); ResultSet rs = new JdbcResultSet(session, this, statement, result, id, false, true);
return rs; return rs;
} }
......
...@@ -82,16 +82,16 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -82,16 +82,16 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
checkClosed(); checkClosed();
closeOld(); closeOld();
ResultInterface result; ResultInterface result;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
synchronized(session) { synchronized(session) {
try { try {
setExecutingStatement(command); setExecutingStatement(command);
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
result = command.executeQuery(maxRows, scrollable); result = command.executeQuery(maxRows, scrollable);
} finally { } finally {
setExecutingStatement(null); setExecutingStatement(null);
} }
} }
resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet); resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet, scrollable);
return resultSet; return resultSet;
} catch(Throwable e) { } catch(Throwable e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -155,7 +155,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -155,7 +155,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
returnsResultSet = true; returnsResultSet = true;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY; boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
ResultInterface result = command.executeQuery(maxRows, scrollable); ResultInterface result = command.executeQuery(maxRows, scrollable);
resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet); resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet, scrollable);
} else { } else {
returnsResultSet = false; returnsResultSet = false;
updateCount = command.executeUpdate(); updateCount = command.executeUpdate();
......
...@@ -46,7 +46,9 @@ import org.h2.value.ValueTimestamp; ...@@ -46,7 +46,9 @@ import org.h2.value.ValueTimestamp;
* and if it contains all columns of a unique index (primary key or other) of this table. * and if it contains all columns of a unique index (primary key or other) of this table.
*/ */
public class JdbcResultSet extends TraceObject implements ResultSet { public class JdbcResultSet extends TraceObject implements ResultSet {
private SessionInterface session; private final SessionInterface session;
private final boolean closeStatement;
private final boolean scrollable;
private ResultInterface result; private ResultInterface result;
private JdbcConnection conn; private JdbcConnection conn;
private JdbcStatement stat; private JdbcStatement stat;
...@@ -54,7 +56,17 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -54,7 +56,17 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
private boolean wasNull; private boolean wasNull;
private Value[] insertRow; private Value[] insertRow;
private Value[] updateRow; private Value[] updateRow;
private boolean closeStatement;
JdbcResultSet(SessionInterface session, JdbcConnection conn, JdbcStatement stat, ResultInterface result, int id, boolean closeStatement, boolean scrollable) {
setTrace(session.getTrace(), TraceObject.RESULT_SET, id);
this.session = session;
this.conn = conn;
this.stat = stat;
this.result = result;
columnCount = result.getVisibleColumnCount();
this.closeStatement = closeStatement;
this.scrollable = scrollable;
}
/** /**
* Moves the cursor to the next row of the result set. * Moves the cursor to the next row of the result set.
...@@ -65,7 +77,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -65,7 +77,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
try { try {
debugCodeCall("next"); debugCodeCall("next");
checkClosed(); checkClosed();
return result.next(); return nextRow();
} catch(Throwable e) { } catch(Throwable e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -2481,7 +2493,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2481,7 +2493,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
try { try {
debugCodeCall("beforeFirst"); debugCodeCall("beforeFirst");
checkClosed(); checkClosed();
result.reset(); if(result.getRowId() >= 0) {
resetResult();
}
} catch(Throwable e) { } catch(Throwable e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -2496,7 +2510,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2496,7 +2510,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
try { try {
debugCodeCall("afterLast"); debugCodeCall("afterLast");
checkClosed(); checkClosed();
while (result.next()) { while (nextRow()) {
// nothing // nothing
} }
} catch(Throwable e) { } catch(Throwable e) {
...@@ -2514,8 +2528,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2514,8 +2528,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
try { try {
debugCodeCall("first"); debugCodeCall("first");
checkClosed(); checkClosed();
result.reset(); if(result.getRowId() < 0) {
return result.next(); return nextRow();
} else {
resetResult();
return nextRow();
}
} catch(Throwable e) { } catch(Throwable e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -2555,14 +2573,11 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2555,14 +2573,11 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
} else if (rowNumber > result.getRowCount() + 1) { } else if (rowNumber > result.getRowCount() + 1) {
rowNumber = result.getRowCount() + 1; rowNumber = result.getRowCount() + 1;
} }
// if (rowNumber == 0) {
// throw Message.getInvalidValueException("" + rowNumber, "rowNumber");
// } else
if (rowNumber <= result.getRowId()) { if (rowNumber <= result.getRowId()) {
result.reset(); resetResult();
} }
while (result.getRowId() + 1 < rowNumber) { while (result.getRowId() + 1 < rowNumber) {
result.next(); nextRow();
} }
int row = result.getRowId(); int row = result.getRowId();
return row >= 0 && row < result.getRowCount(); return row >= 0 && row < result.getRowCount();
...@@ -2786,16 +2801,6 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2786,16 +2801,6 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
// ============================================================= // =============================================================
JdbcResultSet(SessionInterface session, JdbcConnection conn, JdbcStatement stat, ResultInterface result, int id, boolean closeStatement) {
setTrace(session.getTrace(), TraceObject.RESULT_SET, id);
this.session = session;
this.conn = conn;
this.stat = stat;
this.result = result;
columnCount = result.getVisibleColumnCount();
this.closeStatement = closeStatement;
}
private UpdatableRow getUpdatableRow() throws SQLException { private UpdatableRow getUpdatableRow() throws SQLException {
UpdatableRow row = new UpdatableRow(conn, result, session); UpdatableRow row = new UpdatableRow(conn, result, session);
if(!row.isUpdatable()) { if(!row.isUpdatable()) {
...@@ -2894,6 +2899,21 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2894,6 +2899,21 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
return conn; return conn;
} }
private boolean nextRow() throws SQLException {
boolean next = result.next();
if(!next && !scrollable) {
result.close();
}
return next;
}
private void resetResult() throws SQLException {
if(!scrollable) {
throw Message.getSQLException(Message.RESULT_SET_NOT_SCROLLABLE);
}
result.reset();
}
/** /**
* [Not supported] Returns the value of the specified column as a row id. * [Not supported] Returns the value of the specified column as a row id.
*/ */
......
...@@ -60,17 +60,17 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -60,17 +60,17 @@ public class JdbcStatement extends TraceObject implements Statement {
} }
CommandInterface command=conn.prepareCommand(sql); CommandInterface command=conn.prepareCommand(sql);
ResultInterface result; ResultInterface result;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
synchronized(session) { synchronized(session) {
setExecutingStatement(command); setExecutingStatement(command);
try { try {
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
result = command.executeQuery(maxRows, scrollable); result = command.executeQuery(maxRows, scrollable);
} finally { } finally {
setExecutingStatement(null); setExecutingStatement(null);
} }
} }
command.close(); command.close();
resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet); resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet, scrollable);
return resultSet; return resultSet;
} catch(Throwable e) { } catch(Throwable e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -149,7 +149,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -149,7 +149,7 @@ public class JdbcStatement extends TraceObject implements Statement {
returnsResultSet = true; returnsResultSet = true;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY; boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
ResultInterface result = command.executeQuery(maxRows, scrollable); ResultInterface result = command.executeQuery(maxRows, scrollable);
resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet); resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet, scrollable);
} else { } else {
returnsResultSet = false; returnsResultSet = false;
updateCount = command.executeUpdate(); updateCount = command.executeUpdate();
......
...@@ -330,6 +330,7 @@ public class Message { ...@@ -330,6 +330,7 @@ public class Message {
public static final int INVALID_CLASS_2 = 90125; public static final int INVALID_CLASS_2 = 90125;
public static final int DATABASE_IS_NOT_PERSISTENT = 90126; public static final int DATABASE_IS_NOT_PERSISTENT = 90126;
public static final int RESULT_SET_NOT_UPDATABLE = 90127; public static final int RESULT_SET_NOT_UPDATABLE = 90127;
public static final int RESULT_SET_NOT_SCROLLABLE = 90128;
public static SQLException addSQL(SQLException e, String sql) { public static SQLException addSQL(SQLException e, String sql) {
if(e instanceof JdbcSQLException) { if(e instanceof JdbcSQLException) {
......
...@@ -150,6 +150,7 @@ ...@@ -150,6 +150,7 @@
90125=Invalid class, expected {0} but got {1} 90125=Invalid class, expected {0} but got {1}
90126=Database is not persistent 90126=Database is not persistent
90127=The result set is not updatable. The query must select all columns from a unique key. Only one table may be selected. 90127=The result set is not updatable. The query must select all columns from a unique key. Only one table may be selected.
90128=The result set is not scrollable and can not be reset. You may need to use conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY).
HY000=General error: {0} HY000=General error: {0}
HY004=Unknown data type: {0} HY004=Unknown data type: {0}
......
...@@ -16,10 +16,10 @@ import org.h2.message.Message; ...@@ -16,10 +16,10 @@ import org.h2.message.Message;
public class Cache2Q implements Cache { public class Cache2Q implements Cache {
public static final String TYPE_NAME = "TQ"; public static final String TYPE_NAME = "TQ";
private static final int MAIN = 1, IN = 2, OUT = 3; private static final int MAIN = 1, IN = 2, OUT = 3;
private final CacheWriter writer;
private int maxSize; private int maxSize;
private CacheWriter writer;
private int percentIn = 20, percentOut = 50; private int percentIn = 20, percentOut = 50;
private int maxMain, maxIn, maxOut; private int maxMain, maxIn, maxOut;
private CacheObject headMain = new CacheHead(); private CacheObject headMain = new CacheHead();
...@@ -32,10 +32,14 @@ public class Cache2Q implements Cache { ...@@ -32,10 +32,14 @@ public class Cache2Q implements Cache {
public Cache2Q(CacheWriter writer, int maxSize) { public Cache2Q(CacheWriter writer, int maxSize) {
this.writer = writer; this.writer = writer;
resize(maxSize);
}
private void resize(int maxSize) {
this.maxSize = maxSize; this.maxSize = maxSize;
this.len = maxSize / 2; this.len = MathUtils.nextPowerOf2(maxSize / 2);
MathUtils.checkPowerOf2(len);
this.mask = len - 1; this.mask = len - 1;
MathUtils.checkPowerOf2(len);
clear(); clear();
} }
...@@ -306,6 +310,7 @@ public class Cache2Q implements Cache { ...@@ -306,6 +310,7 @@ public class Cache2Q implements Cache {
public void setMaxSize(int newSize) throws SQLException { public void setMaxSize(int newSize) throws SQLException {
maxSize = newSize < 0 ? 0 : newSize; maxSize = newSize < 0 ? 0 : newSize;
recalculateMax(); recalculateMax();
// resize(maxSize);
removeOld(); removeOld();
} }
......
...@@ -19,21 +19,25 @@ public class CacheLRU implements Cache { ...@@ -19,21 +19,25 @@ public class CacheLRU implements Cache {
public static final String TYPE_NAME = "LRU"; public static final String TYPE_NAME = "LRU";
private final CacheWriter writer;
private int len; private int len;
private int maxSize; private int maxSize;
private CacheObject[] values; private CacheObject[] values;
private int mask; private int mask;
private CacheWriter writer;
private int sizeRecords; private int sizeRecords;
private int sizeBlocks; private int sizeBlocks;
private CacheObject head = new CacheHead(); private CacheObject head = new CacheHead();
public CacheLRU(CacheWriter writer, int maxSize) { public CacheLRU(CacheWriter writer, int maxSize) {
this.writer = writer; this.writer = writer;
this.len = maxSize / 2; resize(maxSize);
}
private void resize(int maxSize) {
this.maxSize = maxSize;
this.len = MathUtils.nextPowerOf2(maxSize / 2);
this.mask = len - 1; this.mask = len - 1;
MathUtils.checkPowerOf2(len); MathUtils.checkPowerOf2(len);
this.maxSize = maxSize;
clear(); clear();
} }
...@@ -242,7 +246,9 @@ public class CacheLRU implements Cache { ...@@ -242,7 +246,9 @@ public class CacheLRU implements Cache {
} }
public void setMaxSize(int newSize) throws SQLException { public void setMaxSize(int newSize) throws SQLException {
maxSize = newSize < 0 ? 0 : newSize; newSize = newSize < 0 ? 0 : newSize;
// can not resize, otherwise
// resize(maxSize);
removeOld(); removeOld();
} }
......
...@@ -26,6 +26,14 @@ public class MathUtils { ...@@ -26,6 +26,14 @@ public class MathUtils {
} }
} }
public static int nextPowerOf2(int x) {
int i = 1;
while(i < x && i < (Integer.MAX_VALUE/2)) {
i += i;
}
return (int) i;
}
public static long scaleUp50Percent(long start, long min, long blockSize) { public static long scaleUp50Percent(long start, long min, long blockSize) {
while(start < min) { while(start < min) {
start += start / 2; start += start / 2;
......
...@@ -14,20 +14,22 @@ import org.h2.tools.SimpleResultSet; ...@@ -14,20 +14,22 @@ import org.h2.tools.SimpleResultSet;
public class ValueResultSet extends Value { public class ValueResultSet extends Value {
private ResultSet result; private final ResultSet result;
private ValueResultSet(ResultSet rs) {
this.result = rs;
}
public static ValueResultSet get(ResultSet rs) throws SQLException { public static ValueResultSet get(ResultSet rs) throws SQLException {
ValueResultSet val = new ValueResultSet(); ValueResultSet val = new ValueResultSet(rs);
val.result = rs;
return val; return val;
} }
public static ValueResultSet getCopy(ResultSet rs, int maxrows) throws SQLException { public static ValueResultSet getCopy(ResultSet rs, int maxrows) throws SQLException {
ValueResultSet val = new ValueResultSet();
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount(); int columnCount = meta.getColumnCount();
SimpleResultSet simple = new SimpleResultSet(); SimpleResultSet simple = new SimpleResultSet();
val.result = simple; ValueResultSet val = new ValueResultSet(simple);
for(int i=0; i<columnCount; i++) { for(int i=0; i<columnCount; i++) {
String name = meta.getColumnLabel(i+1); String name = meta.getColumnLabel(i+1);
int sqlType = meta.getColumnType(i+1); int sqlType = meta.getColumnType(i+1);
......
...@@ -94,12 +94,11 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2 ...@@ -94,12 +94,11 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
/* /*
ResultSet.close() required for large query (before the database can be deleted, even if conn.close is called)?
make sure INDEX_LOOKUP_NEW = is true by default. make sure INDEX_LOOKUP_NEW = is true by default.
Test Console (batch, javaw, different platforms) Test Console (batch, javaw, different platforms)
test with openoffice (metadata changes) test with openoffice (metadata changes)
set read-committed as the default set read-committed as the default
testHalt testHalt
...@@ -111,8 +110,6 @@ timer test ...@@ -111,8 +110,6 @@ timer test
backup.sql / lob file problem backup.sql / lob file problem
Change documentation and default database for H2 Console: jdbc:h2:~/test
Mail http://sf.net/projects/samooha Mail http://sf.net/projects/samooha
java.lang.Exception: query was too quick; result: 0 time:968 java.lang.Exception: query was too quick; result: 0 time:968
...@@ -173,6 +170,8 @@ CREATE TABLE TEST( ID BIGINT PRIMARY KEY, CREATED TIMESTAMP); ...@@ -173,6 +170,8 @@ CREATE TABLE TEST( ID BIGINT PRIMARY KEY, CREATED TIMESTAMP);
INSERT INTO TEST VALUES(1, '2007-01-01 00:00:00'); INSERT INTO TEST VALUES(1, '2007-01-01 00:00:00');
SELECT * FROM TEST; SELECT * FROM TEST;
Cache size in KB
*/ */
/* /*
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
package org.h2.test.db; package org.h2.test.db;
import java.sql.*; import java.sql.*;
import java.util.ArrayList;
import org.h2.store.FileLister;
import org.h2.test.TestBase; import org.h2.test.TestBase;
public class TestBigResult extends TestBase { public class TestBigResult extends TestBase {
...@@ -13,10 +15,29 @@ public class TestBigResult extends TestBase { ...@@ -13,10 +15,29 @@ public class TestBigResult extends TestBase {
if(config.memory) { if(config.memory) {
return; return;
} }
testCloseConnectionDelete();
testOrderGroup(); testOrderGroup();
testLimitBufferedResult(); testLimitBufferedResult();
} }
private void testCloseConnectionDelete() throws Exception {
deleteDb("bigResult");
Connection conn = getConnection("bigResult");
Statement stat = conn.createStatement();
stat.execute("SET MAX_MEMORY_ROWS 2");
ResultSet rs = stat.executeQuery("SELECT * FROM SYSTEM_RANGE(1, 100)");
while(rs.next()) {
// ignore
}
// rs.close();
conn.close();
deleteDb("bigResult");
ArrayList files = FileLister.getDatabaseFiles(BASE_DIR, "bigResult", true);
if(files.size() > 0) {
error("file not deleted: " + files.get(0));
}
}
private void testLimitBufferedResult() throws Exception { private void testLimitBufferedResult() throws Exception {
deleteDb("bigResult"); deleteDb("bigResult");
Connection conn = getConnection("bigResult"); Connection conn = getConnection("bigResult");
......
...@@ -188,7 +188,8 @@ public class TestFunctions extends TestBase { ...@@ -188,7 +188,8 @@ public class TestFunctions extends TestBase {
} }
public static ResultSet select(Connection conn, String sql) throws SQLException { public static ResultSet select(Connection conn, String sql) throws SQLException {
return conn.createStatement().executeQuery(sql); Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
return stat.executeQuery(sql);
} }
public static ResultSet selectMaxId(Connection conn) throws SQLException { public static ResultSet selectMaxId(Connection conn) throws SQLException {
......
...@@ -35,23 +35,23 @@ public class TestLob extends TestBase { ...@@ -35,23 +35,23 @@ public class TestLob extends TestBase {
if(config.memory) { if(config.memory) {
return; return;
} }
// testLobNoClose(); testLobNoClose();
// testLobTransactions(10); testLobTransactions(10);
testLobTransactions(10000); testLobTransactions(10000);
// testLobRollbackStop(); testLobRollbackStop();
// testLobCopy(); testLobCopy();
// testLobHibernate(); testLobHibernate();
// testLobCopy(false); testLobCopy(false);
// testLobCopy(true); testLobCopy(true);
// testLobCompression(false); testLobCompression(false);
// testLobCompression(true); testLobCompression(true);
// testManyLobs(); testManyLobs();
// testClob(); testClob();
// testUpdateLob(); testUpdateLob();
// testLobReconnect(); testLobReconnect();
// testLob(false); testLob(false);
// testLob(true); testLob(true);
// testJavaObject(); testJavaObject();
} }
private void testLobNoClose() throws Exception { private void testLobNoClose() throws Exception {
...@@ -90,8 +90,7 @@ public class TestLob extends TestBase { ...@@ -90,8 +90,7 @@ public class TestLob extends TestBase {
if(config.logMode == 0) { if(config.logMode == 0) {
return; return;
} }
int testing; // Constants.LOB_CLOSE_BETWEEN_READS = true;
Constants.LOB_CLOSE_BETWEEN_READS = true;
deleteDb("lob"); deleteDb("lob");
Connection conn = reconnect(null); Connection conn = reconnect(null);
......
...@@ -22,7 +22,7 @@ public class TestUpdatableResultSet extends TestBase { ...@@ -22,7 +22,7 @@ public class TestUpdatableResultSet extends TestBase {
private void testScroll() throws Exception { private void testScroll() throws Exception {
deleteDb("updatableResultSet"); deleteDb("updatableResultSet");
Connection conn = getConnection("updatableResultSet"); Connection conn = getConnection("updatableResultSet");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"); stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World'), (3, 'Test')"); stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World'), (3, 'Test')");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论