@Override public int getType() { return lastValue.getType(); }
@Override public int getType() { return 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(); } }
/** * 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); }
/** * 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); }
private long getTime(Value value) { int type; type = value.getType(); switch (type) { case Value.DATE: case Value.TIME: case Value.TIMESTAMP: ValueTimestamp v = (ValueTimestamp) value.convertTo(Value.TIMESTAMP); return v.getTimestamp().getTime(); default: throw new RuleEvaluateException("Invalid type for " + getClass().getName()); } } }
@Override public void createIndexConditions(Session session, TableFilter filter) { if (value.getType() == Value.BOOLEAN) { boolean v = value.getBoolean().booleanValue(); if (!v) { filter.addIndexCondition(IndexCondition.get(Comparison.FALSE, null, this)); } } }
private boolean sameResultAsLast(Session s, Value[] params, Value[] lastParams) { if (!cacheableChecked) { 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; } } return !(!isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR) || !isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)); }
protected List<Value> enumRange(Value firstV, Value lastV) { if (isNull(firstV) || isNull(lastV)) { return null; } if (firstV.getType() != lastV.getType()) { return null; } int type = firstV.getType(); switch (type) { case Value.BYTE: case Value.INT: case Value.LONG: case Value.SHORT: if (lastV.subtract(firstV).getLong() > 200) { return null; } List<Value> enumValues = New.arrayList(10); Value enumValue = firstV; CompareMode compareMode = CompareMode.getInstance(null, 0); while (enumValue.compareTo(lastV, compareMode) <= 0) { enumValues.add(enumValue); Value increase = ValueLong.get(1).convertTo(enumValue.getType()); enumValue = enumValue.add(increase); } return enumValues; default: return null; } }
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; }
@Override public Value getValue(Session 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); }
/** * 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); } }
private byte[] toBytes(Value value) { byte[] bytes; switch (value.getType()) {
/** * Returns the length. * * @return the length */ @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); } }
public ResultSet getResultSet() { SimpleResultSet rs = new SimpleResultSet(); rs.setAutoClose(false); rs.addColumn("X", DataType.convertTypeToSQLType(getType()), MathUtils.convertLongToInt(getPrecision()), getScale()); rs.addRow(getObject()); return rs; }
/** * Extracts expression columns from ValueArray * * @param session the current session * @param value the value to extract columns from * @return array of expression columns */ static Expression[] getExpressionColumns(Session 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 = getNextId(TraceObject.CLOB); o = new JdbcClob(this, v, id); break; } case Value.BLOB: { int id = getNextId(TraceObject.BLOB); o = new JdbcBlob(this, v, id); break; } case Value.JAVA_OBJECT: if (SysProperties.serializeJavaObject) { o = JdbcUtils.deserialize(v.getBytesNoCopy()); break; } default: o = v.getObject(); } return o; }