/** * Lock the table. This will also lock joined tables. * * @param s the session * @param exclusive true if an exclusive lock is required * @param forceLockEvenInMvcc lock even in the MVCC mode */ public void lock(Session s, boolean exclusive, boolean forceLockEvenInMvcc) { table.lock(s, exclusive, forceLockEvenInMvcc); if (join != null) { join.lock(s, exclusive, forceLockEvenInMvcc); } }
/** {@inheritDoc} */ @Override public boolean lock(Session session, boolean exclusive, boolean force) { return innerTable().lock(session, exclusive, force); }
/** * Lock the metadata table for updates. * * @param session the session * @return whether it was already locked before by this session */ public boolean lockMeta(Session session) { // this method can not be synchronized on the database object, // as unlocking is also synchronized on the database object - // so if locking starts just before unlocking, locking could // never be successful if (meta == null) { return true; } if (SysProperties.CHECK2) { final Session prev = META_LOCK_DEBUGGING.get(); if (prev == null) { META_LOCK_DEBUGGING.set(session); META_LOCK_DEBUGGING_STACK.set(new Throwable("Last meta lock granted in this stack trace, "+ "this is debug information for following IllegalStateException")); } else if (prev != session) { META_LOCK_DEBUGGING_STACK.get().printStackTrace(); throw new IllegalStateException("meta currently locked by " + prev +", sessionid="+ prev.getId() + " and trying to be locked by different session, " + session +", sessionid="+ session.getId() + " on same thread"); } } return meta.lock(session, true, true); }
/** * Remove a table for a recursive query. * * @param isPersistent whether the table is persisted * @param targetSession the session * @param recursiveTable the table */ public static void destroyShadowTableForRecursiveExpression(boolean isPersistent, Session targetSession, Table recursiveTable) { if (recursiveTable != null) { if (isPersistent) { recursiveTable.lock(targetSession, true, true); targetSession.getDatabase().removeSchemaObject(targetSession, recursiveTable); } else { targetSession.removeLocalTempTable(recursiveTable); } // both removeSchemaObject and removeLocalTempTable hold meta locks - release them here targetSession.getDatabase().unlockMeta(targetSession); } } }
@Override public int update() { session.commit(true); if (!table.canTruncate()) { throw DbException.get(ErrorCode.CANNOT_TRUNCATE_1, table.getSQL()); } session.getUser().checkRight(table, Right.DELETE); table.lock(session, true, true); table.truncate(session); return 0; }
@Override public int update() { Table table = getSchema().resolveTableOrView(session, tableName); if (table == null) { if (ifTableExists) { return 0; } throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName); } session.getUser().checkRight(table, Right.ALL); table.lock(session, true, true); switch (type) { case CommandInterface.ALTER_TABLE_SET_REFERENTIAL_INTEGRITY: table.setCheckForeignKeyConstraints(session, value, value ? checkExisting : false); break; default: DbException.throwInternalError("type="+type); } return 0; }
private boolean existsRow(Session session, Index searchIndex, SearchRow check, Row excluding) { Table searchTable = searchIndex.getTable(); searchTable.lock(session, false, false); Cursor cursor = searchIndex.find(session, check, check); while (cursor.next()) { SearchRow found; found = cursor.getSearchRow(); if (excluding != null && found.getKey() == excluding.getKey()) { continue; } Column[] cols = searchIndex.getColumns(); boolean allEqual = true; int len = Math.min(columns.length, cols.length); for (int i = 0; i < len; i++) { int idx = cols[i].getColumnId(); Value c = check.getValue(idx); Value f = found.getValue(idx); if (searchTable.compareTypeSafe(c, f) != 0) { allEqual = false; break; } } if (allEqual) { return true; } } return false; }
@Override public int update() { // clear list of source table keys & rowids we have processed already targetRowidsRemembered.clear(); if (targetTableFilter != null) { targetTableFilter.startQuery(session); targetTableFilter.reset(); } if (sourceTableFilter != null) { sourceTableFilter.startQuery(session); sourceTableFilter.reset(); } sourceQueryRowNumber = 0; checkRights(); setCurrentRowNumber(0); // process source select query data for row creation ResultInterface rows = query.query(0); targetTable.fire(session, evaluateTriggerMasks(), true); targetTable.lock(session, true, false); while (rows.next()) { sourceQueryRowNumber++; Value[] sourceRowValues = rows.currentRow(); Row sourceRow = new RowImpl(sourceRowValues, 0); setCurrentRowNumber(sourceQueryRowNumber); merge(sourceRow); } rows.close(); targetTable.fire(session, evaluateTriggerMasks(), false); return countUpdatedRows; }
boolean done = table.fireBeforeRow(session, null, row); if (!done) { table.lock(session, true, false); table.addRow(session, row); session.log(table, UndoLogRecord.INSERT, row);
count = 0; table.fire(session, Trigger.UPDATE | Trigger.INSERT, true); table.lock(session, true, false); while (rows.next()) { count++;
ArrayList<Table> copyOfDependencies = new ArrayList<>(tableView.getTables()); view.lock(session, true, true); session.getDatabase().removeSchemaObject(session, view);
boolean done = targetTable.fireBeforeRow(session, null, row); if (!done) { targetTable.lock(session, true, false); targetTable.addRow(session, row); session.getGeneratedKeys().confirmRow(row);
count = 0; targetTable.fire(session, Trigger.UPDATE | Trigger.INSERT, true); targetTable.lock(session, true, false); while (rows.next()) { count++;
table.lock(session, true, true);
oldViewFound.lock(session, true, true); database.removeSchemaObject(session, oldViewFound);
session.getUser().checkRight(table, Right.UPDATE); table.fire(session, Trigger.UPDATE, true); table.lock(session, true, false); int columnCount = table.getColumns().length;
table.lock(session, true, true); if (!table.isPersistIndexes()) { persistent = false;
table.lock(session, true, true); if (newColumn != null) { checkDefaultReferencesTable(table, newColumn.getDefaultExpression());
session.getUser().checkRight(table, Right.DELETE); table.fire(session, Trigger.DELETE, true); table.lock(session, true, false); RowList rows = new RowList(session); int limitRows = -1;