Search in sources :

Example 1 with Value

use of org.h2.value.Value in project che by eclipse.

the class H2TestHelper method inMemoryDefault.

/**
     * Creates new default datasource to in memory database
     * with url {@value #DEFAULT_IN_MEMORY_DB_URL}.
     * Boots database if this is invoked first time, database
     * won't be shutdown until 'SHUTDOWN' query is executed
     * or {@link #shutdownDefault()} is called directly.
     *
     * @return datasource to the in memory database
     * @deprecated use {@link H2DBTestServer}.
     */
@Deprecated
public static DataSource inMemoryDefault() {
    final JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setUrl(DEFAULT_IN_MEMORY_DB_URL);
    return dataSource;
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

Example 2 with Value

use of org.h2.value.Value 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 3 with Value

use of org.h2.value.Value in project ignite by apache.

the class IgniteH2Indexing method rebuildIndexesFromHash.

/** {@inheritDoc} */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName) throws IgniteCheckedException {
    H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
    if (tbl == null)
        return;
    assert tbl.table() != null;
    assert tbl.table().rebuildFromHashInProgress();
    H2PkHashIndex hashIdx = tbl.primaryKeyHashIndex();
    Cursor cursor = hashIdx.find((Session) null, null, null);
    while (cursor.next()) {
        CacheDataRow dataRow = (CacheDataRow) cursor.get();
        boolean done = false;
        while (!done) {
            GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key());
            try {
                synchronized (entry) {
                    // TODO : How to correctly get current value and link here?
                    GridH2Row row = tbl.table().rowDescriptor().createRow(entry.key(), entry.partition(), dataRow.value(), entry.version(), entry.expireTime());
                    row.link(dataRow.link());
                    List<Index> indexes = tbl.table().getAllIndexes();
                    for (int i = 2; i < indexes.size(); i++) {
                        Index idx = indexes.get(i);
                        if (idx instanceof H2TreeIndex)
                            ((H2TreeIndex) idx).put(row);
                    }
                    done = true;
                }
            } catch (GridCacheEntryRemovedException e) {
            // No-op
            }
        }
    }
    tbl.table().markRebuildFromHashInProgress(false);
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cursor(org.h2.index.Cursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor)

Example 4 with Value

use of org.h2.value.Value in project ignite by apache.

the class GridH2AbstractKeyValueRow method syncValue.

/**
     * @param waitTime Time to await for value unswap.
     * @return Synchronized value.
     */
protected synchronized Value syncValue(long waitTime) {
    Value v = peekValue(VAL_COL);
    while (v == null && waitTime > 0) {
        // This call must be quite rare, so performance is not a concern.
        long start = System.nanoTime();
        try {
            // Wait for value arrival to allow other threads to make a progress.
            wait(waitTime);
        } catch (InterruptedException e) {
            throw new IgniteInterruptedException(e);
        }
        long t = System.nanoTime() - start;
        if (t > 0)
            waitTime -= TimeUnit.NANOSECONDS.toMillis(t);
        v = peekValue(VAL_COL);
    }
    return v;
}
Also used : Value(org.h2.value.Value) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException)

Example 5 with Value

use of org.h2.value.Value in project ignite by apache.

the class GridH2AbstractKeyValueRow method updateWeakValue.

/**
     * Atomically updates weak value.
     *
     * @param valObj New value.
     * @return New value if old value is empty, old value otherwise.
     * @throws IgniteCheckedException If failed.
     */
protected synchronized Value updateWeakValue(Object valObj) throws IgniteCheckedException {
    Value res = peekValue(VAL_COL);
    if (res != null && !(res instanceof WeakValue))
        return res;
    Value upd = desc.wrap(valObj, desc.valueType());
    setValue(VAL_COL, new WeakValue(upd));
    notifyAll();
    return upd;
}
Also used : Value(org.h2.value.Value)

Aggregations

Value (org.h2.value.Value)291 SQLException (java.sql.SQLException)94 DbException (org.h2.message.DbException)91 ResultSet (java.sql.ResultSet)69 PreparedStatement (java.sql.PreparedStatement)61 Statement (java.sql.Statement)53 Column (org.h2.table.Column)44 ValueString (org.h2.value.ValueString)44 JdbcStatement (org.h2.jdbc.JdbcStatement)42 JdbcPreparedStatement (org.h2.jdbc.JdbcPreparedStatement)36 SimpleResultSet (org.h2.tools.SimpleResultSet)31 StatementBuilder (org.h2.util.StatementBuilder)28 IndexColumn (org.h2.table.IndexColumn)23 Expression (org.h2.expression.Expression)22 IOException (java.io.IOException)21 Row (org.h2.result.Row)19 SearchRow (org.h2.result.SearchRow)18 Connection (java.sql.Connection)17 ValueArray (org.h2.value.ValueArray)17 ValueTimestamp (org.h2.value.ValueTimestamp)17