本文整理汇总了Java中org.h2.mvstore.DataUtils.newIllegalStateException方法的典型用法代码示例。如果您正苦于以下问题:Java DataUtils.newIllegalStateException方法的具体用法?Java DataUtils.newIllegalStateException怎么用?Java DataUtils.newIllegalStateException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.mvstore.DataUtils
的用法示例。
在下文中一共展示了DataUtils.newIllegalStateException方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readChunkHeader
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Read the header from the byte buffer.
*
* @param buff the source buffer
* @param start the start of the chunk in the file
* @return the chunk
*/
private static Chunk readChunkHeader(ByteBuffer buff, long start) {
int pos = buff.position();
byte[] data = new byte[Math.min(buff.remaining(), MAX_HEADER_LENGTH)];
buff.get(data);
try {
for (int i = 0; i < data.length; i++) {
if (data[i] == '\n') {
// set the position to the start of the first page
buff.position(pos + i + 1);
String s = new String(data, 0, i, DataUtils.LATIN).trim();
return fromString(s);
}
}
} catch (Exception e) {
// there could be various reasons
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_FILE_CORRUPT,
"File corrupt reading chunk at position {0}", start, e);
}
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_FILE_CORRUPT,
"File corrupt reading chunk at position {0}", start);
}
示例2: set
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Update the value for the given key. The key must exist.
*
* @param p the page
* @param writeVersion the write version
* @param key the key
* @param value the new value
* @return the old value (never null)
*/
private Object set(Page p, long writeVersion, Object key, Object value) {
if (p.isLeaf()) {
for (int i = 0; i < p.getKeyCount(); i++) {
if (keyType.equals(p.getKey(i), key)) {
return p.setValue(i, value);
}
}
} else {
for (int i = 0; i < p.getKeyCount(); i++) {
if (contains(p, i, key)) {
Page c = p.getChildPage(i);
if (get(c, key) != null) {
c = c.copy(writeVersion);
Object result = set(c, writeVersion, key, value);
p.setChild(i, c);
return result;
}
}
}
}
throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,
"Not found: {0}", key);
}
示例3: TransactionStore
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Create a new transaction store.
*
* @param store the store
* @param dataType the data type for map keys and values
*/
public TransactionStore(MVStore store, DataType dataType) {
this.store = store;
this.dataType = dataType;
preparedTransactions = store.openMap("openTransactions",
new MVMap.Builder<Integer, Object[]>());
VersionedValueType oldValueType = new VersionedValueType(dataType);
ArrayType undoLogValueType = new ArrayType(new DataType[]{
new ObjectDataType(), dataType, oldValueType
});
MVMap.Builder<Long, Object[]> builder =
new MVMap.Builder<Long, Object[]>().
valueType(undoLogValueType);
undoLog = store.openMap("undoLog", builder);
if (undoLog.getValueType() != undoLogValueType) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_CORRUPT,
"Undo map open with a different value type");
}
}
示例4: begin
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Begin a new transaction.
*
* @return the transaction
*/
public synchronized Transaction begin() {
int transactionId;
int status;
if (!init) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_ILLEGAL_STATE,
"Not initialized");
}
transactionId = openTransactions.nextClearBit(1);
if (transactionId > maxTransactionId) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TOO_MANY_OPEN_TRANSACTIONS,
"There are {0} open transactions",
transactionId - 1);
}
openTransactions.set(transactionId);
status = Transaction.STATUS_OPEN;
return new Transaction(this, transactionId, status, null, 0);
}
示例5: logUndo
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Remove a log entry.
*
* @param t the transaction
* @param logId the log id
*/
public void logUndo(Transaction t, long logId) {
Long undoKey = getOperationId(t.getId(), logId);
synchronized (undoLog) {
Object[] old = undoLog.remove(undoKey);
if (old == null) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_ILLEGAL_STATE,
"Transaction {0} was concurrently rolled back",
t.getId());
}
}
}
示例6: checkNotClosed
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Check whether this transaction is open or prepared.
*/
void checkNotClosed() {
if (status == STATUS_CLOSED) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_CLOSED, "Transaction is closed");
}
}
示例7: set
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private V set(K key, V value) {
transaction.checkNotClosed();
V old = get(key);
boolean ok = trySet(key, value, false);
if (ok) {
return old;
}
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_LOCKED, "Entry is locked");
}
示例8: newType
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private AutoDetectDataType newType(int typeId) {
switch (typeId) {
case TYPE_NULL:
return new NullType(this);
case TYPE_BOOLEAN:
return new BooleanType(this);
case TYPE_BYTE:
return new ByteType(this);
case TYPE_SHORT:
return new ShortType(this);
case TYPE_CHAR:
return new CharacterType(this);
case TYPE_INT:
return new IntegerType(this);
case TYPE_LONG:
return new LongType(this);
case TYPE_FLOAT:
return new FloatType(this);
case TYPE_DOUBLE:
return new DoubleType(this);
case TYPE_BIG_INTEGER:
return new BigIntegerType(this);
case TYPE_BIG_DECIMAL:
return new BigDecimalType(this);
case TYPE_STRING:
return new StringType(this);
case TYPE_UUID:
return new UUIDType(this);
case TYPE_DATE:
return new DateType(this);
case TYPE_ARRAY:
return new ObjectArrayType(this);
case TYPE_SERIALIZED_OBJECT:
return new SerializedObjectType(this);
}
throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,
"Unsupported type {0}", typeId);
}
示例9: allocate
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Allocate a number of blocks and mark them as used.
*
* @param length the number of bytes to allocate
* @return the start position in bytes
*/
public synchronized long allocate(int length) {
int required = getBlockCount(length);
for (BlockRange pr : freeSpaceList) {
if (pr.length >= required) {
int result = pr.start;
this.markUsed(pr.start * blockSize, length);
return result * blockSize;
}
}
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL,
"Could not find a free page to allocate");
}
示例10: getBlockCount
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private int getBlockCount(int length) {
if (length <= 0) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL, "Free space invalid length");
}
return MathUtils.roundUpInt(length, blockSize) / blockSize;
}
示例11: markUsed
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Mark the space as in use.
*
* @param pos the position in bytes
* @param length the number of bytes
*/
public synchronized void markUsed(long pos, int length) {
int start = getBlock(pos);
int blocks = getBlockCount(length);
BlockRange x = new BlockRange(start, blocks);
BlockRange prev = freeSpace.floor(x);
if (prev == null) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL, "Free space already marked");
}
if (prev.start == start) {
if (prev.blocks == blocks) {
// match
freeSpace.remove(prev);
} else {
// cut the front
prev.start += blocks;
prev.blocks -= blocks;
}
} else if (prev.start + prev.blocks == start + blocks) {
// cut the end
prev.blocks -= blocks;
} else {
// insert an entry
x.start = start + blocks;
x.blocks = prev.start + prev.blocks - x.start;
freeSpace.add(x);
prev.blocks = start - prev.start;
}
}
示例12: free
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Mark the space as free.
*
* @param pos the position in bytes
* @param length the number of bytes
*/
public synchronized void free(long pos, int length) {
int start = getBlock(pos);
int blocks = getBlockCount(length);
BlockRange x = new BlockRange(start, blocks);
BlockRange next = freeSpace.ceiling(x);
if (next == null) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL, "Free space sentinel is missing");
}
BlockRange prev = freeSpace.lower(x);
if (prev != null) {
if (prev.start + prev.blocks == start) {
// extend the previous entry
prev.blocks += blocks;
if (prev.start + prev.blocks == next.start) {
// merge with the next entry
prev.blocks += next.blocks;
freeSpace.remove(next);
}
return;
}
}
if (start + blocks == next.start) {
// extend the next entry
next.start -= blocks;
next.blocks += blocks;
return;
}
freeSpace.add(x);
}
示例13: read
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
@Override
public Object read(ByteBuffer buff) {
int tag = buff.get();
int typeId;
if (tag <= TYPE_SERIALIZED_OBJECT) {
typeId = tag;
} else {
switch (tag) {
case TAG_BOOLEAN_TRUE:
typeId = TYPE_BOOLEAN;
break;
case TAG_INTEGER_NEGATIVE:
case TAG_INTEGER_FIXED:
typeId = TYPE_INT;
break;
case TAG_LONG_NEGATIVE:
case TAG_LONG_FIXED:
typeId = TYPE_LONG;
break;
case TAG_BIG_INTEGER_0:
case TAG_BIG_INTEGER_1:
case TAG_BIG_INTEGER_SMALL:
typeId = TYPE_BIG_INTEGER;
break;
case TAG_FLOAT_0:
case TAG_FLOAT_1:
case TAG_FLOAT_FIXED:
typeId = TYPE_FLOAT;
break;
case TAG_DOUBLE_0:
case TAG_DOUBLE_1:
case TAG_DOUBLE_FIXED:
typeId = TYPE_DOUBLE;
break;
case TAG_BIG_DECIMAL_0:
case TAG_BIG_DECIMAL_1:
case TAG_BIG_DECIMAL_SMALL:
case TAG_BIG_DECIMAL_SMALL_SCALED:
typeId = TYPE_BIG_DECIMAL;
break;
default:
if (tag >= TAG_INTEGER_0_15 && tag <= TAG_INTEGER_0_15 + 15) {
typeId = TYPE_INT;
} else if (tag >= TAG_STRING_0_15
&& tag <= TAG_STRING_0_15 + 15) {
typeId = TYPE_STRING;
} else if (tag >= TAG_LONG_0_7 && tag <= TAG_LONG_0_7 + 7) {
typeId = TYPE_LONG;
} else if (tag >= TAG_BYTE_ARRAY_0_15
&& tag <= TAG_BYTE_ARRAY_0_15 + 15) {
typeId = TYPE_ARRAY;
} else {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_FILE_CORRUPT, "Unknown tag {0}",
tag);
}
}
}
AutoDetectDataType t = last;
if (typeId != t.typeId) {
last = t = newType(typeId);
}
return t.read(buff, tag);
}
示例14: markUsed
import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
* Mark the space as in use.
*
* @param pos the position in bytes
* @param length the number of bytes
*/
public synchronized void markUsed(long pos, int length) {
int start = (int) (pos / blockSize);
int required = getBlockCount(length);
BlockRange found = null;
int i = 0;
for (BlockRange pr : freeSpaceList) {
if (start >= pr.start && start < (pr.start + pr.length)) {
found = pr;
break;
}
i++;
}
if (found == null) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL,
"Cannot find spot to mark as used in free list");
}
if (start + required > found.start + found.length) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL,
"Runs over edge of free space");
}
if (found.start == start) {
// if the used space is at the beginning of a free-space-range
found.start += required;
found.length -= required;
if (found.length == 0) {
// if the free-space-range is now empty, remove it
freeSpaceList.remove(i);
}
} else if (found.start + found.length == start + required) {
// if the used space is at the end of a free-space-range
found.length -= required;
} else {
// it's in the middle, so split the existing entry
int length1 = start - found.start;
int start2 = start + required;
int length2 = found.start + found.length - start - required;
found.length = length1;
BlockRange newRange = new BlockRange(start2, length2);
freeSpaceList.add(i + 1, newRange);
}
}