Search in sources :

Example 1 with GridH2ValueCacheObject

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject in project ignite by apache.

the class H2RowDescriptor method wrap.

/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
@Override
public Value wrap(Object obj, int type) throws IgniteCheckedException {
    assert obj != null;
    if (obj instanceof CacheObject) {
        // Handle cache object.
        CacheObject co = (CacheObject) obj;
        if (type == Value.JAVA_OBJECT)
            return new GridH2ValueCacheObject(co, idx.objectContext());
        obj = co.value(idx.objectContext(), false);
    }
    switch(type) {
        case Value.BOOLEAN:
            return ValueBoolean.get((Boolean) obj);
        case Value.BYTE:
            return ValueByte.get((Byte) obj);
        case Value.SHORT:
            return ValueShort.get((Short) obj);
        case Value.INT:
            return ValueInt.get((Integer) obj);
        case Value.FLOAT:
            return ValueFloat.get((Float) obj);
        case Value.LONG:
            return ValueLong.get((Long) obj);
        case Value.DOUBLE:
            return ValueDouble.get((Double) obj);
        case Value.UUID:
            UUID uuid = (UUID) obj;
            return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
        case Value.DATE:
            return ValueDate.get((Date) obj);
        case Value.TIME:
            return ValueTime.get((Time) obj);
        case Value.TIMESTAMP:
            if (obj instanceof java.util.Date && !(obj instanceof Timestamp))
                obj = new Timestamp(((java.util.Date) obj).getTime());
            return ValueTimestamp.get((Timestamp) obj);
        case Value.DECIMAL:
            return ValueDecimal.get((BigDecimal) obj);
        case Value.STRING:
            return ValueString.get(obj.toString());
        case Value.BYTES:
            return ValueBytes.get((byte[]) obj);
        case Value.JAVA_OBJECT:
            return ValueJavaObject.getNoCopy(obj, null, null);
        case Value.ARRAY:
            Object[] arr = (Object[]) obj;
            Value[] valArr = new Value[arr.length];
            for (int i = 0; i < arr.length; i++) {
                Object o = arr[i];
                valArr[i] = o == null ? ValueNull.INSTANCE : wrap(o, DataType.getTypeFromClass(o.getClass()));
            }
            return ValueArray.get(valArr);
        case Value.GEOMETRY:
            return ValueGeometry.getFromGeometry(obj);
    }
    throw new IgniteCheckedException("Failed to wrap value[type=" + type + ", value=" + obj + "]");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Value(org.h2.value.Value) ValueJavaObject(org.h2.value.ValueJavaObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) UUID(java.util.UUID) Timestamp(java.sql.Timestamp) ValueTimestamp(org.h2.value.ValueTimestamp) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)

Example 2 with GridH2ValueCacheObject

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject in project ignite by apache.

the class MapQueryResult method fetchNextPage.

/**
 * @param rows Collection to fetch into.
 * @param pageSize Page size.
 * @return {@code true} If there are no more rows available.
 */
