Package org.lealone.dbobject.table

Examples of org.lealone.dbobject.table.Table


            // 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--;
            }
        }
View Full Code Here


        }
        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;
View Full Code Here

    }

    //只用于update语句
    @Override
    protected Column readTableColumn(TableFilter filter) {
        Table t = filter.getTable();
        if (!t.supportsColumnFamily())
            return super.readTableColumn(filter);

        //完整的语法是: catalogName(也就是数据库名).tableAlias.columnFamilyName.columnName
        //如果没有使用表别名,tableAlias实际上就是原始表名
        String columnFamilyName = null;
        String columnName = readColumnIdentifier();
        if (readIf(".")) {
            columnFamilyName = columnName;
            columnName = readColumnIdentifier();
            if (readIf(".")) {
                String tableAlias = columnFamilyName;
                columnFamilyName = columnName;
                columnName = readColumnIdentifier();
                if (readIf(".")) {
                    String schema = tableAlias;
                    tableAlias = columnFamilyName;
                    columnFamilyName = columnName;
                    columnName = readColumnIdentifier();
                    if (readIf(".")) {
                        String catalogName = schema;
                        schema = tableAlias;
                        tableAlias = columnFamilyName;
                        columnFamilyName = columnName;
                        columnName = readColumnIdentifier();
                        if (!equalsToken(catalogName, database.getShortName())) {
                            throw DbException.get(ErrorCode.DATABASE_NOT_FOUND_1, catalogName);
                        }
                    }
                    if (!equalsToken(schema, filter.getTable().getSchema().getName())) {
                        throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schema);
                    }
                }
                if (!equalsToken(tableAlias, filter.getTableAlias())) {
                    throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableAlias);
                }
            }
        }
        if (database.getSettings().rowId) {
            if (Column.ROWID.equals(columnName)) {
                return filter.getRowIdColumn();
            }
        }

        if (columnFamilyName == null) {
            return t.getColumn(columnName);
        } else if (!t.doesColumnFamilyExist(columnFamilyName)) {
            //当columnFamilyName不存在时,有可能是想使用简化的tableAlias.columnName语法
            if (!equalsToken(columnFamilyName, filter.getTableAlias())) {
                throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, columnFamilyName);
            }

            return t.getColumn(columnName);
        } else {
            return t.getColumn(columnFamilyName, columnName, false);
        }
    }
View Full Code Here

