Ejemplo n.º 1
0
 /**
  * Drop and remove the given local temporary table from this session.
  *
  * @param table the table
  */
 public void removeLocalTempTable(Table table) {
   modificationId++;
   localTempTables.remove(table.getName());
   synchronized (database) {
     table.removeChildrenAndResources(this);
   }
 }
Ejemplo n.º 2
0
 /**
  * Add a local temporary table to this session.
  *
  * @param table the table to add
  * @throws DbException if a table with this name already exists
  */
 public void addLocalTempTable(Table table) {
   if (localTempTables == null) {
     localTempTables = database.newStringMap();
   }
   if (localTempTables.get(table.getName()) != null) {
     throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, table.getSQL());
   }
   modificationId++;
   localTempTables.put(table.getName(), table);
 }
Ejemplo n.º 3
0
 /**
  * Add an undo log entry to this session.
  *
  * @param table the table
  * @param operation the operation type (see {@link UndoLogRecord})
  * @param row the row
  */
 public void log(Table table, short operation, Row row) {
   if (undoLogEnabled) {
     UndoLogRecord log = new UndoLogRecord(table, operation, row);
     // called _after_ the row was inserted successfully into the table,
     // otherwise rollback will try to rollback a not-inserted row
     if (SysProperties.CHECK) {
       int lockMode = database.getLockMode();
       if (lockMode != Constants.LOCK_MODE_OFF && !database.isMultiVersion()) {
         String tableType = log.getTable().getTableType();
         if (locks.indexOf(log.getTable()) < 0
             && !Table.TABLE_LINK.equals(tableType)
             && !Table.EXTERNAL_TABLE_ENGINE.equals(tableType)) {
           DbException.throwInternalError();
         }
       }
     }
     undoLog.add(log);
   } else {
     if (database.isMultiVersion()) {
       // see also UndoLogRecord.commit
       ArrayList<Index> indexes = table.getIndexes();
       for (int i = 0, size = indexes.size(); i < size; i++) {
         Index index = indexes.get(i);
         index.commit(operation, row);
       }
       row.commit();
     }
   }
 }
Ejemplo n.º 4
0
 /** 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--;
     }
   }
 }
Ejemplo n.º 5
0
 private void unlockAll() {
   if (SysProperties.CHECK) {
     if (undoLog.size() > 0) {
       DbException.throwInternalError();
     }
   }
   if (locks.size() > 0) {
     synchronized (database) {
       // don't use the enhanced for loop to save memory
       for (int i = 0, size = locks.size(); i < size; i++) {
         Table t = locks.get(i);
         t.unlock(this);
       }
       locks.clear();
     }
   }
   savepoints = null;
   sessionStateChanged = true;
 }
Ejemplo n.º 6
0
 private void cleanTempTables(boolean closeSession) {
   if (localTempTables != null && localTempTables.size() > 0) {
     synchronized (database) {
       for (Table table : New.arrayList(localTempTables.values())) {
         if (closeSession || table.getOnCommitDrop()) {
           modificationId++;
           table.setModified();
           localTempTables.remove(table.getName());
           table.removeChildrenAndResources(this);
           if (closeSession) {
             // need to commit, otherwise recovery might
             // ignore the table removal
             database.commit(this);
           }
         } else if (table.getOnCommitTruncate()) {
           table.truncate(this);
         }
       }
     }
   }
 }