提交 15948d7f authored 作者: Thomas Mueller's avatar Thomas Mueller

Remove unused code.

上级 4a10fc4b
......@@ -11,7 +11,6 @@ import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
......@@ -29,7 +28,6 @@ import org.h2.tools.CompressTool;
import org.h2.util.IOUtils;
import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter;
import org.h2.value.Value;
/**
* This class is the base for RunScriptCommand and ScriptCommand.
......@@ -201,10 +199,6 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
session.getDatabase().freeUpDiskSpace();
}
public int compareTypeSave(Value a, Value b) {
throw DbException.throwInternalError();
}
public int getMaxLengthInplaceLob() {
return session.getDatabase().getMaxLengthInplaceLob();
}
......
......@@ -298,7 +298,7 @@ public class Select extends Query {
}
private void queryGroup(int columnCount, LocalResult result) {
ValueHashMap<HashMap<Expression, Object>> groups = ValueHashMap.newInstance(session.getDatabase());
ValueHashMap<HashMap<Expression, Object>> groups = ValueHashMap.newInstance();
int rowNumber = 0;
setCurrentRowNumber(0);
ValueArray defaultGroup = ValueArray.get(new Value[0]);
......
......@@ -48,11 +48,11 @@ class AggregateData {
if (aggregateType == Aggregate.SELECTIVITY) {
count++;
if (distinctValues == null) {
distinctValues = ValueHashMap.newInstance(database);
distinctValues = ValueHashMap.newInstance();
}
int size = distinctValues.size();
if (size > Constants.SELECTIVITY_DISTINCT_COUNT) {
distinctValues = ValueHashMap.newInstance(database);
distinctValues = ValueHashMap.newInstance();
sum += size;
}
distinctValues.put(v, this);
......@@ -68,7 +68,7 @@ class AggregateData {
count++;
if (distinct) {
if (distinctValues == null) {
distinctValues = ValueHashMap.newInstance(database);
distinctValues = ValueHashMap.newInstance();
}
distinctValues.put(v, this);
return;
......
......@@ -33,7 +33,7 @@ public class HashIndex extends BaseIndex {
}
private void reset() {
rows = ValueHashMap.newInstance(table.getDatabase());
rows = ValueHashMap.newInstance();
}
public void truncate(Session session) {
......
......@@ -35,7 +35,7 @@ public class NonUniqueHashIndex extends HashIndex {
}
private void reset() {
rows = ValueHashMap.newInstance(table.getDatabase());
rows = ValueHashMap.newInstance();
rowCount = 0;
}
......
......@@ -59,5 +59,4 @@ public class TreeCursor implements Cursor {
return node != null;
}
}
......@@ -7,6 +7,7 @@
package org.h2.jdbcx;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.sql.Connection;
......@@ -85,7 +86,7 @@ implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Ref
setTrace(factory.getTrace(), TraceObject.DATA_SOURCE, id);
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
initFactory();
in.defaultReadObject();
}
......
......@@ -61,6 +61,7 @@ implements ObjectFactory
if (trace.isDebugEnabled()) {
trace.debug("getObjectInstance obj=" + obj + " name=" + name + " nameCtx=" + nameCtx + " environment=" + environment);
}
if (obj instanceof Reference) {
Reference ref = (Reference) obj;
if (ref.getClassName().equals(JdbcDataSource.class.getName())) {
JdbcDataSource dataSource = new JdbcDataSource();
......@@ -71,6 +72,7 @@ implements ObjectFactory
dataSource.setLoginTimeout(Integer.parseInt(s));
return dataSource;
}
}
return null;
}
//## Java 1.4 end ##
......
......@@ -180,7 +180,7 @@ public class LocalResult implements ResultInterface {
*/
public void setDistinct() {
distinct = true;
distinctRows = ValueHashMap.newInstance(session.getDatabase());
distinctRows = ValueHashMap.newInstance();
}
/**
......
......@@ -8,7 +8,6 @@ package org.h2.store;
import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter;
import org.h2.value.Value;
/**
* A data handler contains a number of callback methods.
......@@ -56,15 +55,6 @@ public interface DataHandler {
*/
void freeUpDiskSpace();
/**
* Compare two values.
*
* @param a the first value
* @param b the second value
* @return 0 for equal, 1 if a is larger than b, and -1 otherwise
*/
int compareTypeSave(Value a, Value b);
/**
* Get the maximum length of a in-place large object
*
......
......@@ -1149,13 +1149,6 @@ public class Recover extends Tool implements DataHandler {
// nothing to do
}
/**
* INTERNAL
*/
public int compareTypeSave(Value a, Value b) {
throw DbException.throwInternalError();
}
/**
* INTERNAL
*/
......
......@@ -8,7 +8,6 @@ package org.h2.util;
import java.util.ArrayList;
import org.h2.message.DbException;
import org.h2.store.DataHandler;
import org.h2.value.Value;
import org.h2.value.ValueNull;
......@@ -21,17 +20,6 @@ public class ValueHashMap<V> extends HashBase {
private Value[] keys;
private V[] values;
private DataHandler handler;
/**
* Create a new value hash map using the given data handler.
* The data handler is used to compare values.
*
* @param handler the data handler
*/
private ValueHashMap(DataHandler handler) {
this.handler = handler;
}
/**
* Create a new value hash map using the given data handler.
......@@ -40,8 +28,8 @@ public class ValueHashMap<V> extends HashBase {
* @param handler the data handler
* @return the object
*/
public static <T> ValueHashMap<T> newInstance(DataHandler handler) {
return new ValueHashMap<T>(handler);
public static <T> ValueHashMap<T> newInstance() {
return new ValueHashMap<T>();
}
@SuppressWarnings("unchecked")
......@@ -95,7 +83,7 @@ public class ValueHashMap<V> extends HashBase {
if (deleted < 0) {
deleted = index;
}
} else if (handler.compareTypeSave(k, key) == 0) {
} else if (k.equals(key)) {
// update existing
values[index] = value;
return;
......@@ -122,7 +110,7 @@ public class ValueHashMap<V> extends HashBase {
return;
} else if (k == ValueNull.DELETED) {
// found a deleted record
} else if (handler.compareTypeSave(k, key) == 0) {
} else if (k.equals(key)) {
// found the record
keys[index] = ValueNull.DELETED;
values[index] = null;
......@@ -152,7 +140,7 @@ public class ValueHashMap<V> extends HashBase {
return null;
} else if (k == ValueNull.DELETED) {
// found a deleted record
} else if (handler.compareTypeSave(k, key) == 0) {
} else if (k.equals(key)) {
// found it
return values[index];
}
......
......@@ -6,6 +6,8 @@
*/
package org.h2.test.jdbcx;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
......@@ -42,6 +44,20 @@ public class TestConnectionPool extends TestBase {
private void testUncommittedTransaction() throws SQLException {
String url = getURL("connectionPool", true), user = getUser(), password = getPassword();
JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
assertEquals(5 * 60, man.getLoginTimeout());
man.setLoginTimeout(1);
assertEquals(1, man.getLoginTimeout());
man.setLoginTimeout(0);
assertEquals(5 * 60, man.getLoginTimeout());
assertEquals(10, man.getMaxConnections());
PrintWriter old = man.getLogWriter();
PrintWriter pw = new PrintWriter(new StringWriter());
man.setLogWriter(pw);
assertTrue(pw == man.getLogWriter());
man.setLogWriter(old);
Connection conn1 = man.getConnection();
assertTrue(conn1.getAutoCommit());
conn1.setAutoCommit(false);
......
......@@ -9,14 +9,16 @@ package org.h2.test.jdbcx;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
import javax.sql.ConnectionEvent;
import javax.sql.ConnectionEventListener;
import javax.sql.XAConnection;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.h2.jdbcx.JdbcDataSource;
import org.h2.jdbcx.JdbcDataSourceFactory;
import org.h2.test.TestBase;
/**
......@@ -24,6 +26,15 @@ import org.h2.test.TestBase;
*/
public class TestDataSource extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
}
// public static void main(String... args) throws SQLException {
//
// // first, need to start on the command line:
......@@ -49,11 +60,37 @@ public class TestDataSource extends TestBase {
// }
public void test() throws Exception {
testDataSourceFactory();
testDataSource();
testXAConnection();
deleteDb("dataSource");
}
private void testDataSourceFactory() throws Exception {
ObjectFactory factory = new JdbcDataSourceFactory();
assertTrue(null == factory.getObjectInstance("test", null, null, null));
Reference ref = new Reference("java.lang.String");
assertTrue(null == factory.getObjectInstance(ref, null, null, null));
ref = new Reference(JdbcDataSource.class.getName());
ref.add(new StringRefAddr("url", "jdbc:h2:mem:"));
ref.add(new StringRefAddr("user", "u"));
ref.add(new StringRefAddr("password", "p"));
ref.add(new StringRefAddr("loginTimeout", "1"));
JdbcDataSource ds = (JdbcDataSource) factory.getObjectInstance(ref, null, null, null);
assertEquals(1, ds.getLoginTimeout());
assertEquals("jdbc:h2:mem:", ds.getURL());
assertEquals("u", ds.getUser());
assertEquals("p", ds.getPassword());
Reference ref2 = ds.getReference();
assertEquals(ref.size(), ref2.size());
assertEquals(ref.get("url").getContent().toString(), ref2.get("url").getContent().toString());
assertEquals(ref.get("user").getContent().toString(), ref2.get("user").getContent().toString());
assertEquals(ref.get("password").getContent().toString(), ref2.get("password").getContent().toString());
assertEquals(ref.get("loginTimeout").getContent().toString(), ref2.get("loginTimeout").getContent().toString());
ds.setPasswordChars("abc".toCharArray());
assertEquals("abc", ds.getPassword());
}
private void testXAConnection() throws Exception {
deleteDb("dataSource");
JdbcDataSource ds = new JdbcDataSource();
......
......@@ -10,7 +10,6 @@ import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import org.h2.message.DbException;
import org.h2.store.Data;
import org.h2.store.DataHandler;
import org.h2.store.FileStore;
......@@ -285,10 +284,6 @@ public class TestDataPage extends TestBase implements DataHandler {
// nothing to do
}
public int compareTypeSave(Value a, Value b) {
throw DbException.throwInternalError();
}
public int getMaxLengthInplaceLob() {
throw new AssertionError();
}
......
......@@ -13,7 +13,6 @@ import org.h2.test.TestBase;
import org.h2.util.IOUtils;
import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter;
import org.h2.value.Value;
/**
* Tests the in-memory file system.
......@@ -138,10 +137,6 @@ public class TestFile extends TestBase implements DataHandler {
// nothing to do
}
public int compareTypeSave(Value a, Value b) {
return 0;
}
public void freeUpDiskSpace() {
// nothing to do
}
......
......@@ -45,7 +45,7 @@ public class TestValueHashMap extends TestBase implements DataHandler {
}
private void testNotANumber() {
ValueHashMap<Integer> map = ValueHashMap.newInstance(this);
ValueHashMap<Integer> map = ValueHashMap.newInstance();
for (int i = 1; i < 100; i++) {
double d = Double.longBitsToDouble(0x7ff0000000000000L | i);
ValueDouble v = ValueDouble.get(d);
......@@ -55,7 +55,7 @@ public class TestValueHashMap extends TestBase implements DataHandler {
}
private void testRandomized() {
ValueHashMap<Value> map = ValueHashMap.newInstance(this);
ValueHashMap<Value> map = ValueHashMap.newInstance();
HashMap<Value, Value> hash = New.hashMap();
Random random = new Random(1);
Comparator<Value> vc = new Comparator<Value>() {
......@@ -127,10 +127,6 @@ public class TestValueHashMap extends TestBase implements DataHandler {
// nothing to do
}
public int compareTypeSave(Value a, Value b) {
return a.compareTo(b, compareMode);
}
public int getMaxLengthInplaceLob() {
return 0;
}
......
......@@ -194,10 +194,6 @@ public class TestValueMemory extends TestBase implements DataHandler {
// nothing to do
}
public int compareTypeSave(Value a, Value b) {
return 0;
}
public void freeUpDiskSpace() {
// nothing to do
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论