public class HBaseMergedResult extends DelegatedResult {
    public HBaseMergedResult(List<ResultInterface> results, Select newSelect, Select oldSelect) {
        //1. 结果集串行化,为合并做准备
        HBaseSerializedResult serializedResult = new HBaseSerializedResult(results, oldSelect);
        Table table = newSelect.getTopTableFilter().getTable();
        newSelect.getTopTableFilter().setIndex(
                new HBaseMergedIndex(serializedResult, table, -1, IndexColumn.wrap(table.getColumns()), IndexType
                        .createScan(false)));

        //2. 把多个结果集合并
        ResultInterface mergedResult = newSelect.queryGroupMerge();

        //3. 计算合并后的结果集,
        //例如oldSelect="select avg"时,在分布式环境要转成newSelect="select count, sum",
        //此时就由count, sum来算出avg
        ResultInterface calculatedResult = oldSelect.calculate(mergedResult, newSelect);

        //4. 如果不存在avg、stddev这类需要拆分为count、sum的计算,此时mergedResult和calculatedResult是同一个实例
        //否则就是不同实例,需要再一次按oldSelect合并结果集
        if (mergedResult != calculatedResult) {
            table = oldSelect.getTopTableFilter().getTable();
            oldSelect.getTopTableFilter().setIndex(
                    new HBaseMergedIndex(calculatedResult, table, -1, IndexColumn.wrap(table.getColumns()), IndexType
                            .createScan(false)));
            //5. 最终结果集
            result = oldSelect.queryGroupMerge();

            //6. 立刻关闭中间结果集
View Full Code Here

        return columnResolver == null ? null : columnResolver.getTableFilter();
    }

    public void mapColumns(ColumnResolver resolver, int level) {
        if (resolver instanceof TableFilter && resolver.getTableFilter().getTable().supportsColumnFamily()) {
            Table t = resolver.getTableFilter().getTable();

            //            if (!t.isStatic() && t.getRowKeyName().equalsIgnoreCase(columnName)) {
            //                if (columnFamilyName != null) {
            //                    schemaName = tableAlias;
            //                    tableAlias = columnFamilyName;
            //                    columnFamilyName = null;
            //                }
            //                if (tableAlias != null && !database.equalsIdentifiers(tableAlias, resolver.getTableAlias())) {
            //                    return;
            //                }
            //                if (schemaName != null && !database.equalsIdentifiers(schemaName, resolver.getSchemaName())) {
            //                    return;
            //                }
            //                mapColumn(resolver, t.getRowKeyColumn(), level);
            //                return;
            //            }

            if (database.equalsIdentifiers(Column.ROWKEY, columnName)) {
                Column col = t.getRowKeyColumn();
                if (col != null) {
                    mapColumn(resolver, col, level);
                    return;
                }
            }
            if (resolver.getSelect() == null) {
                Column c = t.getColumn(columnName);
                mapColumn(resolver, c, level);
                return;
            }

            String tableAlias = this.tableAlias;
            boolean useAlias = false;
            //当columnFamilyName不存在时,有可能是想使用简化的tableAlias.columnName语法
            if (columnFamilyName != null && !t.doesColumnFamilyExist(columnFamilyName)) {
                //不替换原有的tableAlias,因为有可能在另一个table中存在这样的columnFamilyName
                tableAlias = columnFamilyName;

                if (!t.doesColumnExist(columnName))
                    return;

                useAlias = true;
            }

            if (tableAlias != null && !database.equalsIdentifiers(tableAlias, resolver.getTableAlias())) {
                return;
            }
            if (schemaName != null && !database.equalsIdentifiers(schemaName, resolver.getSchemaName())) {
                return;
            }

            String fullColumnName;
            if (useAlias || columnFamilyName == null)
                fullColumnName = columnName;
            else
                fullColumnName = t.getFullColumnName(columnFamilyName, columnName);

            if (t.doesColumnExist(fullColumnName)) {
                Column c = t.getColumn(fullColumnName);
                resolver.getSelect().addColumn(resolver.getTableFilter(), c);
                mapColumn(resolver, c, level);
                return;
            }
        } else {
View Full Code Here

     * @param obj the object to be removed
     */
    public synchronized void removeSchemaObject(Session session, SchemaObject obj) {
        int type = obj.getType();
        if (type == DbObject.TABLE_OR_VIEW) {
            Table table = (Table) obj;
            if (table.isTemporary() && !table.isGlobalTemporary()) {
                session.removeLocalTempTable(table);
                return;
            }
        } else if (type == DbObject.INDEX) {
            Index index = (Index) obj;
            Table table = index.getTable();
            if (table.isTemporary() && !table.isGlobalTemporary()) {
                session.removeLocalTempTableIndex(index);
                return;
            }
        } else if (type == DbObject.CONSTRAINT) {
            Constraint constraint = (Constraint) obj;
            Table table = constraint.getTable();
            if (table.isTemporary() && !table.isGlobalTemporary()) {
                session.removeLocalTempTableConstraint(constraint);
                return;
            }
        }
        checkWritingAllowed();
        lockMeta(session);
        Comment comment = findComment(obj);
        if (comment != null) {
            removeDatabaseObject(session, comment);
        }
        obj.getSchema().remove(obj);
        int id = obj.getId();
        if (!starting) {
            Table t = getDependentTable(obj, null);
            if (t != null) {
                obj.getSchema().add(obj);
                throw DbException.get(ErrorCode.CANNOT_DROP_2, obj.getSQL(), t.getSQL());
            }
            obj.removeChildrenAndResources(session);
        }
        removeMeta(session, id);
    }
View Full Code Here

    public String getColumnName() {
        return columnName != null ? columnName : column.getName();
    }

    public String getSchemaName() {
        Table table = column.getTable();
        return table == null ? null : table.getSchema().getName();
    }
View Full Code Here

        Table table = column.getTable();
        return table == null ? null : table.getSchema().getName();
    }

    public String getTableName() {
        Table table = column.getTable();
        return table == null ? null : table.getName();
    }
View Full Code Here

    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;
View Full Code Here

    public Value getMergedValue(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;
View Full Code Here

TOP

Related Classes of org.lealone.dbobject.table.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.