⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basetable.java

📁 开源的axion的数据库代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public boolean isColumnIndexed(Column column) {        Iterator indices = _indices.iterator();        while(indices.hasNext()) {            Index index = (Index)indices.next();            if(column.equals(index.getIndexedColumn())) {                return true;            }        }        return false;    }    public RowIterator getMatchingRows(List selectables, List values) throws AxionException {        if(null == selectables || selectables.isEmpty()) {            return getRowIterator(true);        } else {            // TODO: may be able to optimize this by first checking for for indices or            //       with a special subclass of AbstractAcceptingRowIterator rather            //       than creating a WhereNode            WhereNode root = null;            Iterator left = selectables.iterator();            Iterator right = values.iterator();            while(left.hasNext()) {                LeafWhereNode leaf = null;                Object value = right.next();                               leaf = new LeafWhereNode(                    (Selectable)left.next(),                    ComparisonOperator.EQUAL,                    new Literal(value));                if(null == root) {                    root = leaf;                } else {                    BinaryBranchWhereNode branch = new BinaryBranchWhereNode();                    branch.setIsAnd(true);                    branch.setLeft(root);                    branch.setRight(leaf);                    root = branch;                }            }                        return new FilteringRowIterator(getRowIterator(true),makeRowDecorator(),root);        }    }    public RowIterator getIndexedRows(WhereNode node, boolean readOnly) throws AxionException {        if(readOnly) {            return UnmodifiableRowIterator.wrap(getIndexedRows(node));        } else {            return getIndexedRows(node);        }    }        /**     * Add the given {@link Column} to this table.     * This implementation throws an {@link AxionException}     * if rows have already been added to the table.     */    public void addColumn(Column col) throws AxionException {        if(getRowCount() > 0) {            throw new AxionException("Cannot add column because table already contains rows.");        } else {            // XXX FIX ME XXX            if(col.getDataType() instanceof LOBType) {                LOBType lob = (LOBType)(col.getDataType());                if(null == lob.getLobDir()) {                    lob.setLobDir(new File(System.getProperty("axiondb.lobdir", "."), col.getName()));                }            }            _cols.add(col);            _colIndexToColIdMap = null;            publishEvent(new ColumnEvent(this, col));        }    }    public boolean hasColumn(ColumnIdentifier id) {        boolean result = false;        String tableName = id.getTableName();        if(tableName == null || tableName.equals(getName())) {            result = (getColumn(id.getName()) != null);        }        return result;    }    public Column getColumn(int index) {        return (Column)(_cols.get(index));    }    public Column getColumn(String name) {        for(int i = 0; i < _cols.size(); i++) {            Column col = (Column)(_cols.get(i));            if(col.getName().equalsIgnoreCase(name)) {                return col;            }        }        return null;    }    public int getColumnIndex(String name) throws AxionException {        for(int i = 0; i < _cols.size(); i++) {            Column col = (Column)(_cols.get(i));            if(col.getName().equalsIgnoreCase(name)) {                return i;            }        }        throw new AxionException("Column " + name + " not found.");    }    public Iterator getColumnIdentifiers() {        List result = new ArrayList();        for(int i=0;i<_cols.size();i++) {            Column col = (Column)(_cols.get(i));            result.add(new ColumnIdentifier(new TableIdentifier(getName()),col.getName(),null,col.getDataType()));        }        return result.iterator();    }    public int getColumnCount() {        return _cols.size();    }    public void drop() throws AxionException {    }    public void remount(File dir, boolean datafilesonly) throws AxionException {    }    public void checkpoint() throws AxionException {    }    public void shutdown() throws AxionException {    }    public RowDecorator makeRowDecorator() {        if(null == _colIndexToColIdMap) {            Map map = new HashMap();            int i=0;            for(Iterator iter = getColumnIdentifiers();iter.hasNext();) {                map.put(iter.next(),new Integer(i++));            }            _colIndexToColIdMap = map;        }        return new RowDecorator(_colIndexToColIdMap);    }        public TransactableTable makeTransactableTable() {        return new TransactableTableImpl(this);    }    public Iterator getIndices() {        return _indices.iterator();    }        protected void checkConstraints(RowEvent event) throws AxionException {        checkConstraints(event,false);    }        protected void checkConstraints(RowEvent event, boolean deferred) throws AxionException {        for(Iterator iter = getConstraints();iter.hasNext();) {            Constraint c = (Constraint)iter.next();            if(c.isDeferred() == deferred) {                if(!c.evaluate(event)) {                    throw new ConstraintViolationException(c);                }            }        }    }    protected boolean hasDeferredConstraint() {        for(Iterator iter = getConstraints();iter.hasNext();) {            Constraint c = (Constraint)iter.next();            if(c.isDeferred()) {                return true;            }        }        return false;    }    protected void notifyColumnsOfNewLobDir(File directory) {        Iterator iter = _cols.iterator();        while(iter.hasNext()) {            Column col = (Column)(iter.next());            if(col.getDataType() instanceof LOBType) {                LOBType lob = (LOBType)(col.getDataType());                if(null == lob.getLobDir()) {                    lob.setLobDir(new File(directory,col.getName()));                }            }        }    }    private RowIterator getIndexedRows(WhereNode node) throws AxionException {        if(node instanceof LeafWhereNode) {            LeafWhereNode leaf = (LeafWhereNode)node;            Column column = null;            Literal literal = null;            ComparisonOperator op = leaf.getOperator();            if(leaf.getLeft() instanceof ColumnIdentifier && leaf.getRight() instanceof Literal) {                column = getColumn(((ColumnIdentifier)leaf.getLeft()).getName());                literal = (Literal)(leaf.getRight());            } else if(leaf.getLeft() instanceof Literal && leaf.getRight() instanceof ColumnIdentifier) {                column = getColumn(((ColumnIdentifier)leaf.getRight()).getName());                literal = (Literal)(leaf.getLeft());                op = op.flip();            } else {                return null;            }            if(!isColumnIndexed(column)) {                return null;            } else {                Index index = getIndexForColumn(column);                if(!index.supportsOperator(op)) {                    return null;                } else if(literal instanceof BindVariable) {                    return new RebindableIndexedRowIterator(index,this,op,(BindVariable)literal);                } else {                    return index.getRowIterator(this,op,literal.evaluate(null));                }            }        } else {            return null;        }    }        private String _name = null;    private String _type = null;    private List _cols = new ArrayList();    private List _indices = new ArrayList();    private Map _constraints = new HashMap();    private Map _colIndexToColIdMap = null;    private static Log _log = LogFactory.getLog(BaseTable.class);   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -