提交 1f88b71e authored 作者: Thomas Mueller's avatar Thomas Mueller

Faster data conversion from BIGINT or INT to DECIMAL.

上级 f9ade50f
...@@ -18,7 +18,7 @@ Change Log ...@@ -18,7 +18,7 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>- <ul><li>Faster data conversion from BIGINT or INT to DECIMAL.
</li></ul> </li></ul>
<h2>Version 1.2.126 (2009-12-18)</h2> <h2>Version 1.2.126 (2009-12-18)</h2>
......
...@@ -105,13 +105,13 @@ public class RuleFixed implements Rule { ...@@ -105,13 +105,13 @@ public class RuleFixed implements Rule {
public String random(Bnf config, int level) { public String random(Bnf config, int level) {
Random r = config.getRandom(); Random r = config.getRandom();
switch(type) { switch (type) {
case YMD: case YMD:
return "" + (1800 + r.nextInt(200)) + "-" + (1 + r.nextInt(12)) + "-" + (1 + r.nextInt(31)); return (1800 + r.nextInt(200)) + "-" + (1 + r.nextInt(12)) + "-" + (1 + r.nextInt(31));
case HMS: case HMS:
return ""+(r.nextInt(24))+"-"+(r.nextInt(60))+"-"+(r.nextInt(60)); return (r.nextInt(24)) + "-" + (r.nextInt(60)) + "-" + (r.nextInt(60));
case NANOS: case NANOS:
return ""+(r.nextInt(100000)+r.nextInt(10000)); return "" + (r.nextInt(100000) + r.nextInt(10000));
case ANY_UNTIL_EOL: case ANY_UNTIL_EOL:
case ANY_EXCEPT_SINGLE_QUOTE: case ANY_EXCEPT_SINGLE_QUOTE:
case ANY_EXCEPT_DOUBLE_QUOTE: case ANY_EXCEPT_DOUBLE_QUOTE:
......
...@@ -56,7 +56,7 @@ public class Right extends DbObjectBase { ...@@ -56,7 +56,7 @@ public class Right extends DbObjectBase {
} }
public Right(Database db, int id, RightOwner grantee, int grantedRight, Table grantedRightOnTable) { public Right(Database db, int id, RightOwner grantee, int grantedRight, Table grantedRightOnTable) {
initDbObjectBase(db, id, ""+id, Trace.USER); initDbObjectBase(db, id, "" + id, Trace.USER);
this.grantee = grantee; this.grantee = grantee;
this.grantedRight = grantedRight; this.grantedRight = grantedRight;
this.grantedTable = grantedRightOnTable; this.grantedTable = grantedRightOnTable;
......
...@@ -705,7 +705,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -705,7 +705,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
debugCode("getBigDecimal(" + StringUtils.quoteJavaString(columnLabel)+", "+scale+");"); debugCode("getBigDecimal(" + StringUtils.quoteJavaString(columnLabel)+", "+scale+");");
} }
if (scale < 0) { if (scale < 0) {
throw Message.getInvalidValueException(""+scale, "scale"); throw Message.getInvalidValueException("" + scale, "scale");
} }
BigDecimal bd = get(columnLabel).getBigDecimal(); BigDecimal bd = get(columnLabel).getBigDecimal();
return bd == null ? null : MathUtils.setScale(bd, scale); return bd == null ? null : MathUtils.setScale(bd, scale);
...@@ -727,10 +727,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -727,10 +727,10 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
try { try {
if (isDebugEnabled()) { if (isDebugEnabled()) {
debugCode("getBigDecimal(" + columnIndex+", "+scale+");"); debugCode("getBigDecimal(" + columnIndex + ", " + scale + ");");
} }
if (scale < 0) { if (scale < 0) {
throw Message.getInvalidValueException(""+scale, "scale"); throw Message.getInvalidValueException("" + scale, "scale");
} }
BigDecimal bd = get(columnIndex).getBigDecimal(); BigDecimal bd = get(columnIndex).getBigDecimal();
return bd == null ? null : MathUtils.setScale(bd, scale); return bd == null ? null : MathUtils.setScale(bd, scale);
......
...@@ -374,7 +374,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -374,7 +374,7 @@ public class JdbcStatement extends TraceObject implements Statement {
debugCodeCall("setMaxRows", maxRows); debugCodeCall("setMaxRows", maxRows);
checkClosed(); checkClosed();
if (maxRows < 0) { if (maxRows < 0) {
throw Message.getInvalidValueException(""+maxRows, "maxRows"); throw Message.getInvalidValueException("" + maxRows, "maxRows");
} }
this.maxRows = maxRows; this.maxRows = maxRows;
} catch (Exception e) { } catch (Exception e) {
...@@ -692,7 +692,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -692,7 +692,7 @@ public class JdbcStatement extends TraceObject implements Statement {
// nothing to do // nothing to do
break; break;
default: default:
throw Message.getInvalidValueException(""+current, "current"); throw Message.getInvalidValueException("" + current, "current");
} }
return false; return false;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -1078,11 +1078,11 @@ public class MetaTable extends Table { ...@@ -1078,11 +1078,11 @@ public class MetaTable extends Table {
// JAVA_METHOD // JAVA_METHOD
alias.getJavaMethodName(), alias.getJavaMethodName(),
// DATA_TYPE // DATA_TYPE
""+DataType.convertTypeToSQLType(method.getDataType()), "" + DataType.convertTypeToSQLType(method.getDataType()),
// COLUMN_COUNT INT // COLUMN_COUNT INT
""+ method.getColumnClasses().length, "" + method.getColumnClasses().length,
// RETURNS_RESULT SMALLINT // RETURNS_RESULT SMALLINT
""+ returnsResult, "" + returnsResult,
// REMARKS // REMARKS
replaceNullWithEmpty(alias.getComment()), replaceNullWithEmpty(alias.getComment()),
// ID // ID
...@@ -1106,11 +1106,11 @@ public class MetaTable extends Table { ...@@ -1106,11 +1106,11 @@ public class MetaTable extends Table {
// JAVA_METHOD // JAVA_METHOD
"", "",
// DATA_TYPE // DATA_TYPE
""+DataType.convertTypeToSQLType(Value.NULL), "" + DataType.convertTypeToSQLType(Value.NULL),
// COLUMN_COUNT INT // COLUMN_COUNT INT
"1", "1",
// RETURNS_RESULT SMALLINT // RETURNS_RESULT SMALLINT
""+ returnsResult, "" + returnsResult,
// REMARKS // REMARKS
replaceNullWithEmpty(agg.getComment()), replaceNullWithEmpty(agg.getComment()),
// ID // ID
......
...@@ -673,7 +673,7 @@ public class TableFilter implements ColumnResolver { ...@@ -673,7 +673,7 @@ public class TableFilter implements ColumnResolver {
} }
public String toString() { public String toString() {
return alias != null ? alias : "" + table; return alias != null ? alias : table.toString();
} }
/** /**
......
...@@ -25,6 +25,7 @@ public class Profiler implements Runnable { ...@@ -25,6 +25,7 @@ public class Profiler implements Runnable {
"java.lang.Thread.dumpThreads," + "java.lang.Thread.dumpThreads," +
"java.net.PlainSocketImpl.socketAccept," + "java.net.PlainSocketImpl.socketAccept," +
"java.net.SocketInputStream.socketRead0," + "java.net.SocketInputStream.socketRead0," +
"java.net.SocketOutputStream.socketWrite0," +
"java.lang.UNIXProcess.waitForProcessExit," + "java.lang.UNIXProcess.waitForProcessExit," +
"java.lang.Object.wait," + "java.lang.Object.wait," +
"java.lang.Thread.sleep," + "java.lang.Thread.sleep," +
......
...@@ -54,7 +54,7 @@ public class SortedProperties extends Properties { ...@@ -54,7 +54,7 @@ public class SortedProperties extends Properties {
* @return the value if set, or the default value if not * @return the value if set, or the default value if not
*/ */
public static boolean getBooleanProperty(Properties prop, String key, boolean def) { public static boolean getBooleanProperty(Properties prop, String key, boolean def) {
String value = prop.getProperty(key, ""+def); String value = prop.getProperty(key, "" + def);
try { try {
return Boolean.valueOf(value).booleanValue(); return Boolean.valueOf(value).booleanValue();
} catch (Exception e) { } catch (Exception e) {
...@@ -72,7 +72,7 @@ public class SortedProperties extends Properties { ...@@ -72,7 +72,7 @@ public class SortedProperties extends Properties {
* @return the value if set, or the default value if not * @return the value if set, or the default value if not
*/ */
public static int getIntProperty(Properties prop, String key, int def) { public static int getIntProperty(Properties prop, String key, int def) {
String value = prop.getProperty(key, ""+def); String value = prop.getProperty(key, "" + def);
try { try {
return MathUtils.decodeInt(value); return MathUtils.decodeInt(value);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -748,7 +748,7 @@ public class DataType { ...@@ -748,7 +748,7 @@ public class DataType {
case Types.ARRAY: case Types.ARRAY:
return Value.ARRAY; return Value.ARRAY;
default: default:
throw Message.getSQLException(ErrorCode.UNKNOWN_DATA_TYPE_1, ""+sqlType); throw Message.getSQLException(ErrorCode.UNKNOWN_DATA_TYPE_1, "" + sqlType);
} }
} }
......
...@@ -154,8 +154,8 @@ public abstract class Value { ...@@ -154,8 +154,8 @@ public abstract class Value {
public static final int TYPE_COUNT = STRING_FIXED + 1; public static final int TYPE_COUNT = STRING_FIXED + 1;
private static SoftReference<Value[]> softCache = new SoftReference<Value[]>(null); private static SoftReference<Value[]> softCache = new SoftReference<Value[]>(null);
private static final BigDecimal MAX_LONG_DECIMAL = new BigDecimal("" + Long.MAX_VALUE); private static final BigDecimal MAX_LONG_DECIMAL = BigDecimal.valueOf(Long.MAX_VALUE);
private static final BigDecimal MIN_LONG_DECIMAL = new BigDecimal("" + Long.MIN_VALUE); private static final BigDecimal MIN_LONG_DECIMAL = BigDecimal.valueOf(Long.MIN_VALUE);
/** /**
* Get the SQL expression for this value. * Get the SQL expression for this value.
...@@ -592,15 +592,15 @@ public abstract class Value { ...@@ -592,15 +592,15 @@ public abstract class Value {
// convert to string is required for JDK 1.4 // convert to string is required for JDK 1.4
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueDecimal.get(new BigDecimal(getBoolean().booleanValue() ? "1" : "0")); return ValueDecimal.get(BigDecimal.valueOf(getBoolean().booleanValue() ? 1 : 0));
case BYTE: case BYTE:
return ValueDecimal.get(new BigDecimal("" + getByte())); return ValueDecimal.get(BigDecimal.valueOf(getByte()));
case SHORT: case SHORT:
return ValueDecimal.get(new BigDecimal("" + getShort())); return ValueDecimal.get(BigDecimal.valueOf(getShort()));
case INT: case INT:
return ValueDecimal.get(new BigDecimal("" + getInt())); return ValueDecimal.get(BigDecimal.valueOf(getInt()));
case LONG: case LONG:
return ValueDecimal.get(new BigDecimal("" + getLong())); return ValueDecimal.get(BigDecimal.valueOf(getLong()));
case DOUBLE: { case DOUBLE: {
double d = getDouble(); double d = getDouble();
if (Double.isInfinite(d) || Double.isNaN(d)) { if (Double.isInfinite(d) || Double.isNaN(d)) {
...@@ -611,7 +611,7 @@ public abstract class Value { ...@@ -611,7 +611,7 @@ public abstract class Value {
case FLOAT: { case FLOAT: {
float f = getFloat(); float f = getFloat();
if (Float.isInfinite(f) || Float.isNaN(f)) { if (Float.isInfinite(f) || Float.isNaN(f)) {
throw Message.getSQLException(ErrorCode.DATA_CONVERSION_ERROR_1, ""+f); throw Message.getSQLException(ErrorCode.DATA_CONVERSION_ERROR_1, "" + f);
} }
return ValueDecimal.get(new BigDecimal(f)); return ValueDecimal.get(new BigDecimal(f));
} }
......
...@@ -34,7 +34,7 @@ public class ValueBoolean extends Value { ...@@ -34,7 +34,7 @@ public class ValueBoolean extends Value {
private final Boolean value; private final Boolean value;
private ValueBoolean(boolean value) { private ValueBoolean(boolean value) {
this.value = Boolean.valueOf(""+value); this.value = Boolean.valueOf(value);
} }
public int getType() { public int getType() {
......
...@@ -32,8 +32,8 @@ public class ValueLong extends Value { ...@@ -32,8 +32,8 @@ public class ValueLong extends Value {
private static final int STATIC_SIZE = 100; private static final int STATIC_SIZE = 100;
private static final ValueLong[] STATIC_CACHE; private static final ValueLong[] STATIC_CACHE;
private static final BigInteger MIN = new BigInteger("" + Long.MIN_VALUE); private static final BigInteger MIN = BigInteger.valueOf(Long.MIN_VALUE);
private static final BigInteger MAX = new BigInteger("" + Long.MAX_VALUE); private static final BigInteger MAX = BigInteger.valueOf(Long.MAX_VALUE);
private final long value; private final long value;
...@@ -120,8 +120,8 @@ public class ValueLong extends Value { ...@@ -120,8 +120,8 @@ public class ValueLong extends Value {
// if(result / value == other.value && result / other.value == value) { // if(result / value == other.value && result / other.value == value) {
// return ValueLong.get(result); // return ValueLong.get(result);
//} //}
BigInteger bv = new BigInteger("" + value); BigInteger bv = BigInteger.valueOf(value);
BigInteger bo = new BigInteger("" + other.value); BigInteger bo = BigInteger.valueOf(other.value);
BigInteger br = bv.multiply(bo); BigInteger br = bv.multiply(bo);
if (br.compareTo(MIN) < 0 || br.compareTo(MAX) > 0) { if (br.compareTo(MIN) < 0 || br.compareTo(MAX) > 0) {
throw getOverflow(); throw getOverflow();
......
...@@ -143,10 +143,10 @@ public class ValueTimestamp extends Value { ...@@ -143,10 +143,10 @@ public class ValueTimestamp extends Value {
public Value convertScale(boolean onlyToSmallerScale, int targetScale) throws SQLException { public Value convertScale(boolean onlyToSmallerScale, int targetScale) throws SQLException {
if (targetScale < 0 || targetScale > DEFAULT_SCALE) { if (targetScale < 0 || targetScale > DEFAULT_SCALE) {
// TODO convertScale for Timestamps: may throw an exception? // TODO convertScale for Timestamps: may throw an exception?
throw Message.getInvalidValueException(""+targetScale, "scale"); throw Message.getInvalidValueException("" + targetScale, "scale");
} }
int nanos = value.getNanos(); int nanos = value.getNanos();
BigDecimal bd = new BigDecimal("" + nanos); BigDecimal bd = BigDecimal.valueOf(nanos);
bd = bd.movePointLeft(9); bd = bd.movePointLeft(9);
bd = MathUtils.setScale(bd, targetScale); bd = MathUtils.setScale(bd, targetScale);
bd = bd.movePointRight(9); bd = bd.movePointRight(9);
......
...@@ -22,7 +22,6 @@ import java.sql.Types; ...@@ -22,7 +22,6 @@ import java.sql.Types;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.message.TraceSystem; import org.h2.message.TraceSystem;
import org.h2.store.FileLock; import org.h2.store.FileLock;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论