synchronized boolean fetchNextPage(List<Value[]> rows, int pageSize) {
    assert lazyWorker == null || lazyWorker == MapQueryLazyWorker.currentWorker();
    if (closed)
        return true;
    boolean readEvt = cctx != null && cctx.name() != null && cctx.events().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
    page++;
    for (int i = 0; i < pageSize; i++) {
        if (!res.next())
            return true;
        Value[] row = res.currentRow();
        if (cpNeeded) {
            boolean copied = false;
            for (int j = 0; j < row.length; j++) {
                Value val = row[j];
                if (val instanceof GridH2ValueCacheObject) {
                    GridH2ValueCacheObject valCacheObj = (GridH2ValueCacheObject) val;
                    row[j] = new GridH2ValueCacheObject(valCacheObj.getCacheObject(), h2.objectContext()) {

                        @Override
                        public Object getObject() {
                            return getObject(true);
                        }
                    };
                    copied = true;
                }
            }
            if (i == 0 && !copied)
                // No copy on read caches, skip next checks.
                cpNeeded = false;
        }
        assert row != null;
        if (readEvt) {
            GridKernalContext ctx = h2.kernalContext();
            ctx.event().record(new CacheQueryReadEvent<>(ctx.discovery().localNode(), "SQL fields query result set row read.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.SQL.name(), cctx.name(), null, qry.query(), null, null, params, qrySrcNodeId, null, null, null, null, row(row)));
        }
        rows.add(res.currentRow());
    }
    return false;
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) Value(org.h2.value.Value) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)

Example 3 with GridH2ValueCacheObject

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject in project ignite by apache.

the class MapQueryResult method fetchNextPage.

/**
 * @param rows Collection to fetch into.
 * @param pageSize Page size.
 * @param dataPageScanEnabled If data page scan is enabled.
 * @return {@code true} If there are no more rows available.
 */
boolean fetchNextPage(List<Value[]> rows, int pageSize, Boolean dataPageScanEnabled) {
    assert lock.isHeldByCurrentThread();
    if (closed)
        return true;
    assert res != null;
    boolean readEvt = cctx != null && cctx.name() != null && cctx.events().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
    QueryContext.threadLocal(H2Utils.context(ses));
    page++;
    h2.enableDataPageScan(dataPageScanEnabled);
    try {
        for (int i = 0; i < pageSize; i++) {
            if (!res.res.next())
                return true;
            Value[] row = res.res.currentRow();
            if (cpNeeded) {
                boolean copied = false;
                for (int j = 0; j < row.length; j++) {
                    Value val = row[j];
                    if (val instanceof GridH2ValueCacheObject) {
                        GridH2ValueCacheObject valCacheObj = (GridH2ValueCacheObject) val;
                        row[j] = new GridH2ValueCacheObject(valCacheObj.getCacheObject(), h2.objectContext()) {

                            @Override
                            public Object getObject() {
                                return getObject(true);
                            }
                        };
                        copied = true;
                    }
                }
                if (i == 0 && !copied)
                    // No copy on read caches, skip next checks.
                    cpNeeded = false;
            }
            assert row != null;
            if (readEvt) {
                GridKernalContext ctx = h2.kernalContext();
                ctx.event().record(new CacheQueryReadEvent<>(ctx.discovery().localNode(), "SQL fields query result set row read.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.SQL.name(), cctx.name(), null, qry.query(), null, null, params, qrySrcNodeId, null, null, null, null, row(row)));
            }
            rows.add(res.res.currentRow());
            res.fetchSizeInterceptor.checkOnFetchNext();
        }
        return !res.res.hasNext();
    } finally {
        CacheDataTree.setDataPageScanEnabled(false);
    }
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) Value(org.h2.value.Value) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)

Example 4 with GridH2ValueCacheObject

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject in project ignite by apache.

the class GridH2CacheObject method value.

/**
 * {@inheritDoc}
 */
@Override
public Value value(GridKernalContext ctx) throws IgniteCheckedException {
    CacheObjectValueContext valCtx = ctx.query().objectContext();
    obj.finishUnmarshal(valCtx, ctx.cache().context().deploy().globalLoader());
    return new GridH2ValueCacheObject(obj, valCtx);
}
Also used : CacheObjectValueContext(org.apache.ignite.internal.processors.cache.CacheObjectValueContext) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)

Example 5 with GridH2ValueCacheObject

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject in project ignite by apache.

the class H2Utils method wrap.

/**
 * Wraps object to respective {@link Value}.
 *
 * @param obj Object.
 * @param type Value type.
 * @return Value.
 * @throws IgniteCheckedException If failed.
 */
@SuppressWarnings("ConstantConditions")
public static Value wrap(CacheObjectValueContext coCtx, Object obj, int type) throws IgniteCheckedException {
    assert obj != null;
    if (obj instanceof CacheObject) {
        // Handle cache object.
        CacheObject co = (CacheObject) obj;
        if (type == Value.JAVA_OBJECT)
            return new GridH2ValueCacheObject(co, coCtx);
        obj = co.value(coCtx, false);
    }
    switch(type) {
        case Value.BOOLEAN:
            return ValueBoolean.get((Boolean) obj);
        case Value.BYTE:
            return ValueByte.get((Byte) obj);
        case Value.SHORT:
            return ValueShort.get((Short) obj);
        case Value.INT:
            return ValueInt.get((Integer) obj);
        case Value.FLOAT:
            return ValueFloat.get((Float) obj);
        case Value.LONG:
            return ValueLong.get((Long) obj);
        case Value.DOUBLE:
            return ValueDouble.get((Double) obj);
        case Value.UUID:
            UUID uuid = (UUID) obj;
            return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
        case Value.DATE:
            if (LocalDateTimeUtils.LOCAL_DATE == obj.getClass())
                return LocalDateTimeUtils.localDateToDateValue(obj);
            return ValueDate.get((Date) obj);
        case Value.TIME:
            if (LocalDateTimeUtils.LOCAL_TIME == obj.getClass())
                return LocalDateTimeUtils.localTimeToTimeValue(obj);
            return ValueTime.get((Time) obj);
        case Value.TIMESTAMP:
            if (obj instanceof java.util.Date && !(obj instanceof Timestamp))
                obj = new Timestamp(((java.util.Date) obj).getTime());
            if (LocalDateTimeUtils.LOCAL_DATE_TIME == obj.getClass())
                return LocalDateTimeUtils.localDateTimeToValue(obj);
            return ValueTimestamp.get((Timestamp) obj);
        case Value.DECIMAL:
            return ValueDecimal.get((BigDecimal) obj);
        case Value.STRING:
            return ValueString.get(obj.toString());
        case Value.BYTES:
            return ValueBytes.get((byte[]) obj);
        case Value.JAVA_OBJECT:
            return ValueJavaObject.getNoCopy(obj, null, null);
        case Value.ARRAY:
            Object[] arr = BinaryUtils.rawArrayFromBinary(obj);
            Value[] valArr = new Value[arr.length];
            for (int i = 0; i < arr.length; i++) {
                Object o = arr[i];
                valArr[i] = o == null ? ValueNull.INSTANCE : wrap(coCtx, o, DataType.getTypeFromClass(o.getClass()));
            }
            return ValueArray.get(valArr);
        case Value.GEOMETRY:
            return ValueGeometry.getFromGeometry(obj);
    }
    throw new IgniteCheckedException("Failed to wrap value[type=" + type + ", value=" + obj + "]");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Value(org.h2.value.Value) ValueJavaObject(org.h2.value.ValueJavaObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) UUID(java.util.UUID) Timestamp(java.sql.Timestamp) ValueTimestamp(org.h2.value.ValueTimestamp) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)

Aggregations

GridH2ValueCacheObject (org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)6 Value (org.h2.value.Value)5 Timestamp (java.sql.Timestamp)2 UUID (java.util.UUID)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 GridKernalContext (org.apache.ignite.internal.GridKernalContext)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 ValueJavaObject (org.h2.value.ValueJavaObject)2 ValueTimestamp (org.h2.value.ValueTimestamp)2 CacheObjectValueContext (org.apache.ignite.internal.processors.cache.CacheObjectValueContext)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1