ManagedObj(3MO)
ManagedObj - This object is a persistant abstract base class that provides
operational, administrative, and usage state for any object derived from it. Its
puprose is to allow system administration and monitoring.
ManagedObj Base: Entity |
oid |
|
mdt |
|
dt |
|
coid |
|
operState |
closed, open, maintenance |
adminState |
locked, unlocked, implicit |
usageState |
idle, active, busy, standby |
action |
inserted, updated, deleted | |
Namespace Procedure Constructors
Standard Public Interface
|
This procedure resides in this file to load the namespace into memory. It
must be called before any namespace variable is accessed or any of the standard
database interface functions are needed. It should be called when the
application is being initialized.
- Inputs: None
- Outputs: None
- Returns: None
namespace eval ManagedObj {
variable this
variable attr
variable oid
variable coid
variable dt
variable mdt
variable operState
variable adminState
variable usageState
#Minimum static set for both view management and database interface
#View Management uses: type, defWidth, and label
#database interface uses: type, column, table
set this(from) "ManagedObj m"
set this(table) "ManagedObj m"
set this(class) ManagedObj
set this(containedClass) {ManagedObj}
set this(container) {ManagedObj}
set this(where) ""
set this(hierarchy) [list $this(class)]
lappend this(attrs) oid
set oid(type) Integer
set oid(key) Primary
set oid(column) {m.oid}
set oid(table) $this(class)
set oid(defWidth) 9
set oid(label) {(0 - 9); 9 characters max}
set oid(default) {}
set attr(oid) [array get oid]
lappend this(attrs) coid
set coid(type) Integer
set coid(column) {m.coid}
set coid(table) $this(class)
set coid(defWidth) 9
set coid(label) {(0 -9); 9 characters max}
set coid(default) {}
set attr(coid) [array get coid]
lappend this(attrs) dt
set dt(type) Text
set dt(column) {m.dt}
set dt(table) $this(class)
set dt(label) {(a,A - z,Z); 24 characters max}
set dt(defWidth) 24
set dt(default) {}
set attr(dt) [array get dt]
lappend this(attrs) mdt
set mdt(type) Text
set mdt(column) {m.mdt}
set mdt(table) $this(class)
set mdt(label) {(a,A - z,Z); 24 characters max}
set mdt(defWidth) 24
set mdt(default) {}
set attr(mdt) [array get mdt]
lappend this(attrs) operState
set operState(type) EnumText
set operState(column) {m.operState}
set operState(enum) {closed {C: Closed} opened {O: Opened} maintenance {M: Maintenance}}
set operState(table) $this(class)
set operState(defWidth) [Entity::EnumMax $operState(enum)]
set operState(label) {}
set operState(default) {M: Maintenance}
set attr(operState) [array get operState]
lappend this(attrs) adminState
set adminState(type) EnumText
set adminState(column) {m.adminState}
set adminState(enum) {locked {L: Locked} unlocked {U: Unlocked} implicit {I: Implicitly Locked}}
set adminState(table) $this(class)
set adminState(defWidth) [Entity::EnumMax $adminState(enum)]
set adminState(label) {}
set adminState(default) {L: Locked}
set attr(adminState) [array get adminState]
lappend this(attrs) usageState
set usageState(type) EnumText
set usageState(column) {m.usageState}
set usageState(enum) {idle {I: Idle} active {A: Active} busy {B: Busy} standby {S: Standby}}
set usageState(table) $this(class)
set usageState(defWidth) [Entity::EnumMax $usageState(enum)]
set usageState(label) {}
set usageState(default) {I: Idle}
set attr(usageState) [array get usageState]
lappend this(attrs) action
set action(type) EnumText
set action(column) {m.action}
set action(enum) {inserted {I: Inserted} updated {U: Updated} deleted {D: Deleted}}
set action(table) $this(class)
set action(label) {}
set action(defWidth) [Entity::EnumMax $action(enum)]
set action(default) {}
set attr(action) [array get action]
}
#Create the standard member functions, but only once
EntityCreate $ManagedObj::this(class)
EntityQuery $ManagedObj::this(class)
EntityNext $ManagedObj::this(class)
EntityInsert $ManagedObj::this(class)
EntityUpdate $ManagedObj::this(class)
EntityUpdateWhere $ManagedObj::this(class)
EntityDelete $ManagedObj::this(class)
EntityDeleteWhere $ManagedObj::this(class)
EntityRefresh $ManagedObj::this(class)
EntityGetAttribute $ManagedObj::this(class)
EntityRetrieve $ManagedObj::this(class)
EntityContainedList $ManagedObj::this(class)
EntityContainer $ManagedObj::this(class)
EntityArrayCopy $ManagedObj::this(class)
EntityValue $ManagedObj::this(class)
EntityInsertUpdate $ManagedObj::this(class)
EntityMdtRetrieve $ManagedObj::this(class)
EntityRetrieveOidBy $ManagedObj::this(class)
EntityRetrieveObjBy $ManagedObj::this(class)
EntityGetListOf $ManagedObj::this(class)
EntityCount $ManagedObj::this(class)
proc ManagedObjInit { {db DbObject {connection 1} } {
set ManagedObj::this(DbObject) $db
set ManagedObj::this(inst) $connection
return
}
lappend ManagedObj::this(procedures) PercolateAdminState
proc ManagedObj::PercolateAdminState { objOid newState } {
if [catch {
DbObject::Begin
set lockedEnum [ManagedObj::GetAttribute adminState enum locked]
set implicitEnum [ManagedObj::GetAttribute adminState enum implicit]
set unlockedEnum [ManagedObj::GetAttribute adminState enum unlocked]
set disabledEnum [ManagedObj::GetAttribute adminState enum disabled]
#Obtain the instance or mdt
ManagedObj::Retrieve $objOid objRef
if {[string match $newState $lockedEnum] || [string match $newState $implicitEnum]} {
#set adminState of instance to locked
ManagedObj::Value $objRef(oid) adminState $newState
#If an objects administrative state is changed to locked or
#implicitly locked then all objects immediately contained within
#that object, and in an administrative state of unlocked
foreach containedObjList [ManagedObj::RetrieveObjBy coid $objRef(oid) adminState $unlockedEnum] {
array set containedObj $containedObjList
#change contained obj and all immediate contained objects to an
#administrative state of implicitly locked. This is applied
#recursivly.
ManagedObj::Value $containedObj(oid) adminState $implicitEnum
ManagedObj::PercolateAdminState $containedObj(oid) "$implicitEnum"
}
} elseif {[string match $newState $unlockedEnum]} {
if {![string match {} $objRef(coid)]} {
ManagedObj::Retrieve $objRef(coid) container
#test to see if container is locked or implicit, and the objRef
#operState is disabled, if so set operState
if {([string match $container(adminState) $lockedEnum] || [string match $container(adminState) $implicitEnum]) && [string match $objRef(operState) $disabledEnum]} {
ManagedObj::Value $objRef(oid) adminState $implicitEnum
} else {
ManagedObj::Value $objRef(oid) adminState $unlockedEnum
#If an objects administrative state is successfully changed to
#unlocked then all objects immediately contained within that object
#and in an administrative state of implicitly locked are changed
#to an administrative state of unlocked. This is applied recursively
foreach containedObjList [ManagedObj::RetrieveObjBy coid $objRef(oid) adminState $implicitEnum] {
array set containedObj $containedObjList
#change obj and all immediate contained objects to an administrative
#state of unlocked. This is applied recursively.
ManagedObj::Value $containedObj(oid) adminState $unlockedEnum
ManagedObj::PercolateAdminState $containedObj(oid) "$unlockedEnum"
}
}
} elseif {![string match $objRef(operState) $disabledEnum]} {
ManagedObj::Value $objRef(oid) adminState $unlockedEnum
#Container is empty set containees to unlocked
foreach containedObjList [ManagedObj::RetrieveObjBy coid $objRef(oid) adminState $implicitEnum] {
array set containedObj $containedObjList
#change obj and all immediate contained objects to an administrative
#state of unlocked. This is applied recursively.
if {![string match $containedObj(operState) $disabledEnum]} {
ManagedObj::Value $containedObj(oid) adminState $unlockedEnum
}
ManagedObj::PercolateAdminState $containedObj(oid) "$unlockedEnum"
}
}
}
} result] {
DbObject::Rollback
error "$result"
}
DbObject::Commit
return [ManagedObj::Value $objOid adminState]
}
# -----------------------------------
# STANDARD SETUP FOR TCL EXAMPLE SCRIPTS
# Setup a unique name for this test instance
set PROCNAME ManagedObjTest
set SUFFIX [join [list [exec hostname] [pid] ] {.}]
set TESTPROC [format "%s.%s" $PROCNAME $SUFFIX]
#Setup a database connection
global handle scriptName
set scriptName ManagedObj
if {[lsearch [array names env] DBUSER] >= 0} {
set dbuser $env(DBUSER)
} else {
set dbuser tle }
if {[lsearch [array names env] DSQUERY] >= 0} {
set dbserver $env(DSQUERY)
} else {
set dbserver SYBdevgdn
}
if {[lsearch [array names env] DBPASS] >= 0} {
set dbpass $env(DBPASS)
} else {
set dbpass tle123
}
set handle [sybconnect $dbuser $dbpass $dbserver $scriptName]
puts "Making Database Connection"
DbObject::Connect tle tle123
puts "Initializing the ManagedObj Entity"
ManagedObjInit
puts "Creating ManagedObj objects a, b"
ManagedObj::Create a
ManagedObj::Create b
puts "Contents of Array a"
puts "Contents of Array b"
DbObject::Begin
puts "Testing insert of object a"
if [catch {set oid [ManagedObj::Insert a]} result] {
puts $result
DbObject::Rollback
exit
}
puts "Insert ok, oid: $oid"
puts "Testing Query"
puts "Oid: $oid"
if [catch {ManagedObj::Query b "m.oid = $oid"} result] {
puts $result
DbOject::Rollback
exit
}
puts "Retrieving and loading object b"
if [catch {set rtn [ManagedObj::Next b]} result] {
puts $result
DbOject::Rollback
exit
}
puts "Refreshing object a"
if [catch {set rtn [ManagedObj::Refresh a]} result] {
puts $result
DbOject::Rollback
exit
}
if {$rtn} {
puts "a & b comparison"
if {[string compare [array get a] [array get b]] != 0} {
puts "Failed comparison"
DbObject::Rollback
exit
}
}
puts "Testing Update"
set a(operState) [ManagedObj::GetAttribute operState enum closed]
set a(usageState) [ManagedObj::GetAttribute usageState enum idle]
if [catch {ManagedObj::Update a} result] {
puts $result
DbOject::Rollback
exit
}
puts "Refreshing object b"
if [catch {set rtn [ManagedObj::Refresh b]} result] {
puts $result
DbOject::Rollback
exit
}
if {$rtn} {
puts "a & b comparison"
if {[string compare [array get a] [array get b]] != 0} {
puts "Failed comparison"
DbObject::Rollback
exit
}
}
puts "Deleting the object"
if [catch {ManagedObj::Delete b} result] {
puts $result
DbObject::Rollback
exit
}
DbObject::Commit
puts "ManagedObj test Passed!"
DbObject::Close
DbObject.htm
by Timothy L. Eshelman