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;
}
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 + "]");
}
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);
}
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;
}
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;
}
Aggregations