Пример #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);
   }
 }
Пример #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);
 }
Пример #3
0
 private void unlockAll() {
   if (locks.size() > 0) {
     // 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;
 }
Пример #4
0
 private Index getColumnIndex() {
   if (on instanceof ExpressionColumn) {
     ExpressionColumn col = (ExpressionColumn) on;
     Column column = col.getColumn();
     TableFilter filter = col.getTableFilter();
     if (filter != null) {
       Table table = filter.getTable();
       Index index = table.getIndexForColumn(column);
       return index;
     }
   }
   return null;
 }
Пример #5
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++;
           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);
         }
       }
     }
   }
 }
Пример #6
0
 @Override
 public Value getValue(Session session) {
   if (select.isQuickAggregateQuery()) {
     switch (type) {
       case COUNT:
       case COUNT_ALL:
         Table table = select.getTopTableFilter().getTable();
         return ValueLong.get(table.getRowCount(session));
       case MIN:
       case MAX:
         boolean first = type == MIN;
         Index index = getColumnIndex();
         int sortType = index.getIndexColumns()[0].sortType;
         if ((sortType & SortOrder.DESCENDING) != 0) {
           first = !first;
         }
         Cursor cursor = index.findFirstOrLast(session, first);
         SearchRow row = cursor.getSearchRow();
         Value v;
         if (row == null) {
           v = ValueNull.INSTANCE;
         } else {
           v = row.getValue(index.getColumns()[0].getColumnId());
         }
         return v;
       default:
         DbException.throwInternalError("type=" + type);
     }
   }
   HashMap<Expression, Object> group = select.getCurrentGroup();
   if (group == null) {
     throw DbException.get(ErrorCode.INVALID_USE_OF_AGGREGATE_FUNCTION_1, getSQL());
   }
   AggregateData data = (AggregateData) group.get(this);
   if (data == null) {
     data = AggregateData.create(type);
   }
   Value v = data.getValue(session.getDatabase(), dataType, distinct);
   if (type == GROUP_CONCAT) {
     ArrayList<Value> list = ((AggregateDataGroupConcat) data).getList();
     if (list == null || list.size() == 0) {
       return ValueNull.INSTANCE;
     }
     if (groupConcatOrderList != null) {
       final SortOrder sortOrder = groupConcatSort;
       Collections.sort(
           list,
           new Comparator<Value>() {
             @Override
             public int compare(Value v1, Value v2) {
               Value[] a1 = ((ValueArray) v1).getList();
               Value[] a2 = ((ValueArray) v2).getList();
               return sortOrder.compare(a1, a2);
             }
           });
     }
     StatementBuilder buff = new StatementBuilder();
     String sep =
         groupConcatSeparator == null ? "," : groupConcatSeparator.getValue(session).getString();
     for (Value val : list) {
       String s;
       if (val.getType() == Value.ARRAY) {
         s = ((ValueArray) val).getList()[0].getString();
       } else {
         s = val.getString();
       }
       if (s == null) {
         continue;
       }
       if (sep != null) {
         buff.appendExceptFirst(sep);
       }
       buff.append(s);
     }
     v = ValueString.get(buff.toString());
   }
   return v;
 }