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 {
if (isPersistent) {
db.addSchemaObject(targetSession, view);
view.lock(targetSession, true, true);
targetSession.getDatabase().removeSchemaObject(targetSession, view);
db.removeSchemaObject(targetSession, view);
} else {
session.removeLocalTempTable(view);
}
......@@ -5330,7 +5330,7 @@ public class Parser {
isPersistent);
}
// both removeSchemaObject and removeLocalTempTable hold meta locks
targetSession.getDatabase().unlockMeta(targetSession);
db.unlockMeta(targetSession);
}
view.setTableExpression(true);
view.setTemporary(!isPersistent);
......@@ -5929,8 +5929,8 @@ public class Parser {
boolean isDualTable(String tableName) {
return ((schemaName == null || equalsToken(schemaName, "SYS")) && equalsToken("DUAL", tableName))
|| (database.getMode().sysDummy1 && (schemaName == null || equalsToken(schemaName, "SYSIBM")))
&& equalsToken("SYSDUMMY1", tableName);
|| (database.getMode().sysDummy1 && (schemaName == null || equalsToken(schemaName, "SYSIBM"))
&& equalsToken("SYSDUMMY1", tableName));
}
private Table readTableOrView() {
......
......@@ -7,11 +7,9 @@ package org.h2.command.dml;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.TreeMap;
import org.h2.api.ErrorCode;
import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
......@@ -48,7 +46,6 @@ import org.h2.util.ColumnNamer;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
import org.h2.value.CompareMode;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueNull;
......@@ -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.
*/
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
*/
......@@ -119,7 +116,7 @@ public class Select extends Query {
/**
* Key into groupByData that produces currentGroupByExprData. Not used in lazy mode.
*/
private ValueArray currentGroupsKey;
ValueArray currentGroupsKey;
private int havingIndex;
private boolean isGroupQuery, isGroupSortedQuery;
......
......@@ -5,7 +5,6 @@
*/
package org.h2.expression;
import java.util.HashMap;
import org.h2.api.ErrorCode;
import org.h2.command.Parser;
import org.h2.command.dml.Select;
......
......@@ -7,7 +7,6 @@ package org.h2.expression;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import org.h2.api.Aggregate;
import org.h2.api.ErrorCode;
import org.h2.command.Parser;
......
......@@ -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.
*
......
......@@ -673,7 +673,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
@Override
public Entry<K, V> next() {
K k = cursor.next();
return new DataUtils.MapEntry<>(k, cursor.getValue());
return new SimpleImmutableEntry<>(k, cursor.getValue());
}
@Override
......
......@@ -5,6 +5,7 @@
*/
package org.h2.mvstore.db;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
......@@ -18,7 +19,6 @@ import org.h2.index.BaseIndex;
import org.h2.index.Cursor;
import org.h2.index.IndexType;
import org.h2.message.DbException;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.tx.Transaction;
import org.h2.mvstore.tx.TransactionMap;
import org.h2.result.Row;
......@@ -261,7 +261,7 @@ public class MVPrimaryIndex extends BaseIndex {
Collections.<Entry<Value, Value>> emptyList().iterator());
}
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);
MVStoreCursor c = new MVStoreCursor(session, list.iterator());
c.next();
......
......@@ -9,6 +9,8 @@ import org.h2.mvstore.Cursor;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.type.DataType;
import java.util.AbstractMap;
import java.util.Iterator;
import java.util.Map;
......@@ -671,7 +673,7 @@ public class TransactionMap<K, V> {
if (data != null && data.value != null) {
@SuppressWarnings("unchecked")
final V value = (V) data.value;
current = new DataUtils.MapEntry<>(key, value);
current = new AbstractMap.SimpleImmutableEntry<>(key, value);
currentKey = key;
return;
}
......
......@@ -7,13 +7,12 @@ package org.h2.value;
import java.lang.reflect.Array;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Arrays;
import org.h2.engine.Constants;
import org.h2.engine.SysProperties;
import org.h2.util.MathUtils;
import org.h2.util.StatementBuilder;
import org.h2.util.Utils;
/**
* Implementation of the ARRAY data type.
......@@ -29,10 +28,6 @@ public class ValueArray extends Value {
this.values = list;
}
private ValueArray(Value[] list) {
this(Object.class, list);
}
/**
* Get or create a array value for the given value array.
* Do not clone the data.
......@@ -41,7 +36,7 @@ public class ValueArray extends Value {
* @return the value
*/
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 {
if (!force) {
return this;
}
ArrayList<Value> list = Utils.newSmallArrayList();
for (Value v : values) {
v = v.convertPrecision(precision, true);
int length = values.length;
Value[] newValues = new Value[length];
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
// they count as precision 1 here
precision -= Math.max(1, v.getPrecision());
if (precision < 0) {
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 {
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
* not throw an exception.
......
......@@ -61,6 +61,7 @@ public class TestValue extends TestBase {
testCastTrim();
testValueResultSet();
testDataType();
testArray();
testUUID();
testDouble(false);
testDouble(true);
......@@ -330,6 +331,27 @@ public class TestValue extends TestBase {
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() {
long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L;
for (int i = 0; i < 100; i++) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论