/** * @param row Values array row. * @return Objects list row. */ private List<?> row(Value[] row) { List<Object> res = new ArrayList<>(row.length); for (Value v : row) res.add(v.getObject()); return res; }
private Object[] get() { return (Object[]) value.convertTo(Value.ARRAY).getObject(); }
/** {@inheritDoc} */ @Override public boolean equals(Object other) { if (!(other instanceof Value)) return false; Value otherVal = (Value)other; return otherVal.getType() == Value.JAVA_OBJECT && getObject().equals(otherVal.getObject()); }
private static Object[] convertToObjectList(Row row) { if (row == null) { return null; } int len = row.getColumnCount(); Object[] list = new Object[len]; for (int i = 0; i < len; i++) { list[i] = row.getValue(i).getObject(); } return list; }
@Override public Object getObject() { int len = values.length; Object[] list = (Object[]) Array.newInstance(componentType, len); for (int i = 0; i < len; i++) { final Value value = values[i]; if (!SysProperties.OLD_RESULT_SET_GET_OBJECT) { final int type = value.getType(); if (type == Value.BYTE || type == Value.SHORT) { list[i] = value.getInt(); continue; } } list[i] = value.getObject(); } return list; }
@Override protected int compareSecure(Value v, CompareMode mode) { Object o1 = getObject(); Object o2 = v.getObject(); boolean o1Comparable = o1 instanceof Comparable; boolean o2Comparable = o2 instanceof Comparable; if (o1Comparable && o2Comparable && Utils.haveCommonComparableSuperclass(o1.getClass(), o2.getClass())) { @SuppressWarnings("unchecked") Comparable<Object> c1 = (Comparable<Object>) o1; return c1.compareTo(o2); } // group by types if (o1.getClass() != o2.getClass()) { if (o1Comparable != o2Comparable) { return o1Comparable ? -1 : 1; } return o1.getClass().getName().compareTo(o2.getClass().getName()); } // compare hash codes int h1 = hashCode(); int h2 = v.hashCode(); if (h1 == h2) { if (o1.equals(o2)) { return 0; } return Bits.compareNotNullSigned(getBytesNoCopy(), v.getBytesNoCopy()); } return h1 > h2 ? 1 : -1; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected int compareSecure(Value v, CompareMode mode) { Object o1 = getObject(); Object o2 = v.getObject(); boolean o1Comparable = o1 instanceof Comparable; boolean o2Comparable = o2 instanceof Comparable; if (o1Comparable && o2Comparable && Utils.haveCommonComparableSuperclass(o1.getClass(), o2.getClass())) { Comparable<Object> c1 = (Comparable<Object>)o1; return c1.compareTo(o2); } // Group by types. if (o1.getClass() != o2.getClass()) { if (o1Comparable != o2Comparable) return o1Comparable ? -1 : 1; return o1.getClass().getName().compareTo(o2.getClass().getName()); } // Compare hash codes. int h1 = hashCode(); int h2 = v.hashCode(); if (h1 == h2) { if (o1.equals(o2)) return 0; return Bits.compareNotNullSigned(getBytesNoCopy(), v.getBytesNoCopy()); } return h1 > h2 ? 1 : -1; }
/** * @return Default value. */ public Object defaultValue() { Expression dfltExpr = col.getDefaultExpression(); return dfltExpr != null ? col.convert(dfltExpr.getValue(null)).getObject() : null; }
/** * Create argument from AST element. * * @param el Element. * @return DML argument. */ public static DmlArgument create(@Nullable GridSqlElement el) { assert el == null ^ (el instanceof GridSqlConst || el instanceof GridSqlParameter); if (el == null) return NULL_ARG; if (el instanceof GridSqlConst) return new ConstantArgument(((GridSqlConst)el).value().getObject()); else return new ParamArgument(((GridSqlParameter)el).index()); }
/** * Convert value to column's expected type by means of H2. * * @param val Source value. * @param idx Row descriptor. * @param type Expected column type to convert to. * @return Converted object. * @throws IgniteCheckedException if failed. */ public static Object convert(Object val, IgniteH2Indexing idx, int type) throws IgniteCheckedException { if (val == null) return null; int objType = DataType.getTypeFromClass(val.getClass()); if (objType == type) return val; Value h2Val = wrap(idx.objectContext(), val, objType); return h2Val.convertTo(type).getObject(); }
row[c] = val.getObject();
/** * Advance iterator. */ private void advance() { next = null; try { boolean hasNext = false; while (cursor == null || !(hasNext = cursor.next())) { if (idxIter.hasNext()) cursor = idxIter.next().findInStream(null, null); else { releaseIfNeeded(); break; } } if (hasNext) { Row row = cursor.get(); int cols = row.getColumnCount(); List<Object> res = new ArrayList<>(cols); for (int c = 0; c < cols; c++) res.add(row.getValue(c).getObject()); next = res; } } catch (Exception e) { releaseIfNeeded(); throw e; } }
/** * @param row Table row. * @return Segment ID for given row. */ @SuppressWarnings("IfMayBeConditional") protected int segmentForRow(SearchRow row) { assert row != null; if (segmentsCount() == 1 || ctx == null) return 0; CacheObject key; final Value keyColValue = row.getValue(KEY_COL); assert keyColValue != null; final Object o = keyColValue.getObject(); if (o instanceof CacheObject) key = (CacheObject)o; else key = ctx.toCacheKeyObject(o); return segmentForPartition(ctx.affinity().partition(key)); }
Value v = args[i].getValue(session); v = v.convertTo(argTypes[i]); arg = v.getObject(); argValues[i] = arg;
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; }
return v.getObject();
rightConst.value().getObject(), leftCol0.getType(), tbl.cacheName()
private static SimpleResultSet getSimpleResultSet(LocalResult rs, int maxrows) { int columnCount = rs.getVisibleColumnCount(); SimpleResultSet simple = new SimpleResultSet(); simple.setAutoClose(false); for (int i = 0; i < columnCount; i++) { String name = rs.getColumnName(i); /* * TODO Some types, such as Value.BYTES and Value.UUID are mapped to the same * SQL type and we can lose real type here. */ int sqlType = DataType.convertTypeToSQLType(rs.getColumnType(i)); int precision = MathUtils.convertLongToInt(rs.getColumnPrecision(i)); int scale = rs.getColumnScale(i); simple.addColumn(name, sqlType, precision, scale); } rs.reset(); for (int i = 0; i < maxrows && rs.next(); i++) { Object[] list = new Object[columnCount]; for (int j = 0; j < columnCount; j++) { list[j] = rs.currentRow()[j].getObject(); } simple.addRow(list); } return simple; }