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

📄 tabledata.java

📁 一个简单的数据库
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package database;import bufferedManager.*;import java.util.*;import java.io.*;import indexManager.*;import apiManager.*;/** * * @author outlaw */public class TableData implements Serializable{    String path;    String name;    String fullName;    Date createTime;    int dbID;    int tbID;    int blockNumber;    int tupleNumber;    public ArrayList<Boolean> blockInFile;    public ArrayList<Boolean> blockIsFull;    ArrayList<Attribute> attributes;     ArrayList<IndexTag> indices;        public TableData(int dbID,int tbID,String path,String name,Date createTime) throws Exception{        this.path=path;        this.tbID=tbID;        this.name=name;        this.fullName=path+name+".tbl";        this.tupleNumber=0;        this.createTime=createTime;        this.dbID=dbID;        this.blockNumber=0;        this.indices=new ArrayList<IndexTag>();        blockInFile=new ArrayList<Boolean>();        blockIsFull=new ArrayList<Boolean>();        attributes=new ArrayList<Attribute>();    }    public void reset() throws Exception    {        this.tupleNumber=0;        this.blockNumber=0;        this.blockInFile=new ArrayList<Boolean>();        this.blockIsFull=new ArrayList<Boolean>();        APIManager.resetTableIndex(this.name,indices);    }        public int getAttribNumber()    {        return attributes.size();    }    public void incTupleNumber()    {        this.tupleNumber++;    }    public void decTupleNumber()    {        this.tupleNumber--;    }    public void incTupleNumber(int count)    {        this.tupleNumber+=count;    }    public void decTupleNumber(int count)    {        this.tupleNumber-=count;    }    public int getTupleNumber()    {        return this.tupleNumber;    }    public boolean isAttribKey(int index)    {        return attributes.get(index).isKey;    }    public void addIndexTag(IndexTag indTag)    {        this.indices.add(indTag);    }    public void addBlockLogical()    {        blockNumber++;        blockInFile.add(false);        blockIsFull.add(false);    }    public void addAttri(Attribute newAttri){        attributes.add(newAttri);    }    public ArrayList<Attribute> getAttributes(){        return attributes;    }    public String getPath()    {        return path;    }    public String getName()    {        return name;    }    public String getFullName()    {        return path+name;    }    public String[] getAttribTypes()    {        int len=attributes.size();        String[] types=new String[len];        for(int i=0;i<len;i++)        {            types[i]=attributes.get(i).getType();        }        return types;    }    public int getBlockNumber()    {        return blockNumber;    }    public void incBlockNumber()    {        blockNumber++;    }    public int getTupleLengtInBytes()    {        int count=0;        Attribute attrib=null;        for(int i=0;i<attributes.size();i++)        {            attrib=attributes.get(i);            String type=attrib.getType();              if(type.equals("int"))                count+=4;            if(type.equals("float"))                count+=4;            if(type.startsWith("char"))            {                int len=Integer.parseInt(type.substring(4));                count+=len*2+1;            }        }        return count;    }    public boolean hasThisIndex(String attribName)    {        for(int i=0;i<indices.size();i++)        {            if(indices.get(i).getAttribName().equals(attribName))             return true;        }        return false;    }    public int getTupleSizeInBlock()    {        int len=getTupleLengtInBytes();        return (Block.BLOCKSIZE-4)/(len+1);    }    public boolean isBlockInFile(int index)    {        return blockInFile.get(index);    }    public void setBlockInFile(int index)    {        blockInFile.set(index, true);    }    public void setBlockNotInFile(int index)    {        blockInFile.set(index, false);    }    public boolean isBlockFull(int index)    {        return blockIsFull.get(index);    }    public void setBlockFull(int index)    {        blockIsFull.set(index, true);    }    public void setBlockNotFull(int index)    {        blockIsFull.set(index,false);    }    public ArrayList<IndexTag> getIndices()    {        return indices;    }    public int getAttribIDByName(String name)    {        int len=attributes.size();        Attribute attrib;        for(int i=0;i<len;i++)        {            attrib=attributes.get(i);            if(attrib.getName().equals(name))                return i;        }        return -1;    }    public String getAttribType(int attribID)    {        Attribute attri=attributes.get(attribID);        return attri.getType();    }    public void init()    {        for(int i=0;i<blockNumber;i++)        {            blockInFile.set(i, true);        }    }    public boolean isAttriUnique(int index)    {        return attributes.get(index).isUnique;    }    public String[] getAttribNames()    {        int len=attributes.size();        String[] attribs=new String[len];        for(int i=0;i<len;i++)        {            attribs[i]=attributes.get(i).getName();        }        return attribs;    }    public String getAttribName(int index)    {        return attributes.get(index).name;    }    public void closeIndex()    {        int len=indices.size();                for(int i=0;i<len;i++)            indices.get(i).setInFile();    }    public IndexTag getIndexTag(String attribName)    {        for(int i=0;i<indices.size();i++)        {            if(indices.get(i).getAttribName().equals(attribName))                return indices.get(i);        }        return null;    }    public IndexTag getIndexTagByIndexName(String indName)    {        for(int i=0;i<indices.size();i++)        {            if(indices.get(i).getIndexName().equals(indName))                return indices.get(i);        }        return null;    }    public void removeIndexTagByIndexName(String indName)    {        for(int i=0;i<indices.size();i++)        {            if(indices.get(i).getIndexName().equals(indName))            {                indices.remove(i);                i--;            }        }    }    public String getFullNameWithSuffix()    {        return fullName;    }}

⌨️ 快捷键说明

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