private static ValueInt checkRange(long x) { if (x < Integer.MIN_VALUE || x > Integer.MAX_VALUE) { throw DbException.get(ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1, Long.toString(x)); } return ValueInt.get((int) x); }
/** * Get or create an int value for the given int. * * @param i the int * @return the value */ public static ValueInt get(int i) { if (i >= 0 && i < STATIC_SIZE) { return STATIC_CACHE[i]; } ValueInt v = DYNAMIC_CACHE[i & (DYNAMIC_SIZE - 1)]; if (v == null || v.value != i) { v = new ValueInt(i); DYNAMIC_CACHE[i & (DYNAMIC_SIZE - 1)] = v; } return v; }
@Override public Value add(Value v) { ValueInt other = (ValueInt) v; return checkRange((long) value + (long) other.value); }
@Override public String getSQL() { return getString(); }
@Override public Value getValue(Session session) { return ValueInt.get(prepared.getCurrentRowNumber()); }
@Override public Value subtract(Value v) { ValueInt other = (ValueInt) v; return checkRange((long) value - (long) other.value); }
public void setInt(int value) { this.expression = ValueExpression.get(ValueInt.get(value)); }
@Override public Value multiply(Value v) { ValueInt other = (ValueInt) v; return checkRange((long) value * (long) other.value); }
@Override Value getValue(Database database, int dataType, boolean distinct) { if (distinct) { count = 0; } Value v = null; int s = 0; if (count == 0) { s = 0; } else { m2 += distinctHashes.size(); m2 = 100 * m2 / count; s = (int) m2; s = s <= 0 ? 1 : s > 100 ? 100 : s; } v = ValueInt.get(s); return v.convertTo(dataType); } }
@Override public Value negate() { return checkRange(-(long) value); }
/** * Updates a column in the current or insert row. * * @param columnIndex (1,2,...) * @param x the value * @throws SQLException if the result set is closed or not updatable */ @Override public void updateInt(int columnIndex, int x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateInt(" + columnIndex + ", " + x + ");"); } update(columnIndex, ValueInt.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
/** * Sets the value of a parameter. * * @param parameterIndex the parameter index (1, 2, ...) * @param x the value * @throws SQLException if this object is closed */ @Override public void setInt(int parameterIndex, int x) throws SQLException { try { if (isDebugEnabled()) { debugCode("setInt(" + parameterIndex + ", " + x + ");"); } setParameter(parameterIndex, ValueInt.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
/** * Updates a column in the current or insert row. * * @param columnLabel the column label * @param x the value * @throws SQLException if the result set is closed or not updatable */ @Override public void updateInt(String columnLabel, int x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateInt(" + quote(columnLabel) + ", " + x + ");"); } update(columnLabel, ValueInt.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
int value = rs.getInt(columnIndex); v = rs.wasNull() ? (Value) ValueNull.INSTANCE : ValueInt.get(value); break;
return ValueLong.get(((Long) x).longValue()); } else if (x instanceof Integer) { return ValueInt.get(((Integer) x).intValue()); } else if (x instanceof BigDecimal) { return ValueDecimal.get((BigDecimal) x);
expressionSQL.add(sql); o.columnIndexExpr = ValueExpression.get(ValueInt.get(idx + 1)); Expression expr = expressions.get(idx).getNonAliasExpression(); o.expression = expr;
switch (getType()) { case BOOLEAN: return ValueInt.get(getBoolean().booleanValue() ? 1 : 0); case BYTE: return ValueInt.get(getByte()); case SHORT: return ValueInt.get(getShort()); case LONG: return ValueInt.get(convertToInt(getLong())); case DECIMAL: return ValueInt.get(convertToInt(convertToLong(getBigDecimal()))); case DOUBLE: return ValueInt.get(convertToInt(convertToLong(getDouble()))); case FLOAT: return ValueInt.get(convertToInt(convertToLong(getFloat()))); case BYTES: return ValueInt.get((int) Long.parseLong(getString(), 16)); return ValueShort.get(Short.parseShort(s.trim())); case INT: return ValueInt.get(Integer.parseInt(s.trim())); case LONG: return ValueLong.get(Long.parseLong(s.trim()));