Unverified 提交 1484337a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1122 from katzyn/misc

Assorted changes
...@@ -5320,7 +5320,7 @@ public class Parser { ...@@ -5320,7 +5320,7 @@ public class Parser {
if (isPersistent) { if (isPersistent) {
db.addSchemaObject(targetSession, view); db.addSchemaObject(targetSession, view);
view.lock(targetSession, true, true); view.lock(targetSession, true, true);
targetSession.getDatabase().removeSchemaObject(targetSession, view); db.removeSchemaObject(targetSession, view);
} else { } else {
session.removeLocalTempTable(view); session.removeLocalTempTable(view);
} }
...@@ -5330,7 +5330,7 @@ public class Parser { ...@@ -5330,7 +5330,7 @@ public class Parser {
isPersistent); isPersistent);
} }
// both removeSchemaObject and removeLocalTempTable hold meta locks // both removeSchemaObject and removeLocalTempTable hold meta locks
targetSession.getDatabase().unlockMeta(targetSession); db.unlockMeta(targetSession);
} }
view.setTableExpression(true); view.setTableExpression(true);
view.setTemporary(!isPersistent); view.setTemporary(!isPersistent);
...@@ -5929,8 +5929,8 @@ public class Parser { ...@@ -5929,8 +5929,8 @@ public class Parser {
boolean isDualTable(String tableName) { boolean isDualTable(String tableName) {
return ((schemaName == null || equalsToken(schemaName, "SYS")) && equalsToken("DUAL", tableName)) return ((schemaName == null || equalsToken(schemaName, "SYS")) && equalsToken("DUAL", tableName))
|| (database.getMode().sysDummy1 && (schemaName == null || equalsToken(schemaName, "SYSIBM"))) || (database.getMode().sysDummy1 && (schemaName == null || equalsToken(schemaName, "SYSIBM"))
&& equalsToken("SYSDUMMY1", tableName); && equalsToken("SYSDUMMY1", tableName));
} }
private Table readTableOrView() { private Table readTableOrView() {
......
...@@ -7,11 +7,9 @@ package org.h2.command.dml; ...@@ -7,11 +7,9 @@ package org.h2.command.dml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
...@@ -48,7 +46,6 @@ import org.h2.util.ColumnNamer; ...@@ -48,7 +46,6 @@ import org.h2.util.ColumnNamer;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.CompareMode;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -111,7 +108,7 @@ public class Select extends Query { ...@@ -111,7 +108,7 @@ public class Select extends Query {
/** /**
* Maps an expression object to an index, to use in accessing the Object[] pointed to by groupByData. * Maps an expression object to an index, to use in accessing the Object[] pointed to by groupByData.
*/ */
private final HashMap<Expression,Integer> exprToIndexInGroupByData = new HashMap<>(); final HashMap<Expression,Integer> exprToIndexInGroupByData = new HashMap<>();
/** /**
* Map of group-by key to group-by expression data e.g. AggregateData * Map of group-by key to group-by expression data e.g. AggregateData
*/ */
...@@ -119,7 +116,7 @@ public class Select extends Query { ...@@ -119,7 +116,7 @@ public class Select extends Query {
/** /**
* Key into groupByData that produces currentGroupByExprData. Not used in lazy mode. * Key into groupByData that produces currentGroupByExprData. Not used in lazy mode.
*/ */
private ValueArray currentGroupsKey; ValueArray currentGroupsKey;
private int havingIndex; private int havingIndex;
private boolean isGroupQuery, isGroupSortedQuery; private boolean isGroupQuery, isGroupSortedQuery;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
package org.h2.expression; package org.h2.expression;
import java.util.HashMap;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.command.dml.Select; import org.h2.command.dml.Select;
......
...@@ -7,7 +7,6 @@ package org.h2.expression; ...@@ -7,7 +7,6 @@ package org.h2.expression;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap;
import org.h2.api.Aggregate; import org.h2.api.Aggregate;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.Parser; import org.h2.command.Parser;
......
...@@ -1026,39 +1026,6 @@ public final class DataUtils { ...@@ -1026,39 +1026,6 @@ public final class DataUtils {
} }
} }
/**
* An entry of a map.
*
* @param <K> the key type
* @param <V> the value type
*/
public static final class MapEntry<K, V> implements Map.Entry<K, V> {
private final K key;
private final V value;
public MapEntry(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
throw newUnsupportedOperationException("Updating the value is not supported");
}
}
/** /**
* Get the configuration parameter value, or default. * Get the configuration parameter value, or default.
* *
......
...@@ -673,7 +673,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -673,7 +673,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
@Override @Override
public Entry<K, V> next() { public Entry<K, V> next() {
K k = cursor.next(); K k = cursor.next();
return new DataUtils.MapEntry<>(k, cursor.getValue()); return new SimpleImmutableEntry<>(k, cursor.getValue());
} }
@Override @Override
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
package org.h2.mvstore.db; package org.h2.mvstore.db;
import java.util.AbstractMap;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -18,7 +19,6 @@ import org.h2.index.BaseIndex; ...@@ -18,7 +19,6 @@ import org.h2.index.BaseIndex;
import org.h2.index.Cursor; import org.h2.index.Cursor;
import org.h2.index.IndexType; import org.h2.index.IndexType;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.tx.Transaction; import org.h2.mvstore.tx.Transaction;
import org.h2.mvstore.tx.TransactionMap; import org.h2.mvstore.tx.TransactionMap;
import org.h2.result.Row; import org.h2.result.Row;
...@@ -261,7 +261,7 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -261,7 +261,7 @@ public class MVPrimaryIndex extends BaseIndex {
Collections.<Entry<Value, Value>> emptyList().iterator()); Collections.<Entry<Value, Value>> emptyList().iterator());
} }
Value value = map.get(v); Value value = map.get(v);
Entry<Value, Value> e = new DataUtils.MapEntry<Value, Value>(v, value); Entry<Value, Value> e = new AbstractMap.SimpleImmutableEntry<Value, Value>(v, value);
List<Entry<Value, Value>> list = Collections.singletonList(e); List<Entry<Value, Value>> list = Collections.singletonList(e);
MVStoreCursor c = new MVStoreCursor(session, list.iterator()); MVStoreCursor c = new MVStoreCursor(session, list.iterator());
c.next(); c.next();
......
...@@ -9,6 +9,8 @@ import org.h2.mvstore.Cursor; ...@@ -9,6 +9,8 @@ import org.h2.mvstore.Cursor;
import org.h2.mvstore.DataUtils; import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap; import org.h2.mvstore.MVMap;
import org.h2.mvstore.type.DataType; import org.h2.mvstore.type.DataType;
import java.util.AbstractMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
...@@ -671,7 +673,7 @@ public class TransactionMap<K, V> { ...@@ -671,7 +673,7 @@ public class TransactionMap<K, V> {
if (data != null && data.value != null) { if (data != null && data.value != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final V value = (V) data.value; final V value = (V) data.value;
current = new DataUtils.MapEntry<>(key, value); current = new AbstractMap.SimpleImmutableEntry<>(key, value);
currentKey = key; currentKey = key;
return; return;
} }
......
...@@ -7,13 +7,12 @@ package org.h2.value; ...@@ -7,13 +7,12 @@ package org.h2.value;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList; import java.util.Arrays;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.Utils;
/** /**
* Implementation of the ARRAY data type. * Implementation of the ARRAY data type.
...@@ -29,10 +28,6 @@ public class ValueArray extends Value { ...@@ -29,10 +28,6 @@ public class ValueArray extends Value {
this.values = list; this.values = list;
} }
private ValueArray(Value[] list) {
this(Object.class, list);
}
/** /**
* Get or create a array value for the given value array. * Get or create a array value for the given value array.
* Do not clone the data. * Do not clone the data.
...@@ -41,7 +36,7 @@ public class ValueArray extends Value { ...@@ -41,7 +36,7 @@ public class ValueArray extends Value {
* @return the value * @return the value
*/ */
public static ValueArray get(Value[] list) { public static ValueArray get(Value[] list) {
return new ValueArray(list); return new ValueArray(Object.class, list);
} }
/** /**
...@@ -211,18 +206,28 @@ public class ValueArray extends Value { ...@@ -211,18 +206,28 @@ public class ValueArray extends Value {
if (!force) { if (!force) {
return this; return this;
} }
ArrayList<Value> list = Utils.newSmallArrayList(); int length = values.length;
for (Value v : values) { Value[] newValues = new Value[length];
v = v.convertPrecision(precision, true); int i = 0;
boolean modified = false;
for (; i < length; i++) {
Value old = values[i];
Value v = old.convertPrecision(precision, true);
if (v != old) {
modified = true;
}
// empty byte arrays or strings have precision 0 // empty byte arrays or strings have precision 0
// they count as precision 1 here // they count as precision 1 here
precision -= Math.max(1, v.getPrecision()); precision -= Math.max(1, v.getPrecision());
if (precision < 0) { if (precision < 0) {
break; break;
} }
list.add(v); newValues[i] = v;
}
if (i < length) {
return get(componentType, Arrays.copyOf(newValues, i));
} }
return get(list.toArray(new Value[0])); return modified ? get(componentType, newValues) : this;
} }
} }
...@@ -849,6 +849,19 @@ public abstract class TestBase { ...@@ -849,6 +849,19 @@ public abstract class TestBase {
assertFalse(message, rs1.next()); assertFalse(message, rs1.next());
} }
/**
* Check if two objects are the same, and if not throw an exception.
*
* @param expected the expected value
* @param actual the actual value
* @throws AssertionError if the objects are not the same
*/
public void assertSame(Object expected, Object actual) {
if (expected != actual) {
fail(" expected: " + expected + " != actual: " + actual);
}
}
/** /**
* Check if the first value is larger or equal than the second value, and if * Check if the first value is larger or equal than the second value, and if
* not throw an exception. * not throw an exception.
......
...@@ -61,6 +61,7 @@ public class TestValue extends TestBase { ...@@ -61,6 +61,7 @@ public class TestValue extends TestBase {
testCastTrim(); testCastTrim();
testValueResultSet(); testValueResultSet();
testDataType(); testDataType();
testArray();
testUUID(); testUUID();
testDouble(false); testDouble(false);
testDouble(true); testDouble(true);
...@@ -330,6 +331,27 @@ public class TestValue extends TestBase { ...@@ -330,6 +331,27 @@ public class TestValue extends TestBase {
assertEquals(123123123, ts.getNanos()); assertEquals(123123123, ts.getNanos());
} }
private void testArray() {
ValueArray src = ValueArray.get(String.class,
new Value[] {ValueString.get("1"), ValueString.get("22"), ValueString.get("333")});
assertEquals(6, src.getPrecision());
assertSame(src, src.convertPrecision(5, false));
assertSame(src, src.convertPrecision(6, true));
ValueArray exp = ValueArray.get(String.class,
new Value[] {ValueString.get("1"), ValueString.get("22"), ValueString.get("33")});
Value got = src.convertPrecision(5, true);
assertEquals(exp, got);
assertEquals(String.class, ((ValueArray) got).getComponentType());
exp = ValueArray.get(String.class, new Value[] {ValueString.get("1"), ValueString.get("22")});
got = src.convertPrecision(3, true);
assertEquals(exp, got);
assertEquals(String.class, ((ValueArray) got).getComponentType());
exp = ValueArray.get(String.class, new Value[0]);
got = src.convertPrecision(0, true);
assertEquals(exp, got);
assertEquals(String.class, ((ValueArray) got).getComponentType());
}
private void testUUID() { private void testUUID() {
long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L; long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论