public abstract class OracleBlock
{
public static final int FORMAT_V7 = 0x01;
public static final int FORMAT_V8 = 0x02;
public static final int FORMAT_V9 = 0x02;
public static final int ROW_CLUSTER_KEY = 0x80;
public static final int ROW_CTABLE_NUMBER = 0x40;
public static final int ROW_HEAD_PIECE = 0x20;
public static final int ROW_DELETED_ROW = 0x10;
public static final int ROW_FIRST_PIECE = 0x08;
public static final int ROW_LAST_PIECE = 0x04;
public static final int ROW_FROM_PREVIOUS = 0x02;
public static final int ROW_CONTINUE_NEXT = 0x01;
public static final int ROW_SINGLE =
ROW_HEAD_PIECE + ROW_FIRST_PIECE + ROW_LAST_PIECE;
public static final int ROW_CLUSTER =
ROW_CLUSTER_KEY + ROW_HEAD_PIECE + ROW_FIRST_PIECE + ROW_LAST_PIECE;
public static final int ROW_HASH_CLUSTER =
ROW_CLUSTER + ROW_FROM_PREVIOUS + ROW_CONTINUE_NEXT;
public static final int BLOCK_BLANK = 0x00;
public static final int BLOCK_KUNDO_HEADER = 0x01;
public static final int BLOCK_KUNDO_BLOCK = 0x02;
public static final int BLOCK_SUNDO_HEADER = 0x03;
public static final int BLOCK_SUNDO_BLOCK = 0x04;
public static final int BLOCK_SEG_HEADER = 0x05;
public static final int BLOCK_DATA = 0x06;
public static final int BLOCK_TEMP = 0x07;
public static final int BLOCK_SORT_KEY = 0x09;
public static final int BLOCK_SORT_RUN = 0x0a;
public static final int BLOCK_FILE_HEADER = 0x0b;
public static final int BLOCK_FLGSEG_HEADER= 0x0c;
public static final int BLOCK_COMPATIBILITY= 0x0d;
public static final int BLOCK_UUNDO_HEADER = 0x0e;
public static final int BLOCK_USUNDO_HEADER= 0x0f;
public static final int BLOCK_USEG_HEADER = 0x10;
public static final int BLOCK_UFLGSEG_HEADER=0x11;
public static final int BLOCK_EXTENT_MAP = 0x12;
public static final int BLOCK_CONTROL_FILE = 0x15;
public static final int BLOCK_BMPSEG_HEADER= 0x17;
public static final int BLOCK_BMPFREE_LIST = 0x18;
public static final int BLOCK_BITMAP_INDEX = 0x19;
public static final int BLOCK_BITMAP_DATA = 0x1a;
public static final int BLOCK_LOB_DATA = 0x1b;
public static final int DATA_TYPE_DATA = 0x01;
public static final int DATA_TYPE_INDEX= 0x02;
public static final int TRANSACTION_COMMITED = 0x08;
public static final int TRANSACTION_UPBOUND = 0x02;
public static final int TRANSACTION_ACTIVE = 0x01;
public static final int ORACLE_VARCHAR2 = 1;
public static final int ORACLE_NUMBER = 2;
public static final int ORACLE_LONG = 8;
public static final int ORACLE_VARCHAR = 9;
public static final int ORACLE_DATE = 12;
public static final int ORACLE_RAW = 23;
public static final int ORACLE_LONG_RAW = 24;
public static final int ORACLE_CHAR = 96;
public static final int ORACLE_BINARY_FLOAT = 100;
public static final int ORACLE_BINARY_DOUBLE= 101;
public static final int ORACLE_CLOB = 112;
public static final int ORACLE_BLOB = 113;
public static final int ORACLE_BFILE = 114;
public static final int ORACLE_CFILE = 115;
public static final int ORACLE_TIME = 178;
public static final int ORACLE_TIME_TZ = 179;
public static final int ORACLE_TIMESTAMP= 180;
public static final int ORACLE_TIMESTAMP_TZ = 181;
public static final int ORACLE_TIMESTAMP_LTZ = 231;
public static final int ORACLE_INTERVAL_YEAR = 182;
public static final int ORACLE_INTERVAL_DAY = 183;
protected static char _HEX_ARRAY[] = {'0','1','2','3','4','5','6'
,'7','8','9','a','b','c','d','e','f'};
protected String _field_sep = ",";
protected int _block_size = 8192;
protected byte _block_buf[] = new byte[8192];
protected int _column_type[] = null;
protected OracleDumpConfig _dump_config = null;
private StringBuffer temp = new StringBuffer();
protected java.io.PrintWriter _output_file = new java.io.PrintWriter(System.out);
protected int _fid = -1;
protected int _bno = -1;
public final void setDumpConfig(OracleDumpConfig odcfg)
{
_dump_config = odcfg;
}
public final void setOutputFile(java.io.PrintWriter _out)
{
if (_out != null)
_output_file = _out;
}
public final int getDataFileID(int rdba)
{
return (0x3FF & (rdba >> 22));
}
public final int getDataBlockID(int rdba)
{
return (rdba & 0x3FFFFF) ;
}
public final void setFieldSeperator(String sep)
{
if (sep != null)
_field_sep = sep;
}
public final String getFieldSeperator()
{
return _field_sep;
}
public final java.io.PrintWriter getOutputFile()
{
return _output_file;
}
public final int getBlockSize()
{
return _block_size;
}
public final void setBlockSize(int bs)
{
if (bs == 2048 || bs == 4096 || bs == 8192 ||
bs == 16384 || bs == 32768)
{
if (bs != _block_size)
{
_block_size = bs;
_block_buf = new byte[_block_size];
}
}
}
public final void setColumnType(int coltypes[])
{
_column_type = coltypes;
}
public final static int getColumnType(String type)
{
if (type == null)
return ORACLE_RAW;
if (type.equalsIgnoreCase("VARCHAR2"))
return ORACLE_VARCHAR2;
else if (type.equalsIgnoreCase("NUMBER"))
return ORACLE_NUMBER;
else if (type.equalsIgnoreCase("VARCHAR"))
return ORACLE_VARCHAR;
else if (type.equalsIgnoreCase("DATE"))
return ORACLE_DATE;
else if (type.equalsIgnoreCase("RAW"))
return ORACLE_RAW;
else if (type.equalsIgnoreCase("LONG"))
return ORACLE_LONG;
else if (type.equalsIgnoreCase("LONGRAW"))
return ORACLE_LONG_RAW;
else if (type.equalsIgnoreCase("CHAR"))
return ORACLE_CHAR;
else if (type.equalsIgnoreCase("TIMESTAMP"))
return ORACLE_TIMESTAMP;
else if (type.equalsIgnoreCase("BINARY_FLOAT"))
return ORACLE_BINARY_FLOAT;
else if (type.equalsIgnoreCase("BINARY_DOUBLE"))
return ORACLE_BINARY_DOUBLE;
else
return ORACLE_RAW;
}
public final boolean readBlock(int rdba)
throws java.io.IOException
{
int file_id = getDataFileID(rdba);
int block_id = getDataBlockID(rdba);
if (_dump_config == null) return false;
java.io.RandomAccessFile raf = _dump_config.getRandomAccessFile(file_id);
if (raf != null)
{
readBlock(raf,block_id);
return true;
}
return false;
}
public final boolean readBlock(int file_id, int block_id)
throws java.io.IOException
{
if (_dump_config == null) return false;
java.io.RandomAccessFile raf = _dump_config.getRandomAccessFile(file_id);
if (raf != null)
{
readBlock(raf,block_id);
return true;
}
return false;
}
public final boolean readBlock(OracleDumpConfig odcfg, int file_id, int block_id)
throws java.io.IOException
{
java.io.RandomAccessFile raf = odcfg.getRandomAccessFile(file_id);
if (raf != null)
{
if (file_id == _fid && block_id == _bno + 1)
{
_fid = -1;
_bno = -1;
raf.readFully(_block_buf,0,_block_size);
_fid = file_id;
_bno = block_id;
}
else
{
_fid = -1;
_bno = -1;
readBlock(raf,block_id);
_fid = file_id;
_bno = block_id;
}
return true;
}
return false;
}
public final void readBlock(java.io.RandomAccessFile raf,int offset)
throws java.io.IOException
{
raf.seek((long)(offset) * (long)(_block_size));
raf.readFully(_block_buf,0,_block_size);
}
public final String getStringAddress(int addr)
{
char _buf[] = new char[8];
_buf[0] = _HEX_ARRAY[(addr >> 28) & 0x0f];
_buf[1] = _HEX_ARRAY[(addr >> 24) & 0x0f];
_buf[2] = _HEX_ARRAY[(addr >> 20) & 0x0f];
_buf[3] = _HEX_ARRAY[(addr >> 16) & 0x0f];
_buf[4] = _HEX_ARRAY[(addr >> 12) & 0x0f];
_buf[5] = _HEX_ARRAY[(addr >> 8) & 0x0f];
_buf[6] = _HEX_ARRAY[(addr >> 4) & 0x0f];
_buf[7] = _HEX_ARRAY[(addr) & 0x0f];
return String.valueOf(_buf);
}
public abstract OracleBlock createBlock();
public abstract int getBlockType();
public abstract int getFormat();
public abstract int getDataFileID();
public abstract int getDataBlockID();
public abstract String getDataBlockAddress();
public abstract String getDataBlockTail();
public abstract int getDataObjectID();
public abstract String getSCNBase();
public abstract String getSCNWrap();
public abstract int getBlockSequence();
public abstract int getBlockFlag();
public abstract String getCheckValue();
public abstract String getCleanSCN();
public abstract int getITLNumber();
public abstract int getITLRecordSize();
public abstract int getDataType();
public abstract String getITLXID(int itlno);
public abstract String getITLUBA(int itlno);
public abstract String getITLFlag(int itlno);
public abstract int getITLStatus(int itlno);
public abstract int getITLLock(int itlno);
public abstract String getITLSCN(int itlno);
public abstract String getITLFSC(int itlno);
public abstract int getDataFlag();
public abstract int getITLEndOffset();
public abstract int getTableCount();
public abstract int getRecordCount();
public abstract int getFirstFreeRowEntry();
public abstract int getFreeSpaceBeginOffset();
public abstract int getFreeSpaceEndOffset();
public abstract int getAvailSpace();
public abstract int getTotalSpace();
public abstract int getTableRowCount(int tno);
public abstract int getTableRowOffset(int tno,int row);
// Index Block
/*
-- Non IOT Leaf Block
kdxcolev = 1 byte
kdxcolok = 1 byte
kdxcoopc = 1 byte (opcode=0: iot flags=--- is converted=Y)
kdxconco = 1 byte
kdxcosdc = 4 bytes
kdxconro = 2 bytes
kdxcofbo = 2 bytes
kdxcofeo = 2 bytes
kdxcoavs = 2 bytes
*/
public abstract int getIndexHeaderAddress();
public abstract int getIndexColev();
public abstract int getIndexColok();
public abstract int getIndexCoopc();
public abstract int getIndexOpcode();
public abstract int getIndexColumnCount();
public abstract int getIndexCosdc();
public abstract int getIndexRowCount();
public abstract int getIndexFreeSpaceBegin();
public abstract int getIndexFreeSpaceEnd();
public abstract int getIndexFreeSpace();
public abstract int getIndexOffset(int row);
/*
// Branch block
kdxbrlmc = 4 bytes
kdxbrsno = 4 bytes
kdxbrbksz = 4 bytes
*/
public abstract int getIndexBrlmc();
public abstract int getIndexBrsno();
public abstract int getIndexBrbksz();
/*
// Leaf block
kdxlespl = 2 bytes
kdxlende = 2 bytes
kdxlenxt = 4 bytes (16777252=0x1000024)
kdxleprv = 4 bytes
kdxledsz = 4 bytes
kdxlebksz = 4 bytes
*/
public abstract int getIndexLespl();
public abstract int getIndexLende();
public abstract int getIndexLenxt();
public abstract int getIndexLeprv();
public abstract int getIndexLedsz();
public abstract int getIndexLebksz();
// Data File Header
public abstract String getSoftwareVersion(); //0x14 - 0x17
public abstract String getCompatibleVersion(); //0x18 - 0x1b
public abstract long getDBIDInt(); // 0x1c - 0x1f
public abstract String getDBIDHex(); // 0x1c - 0x1f
public abstract String getDatabaseName(); //0x20 - 0x27
public abstract int getControlSeq(); //0x28 - 0x2b
public abstract int getBlockCount(); //0x2c - 0x2f
public abstract int getDBBlockSize(); //0x30 - 0x21
public abstract int getFileNumber(); //0x34 - 0x35
public abstract int getFileType(); //0x36 - 0x37
public abstract int getTablespaceID(); //0xf4 - 0xf7
public abstract String getTablespaceName(); // 0xf8 -0xf9 -- len 0xfa - length;
// Segment Header Function
public abstract int getSegExtentCount(); // 0x24 - 0x27
public abstract int getSegBlockCount(); // 0x28 - 0x2B
// 0x6c + extid * 8 + 0x00 - 0x03
public abstract int getSegExtentRDBA(int extid);
// 0x6c + extid * 8 + 0x04 - 0x07
public abstract int getSegExtentBlocks(int extid);
public abstract int getSegNextMapRDBA(); // 0x60 - 0x63
public abstract int getSegMapFlag(); // 0x68 - 0x6B
public abstract int getSegFLGBlocks(); // 0x48 - 0x4b
public abstract int getSegFLGBellow(); // 0x4c - 0x4f
public abstract int getSegHWMAddress(); //0x3c - 0x3f
public abstract int getSegHWMExtent(); // 0x31 - 0x33
public abstract int getSegHWMBlocks(); // 0x34 - 0x37
public abstract int getSegHWMExtSize(); // 0x38 - 0x3b
public abstract int getSegNextMAP(); // 0x40 - 0x44
public abstract int getBlockExtentCount(); // 0x5c - 0x5f
[此贴子已经被作者于2007-6-12 9:52:32编辑过]