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

--no commit message

--no commit message
上级 a22f28fa
...@@ -24,6 +24,7 @@ import org.h2.util.StringUtils; ...@@ -24,6 +24,7 @@ import org.h2.util.StringUtils;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueLong;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
import org.h2.value.ValueString; import org.h2.value.ValueString;
import org.h2.value.ValueTime; import org.h2.value.ValueTime;
...@@ -54,6 +55,7 @@ public class Column { ...@@ -54,6 +55,7 @@ public class Column {
private int selectivity; private int selectivity;
private SingleColumnResolver resolver; private SingleColumnResolver resolver;
private String comment; private String comment;
private boolean primaryKey;
// must be equal to ResultSetMetaData columnNoNulls, columnNullable, columnNullableUnknown // must be equal to ResultSetMetaData columnNoNulls, columnNullable, columnNullableUnknown
public static final int NOT_NULLABLE = 0, NULLABLE = 1, NULLABLE_UNKNOWN = 2; public static final int NOT_NULLABLE = 0, NULLABLE = 1, NULLABLE_UNKNOWN = 2;
...@@ -148,6 +150,9 @@ public class Column { ...@@ -148,6 +150,9 @@ public class Column {
value = ValueNull.INSTANCE; value = ValueNull.INSTANCE;
} else { } else {
value = defaultExpression.getValue(session).convertTo(type); value = defaultExpression.getValue(session).convertTo(type);
if(primaryKey) {
session.setLastIdentity(value);
}
} }
} }
if (value == ValueNull.INSTANCE) { if (value == ValueNull.INSTANCE) {
...@@ -203,7 +208,7 @@ public class Column { ...@@ -203,7 +208,7 @@ public class Column {
} }
if(update) { if(update) {
sequence.setStartValue(now + increment); sequence.setStartValue(now + increment);
session.setLastIdentity(now); session.setLastIdentity(ValueLong.get(now));
sequence.flush(); sequence.flush();
} }
} }
...@@ -425,4 +430,8 @@ public class Column { ...@@ -425,4 +430,8 @@ public class Column {
return comment; return comment;
} }
public void setPrimaryKey(boolean primaryKey) {
this.primaryKey = primaryKey;
}
} }
...@@ -654,7 +654,7 @@ public class MetaTable extends Table { ...@@ -654,7 +654,7 @@ public class MetaTable extends Table {
add(rows, new String[]{"h2.lobFilesInDirectories", "" + Constants.LOB_FILES_IN_DIRECTORIES}); add(rows, new String[]{"h2.lobFilesInDirectories", "" + Constants.LOB_FILES_IN_DIRECTORIES});
add(rows, new String[]{"h2.lobFilesPerDirectory", "" + Constants.LOB_FILES_PER_DIRECTORY}); add(rows, new String[]{"h2.lobFilesPerDirectory", "" + Constants.LOB_FILES_PER_DIRECTORY});
add(rows, new String[]{"h2.multiThreadedKernel", "" + Constants.MULTI_THREADED_KERNEL}); add(rows, new String[]{"h2.multiThreadedKernel", "" + Constants.MULTI_THREADED_KERNEL});
add(rows, new String[]{"h2.runFinalizers", "" + Constants.RUN_FINALIZERS}); add(rows, new String[]{"h2.runFinalize", "" + Constants.RUN_FINALIZE});
add(rows, new String[]{"h2.optimizeMinMax", "" + Constants.OPTIMIZE_MIN_MAX}); add(rows, new String[]{"h2.optimizeMinMax", "" + Constants.OPTIMIZE_MIN_MAX});
add(rows, new String[]{"h2.optimizeIn", "" + Constants.OPTIMIZE_IN}); add(rows, new String[]{"h2.optimizeIn", "" + Constants.OPTIMIZE_IN});
add(rows, new String[]{"h2.redoBufferSize", "" + Constants.REDO_BUFFER_SIZE}); add(rows, new String[]{"h2.redoBufferSize", "" + Constants.REDO_BUFFER_SIZE});
...@@ -664,7 +664,7 @@ public class MetaTable extends Table { ...@@ -664,7 +664,7 @@ public class MetaTable extends Table {
add(rows, new String[]{"h2.logAllErrors", "" + Constants.LOG_ALL_ERRORS}); add(rows, new String[]{"h2.logAllErrors", "" + Constants.LOG_ALL_ERRORS});
add(rows, new String[]{"h2.logAllErrorsFile", "" + Constants.LOG_ALL_ERRORS_FILE}); add(rows, new String[]{"h2.logAllErrorsFile", "" + Constants.LOG_ALL_ERRORS_FILE});
add(rows, new String[]{"h2.serverCachedObjects", "" + Constants.SERVER_CACHED_OBJECTS}); add(rows, new String[]{"h2.serverCachedObjects", "" + Constants.SERVER_CACHED_OBJECTS});
add(rows, new String[]{"h2.serverSmallResultSetSize", "" + Constants.SERVER_SMALL_RESULTSET_SIZE}); add(rows, new String[]{"h2.serverSmallResultSetSize", "" + Constants.SERVER_SMALL_RESULT_SET_SIZE});
add(rows, new String[]{"h2.emergencySpaceInitial", "" + Constants.EMERGENCY_SPACE_INITIAL}); add(rows, new String[]{"h2.emergencySpaceInitial", "" + Constants.EMERGENCY_SPACE_INITIAL});
add(rows, new String[]{"h2.emergencySpaceMin", "" + Constants.EMERGENCY_SPACE_MIN}); add(rows, new String[]{"h2.emergencySpaceMin", "" + Constants.EMERGENCY_SPACE_MIN});
add(rows, new String[]{"h2.objectCache", "" + Constants.OBJECT_CACHE}); add(rows, new String[]{"h2.objectCache", "" + Constants.OBJECT_CACHE});
......
...@@ -25,14 +25,14 @@ public class Plan { ...@@ -25,14 +25,14 @@ public class Plan {
this.filters = new TableFilter[count]; this.filters = new TableFilter[count];
System.arraycopy(filters, 0, this.filters, 0, count); System.arraycopy(filters, 0, this.filters, 0, count);
ObjectArray allCond = new ObjectArray(); ObjectArray allCond = new ObjectArray();
ObjectArray allFilt= new ObjectArray(); ObjectArray all = new ObjectArray();
if(condition != null) { if(condition != null) {
allCond.add(condition); allCond.add(condition);
} }
for(int i=0; i<count; i++) { for(int i=0; i<count; i++) {
TableFilter f = filters[i]; TableFilter f = filters[i];
do { do {
allFilt.add(f); all.add(f);
if(f.getJoinCondition() != null) { if(f.getJoinCondition() != null) {
allCond.add(f.getJoinCondition()); allCond.add(f.getJoinCondition());
} }
...@@ -41,8 +41,8 @@ public class Plan { ...@@ -41,8 +41,8 @@ public class Plan {
} }
allConditions = new Expression[allCond.size()]; allConditions = new Expression[allCond.size()];
allCond.toArray(allConditions); allCond.toArray(allConditions);
allFilters = new TableFilter[allFilt.size()]; allFilters = new TableFilter[all.size()];
allFilt.toArray(allFilters); all.toArray(allFilters);
} }
public PlanItem getItem(TableFilter filter) { public PlanItem getItem(TableFilter filter) {
......
...@@ -11,11 +11,26 @@ import org.h2.index.Index; ...@@ -11,11 +11,26 @@ import org.h2.index.Index;
*/ */
public class PlanItem { public class PlanItem {
public double cost; public double cost;
public Index index;
public PlanItem joinPlan; private Index index;
private int todoObjectArray;
private PlanItem joinPlan;
public void setIndex(Index index) {
this.index = index;
}
public Index getIndex() { public Index getIndex() {
return index; return index;
} }
public PlanItem getJoinPlan() {
return joinPlan;
}
public void setJoinPlan(PlanItem joinPlan) {
this.joinPlan = joinPlan;
}
} }
...@@ -225,15 +225,15 @@ public abstract class Table extends SchemaObject { ...@@ -225,15 +225,15 @@ public abstract class Table extends SchemaObject {
*/ */
public PlanItem getBestPlanItem(Session session, int[] masks) throws SQLException { public PlanItem getBestPlanItem(Session session, int[] masks) throws SQLException {
PlanItem item = new PlanItem(); PlanItem item = new PlanItem();
item.index = getScanIndex(session); item.setIndex(getScanIndex(session));
item.cost = item.index.getCost(null); item.cost = item.getIndex().getCost(null);
ObjectArray indexes = getIndexes(); ObjectArray indexes = getIndexes();
for (int i = 1; indexes != null && masks != null && i < indexes.size(); i++) { for (int i = 1; indexes != null && masks != null && i < indexes.size(); i++) {
Index index = (Index) indexes.get(i); Index index = (Index) indexes.get(i);
int cost = index.getCost(masks); int cost = index.getCost(masks);
if (cost < item.cost) { if (cost < item.cost) {
item.cost = cost; item.cost = cost;
item.index = index; item.setIndex(index);
} }
} }
return item; return item;
...@@ -289,6 +289,12 @@ public abstract class Table extends SchemaObject { ...@@ -289,6 +289,12 @@ public abstract class Table extends SchemaObject {
ObjectArray indexes = getIndexes(); ObjectArray indexes = getIndexes();
if(indexes != null) { if(indexes != null) {
remove(indexes, index); remove(indexes, index);
if(index.indexType.isPrimaryKey()) {
Column[] cols = index.getColumns();
for(int i=0; i<cols.length; i++) {
cols[i].setPrimaryKey(false);
}
}
} }
} }
...@@ -334,7 +340,7 @@ public abstract class Table extends SchemaObject { ...@@ -334,7 +340,7 @@ public abstract class Table extends SchemaObject {
if(list == null) { if(list == null) {
list = new ObjectArray(); list = new ObjectArray();
} }
// self contraints are two entries in the list // self constraints are two entries in the list
// if(Database.CHECK) { // if(Database.CHECK) {
// if(list.indexOf(obj) >= 0) { // if(list.indexOf(obj) >= 0) {
// throw Message.internal("object already in list: " + obj.getName()); // throw Message.internal("object already in list: " + obj.getName());
......
...@@ -96,7 +96,7 @@ public class TableData extends Table implements RecordReader { ...@@ -96,7 +96,7 @@ public class TableData extends Table implements RecordReader {
} }
} }
} catch(SQLException e2) { } catch(SQLException e2) {
// this could happend, for example on failure in the storage // this could happen, for example on failure in the storage
// but if that is not the case it means there is something wrong with the database // but if that is not the case it means there is something wrong with the database
// TODO log this problem // TODO log this problem
throw e2; throw e2;
...@@ -132,6 +132,7 @@ public class TableData extends Table implements RecordReader { ...@@ -132,6 +132,7 @@ public class TableData extends Table implements RecordReader {
if(column.getNullable()) { if(column.getNullable()) {
throw Message.getSQLException(Message.COLUMN_MUST_NOT_BE_NULLABLE_1, column.getName()); throw Message.getSQLException(Message.COLUMN_MUST_NOT_BE_NULLABLE_1, column.getName());
} }
column.setPrimaryKey(true);
} }
} }
Index index; Index index;
...@@ -175,7 +176,7 @@ public class TableData extends Table implements RecordReader { ...@@ -175,7 +176,7 @@ public class TableData extends Table implements RecordReader {
try { try {
index.remove(session); index.remove(session);
} catch(SQLException e2) { } catch(SQLException e2) {
// this could happend, for example on failure in the storage // this could happen, for example on failure in the storage
// but if that is not the case it means there is something wrong with the database // but if that is not the case it means there is something wrong with the database
// TODO log this problem // TODO log this problem
throw e2; throw e2;
......
...@@ -44,7 +44,11 @@ public class TableFilter implements ColumnResolver { ...@@ -44,7 +44,11 @@ public class TableFilter implements ColumnResolver {
private Expression joinCondition; private Expression joinCondition;
private Row current; private Row current;
private int state; private int state;
private TableFilter join;
private int todo;
private ObjectArray joins;
// private TableFilter join;
private boolean outerJoin; private boolean outerJoin;
private boolean foundOne; private boolean foundOne;
private Expression fullCondition; private Expression fullCondition;
...@@ -70,17 +74,21 @@ public class TableFilter implements ColumnResolver { ...@@ -70,17 +74,21 @@ public class TableFilter implements ColumnResolver {
session.getUser().checkRight(table, Right.SELECT); session.getUser().checkRight(table, Right.SELECT);
} }
table.lock(session, exclusive); table.lock(session, exclusive);
if (join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
join.lock(session, exclusive); getTableFilter(i).lock(session, exclusive);
} }
} }
private TableFilter getTableFilter(int i) {
return (TableFilter) joins.get(i);
}
public PlanItem getBestPlanItem(Session session) throws SQLException { public PlanItem getBestPlanItem(Session session) throws SQLException {
PlanItem item; PlanItem item;
if (indexConditions.size() == 0) { if (indexConditions.size() == 0) {
item = new PlanItem(); item = new PlanItem();
item.index = table.getScanIndex(session); item.setIndex(table.getScanIndex(session));
item.cost = item.index.getCost(null); item.cost = item.getIndex().getCost(null);
} else { } else {
int len = table.getColumns().length; int len = table.getColumns().length;
int[] masks = new int[len]; int[] masks = new int[len];
...@@ -98,27 +106,34 @@ public class TableFilter implements ColumnResolver { ...@@ -98,27 +106,34 @@ public class TableFilter implements ColumnResolver {
} }
item = table.getBestPlanItem(session, masks); item = table.getBestPlanItem(session, masks);
} }
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter j = join; TableFilter join = getTableFilter(i);
setEvaluatable(join);
item.setJoinPlan(join.getBestPlanItem(session));
// TODO optimizer: calculate cost of a join: should use separate expected row number and lookup cost
item.cost += item.cost * item.getJoinPlan().cost;
}
return item;
}
private void setEvaluatable(TableFilter join) {
// this table filter is now evaluatable - in all sub-joins // this table filter is now evaluatable - in all sub-joins
do { do {
Expression e = j.getJoinCondition(); Expression e = join.getJoinCondition();
if(e != null) { if(e != null) {
e.setEvaluatable(this, true); e.setEvaluatable(this, true);
} }
j = j.getJoin(); join = join.getJoin();
} while(j != null); } while(join != null);
item.joinPlan = join.getBestPlanItem(session);
// TODO optimizer: calculate cost of a join: should use separate expected row number and lookup cost
item.cost += item.cost * item.joinPlan.cost;
}
return item;
} }
public void setPlanItem(PlanItem item) { public void setPlanItem(PlanItem item) {
this.index = item.index; this.index = item.getIndex();
if(join != null && item.joinPlan!=null) { for(int i=0; joins != null && i<joins.size(); i++) {
join.setPlanItem(item.joinPlan); TableFilter join = getTableFilter(i);
if(item.getJoinPlan()!=null) {
join.setPlanItem(item.getJoinPlan());
}
} }
} }
...@@ -134,7 +149,8 @@ public class TableFilter implements ColumnResolver { ...@@ -134,7 +149,8 @@ public class TableFilter implements ColumnResolver {
} }
} }
} }
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
if(Constants.CHECK && join==this) { if(Constants.CHECK && join==this) {
throw Message.getInternalError("self join"); throw Message.getInternalError("self join");
} }
...@@ -144,13 +160,15 @@ public class TableFilter implements ColumnResolver { ...@@ -144,13 +160,15 @@ public class TableFilter implements ColumnResolver {
public void startQuery() { public void startQuery() {
scanCount = 0; scanCount = 0;
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.startQuery(); join.startQuery();
} }
} }
public void reset() throws SQLException { public void reset() throws SQLException {
if (join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.reset(); join.reset();
} }
state = BEFORE_FIRST; state = BEFORE_FIRST;
...@@ -190,14 +208,23 @@ public class TableFilter implements ColumnResolver { ...@@ -190,14 +208,23 @@ public class TableFilter implements ColumnResolver {
} }
if(!alwaysFalse) { if(!alwaysFalse) {
cursor = index.find(session, start, end); cursor = index.find(session, start, end);
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.reset(); join.reset();
} }
} }
} else { } else {
// state == FOUND || LAST_ROW // state == FOUND || LAST_ROW
// the last row was ok - try next row of the join // the last row was ok - try next row of the join
if(join != null && join.next()) { boolean found = joins != null;
for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
if(!join.next()) {
found = false;
break;
}
}
if(found) {
return true; return true;
} }
} }
...@@ -233,12 +260,20 @@ public class TableFilter implements ColumnResolver { ...@@ -233,12 +260,20 @@ public class TableFilter implements ColumnResolver {
if(state==FOUND && joinConditionOk) { if(state==FOUND && joinConditionOk) {
foundOne = true; foundOne = true;
} }
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.reset(); join.reset();
}
boolean cont = false;
for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
if(!join.next()) { if(!join.next()) {
continue; cont = true;
} }
} }
if(cont) {
continue;
}
// check if it's ok // check if it's ok
if(state==NULL_ROW || joinConditionOk) { if(state==NULL_ROW || joinConditionOk) {
return true; return true;
...@@ -295,19 +330,16 @@ public class TableFilter implements ColumnResolver { ...@@ -295,19 +330,16 @@ public class TableFilter implements ColumnResolver {
if(on != null) { if(on != null) {
on.mapColumns(this, 0); on.mapColumns(this, 0);
} }
if(join == null) { if(joins == null) {
this.join = filter; this.joins = new ObjectArray();
joins.add(filter);
filter.outerJoin = outer; filter.outerJoin = outer;
if(on != null) { if(on != null) {
TableFilter f = filter; filter.mapAndAddFilter(on);
do {
on.mapColumns(f, 0);
f.addFilterCondition(on, true);
on.createIndexConditions(f);
f = f.join;
} while(f != null);
} }
} else { } else {
int todoAddJoinNestedOrSameLevel;
TableFilter join = getTableFilter(0);
join.addJoin(filter, outer, on); join.addJoin(filter, outer, on);
} }
if(on != null) { if(on != null) {
...@@ -315,8 +347,19 @@ public class TableFilter implements ColumnResolver { ...@@ -315,8 +347,19 @@ public class TableFilter implements ColumnResolver {
} }
} }
private void mapAndAddFilter(Expression on) throws SQLException {
on.mapColumns(this, 0);
addFilterCondition(on, true);
on.createIndexConditions(this);
for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.mapAndAddFilter(on);
}
}
public TableFilter getJoin() { public TableFilter getJoin() {
return join; int todoGetJoin;
return joins == null ? null : getTableFilter(0);
} }
public boolean isJoinOuter() { public boolean isJoinOuter() {
...@@ -392,7 +435,8 @@ public class TableFilter implements ColumnResolver { ...@@ -392,7 +435,8 @@ public class TableFilter implements ColumnResolver {
} }
public void removeJoin() { public void removeJoin() {
this.join = null; int todoRemoveJoin;
this.joins = null;
} }
public Expression getJoinCondition() { public Expression getJoinCondition() {
...@@ -413,7 +457,8 @@ public class TableFilter implements ColumnResolver { ...@@ -413,7 +457,8 @@ public class TableFilter implements ColumnResolver {
public void setFullCondition(Expression condition) { public void setFullCondition(Expression condition) {
this.fullCondition = condition; this.fullCondition = condition;
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.setFullCondition(condition); join.setFullCondition(condition);
} }
} }
...@@ -421,7 +466,8 @@ public class TableFilter implements ColumnResolver { ...@@ -421,7 +466,8 @@ public class TableFilter implements ColumnResolver {
public void optimizeFullCondition(boolean fromOuterJoin) { public void optimizeFullCondition(boolean fromOuterJoin) {
if(fullCondition != null) { if(fullCondition != null) {
fullCondition.addFilterConditions(this, fromOuterJoin || outerJoin); fullCondition.addFilterConditions(this, fromOuterJoin || outerJoin);
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.optimizeFullCondition(fromOuterJoin || outerJoin); join.optimizeFullCondition(fromOuterJoin || outerJoin);
} }
} }
...@@ -434,7 +480,8 @@ public class TableFilter implements ColumnResolver { ...@@ -434,7 +480,8 @@ public class TableFilter implements ColumnResolver {
if(joinCondition != null) { if(joinCondition != null) {
joinCondition.setEvaluatable(filter, b); joinCondition.setEvaluatable(filter, b);
} }
if(join != null) { for(int i=0; joins != null && i<joins.size(); i++) {
TableFilter join = getTableFilter(i);
join.setEvaluatable(filter, b); join.setEvaluatable(filter, b);
} }
} }
......
...@@ -88,7 +88,7 @@ public class TableView extends Table { ...@@ -88,7 +88,7 @@ public class TableView extends Table {
public PlanItem getBestPlanItem(Session session, int[] masks) throws SQLException { public PlanItem getBestPlanItem(Session session, int[] masks) throws SQLException {
PlanItem item = new PlanItem(); PlanItem item = new PlanItem();
item.cost = index.getCost(session, masks); item.cost = index.getCost(session, masks);
item.index = index; item.setIndex(index);
return item; return item;
} }
...@@ -187,7 +187,7 @@ public class TableView extends Table { ...@@ -187,7 +187,7 @@ public class TableView extends Table {
throw Message.getSQLException(Message.VIEW_IS_INVALID_1, getSQL()); throw Message.getSQLException(Message.VIEW_IS_INVALID_1, getSQL());
} }
PlanItem item = getBestPlanItem(session, null); PlanItem item = getBestPlanItem(session, null);
return item.index; return item.getIndex();
} }
public ObjectArray getIndexes() { public ObjectArray getIndexes() {
......
...@@ -19,7 +19,7 @@ import java.util.zip.ZipOutputStream; ...@@ -19,7 +19,7 @@ import java.util.zip.ZipOutputStream;
import org.h2.compress.CompressDeflate; import org.h2.compress.CompressDeflate;
import org.h2.compress.CompressLZF; import org.h2.compress.CompressLZF;
import org.h2.compress.CompressNo; import org.h2.compress.CompressNo;
import org.h2.compress.Compresser; import org.h2.compress.Compressor;
import org.h2.compress.LZFInputStream; import org.h2.compress.LZFInputStream;
import org.h2.compress.LZFOutputStream; import org.h2.compress.LZFOutputStream;
import org.h2.message.Message; import org.h2.message.Message;
...@@ -69,7 +69,7 @@ public class CompressTool { ...@@ -69,7 +69,7 @@ public class CompressTool {
if(in.length < 5) { if(in.length < 5) {
algorithm = "NO"; algorithm = "NO";
} }
Compresser compress = getCompresser(algorithm); Compressor compress = getCompressor(algorithm);
byte[] buff = getBuffer((len < 100 ? len + 100 : len) * 2); byte[] buff = getBuffer((len < 100 ? len + 100 : len) * 2);
int newLen = compress(in, in.length, compress, buff); int newLen = compress(in, in.length, compress, buff);
byte[] out = new byte[newLen]; byte[] out = new byte[newLen];
...@@ -80,13 +80,13 @@ public class CompressTool { ...@@ -80,13 +80,13 @@ public class CompressTool {
/** /**
* INTERNAL * INTERNAL
*/ */
public synchronized int compress(byte[] in, int len, Compresser compress, byte[] out) { public synchronized int compress(byte[] in, int len, Compressor compress, byte[] out) {
int newLen = 0; int newLen = 0;
out[0] = (byte)compress.getAlgorithm(); out[0] = (byte)compress.getAlgorithm();
int start = 1 + writeInt(out, 1, len); int start = 1 + writeInt(out, 1, len);
newLen = compress.compress(in, len, out, start); newLen = compress.compress(in, len, out, start);
if(newLen > len + start || newLen <= 0) { if(newLen > len + start || newLen <= 0) {
out[0] = Compresser.NO; out[0] = Compressor.NO;
System.arraycopy(in, 0, out, start, len); System.arraycopy(in, 0, out, start, len);
newLen = len + start; newLen = len + start;
} }
...@@ -102,7 +102,7 @@ public class CompressTool { ...@@ -102,7 +102,7 @@ public class CompressTool {
*/ */
public byte[] expand(byte[] in) throws SQLException { public byte[] expand(byte[] in) throws SQLException {
int algorithm = in[0]; int algorithm = in[0];
Compresser compress = getCompresser(algorithm); Compressor compress = getCompressor(algorithm);
try { try {
int len = readInt(in, 1); int len = readInt(in, 1);
int start = 1 + getLength(len); int start = 1 + getLength(len);
...@@ -119,7 +119,7 @@ public class CompressTool { ...@@ -119,7 +119,7 @@ public class CompressTool {
*/ */
public void expand(byte[] in, byte[] out, int outPos) throws SQLException { public void expand(byte[] in, byte[] out, int outPos) throws SQLException {
int algorithm = in[0]; int algorithm = in[0];
Compresser compress = getCompresser(algorithm); Compressor compress = getCompressor(algorithm);
try { try {
int len = readInt(in, 1); int len = readInt(in, 1);
int start = 1 + getLength(len); int start = 1 + getLength(len);
...@@ -198,7 +198,7 @@ public class CompressTool { ...@@ -198,7 +198,7 @@ public class CompressTool {
} }
} }
private Compresser getCompresser(String algorithm) throws SQLException { private Compressor getCompressor(String algorithm) throws SQLException {
if(algorithm == null) { if(algorithm == null) {
algorithm = "LZF"; algorithm = "LZF";
} }
...@@ -209,7 +209,7 @@ public class CompressTool { ...@@ -209,7 +209,7 @@ public class CompressTool {
algorithm = algorithm.substring(0, idx); algorithm = algorithm.substring(0, idx);
} }
int a = getCompressAlgorithm(algorithm); int a = getCompressAlgorithm(algorithm);
Compresser compress = getCompresser(a); Compressor compress = getCompressor(a);
compress.setOptions(options); compress.setOptions(options);
return compress; return compress;
} }
...@@ -220,23 +220,23 @@ public class CompressTool { ...@@ -220,23 +220,23 @@ public class CompressTool {
public int getCompressAlgorithm(String algorithm) throws SQLException { public int getCompressAlgorithm(String algorithm) throws SQLException {
algorithm = StringUtils.toUpperEnglish(algorithm); algorithm = StringUtils.toUpperEnglish(algorithm);
if("NO".equals(algorithm)) { if("NO".equals(algorithm)) {
return Compresser.NO; return Compressor.NO;
} else if("LZF".equals(algorithm)) { } else if("LZF".equals(algorithm)) {
return Compresser.LZF; return Compressor.LZF;
} else if("DEFLATE".equals(algorithm)) { } else if("DEFLATE".equals(algorithm)) {
return Compresser.DEFLATE; return Compressor.DEFLATE;
} else { } else {
throw Message.getSQLException(Message.UNSUPPORTED_COMPRESSION_ALGORITHM_1, algorithm); throw Message.getSQLException(Message.UNSUPPORTED_COMPRESSION_ALGORITHM_1, algorithm);
} }
} }
private Compresser getCompresser(int algorithm) throws SQLException { private Compressor getCompressor(int algorithm) throws SQLException {
switch(algorithm) { switch(algorithm) {
case Compresser.NO: case Compressor.NO:
return new CompressNo(); return new CompressNo();
case Compresser.LZF: case Compressor.LZF:
return new CompressLZF(); return new CompressLZF();
case Compresser.DEFLATE: case Compressor.DEFLATE:
return new CompressDeflate(); return new CompressDeflate();
default: default:
throw Message.getSQLException(Message.UNSUPPORTED_COMPRESSION_ALGORITHM_1, ""+algorithm); throw Message.getSQLException(Message.UNSUPPORTED_COMPRESSION_ALGORITHM_1, ""+algorithm);
......
...@@ -193,7 +193,7 @@ public class Csv implements SimpleRowSource { ...@@ -193,7 +193,7 @@ public class Csv implements SimpleRowSource {
private void writeHeader() { private void writeHeader() {
for(int i=0; i<columnNames.length; i++) { for(int i=0; i<columnNames.length; i++) {
if(i>0) { if(i>0) {
writer.print(fieldSeparatorRead); writer.print(fieldSeparatorWrite);
} }
writer.print(columnNames[i]); writer.print(columnNames[i]);
} }
...@@ -476,6 +476,14 @@ public class Csv implements SimpleRowSource { ...@@ -476,6 +476,14 @@ public class Csv implements SimpleRowSource {
this.fieldSeparatorWrite = fieldSeparatorWrite; this.fieldSeparatorWrite = fieldSeparatorWrite;
} }
/**
* Override the field separator for reading. The default is ','.
* @param fieldSeparatorRead
*/
public void setFieldSeparatorRead(char fieldSeparatorRead) {
this.fieldSeparatorRead = fieldSeparatorRead;
}
/** /**
* Override the end-of-row marker for writing. The default is null. * Override the end-of-row marker for writing. The default is null.
* @param fieldSeparatorWrite * @param fieldSeparatorWrite
...@@ -489,7 +497,7 @@ public class Csv implements SimpleRowSource { ...@@ -489,7 +497,7 @@ public class Csv implements SimpleRowSource {
* This is not supported at this time, and this methods throws a SQLException * This is not supported at this time, and this methods throws a SQLException
*/ */
public void reset() throws SQLException { public void reset() throws SQLException {
throw new SQLException("Method is notsupported", "CSV"); throw new SQLException("Method is not supported", "CSV");
} }
} }
...@@ -277,7 +277,7 @@ public class Recover implements DataHandler { ...@@ -277,7 +277,7 @@ public class Recover implements DataHandler {
} }
private void writeDataError(PrintWriter writer, String error, byte[] data, int dumpBlocks) throws IOException { private void writeDataError(PrintWriter writer, String error, byte[] data, int dumpBlocks) throws IOException {
writer.println("-- ERROR:" + error + " block:"+block+" blockCount:"+blockCount+" storageId:" + storageId+" recordLength: " + recordLength+" valudId:" + valueId); writer.println("-- ERROR:" + error + " block:"+block+" blockCount:"+blockCount+" storageId:" + storageId+" recordLength: " + recordLength+" valueId:" + valueId);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for(int i=0; i<dumpBlocks * DiskFile.BLOCK_SIZE; i++) { for(int i=0; i<dumpBlocks * DiskFile.BLOCK_SIZE; i++) {
int x = (data[i] & 0xff); int x = (data[i] & 0xff);
......
...@@ -107,7 +107,7 @@ public class RunScript { ...@@ -107,7 +107,7 @@ public class RunScript {
showUsage(); showUsage();
return; return;
} }
// long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
// for(int i=0; i<10; i++) { // for(int i=0; i<10; i++) {
// int test; // int test;
if (options != null) { if (options != null) {
...@@ -116,8 +116,8 @@ public class RunScript { ...@@ -116,8 +116,8 @@ public class RunScript {
execute(url, user, password, script, null, continueOnError); execute(url, user, password, script, null, continueOnError);
} }
// } // }
// time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
// System.out.println("Done in " + time + " ms"); System.out.println("Done in " + time + " ms");
} }
/** /**
...@@ -136,8 +136,8 @@ public class RunScript { ...@@ -136,8 +136,8 @@ public class RunScript {
if (sql == null) { if (sql == null) {
break; break;
} }
boolean resultset = stat.execute(sql); boolean resultSet = stat.execute(sql);
if (resultset) { if (resultSet) {
if (rs != null) { if (rs != null) {
rs.close(); rs.close();
rs = null; rs = null;
......
...@@ -318,7 +318,7 @@ public class Server implements Runnable { ...@@ -318,7 +318,7 @@ public class Server implements Runnable {
/** /**
* Tries to start the server. * Tries to start the server.
* @return the server if successfull * @return the server if successful
* @throws SQLException if the server could not be started * @throws SQLException if the server could not be started
*/ */
public Server start() throws SQLException { public Server start() throws SQLException {
......
...@@ -162,7 +162,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -162,7 +162,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
/** /**
* Moves the cursor to the next row of the result set. * Moves the cursor to the next row of the result set.
* *
* @return true if successfull, false if there are no more rows * @return true if successful, false if there are no more rows
*/ */
public boolean next() throws SQLException { public boolean next() throws SQLException {
if (source != null) { if (source != null) {
...@@ -1228,30 +1228,30 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1228,30 +1228,30 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
return (Column) columns.get(i); return (Column) columns.get(i);
} }
//#ifdef JDK16 //#ifdef JDK16
/* /*
public RowId getRowId(int columnIndex) throws SQLException { public RowId getRowId(int columnIndex) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
//#ifdef JDK16 //#ifdef JDK16
/* /*
public RowId getRowId(String columnName) throws SQLException { public RowId getRowId(String columnName) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public void updateRowId(int columnIndex, RowId x) throws SQLException { public void updateRowId(int columnIndex, RowId x) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
...@@ -1293,76 +1293,76 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1293,76 +1293,76 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
} }
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public void updateNClob(int columnIndex, NClob nClob) throws SQLException { public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public void updateNClob(String columnName, NClob nClob) throws SQLException { public void updateNClob(String columnName, NClob nClob) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public NClob getNClob(int columnIndex) throws SQLException { public NClob getNClob(int columnIndex) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public NClob getNClob(String columnName) throws SQLException { public NClob getNClob(String columnName) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public SQLXML getSQLXML(int columnIndex) throws SQLException { public SQLXML getSQLXML(int columnIndex) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public SQLXML getSQLXML(String columnName) throws SQLException { public SQLXML getSQLXML(String columnName) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public void updateSQLXML(String columnName, SQLXML xmlObject) throws SQLException { public void updateSQLXML(String columnName, SQLXML xmlObject) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
public String getNString(int columnIndex) throws SQLException { public String getNString(int columnIndex) throws SQLException {
...@@ -1395,22 +1395,22 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1395,22 +1395,22 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
} }
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
//#ifdef JDK16 //#ifdef JDK16
/* /*
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
*/ */
//#endif //#endif
/** INTERNAL */ /** INTERNAL */
public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
......
...@@ -55,7 +55,7 @@ public class IOUtils { ...@@ -55,7 +55,7 @@ public class IOUtils {
} }
public static long copyAndCloseInput(InputStream in, OutputStream out) throws IOException { public static long copyAndCloseInput(InputStream in, OutputStream out) throws IOException {
int written = 0; long written = 0;
try { try {
byte[] buffer = new byte[4 * 1024]; byte[] buffer = new byte[4 * 1024];
while(true) { while(true) {
...@@ -145,6 +145,7 @@ public class IOUtils { ...@@ -145,6 +145,7 @@ public class IOUtils {
} }
public static String readStringAndClose(Reader in, int length) throws IOException { public static String readStringAndClose(Reader in, int length) throws IOException {
try {
if(length <= 0) { if(length <= 0) {
length = Integer.MAX_VALUE; length = Integer.MAX_VALUE;
} }
...@@ -160,8 +161,10 @@ public class IOUtils { ...@@ -160,8 +161,10 @@ public class IOUtils {
out.write(buff, 0, len); out.write(buff, 0, len);
length -= len; length -= len;
} }
in.close();
return out.toString(); return out.toString();
} finally {
in.close();
}
} }
public static int readFully(InputStream in, byte[] buffer, int max) throws IOException { public static int readFully(InputStream in, byte[] buffer, int max) throws IOException {
......
...@@ -35,7 +35,7 @@ public class MathUtils { ...@@ -35,7 +35,7 @@ public class MathUtils {
} }
public static BigDecimal setScale(BigDecimal bd, int scale) throws SQLException { public static BigDecimal setScale(BigDecimal bd, int scale) throws SQLException {
if(scale > Constants.BIGDECIMAL_SCALE_MAX) { if(scale > Constants.BIG_DECIMAL_SCALE_MAX) {
throw Message.getInvalidValueException(""+scale, "scale"); throw Message.getInvalidValueException(""+scale, "scale");
} else if(scale < 0) { } else if(scale < 0) {
throw Message.getInvalidValueException(""+scale, "scale"); throw Message.getInvalidValueException(""+scale, "scale");
......
...@@ -24,19 +24,19 @@ import org.h2.message.Message; ...@@ -24,19 +24,19 @@ import org.h2.message.Message;
public class StringUtils { public class StringUtils {
// TODO hack for gcj // TODO hack for gcj
//#GCJHACK private static final Class[] gcjClasses = { //#GCJHACK private static final Class[] gcjClasses = {
//#GCJHACK gnu.gcj.convert.Input_ASCII.class, //#GCJHACK gnu.gcj.convert.Input_ASCII.class,
//#GCJHACK gnu.gcj.convert.Input_UTF8.class, //#GCJHACK gnu.gcj.convert.Input_UTF8.class,
//#GCJHACK gnu.gcj.convert.Input_8859_1.class, //#GCJHACK gnu.gcj.convert.Input_8859_1.class,
//#GCJHACK gnu.gcj.convert.Output_ASCII.class, //#GCJHACK gnu.gcj.convert.Output_ASCII.class,
//#GCJHACK gnu.gcj.convert.Output_UTF8.class, //#GCJHACK gnu.gcj.convert.Output_UTF8.class,
//#GCJHACK gnu.gcj.convert.UnicodeToBytes.class, //#GCJHACK gnu.gcj.convert.UnicodeToBytes.class,
//#GCJHACK gnu.gcj.convert.BytesToUnicode.class, //#GCJHACK gnu.gcj.convert.BytesToUnicode.class,
//#GCJHACK gnu.java.locale.Calendar.class, //#GCJHACK gnu.java.locale.Calendar.class,
//#GCJHACK gnu.java.locale.LocaleInformation.class, //#GCJHACK gnu.java.locale.LocaleInformation.class,
//#GCJHACK gnu.java.locale.LocaleInformation_de.class, //#GCJHACK gnu.java.locale.LocaleInformation_de.class,
//#GCJHACK java.util.GregorianCalendar.class, //#GCJHACK java.util.GregorianCalendar.class,
//#GCJHACK }; //#GCJHACK };
public static boolean equals(String a, String b) { public static boolean equals(String a, String b) {
if(a==null) { if(a==null) {
...@@ -127,7 +127,7 @@ public class StringUtils { ...@@ -127,7 +127,7 @@ public class StringUtils {
return buff.toString(); return buff.toString();
} }
public static String addAsterix(String s, int index) { public static String addAsterisk(String s, int index) {
if (s != null && index < s.length()) { if (s != null && index < s.length()) {
s = s.substring(0, index) + "[*]" + s.substring(index); s = s.substring(0, index) + "[*]" + s.substring(index);
} }
...@@ -135,7 +135,7 @@ public class StringUtils { ...@@ -135,7 +135,7 @@ public class StringUtils {
} }
private static SQLException getFormatException(String s, int i) { private static SQLException getFormatException(String s, int i) {
return Message.getSQLException(Message.STRING_FORMAT_ERROR_1, addAsterix(s, i)); return Message.getSQLException(Message.STRING_FORMAT_ERROR_1, addAsterisk(s, i));
} }
public static String javaDecode(String s) throws SQLException { public static String javaDecode(String s) throws SQLException {
...@@ -378,8 +378,8 @@ public class StringUtils { ...@@ -378,8 +378,8 @@ public class StringUtils {
* Formats a date using a format string * Formats a date using a format string
*/ */
public static String formatDateTime(Date date, String format, String locale, String timezone) throws SQLException { public static String formatDateTime(Date date, String format, String locale, String timezone) throws SQLException {
SimpleDateFormat sdf = getDateFormat(format, locale, timezone); SimpleDateFormat dateFormat = getDateFormat(format, locale, timezone);
return sdf.format(date); return dateFormat.format(date);
} }
/** /**
......
...@@ -534,7 +534,7 @@ public class DataType { ...@@ -534,7 +534,7 @@ public class DataType {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
if(type == Value.JAVA_OBJECT) { if(type == Value.JAVA_OBJECT) {
// serialize JAVA_OBJECTs, even if the type is known // serialize JAVA_OBJECT, even if the type is known
if(Constants.SERIALIZE_JAVA_OBJECTS) { if(Constants.SERIALIZE_JAVA_OBJECTS) {
return ValueJavaObject.getNoCopy(ByteUtils.serialize(x)); return ValueJavaObject.getNoCopy(ByteUtils.serialize(x));
} }
......
...@@ -49,7 +49,7 @@ public class Transfer { ...@@ -49,7 +49,7 @@ public class Transfer {
} }
protected void finalize() { protected void finalize() {
if (!Constants.RUN_FINALIZERS) { if (!Constants.RUN_FINALIZE) {
return; return;
} }
if(socket != null) { if(socket != null) {
......
...@@ -161,7 +161,7 @@ public class ValueDecimal extends Value { ...@@ -161,7 +161,7 @@ public class ValueDecimal extends Value {
} else if (DEC_ONE.equals(dec)) { } else if (DEC_ONE.equals(dec)) {
return ONE; return ONE;
} }
// TODO value optimization: find a way to read size of bigdecimal, // TODO value optimization: find a way to read size of BigDecimal,
// check max cache size // check max cache size
return (ValueDecimal) Value.cache(new ValueDecimal(dec)); return (ValueDecimal) Value.cache(new ValueDecimal(dec));
} }
......
...@@ -534,7 +534,7 @@ public class ValueLob extends Value { ...@@ -534,7 +534,7 @@ public class ValueLob extends Value {
// } // }
public int getDisplaySize() { public int getDisplaySize() {
// TODO displaysize of lob? // TODO display size of lob?
return 40; return 40;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论