@Override public Value negate() { if (value == Long.MIN_VALUE) { throw getOverflow(); } return ValueLong.get(-value); }
@Override public Value getValue(int i) { return i == -1 ? ValueLong.get(key) : data[i]; }
@Override public Value divide(Value v) { ValueLong other = (ValueLong) v; if (other.value == 0) { throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL()); } return ValueLong.get(value / other.value); }
/** {@inheritDoc} */ @Override public Value value(GridKernalContext ctx) { return ValueLong.get(x); }
@Override public Value modulus(Value v) { ValueLong other = (ValueLong) v; if (other.value == 0) { throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL()); } return ValueLong.get(this.value % other.value); }
@Override public Value add(Value v) { ValueLong other = (ValueLong) v; long result = value + other.value; int sv = Long.signum(value); int so = Long.signum(other.value); int sr = Long.signum(result); // if the operands have different signs overflow can not occur // if the operands have the same sign, // and the result has a different sign, then it is an overflow // it can not be an overflow when one of the operands is 0 if (sv != so || sr == so || sv == 0 || so == 0) { return ValueLong.get(result); } throw getOverflow(); }
@Override public boolean next() { if (beforeFirst) { beforeFirst = false; current = start; } else { current += step; } currentRow = session.createRow(new Value[]{ValueLong.get(current)}, 1); return step > 0 ? current <= end : current >= end; }
@Override public Value subtract(Value v) { ValueLong other = (ValueLong) v; int sv = Long.signum(value); int so = Long.signum(other.value); // if the operands have the same sign, then overflow can not occur // if the second operand is 0, then overflow can not occur if (sv == so || so == 0) { return ValueLong.get(value - other.value); } // now, if the other value is Long.MIN_VALUE, it must be an overflow // x - Long.MIN_VALUE overflows for x>=0 return add(other.negate()); }
@Override Value getValue(Database database, int dataType, boolean distinct) { if (distinct) { throw DbException.throwInternalError(); } Value v = ValueLong.get(count); return v == null ? ValueNull.INSTANCE : v.convertTo(dataType); }
@Override Value getValue(Database database, int dataType, boolean distinct) { if (distinct) { if (distinctValues != null) { count = distinctValues.size(); } else { count = 0; } } Value v = ValueLong.get(count); return v.convertTo(dataType); }
private Table getDualTable(boolean noColumns) { Schema main = database.findSchema(Constants.SCHEMA_MAIN); Expression one = ValueExpression.get(ValueLong.get(1)); return new RangeTable(main, one, one, noColumns); }
/** * 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 updateLong(int columnIndex, long x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateLong("+columnIndex+", "+x+"L);"); } update(columnIndex, ValueLong.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 setLong(int parameterIndex, long x) throws SQLException { try { if (isDebugEnabled()) { debugCode("setLong("+parameterIndex+", "+x+"L);"); } setParameter(parameterIndex, ValueLong.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
private static Value divide(Value a, long by) { if (by == 0) { return ValueNull.INSTANCE; } int type = Value.getHigherOrder(a.getType(), Value.LONG); Value b = ValueLong.get(by).convertTo(type); a = a.convertTo(type).divide(b); return a; }
/** * 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 updateLong(String columnLabel, long x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateLong("+quote(columnLabel)+", "+x+"L);"); } update(columnLabel, ValueLong.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
private ValueArray convertToKey(SearchRow r) { if (r == null) { return null; } Value[] array = new Value[keyColumns]; for (int i = 0; i < columns.length; i++) { Column c = columns[i]; int idx = c.getColumnId(); Value v = r.getValue(idx); if (v != null) { array[i] = v.convertTo(c.getType()); } } array[keyColumns - 1] = ValueLong.get(r.getKey()); return ValueArray.get(array); }
private void updateSequenceIfRequired(Session session, Value value) { if (sequence != null) { long current = sequence.getCurrentValue(); long inc = sequence.getIncrement(); long now = value.getLong(); boolean update = false; if (inc > 0 && now > current) { update = true; } else if (inc < 0 && now < current) { update = true; } if (update) { sequence.modify(now + inc, null, null, null); session.setLastIdentity(ValueLong.get(now)); sequence.flush(session); } } }
@Override public Row getRow(Session session, long key) { TransactionMap<Value, Value> map = getMap(session); Value v = map.get(ValueLong.get(key)); if (v == null) { throw DbException.get(ErrorCode.ROW_NOT_FOUND_IN_PRIMARY_INDEX, getSQL() + ": " + key); } ValueArray array = (ValueArray) v; Row row = session.createRow(array.getList(), 0); row.setKey(key); return row; }