use of org.h2.command.dml.Update in project h2database by h2database.
the class DropSynonym method update.
@Override
public int update() {
session.commit(true);
session.getUser().checkAdmin();
TableSynonym synonym = getSchema().getSynonym(synonymName);
if (synonym == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName);
}
} else {
session.getDatabase().removeSchemaObject(session, synonym);
}
return 0;
}
use of org.h2.command.dml.Update in project h2database by h2database.
the class Session method unlockReadLocks.
/**
* Unlock all read locks. This is done if the transaction isolation mode is
* READ_COMMITTED.
*/
public void unlockReadLocks() {
if (database.isMultiVersion()) {
// MVCC: keep shared locks (insert / update / delete)
return;
}
// locks is modified in the loop
for (int i = 0; i < locks.size(); i++) {
Table t = locks.get(i);
if (!t.isLockedExclusively()) {
synchronized (database) {
t.unlock(this);
locks.remove(i);
}
i--;
}
}
}
use of org.h2.command.dml.Update 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.command.dml.Update in project h2database by h2database.
the class LinkedIndex method update.
/**
* Update a row using a UPDATE statement. This method is to be called if the
* emit updates option is enabled.
*
* @param oldRow the old data
* @param newRow the new data
*/
public void update(Row oldRow, Row newRow) {
ArrayList<Value> params = New.arrayList();
StatementBuilder buff = new StatementBuilder("UPDATE ");
buff.append(targetTableName).append(" SET ");
for (int i = 0; i < newRow.getColumnCount(); i++) {
buff.appendExceptFirst(", ");
buff.append(table.getColumn(i).getSQL()).append('=');
Value v = newRow.getValue(i);
if (v == null) {
buff.append("DEFAULT");
} else {
buff.append('?');
params.add(v);
}
}
buff.append(" WHERE ");
buff.resetCount();
for (int i = 0; i < oldRow.getColumnCount(); i++) {
Column col = table.getColumn(i);
buff.appendExceptFirst(" AND ");
buff.append(col.getSQL());
Value v = oldRow.getValue(i);
if (isNull(v)) {
buff.append(" IS NULL");
} else {
buff.append('=');
params.add(v);
addParameter(buff, col);
}
}
String sql = buff.toString();
try {
link.execute(sql, params, true);
} catch (Exception e) {
throw TableLink.wrapException(sql, e);
}
}
use of org.h2.command.dml.Update in project h2database by h2database.
the class FileLock method lockFile.
private void lockFile() {
method = FILE;
properties = new SortedProperties();
properties.setProperty("method", String.valueOf(method));
setUniqueId();
FileUtils.createDirectories(FileUtils.getParent(fileName));
if (!FileUtils.createFile(fileName)) {
waitUntilOld();
String m2 = load().getProperty("method", FILE);
if (!m2.equals(FILE)) {
throw getExceptionFatal("Unsupported lock method " + m2, null);
}
save();
sleep(2 * sleep);
if (!load().equals(properties)) {
throw getExceptionAlreadyInUse("Locked by another process: " + fileName);
}
FileUtils.delete(fileName);
if (!FileUtils.createFile(fileName)) {
throw getExceptionFatal("Another process was faster", null);
}
}
save();
sleep(SLEEP_GAP);
if (!load().equals(properties)) {
fileName = null;
throw getExceptionFatal("Concurrent update", null);
}
locked = true;
watchdog = new Thread(this, "H2 File Lock Watchdog " + fileName);
Driver.setThreadContextClassLoader(watchdog);
watchdog.setDaemon(true);
watchdog.setPriority(Thread.MAX_PRIORITY - 1);
watchdog.start();
}
Aggregations