using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;
using Harlinn.Common;
using Harlinn.DBTool.Common;
using Harlinn.DBTool.DataSources.Oracle.DB;
namespace Harlinn.DBTool.DataSources.Oracle
{
public class DBOracleTable : DBOracleUserObject, IDBTabular,IDBTable
{
private static readonly log4net.ILog sfLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static void LogException(Exception exc, System.Reflection.MethodBase method)
{
Logger.LogException(sfLog, exc, method);
}
string tablespaceName;
string clusterName;
string iotName;
string status;
double pctFree;
double? pctUsed;
int iniTrans;
int maxTrans;
int initialExtent;
int nextExtent;
int minExtents;
int maxExtents;
double? pctIncrease;
int? freelists;
int? freelistGroups;
bool logging;
bool backedUp;
int numRows;
int blocks;
int emptyBlocks;
int avgSpace;
int chainCount;
int avgRowLen;
int avgSpaceFreelistBlocks;
int numFreelistBlocks;
string degree;
string instances;
string cache;
string tableLock;
int sampleSize;
DateTime lastAnalyzed;
bool partitioned;
string iotType;
bool temporary;
bool secondary;
bool nested;
string bufferPool;
string flashCache;
string cellFlashCache;
string rowMovement;
bool globalStats;
bool userStats;
string duration;
string skipCorrupt;
bool monitoring;
string clusterOwner;
string dependencies;
string compression;
string compressFor;
bool dropped;
bool readOnly;
bool segmentCreated;
string resultCache;
public DBOracleTable()
{
}
public DBOracleTable(NodeBase parent, ObjectReader reader)
: base(parent, reader)
{
TableReader tableReader = new TableReader(Owner, Name);
using(tableReader)
{
if (tableReader.Read())
{
tablespaceName = tableReader.TablespaceName;
clusterName = tableReader.ClusterName;
iotName = tableReader.IOTName;
status = tableReader.Status;
pctFree = tableReader.PctFree;
pctUsed = tableReader.PctUsed;
iniTrans = tableReader.IniTrans;
maxTrans = tableReader.MaxTrans;
initialExtent = tableReader.InitialExtent;
nextExtent = tableReader.NextExtent;
minExtents = tableReader.MinExtents;
maxExtents = tableReader.MaxExtents;
pctIncrease = tableReader.PctIncrease;
freelists = tableReader.Freelists;
freelistGroups = tableReader.FreelistGroups;
logging = tableReader.Logging;
backedUp = tableReader.BackedUp;
numRows = tableReader.NumRows;
blocks = tableReader.Blocks;
emptyBlocks = tableReader.EmptyBlocks;
avgSpace = tableReader.AvgSpace;
chainCount = tableReader.ChainCount;
avgRowLen = tableReader.AvgRowLen;
avgSpaceFreelistBlocks = tableReader.AvgSpaceFreelistBlocks;
numFreelistBlocks = tableReader.NumFreelistBlocks;
degree = tableReader.Degree;
instances = tableReader.Instances;
cache = tableReader.Cache;
tableLock = tableReader.TableLock;
sampleSize = tableReader.SampleSize;
lastAnalyzed = tableReader.LastAnalyzed;
partitioned = tableReader.Partitioned;
iotType = tableReader.IOTType;
temporary = tableReader.Temporary;
secondary = tableReader.Secondary;
nested = tableReader.Nested;
bufferPool = tableReader.BufferPool;
flashCache = tableReader.FlashCache;
cellFlashCache = tableReader.CellFlashCache;
rowMovement = tableReader.RowMovement;
globalStats = tableReader.GlobalStats;
userStats = tableReader.UserStats;
duration = tableReader.Duration;
skipCorrupt = tableReader.SkipCorrupt;
monitoring = tableReader.Monitoring;
clusterOwner = tableReader.ClusterOwner;
dependencies = tableReader.Dependencies;
compression = tableReader.Compression;
compressFor = tableReader.CompressFor;
dropped = tableReader.Dropped;
readOnly = tableReader.ReadOnly;
segmentCreated = tableReader.SegmentCreated;
resultCache = tableReader.ResultCache;
}
}
}
[Browsable(false)]
public DBOracleTables Tables
{
get
{
DBOracleTables result = (DBOracleTables)Parent;
return result;
}
}
public override DBOracleElementType ElementType
{
get
{
return DBOracleElementType.UserTable;
}
}
public override ObjectType GetObjectType()
{
return ObjectType.Table;
}
public string GetQualifiedName()
{
string userName = Parent.Parent.Parent.Name;
string qualifiedName = userName + "." + Name;
return qualifiedName;
}
public override void Refresh()
{
base.Refresh();
try
{
string qualifiedName = GetQualifiedName();
DBOracleFields fields = new DBOracleFields(this, qualifiedName);
Children.Add(fields);
DBOracleTableConstraints constraints = new DBOracleTableConstraints(this);
Children.Add(constraints);
DBOracleTableForeignKeys foreignKeys = new DBOracleTableForeignKeys(this);
Children.Add(foreignKeys);
string userName = Parent.Parent.Parent.Name;
string tableName = Name;
ConstraintsReader reader = new ConstraintsReader(userName, tableName);
using (reader)
{
while (reader.Read())
{
if (reader.ConstraintType == "R")
{
DBOracleTableForeignKey dbElement = new DBOracleTableForeignKey(foreignKeys, reader);
constraints.Children.Add(dbElement);
}
else
{
DBOracleTableConstraint dbElement = new DBOracleTableConstraint(constraints, reader);
constraints.Children.Add(dbElement);
}
}
}
DBOracleTableIndexes indexes = new DBOracleTableIndexes(this);
Children.Add(indexes);
}
catch (Exception exc)
{
LogException(exc, MethodBase.GetCurrentMethod());
throw;
}
}
[Browsable(false)]
public DBOracleFields Fields
{
get
{
DBOracleFields result = GetChildByName<DBOracleFields>("Fields");
return result;
}
}
[Browsable(false)]
public DBOracleTableConstraints Constraints
{
get
{
DBOracleTableConstraints result = GetChildByName<DBOracleTableConstraints>("Constraints");
return result;
}
}
[Browsable(false)]
public DBOracleTableForeignKeys ForeignKeys
{
get
{
DBOracleTableForeignKeys result = GetChildByName<DBOracleTableForeignKeys>("Foreign Keys");
return result;
}
}
[Browsable(false)]
public DBOracleTableIndexes Indexes
{
get
{
DBOracleTableIndexes result = GetChildByName<DBOracleTableIndexes>("Indexes");
return result;
}
}
public string GetOwner()
{
return Parent.Parent.Parent.Name;
}
public string GetName()
{
return Name;
}
public List<DBOracleField> GetFields()
{
List<DBOracleField> result = new List<DBOracleField>();
DBOracleFields fields = GetChildByName<DBOracleFields>("Fields");
foreach (DBOracleField field in fields.Children)
{
result.Add(field);
}
return result;
}
[Browsable(false)]
public bool IsTable
{
get
{
return true;
}
}
[Browsable(false)]
public bool IsView
{
get
{
return false;
}
}
public List<DBOracleField> GetPrimaryKeyFields()
{
DBOracleTableConstraint primaryKeyConstraint = Constraints.GetPrimaryKey();
if (primaryKeyConstraint != null)
{
return primaryKeyConstraint.GetFields();
}
return null;
}
public DBOracleField GetOptimisticLockField()
{
DBOracleField result = null;
DBOracleFields fields = GetChildByName<DBOracleFields>("Fields");
foreach (DBOracleField field in fields.Children)
{
if (field.Name == "OPTIMISTIC_LOCK")
{
result = field;
break;
}
}
return result;
}
[Description("Name of the tablespace containing the table")]
[DisplayName("Tablespace Name")]
public string TablespaceName
{
get
{
return tablespaceName;
}
}
[Description("Name of the cluster, if any, to which the table belongs")]
[DisplayName("Cluster Name")]
public string ClusterName
{
get
{
return clusterName;
}
}
[Description("Name of the index-only table, if any, to which the overflow or mapping table entry belongs")]
[DisplayName("IOT Name")]
public string IOTName
{
get
{
return iotName;
}
}
/*[Description("Status of the table will be UNUSABLE if a previous DROP TABLE operation failed, VALID otherwise")]
[DisplayName("Status")]
public string Status
{
get
{
return status;
}
}*/
[Description("Minimum percentage of free space in a block")]
[DisplayName("% Free")]
public double PctFree
{
get
{
return pctFree;
}
}
[Description("Minimum percentage of used space in a block")]
[DisplayName("% Used")]
public double? PctUsed
{
get
{
return pctUsed;
}
}
[Description("Initial number of transactions")]
[DisplayName("Ini Trans")]
public int IniTrans
{
get
{
return iniTrans;
}
}
[Description("Maximum number of transactions")]
[DisplayName("Max Trans")]
public int MaxTrans
{
get
{
return maxTrans;
}
}
[Description("Size of the initial extent in bytes")]
[DisplayName("Initial Extent")]
public int InitialExtent
{
get
{
return initialExtent;
}
}
[Description("Size of secondary extents in bytes")]
[DisplayName("Next Extent")]
public int NextExtent
{
get
{
return nextExtent;
}
}
[Description("Minimum number of extents allowed in the segment")]
[DisplayName("Min Extents")]
public int MinExtents
{
get
{
return minExtents;
}
}
[Description("Maximum number of extents allowed in the segment")]
[DisplayName("MaxExtents")]
public int MaxExtents
{
get
{
return maxExtents;
}
}
[Description("Percentage increase in extent size")]
[DisplayName("% Increase")]
public double? PctIncrease
{
get
{
return pctIncrease;
}
}
[Description("Number of process freelists allocated in this segment")]
[DisplayName("Freelists")]
public int? Freelists
{
get
{
return freelists;
}
}
[Description("Number of freelist groups allocated in this segment")]
[DisplayName("Freelist Groups")]
public int? FreelistGroups
{
get
{
return freelistGroups;
}
}
[Description("Logging attribute")]
[DisplayName("Logging")]
public bool Logging
{
get
{
return logging;
}
}
[Description("Has table been backed up since last modification?")]
[DisplayName("Backed Up")]
public bool BackedUp
{
get
{
return backedUp;
}
}
[Description("The number of rows in the table")]
[DisplayName("Num Rows")]
public int NumRows
{
get
{
return numRows;
}
}
[Description("The number of used blocks in the table")]
[DisplayName("Blocks")]
public int Blocks
{
get
{
return blocks;
}
}
[Description("The number of empty (never used) blocks in the table")]
[DisplayName("Empty Blocks")]
public int EmptyBlocks
{
get
{
return emptyBlocks;
}
}
[Description("The average available free space in the table")]
[DisplayName("Avg. Space")]
public int AvgSpace
{
get
{
return avgSpace;
}
}
[Description("The number of chained rows in the table")]
[DisplayName("Chain Count")]
public int ChainCount
{
get
{
return chainCount;
}
}
[Description("The average row length, including row overhead")]
[DisplayName("Avg. Row Length")]
public int AvgRowLen
{
get
{
return avgRowLen;
}
}
[Description("The average freespace of all blocks on a freelist")]
[DisplayName("Avg. Space Freelist Blocks")]
public int AvgSpaceFreelistBlocks
{
get
{
return avgSpaceFreelistBlocks;
}
}
[Description("The number of blocks on the freelist")]
[DisplayName("Num. Freelist Blocks")]
public int NumFreelistBlocks
{
get
{
return numFreelistBlocks;
}
}
[Description("The number of threads per instance for scanning the table")]
[DisplayName("Degree")]
public string Degree
{
get
{
return degree;
}
}
[Description("The number of instances across which the table is to be scanned")]
[DisplayName("Instances")]
public string Instances
{
get
{
return instances;
}
}
[Description("Whether the table is to be cached in the buffer cache")]
[DisplayName("Cache")]
public string Cache
{
get
{
return cache;
}
}
[Description("Whether table locking is enabled or disabled")]
[DisplayName("Table Lock")]
public string TableLock
{
get
{
return tableLock;
}
}
[Description("The sample size used in analyzing this table")]
[DisplayName("Sample Size")]
public int SampleSize
{
get
{
return sampleSize;
}
}
[Description("The date of the most recent time this table was analyzed")]
[DisplayName("Last Analyzed")]
public DateTime LastAnalyzed
{
get
{
return lastAnalyzed;
}
}
[Description("Is this table partitioned?")]
[DisplayName("Partitioned")]
public bool Partitioned
{
get
{
return partitioned;
}
}
[Description("If index-only table, then IOT_TYPE is IOT or IOT_OVERFLOW or IOT_MAPPING else NULL")]
[DisplayName("IOT Type")]
public string IOTType
{
get
{
return iotType;
}
}
/*[Description("Can the current session only see data that it place in this object itself?")]
[DisplayName("Temporary")]
public bool Temporary
{
get
{
return temporary;
}
}*/
/*[Description("Is this table object created as part of icreate for domain indexes?")]
[DisplayName("Secondary")]
public bool Secondary
{
get
{
return secondary;
}
}*/
[Description("Is the table a nested table?")]
[DisplayName("Nested")]
public bool Nested
{
get
{
return nested;
}
}
[Description("The default buffer pool to be used for table blocks")]
[DisplayName("Buffer Pool")]
public string BufferPool
{
get
{
return bufferPool;
}
}
[Description("The default flash cache hint to be used for table blocks")]
[DisplayName("Flash Cache")]
public string FlashCache
{
get
{
return flashCache;
}
}
[Description("The default cell flash cache hint to be used for table blocks")]
[DisplayName("Cell Flash Cache")]
public string CellFlashCache
{
get
{
return cellFlashCache;
}
}
[Description("Whether partitioned row movement is enabled or disabled")]
[DisplayName("Row Movement")]
public string RowMovement
{
get
{
return rowMovement;
}
}
[Description("Are the statistics calculated without merging underlying partitions?")]
[DisplayName("Global Stats")]
public bool GlobalStats
{
get
{
return globalStats;
}
}
[Description("Were the statistics entered directly by the user?")]
[DisplayName("User Stats")]
public bool UserStats
{
get
{
return userStats;
}
}
[Description("If temporary table, then duration is sys$session or sys$transaction else NULL")]
[DisplayName("Duration")]
public string Duration
{
get
{
return duration;
}
}
[Description("Whether skip corrupt blocks is enabled or disabled")]
[DisplayName("Skip Corrupt")]
public string SkipCorrupt
{
get
{
return skipCorrupt;
}
}
[Description("Should we keep track of the amount of modification?")]
[DisplayName("Monitoring")]
public bool Monitoring
{
get
{
return monitoring;
}
}
[Description("Owner of the cluster, if any, to which the table belongs")]
[DisplayName("Cluster Owner")]
public string ClusterOwner
{
get
{
return clusterOwner;
}
}
[Description("Should we keep track of row level dependencies?")]
[DisplayName("Dependencies")]
public string Dependencies
{
get
{
return dependencies;
}
}
[Description("Whether table compression is enabled or not")]
[DisplayName("Compression")]
public string Compression
{
get
{
return compression;
}
}
[Description("Compress what kind of operations")]
[DisplayName("Compress For")]
public string CompressFor
{
get
{
return compressFor;
}
}
[Description("Whether table is dropped and is in Recycle Bin")]
[DisplayName("Dropped")]
public bool Dropped
{
get
{
return dropped;
}
}
[Description("Whether table is read only or not")]
[DisplayName("Read Only")]
public bool ReadOnly
{
get
{
return readOnly;
}
}
[Description("Whether the table segment is created or not")]
[DisplayName("Segment Created")]
public bool SegmentCreated
{
get
{
return segmentCreated;
}
}
[Description("The result cache mode annotation for the table")]
[DisplayName("Result Cache")]
public string ResultCache
{
get
{
return resultCache;
}
}
IDBIndex DataSources.IDBTabular.PrimaryKey
{
get
{
DBOracleTableConstraint primaryKeyConstraint = Constraints.GetPrimaryKey();
if (primaryKeyConstraint != null)
{
DBOracleTableIndex index = Indexes.GetChildByName<DBOracleTableIndex>(primaryKeyConstraint.IndexName);
return index;
}
return null;
}
}
IDBColumns DataSources.IDBTabular.Columns
{
get
{
return Fields;
}
}
IDBIndexes DataSources.IDBTabular.Indexes
{
get
{
return Indexes;
}
}
IDBForeignKeys IDBTabular.ForeignKeys
{
get
{
return ForeignKeys;
}
}
public IDBSchema Schema
{
get
{
return (IDBSchema)Parent.Parent;
}
}
}
}