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

Faster data conversion from BIGINT or INT to DECIMAL.

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