mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
decrease JdbcParameter memory used
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public final class JdbcParameterDate implements JdbcParameter {
|
||||
|
||||
private final Date value;
|
||||
|
||||
public JdbcParameterDate(Date value){
|
||||
|
||||
@@ -6,12 +6,32 @@ import java.util.Calendar;
|
||||
|
||||
public final class JdbcParameterDecimal implements JdbcParameter {
|
||||
|
||||
private final BigDecimal value;
|
||||
private final BigDecimal value;
|
||||
|
||||
public JdbcParameterDecimal(BigDecimal value){
|
||||
public static JdbcParameterDecimal NULL = new JdbcParameterDecimal(null);
|
||||
public static JdbcParameterDecimal ZERO = new JdbcParameterDecimal(BigDecimal.ZERO);
|
||||
public static JdbcParameterDecimal TEN = new JdbcParameterDecimal(BigDecimal.TEN);
|
||||
|
||||
private JdbcParameterDecimal(BigDecimal value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static JdbcParameterDecimal valueOf(BigDecimal x) {
|
||||
if (x == null) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (x == BigDecimal.ZERO) {
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
if (x == BigDecimal.TEN) {
|
||||
return TEN;
|
||||
}
|
||||
|
||||
return new JdbcParameterDecimal(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
|
||||
@@ -4,12 +4,30 @@ import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
|
||||
public final class JdbcParameterInt implements JdbcParameter {
|
||||
|
||||
private static JdbcParameterInt[] cache;
|
||||
|
||||
static {
|
||||
int cacheSize = 127;
|
||||
cache = new JdbcParameterInt[cacheSize];
|
||||
for (int i = 0; i < cache.length; ++i) {
|
||||
cache[i] = new JdbcParameterInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
private final int value;
|
||||
|
||||
public JdbcParameterInt(int value){
|
||||
private JdbcParameterInt(int value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static JdbcParameterInt valueOf(int value) {
|
||||
if (value >= 0 && value < cache.length) {
|
||||
return cache[value];
|
||||
}
|
||||
|
||||
return new JdbcParameterInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
|
||||
@@ -4,12 +4,29 @@ import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
|
||||
public final class JdbcParameterLong implements JdbcParameter {
|
||||
|
||||
private static JdbcParameterLong[] cache;
|
||||
|
||||
static {
|
||||
int cacheSize = 127;
|
||||
cache = new JdbcParameterLong[cacheSize];
|
||||
for (int i = 0; i < cache.length; ++i) {
|
||||
cache[i] = new JdbcParameterLong(i);
|
||||
}
|
||||
}
|
||||
|
||||
private final long value;
|
||||
|
||||
public JdbcParameterLong(long value){
|
||||
private JdbcParameterLong(long value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static JdbcParameterLong valueOf(long value) {
|
||||
if (value >= 0 && value < cache.length) {
|
||||
return cache[(int) value];
|
||||
}
|
||||
|
||||
return new JdbcParameterLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
|
||||
@@ -1,12 +1,36 @@
|
||||
package com.alibaba.druid.proxy.jdbc;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
|
||||
public final class JdbcParameterNull implements JdbcParameter {
|
||||
|
||||
private final int sqlType;
|
||||
private final int sqlType;
|
||||
|
||||
public JdbcParameterNull(int sqlType){
|
||||
public final static JdbcParameterNull CHAR = new JdbcParameterNull(Types.CHAR);
|
||||
public final static JdbcParameterNull VARCHAR = new JdbcParameterNull(Types.VARCHAR);
|
||||
public final static JdbcParameterNull NVARCHAR = new JdbcParameterNull(Types.NVARCHAR);
|
||||
|
||||
public final static JdbcParameterNull BINARY = new JdbcParameterNull(Types.BINARY);
|
||||
public final static JdbcParameterNull VARBINARY = new JdbcParameterNull(Types.VARBINARY);
|
||||
|
||||
public final static JdbcParameterNull TINYINT = new JdbcParameterNull(Types.TINYINT);
|
||||
public final static JdbcParameterNull SMALLINT = new JdbcParameterNull(Types.SMALLINT);
|
||||
public final static JdbcParameterNull INTEGER = new JdbcParameterNull(Types.INTEGER);
|
||||
public final static JdbcParameterNull BIGINT = new JdbcParameterNull(Types.BIGINT);
|
||||
|
||||
public final static JdbcParameterNull DECIMAL = new JdbcParameterNull(Types.DECIMAL);
|
||||
public final static JdbcParameterNull NUMERIC = new JdbcParameterNull(Types.NUMERIC);
|
||||
public final static JdbcParameterNull FLOAT = new JdbcParameterNull(Types.FLOAT);
|
||||
public final static JdbcParameterNull DOUBLE = new JdbcParameterNull(Types.DOUBLE);
|
||||
|
||||
public final static JdbcParameterNull NULL = new JdbcParameterNull(Types.NULL);
|
||||
|
||||
public final static JdbcParameterNull DATE = new JdbcParameterNull(Types.DATE);
|
||||
public final static JdbcParameterNull TIME = new JdbcParameterNull(Types.TIME);
|
||||
public final static JdbcParameterNull TIMESTAMP = new JdbcParameterNull(Types.TIMESTAMP);
|
||||
|
||||
private JdbcParameterNull(int sqlType){
|
||||
this.sqlType = sqlType;
|
||||
}
|
||||
|
||||
@@ -30,4 +54,50 @@ public final class JdbcParameterNull implements JdbcParameter {
|
||||
return sqlType;
|
||||
}
|
||||
|
||||
public static JdbcParameterNull valueOf(int sqlType) {
|
||||
switch (sqlType) {
|
||||
case Types.TINYINT:
|
||||
return INTEGER;
|
||||
case Types.SMALLINT:
|
||||
return SMALLINT;
|
||||
case Types.INTEGER:
|
||||
return INTEGER;
|
||||
case Types.BIGINT:
|
||||
return BIGINT;
|
||||
|
||||
case Types.DECIMAL:
|
||||
return DECIMAL;
|
||||
case Types.NUMERIC:
|
||||
return NUMERIC;
|
||||
case Types.FLOAT:
|
||||
return FLOAT;
|
||||
case Types.DOUBLE:
|
||||
return DOUBLE;
|
||||
|
||||
case Types.CHAR:
|
||||
return CHAR;
|
||||
case Types.VARCHAR:
|
||||
return VARCHAR;
|
||||
case Types.NVARCHAR:
|
||||
return NVARCHAR;
|
||||
|
||||
case Types.BINARY:
|
||||
return BINARY;
|
||||
case Types.VARBINARY:
|
||||
return VARBINARY;
|
||||
|
||||
case Types.TIME:
|
||||
return TIME;
|
||||
case Types.DATE:
|
||||
return DATE;
|
||||
case Types.TIMESTAMP:
|
||||
return TIMESTAMP;
|
||||
|
||||
case Types.NULL:
|
||||
return NULL;
|
||||
|
||||
default:
|
||||
return new JdbcParameterNull(sqlType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,30 +612,47 @@ public class PreparedStatementProxyImpl extends StatementProxyImpl implements Pr
|
||||
}
|
||||
|
||||
private JdbcParameter createParemeter(int x) {
|
||||
return new JdbcParameterInt(x);
|
||||
return JdbcParameterInt.valueOf(x);
|
||||
}
|
||||
|
||||
private JdbcParameter createParameter(long x) {
|
||||
return new JdbcParameterLong(x);
|
||||
return JdbcParameterLong.valueOf(x);
|
||||
}
|
||||
|
||||
private JdbcParameter createParameterNull(int sqlType) {
|
||||
return new JdbcParameterNull(sqlType);
|
||||
return JdbcParameterNull.valueOf(sqlType);
|
||||
|
||||
}
|
||||
|
||||
private JdbcParameter createParameter(java.util.Date x) {
|
||||
if (x == null) {
|
||||
return JdbcParameterNull.DATE;
|
||||
}
|
||||
|
||||
return new JdbcParameterDate(x);
|
||||
}
|
||||
|
||||
private JdbcParameter createParameter(BigDecimal x) {
|
||||
return new JdbcParameterDecimal(x);
|
||||
if (x == null) {
|
||||
return JdbcParameterNull.DECIMAL;
|
||||
}
|
||||
|
||||
return JdbcParameterDecimal.valueOf(x);
|
||||
}
|
||||
|
||||
private JdbcParameter createParameter(String x) {
|
||||
if (x == null) {
|
||||
return JdbcParameterNull.VARCHAR;
|
||||
}
|
||||
|
||||
return new JdbcParameterString(x);
|
||||
}
|
||||
|
||||
private JdbcParameter createParameter(Timestamp x) {
|
||||
if (x == null) {
|
||||
return JdbcParameterNull.TIMESTAMP;
|
||||
}
|
||||
|
||||
return new JdbcParameterTimestamp(x);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user