@Override public int getType() { return value.getType(); }
@Override public int getType() { return lastValue.getType(); }
@Override public int getType() { return value == null ? dataType : value.getType(); }
/** * Get the memory used by this object. * * @return the memory used in bytes */ public int getMemory() { return DataType.getDataType(getType()).memory; }
@Override public int getType() { if (value != null) { return value.getType(); } if (column != null) { return column.getType(); } return Value.UNKNOWN; }
private static long length(Value v) { switch (v.getType()) { case Value.BLOB: case Value.CLOB: case Value.BYTES: case Value.JAVA_OBJECT: return v.getPrecision(); default: return v.getString().length(); } }
/** * Compare this value against another value using the specified compare * mode. * * @param v the other value * @param mode the compare mode * @return 0 if both values are equal, -1 if the other value is smaller, and * 1 otherwise */ public final int compareTo(Value v, CompareMode mode) { if (this == v) { return 0; } if (this == ValueNull.INSTANCE) { return v == ValueNull.INSTANCE ? 0 : -1; } else if (v == ValueNull.INSTANCE) { return 1; } if (getType() == v.getType()) { return compareSecure(v, mode); } int t2 = Value.getHigherOrder(getType(), v.getType()); return convertTo(t2).compareSecure(v.convertTo(t2), mode); }
/** * Throw the exception that the feature is not support for the given data type. * * @param op the operation * @return never returns normally * @throws DbException the exception */ protected DbException throwUnsupportedExceptionForType(String op) { throw DbException.getUnsupportedException(DataType.getDataType(getType()).name + " " + op); }
@Override public void createIndexConditions(ServerSession session, TableFilter filter) { if (value.getType() == Value.BOOLEAN) { boolean v = ((ValueBoolean) value).getBoolean().booleanValue(); if (!v) { filter.addIndexCondition(IndexCondition.get(Comparison.FALSE, null, this)); } } }
/** * Compare two values with the current comparison mode. The values may be of * different type. * * @param a the first value * @param b the second value * @return 0 if both values are equal, -1 if the first value is smaller, and * 1 otherwise */ public int compareTypeSafe(Value a, Value b) { if (a == b) { return 0; } int dataType = Value.getHigherOrder(a.getType(), b.getType()); a = a.convertTo(dataType); b = b.convertTo(dataType); return a.compareTypeSafe(b, compareMode); }
@Override void merge(Database database, int dataType, boolean distinct, Value v) { count++; if (value == null) { value = v.convertTo(dataType); } else { v = v.convertTo(value.getType()); value = value.add(v); } }
@Override public int update() { Value v = expression.getValue(session); int type = v.getType(); switch (type) { case Value.RESULT_SET: // this will throw an exception // methods returning a result set may not be called like this. return super.update(); case Value.UNKNOWN: case Value.NULL: return 0; default: return v.getInt(); } }
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; } }
private boolean sameResultAsLast(ServerSession s, Value[] params, Value[] lastParams, long lastEval) { if (!cacheableChecked) { long max = getMaxDataModificationId(); noCache = max == Long.MAX_VALUE; cacheableChecked = true; } if (noCache) { return false; } Database db = s.getDatabase(); for (int i = 0; i < params.length; i++) { Value a = lastParams[i], b = params[i]; if (a.getType() != b.getType() || !db.areEqual(a, b)) { return false; } } if (!isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR) || !isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)) { return false; } if (db.getModificationDataId() > lastEval && getMaxDataModificationId() > lastEval) { return false; } return true; }
@Override public Value getValue(ServerSession session) { Value l = left.getValue(session); if (l == ValueNull.INSTANCE) { return l; } boolean result = false; boolean hasNull = false; for (Expression e : valueList) { Value r = e.getValue(session); if (r == ValueNull.INSTANCE) { hasNull = true; } else { r = r.convertTo(l.getType()); result = Comparison.compareNotNull(database, l, r, Comparison.EQUAL); if (result) { break; } } } if (!result && hasNull) { return ValueNull.INSTANCE; } return ValueBoolean.get(result); }
public ResultSet getResultSet() { SimpleResultSet rs = new SimpleResultSet(); rs.addColumn("X", DataType.convertTypeToSQLType(getType()), MathUtils.convertLongToInt(getPrecision()), getScale()); rs.addRow(getObject()); return rs; }
/** * Returns the length. * * @return the length * @throws SQLException */ @Override public long length() throws SQLException { try { debugCodeCall("length"); checkClosed(); if (value.getType() == Value.BLOB) { long precision = value.getPrecision(); if (precision > 0) { return precision; } } return IOUtils.copyAndCloseInput(value.getInputStream(), null); } catch (Exception e) { throw logAndConvert(e); } }
/** * Returns the length. * * @return the length */ @Override public long length() throws SQLException { try { debugCodeCall("length"); checkClosed(); if (value.getType() == Value.CLOB) { long precision = value.getPrecision(); if (precision > 0) { return precision; } } return IOUtils.copyAndCloseInput(value.getReader(), null, Long.MAX_VALUE); } catch (Exception e) { throw logAndConvert(e); } }
/** * Extracts expression columns from ValueArray * * @param session the current session * @param value the value to extract columns from * @return array of expression columns */ public static Expression[] getExpressionColumns(ServerSession session, ValueArray value) { Value[] list = value.getList(); ExpressionColumn[] expr = new ExpressionColumn[list.length]; for (int i = 0, len = list.length; i < len; i++) { Value v = list[i]; Column col = new Column("C" + (i + 1), v.getType(), v.getPrecision(), v.getScale(), v.getDisplaySize()); expr[i] = new ExpressionColumn(session.getDatabase(), col); } return expr; }
/** * Convert an object to the default Java object for the given SQL type. For * example, LOB objects are converted to java.sql.Clob / java.sql.Blob. * * @param v the value * @return the object */ Object convertToDefaultObject(Value v) { Object o; switch (v.getType()) { case Value.CLOB: { int id = getNextTraceId(TraceObject.CLOB); o = new JdbcClob(this, v, id); break; } case Value.BLOB: { int id = getNextTraceId(TraceObject.BLOB); o = new JdbcBlob(this, v, id); break; } case Value.JAVA_OBJECT: if (SysProperties.SERIALIZE_JAVA_OBJECT) { o = Utils.deserialize(v.getBytesNoCopy()); break; } default: o = v.getObject(); } return o; }