use of org.h2.result.Row in project h2database by h2database.
the class PageBtreeIndex method writeRow.
/**
* Write a row to the data page at the given offset.
*
* @param data the data
* @param offset the offset
* @param onlyPosition whether only the position of the row is stored
* @param row the row to write
*/
void writeRow(Data data, int offset, SearchRow row, boolean onlyPosition) {
data.setPos(offset);
data.writeVarLong(row.getKey());
if (!onlyPosition) {
for (Column col : columns) {
int idx = col.getColumnId();
data.writeValue(row.getValue(idx));
}
}
}
use of org.h2.result.Row in project h2database by h2database.
the class PageBtreeIndex method readRow.
/**
* Read a row from the data page at the given offset.
*
* @param data the data
* @param offset the offset
* @param onlyPosition whether only the position of the row is stored
* @param needData whether the row data is required
* @return the row
*/
SearchRow readRow(Data data, int offset, boolean onlyPosition, boolean needData) {
synchronized (data) {
data.setPos(offset);
long key = data.readVarLong();
if (onlyPosition) {
if (needData) {
return tableData.getRow(null, key);
}
SearchRow row = table.getTemplateSimpleRow(true);
row.setKey(key);
return row;
}
SearchRow row = table.getTemplateSimpleRow(columns.length == 1);
row.setKey(key);
for (Column col : columns) {
int idx = col.getColumnId();
row.setValue(idx, data.readValue());
}
return row;
}
}
use of org.h2.result.Row in project h2database by h2database.
the class PageBtreeNode method remove.
@Override
SearchRow remove(SearchRow row) {
int at = find(row, false, false, true);
// merge is not implemented to allow concurrent usage
// TODO maybe implement merge
PageBtree page = index.getPage(childPageIds[at]);
SearchRow last = page.remove(row);
index.getPageStore().logUndo(this, data);
updateRowCount(-1);
written = false;
changeCount = index.getPageStore().getChangeCount();
if (last == null) {
// the last row didn't change - nothing to do
return null;
} else if (last == row) {
// this child is now empty
index.getPageStore().free(page.getPos());
if (entryCount < 1) {
// no more children - this page is empty as well
return row;
}
if (at == entryCount) {
// removing the last child
last = getRow(at - 1);
} else {
last = null;
}
removeChild(at);
index.getPageStore().update(this);
return last;
}
// the last row is in the last child
if (at == entryCount) {
return last;
}
int child = childPageIds[at];
removeChild(at);
// TODO this can mean only the position is now stored
// should split at the next possible moment
addChild(at, child, last);
// remove and add swapped two children, fix that
int temp = childPageIds[at];
childPageIds[at] = childPageIds[at + 1];
childPageIds[at + 1] = temp;
index.getPageStore().update(this);
return null;
}
use of org.h2.result.Row in project h2database by h2database.
the class PageDataIndex method add.
@Override
public void add(Session session, Row row) {
boolean retry = false;
if (mainIndexColumn != -1) {
row.setKey(row.getValue(mainIndexColumn).getLong());
} else {
if (row.getKey() == 0) {
row.setKey((int) ++lastKey);
retry = true;
}
}
if (tableData.getContainsLargeObject()) {
for (int i = 0, len = row.getColumnCount(); i < len; i++) {
Value v = row.getValue(i);
Value v2 = v.copy(database, getId());
if (v2.isLinkedToTable()) {
session.removeAtCommitStop(v2);
}
if (v != v2) {
row.setValue(i, v2);
}
}
}
// tries are required (specially if there was originally a primary key)
if (trace.isDebugEnabled()) {
trace.debug("{0} add {1}", getName(), row);
}
long add = 0;
while (true) {
try {
addTry(session, row);
break;
} catch (DbException e) {
if (e != fastDuplicateKeyException) {
throw e;
}
if (!retry) {
throw getNewDuplicateKeyException();
}
if (add == 0) {
// in the first re-try add a small random number,
// to avoid collisions after a re-start
row.setKey((long) (row.getKey() + Math.random() * 10_000));
} else {
row.setKey(row.getKey() + add);
}
add++;
} finally {
store.incrementChangeCount();
}
}
lastKey = Math.max(lastKey, row.getKey());
}
use of org.h2.result.Row in project h2database by h2database.
the class UndoLogRecord method append.
/**
* Append the row to the buffer.
*
* @param buff the buffer
* @param log the undo log
*/
void append(Data buff, UndoLog log) {
int p = buff.length();
buff.writeInt(0);
buff.writeInt(operation);
buff.writeByte(row.isDeleted() ? (byte) 1 : (byte) 0);
buff.writeInt(log.getTableId(table));
buff.writeLong(row.getKey());
buff.writeInt(row.getSessionId());
int count = row.getColumnCount();
buff.writeInt(count);
for (int i = 0; i < count; i++) {
Value v = row.getValue(i);
buff.checkCapacity(buff.getValueLen(v));
buff.writeValue(v);
}
buff.fillAligned();
buff.setInt(p, (buff.length() - p) / Constants.FILE_BLOCK_SIZE);
}
Aggregations