| NAME | SYNOPSIS | DESCRIPTION | IMPLEMENTATION | NOTES | WARNINGS | SEE ALSO | AUTHORS |
TableConstruct - 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.
proc demoDb::entityObjectConstruct {}
proc demoDb::entityObjectInsert {}
proc demoDb::ManagedObjConstruct {}
proc demoDb::BuildingConstruct {}
proc demoDb::ServiceConstruct {}
proc demoDb::BuildingServiceConstruct {}
proc demoDb::ServiceDescriptionConstruct {}
proc demoDb::ServiceDescriptionInsert {}
This procedure creates the entityObject Table
This procedure inserts all of the known entities for siWisql.
This procedure creates the ManagedObj Table
This procedure creates the Building Table
This procedure creates the Service Table
This procedure creates the BuildingService Table
This procedure creates the ServiceDescription Table
namespace eval demoDb {}
proc demoDb::entityObjectConstruct {} {
catch { DbObject::Sql { drop table entityObject} }
if {[catch { DbObject::Sql "
create table entityObject (
oid numeric(9,0) identity,
objectName char(33) null)
"} result]} { error "entityObjectConstruct: $result "}
if {[catch { DbObject::Sql "
create unique index entObjINdx on entityObject(oid)
"} result]} { error "entityObjectConstruct: $result"}
}
proc demoDb::entityObjectInsert {} {
set all_object [list ManagedObj Building Service BuildingService ServiceDescription View entityObject]
entityObjectInit
entityObject::Create a
DbObject::Sql "truncate table entityObject"
foreach name $all_objects {
set a(objectName) $name
entityObject::Insert a
}
}
proc demoDb::ManagedObjConstruct {} {
catch { DbObject::Sql { drop table ManagedObj} }
if {[catch { DbObject::Sql "
create table ManagedObj (
oid numeric(9,0) identity,
mdt char(24) null,
dt char(24) null,
coid numeric(9,0) null,
operState char(1) not null, -- (C)losed, (O)pened, (M)aintenance
adminState char(1) not null, -- (L)locked, (U)nlocked, (I)mplicit
usageState char(1) not null, -- (I)dle, (A)ctive, (B)usy,
-- (S)tandby
action char(1) null) -- (I)nserted, (U)pdated, (D)eleted
"} result]} { error "ManagedObjConstruct: $result "}
if {[catch { DbObject::Sql "
create unique index ManObjINdx on ManagedObj(oid)
create nonclustered index ManObj_coid_NcINdx on ManagedObj(coid)
"} result]} { error "ManagedObjConstruct: $result"}
}
proc demoDb::BuildingConstruct {} {
catch { DbObject::Sql { drop table Building} }
if {[catch { DbObject::Sql "
create table Building (
managedObjOid numeric(9,0) not null,
dt char(24) null,
buildingName char(25) null,
location varchar(50) null,
comment varchar(255) null,
type char(1) not null, -- (R)esidential, (P)rofessional,
-- (I)ndustrial
buildingNumber int null,
certificateOfOccupancy char(1) not null) -- (Y)es, (N)o
"} result]} { error "BuildingConstruct: $result "}
if {[catch { DbObject::Sql "
create unique index BuildingINdx on Building(managedObjOid)
create nonclustered index Building_name_NcINdx on Building(buildingName)
create nonclustered index Building_type_NcINdx on Building(type)
"} result]} { error "ManagedObjConstruct: $result"}
}
proc demoDb::ServiceConstruct {} {
catch { DbObject::Sql { drop table Service} }
if {[catch { DbObject::Sql "
create table Service (
managedObjOid numeric(9,0) not null,
dt char(24) null,
serviceDescriptionOid numeric(9,0) null,
buildingName char(25) null,
owner varchar(50) null,
hours varchar(255) null)
"} result]} { error "ServiceConstruct: $result "}
if {[catch { DbObject::Sql "
create unique index ServiceINdx on Service(managedObjOid)
"} result]} { error "ServiceConstruct: $result"}
}
proc demoDb::BuildingServiceConstruct {} {
catch { DbObject::Sql { drop table BuildingService} }
if {[catch { DbObject::Sql "
create table BuildingService (
serviceOid numeric(9,0) not null,
dt char(24) null,
buildingLocation varchar(50) null)
"} result]} { error "BuildingServiceConstruct: $result "}
if {[catch { DbObject::Sql "
create unique index BuildingServiceINdx on BuildingService(serviceOid)
"} result]} { error "BuildingServiceConstruct: $result"}
}
proc demoDb::ServiceDescriptionConstruct {} {
catch { DbObject::Sql { drop table ServiceDescription} }
if {[catch { DbObject::Sql "
create table ServiceDescription (
oid numeric(9,0) identity,
serviceName char(20) null,
serviceType char(1) null, -- (F)ood, (P)ostal,
-- (C)leaning,
-- (B)anking,
-- (R)etail,
-- (N)onference
-- (M)aintenance
description varchar(255) null)
"} result]} { error "ServiceDescriptionConstruct: $result "}
if {[catch { DbObject::Sql "
create unique index ServiceDescriptionINdx on ServiceDescription(oid)
create nonclustered index ServiceDesc_serviceName_NcINdx on ServiceDescription(serviceName)
"} result]} { error "ServiceDescriptionConstruct: $result"}
}
proc demoDb::ServiceDescriptionInsert {} {
#Notes:
#Various Services
array set sd1 "ARAMARK { food {Food Service with Great taste} }"
array set sd2 "USPS { postal {Auxilliary United State Post Office} }"
array set sd3 "{Vince's Cleaning Service} { cleaning {Private Dry Cleaning Contractor} }"
array set sd4 "{Credit Union} { banking {AT&T Credit Union} }"
array set sd5 "{Gift Shop} { retail {Space for various vendors} }"
array set sd6 "{Building Maintenance} { maintenance {Private Jantorial Contractor} }"
#Erase any data that might already exist in the ServiceDescription
#Table, this will prevent duplicate entries
catch { DbObject::Sql "delete ServiceDescription" }
ServiceDescriptionInit
ServiceDescription::Create sd
DbObject::Begin
set cnt 1
while { $cnt < 20 } {
if { [array exists sd${cnt}] == 0} {
incr cnt
continue
}
set serviceName [lindex [array get sd${cnt}] 0]
set val [lindex [array get sd${cnt}] 1]
set type [lindex ${val} 0]
set description [lindex ${val} 1]
set a(serviceName) $serviceName
set a(serviceType) [ServiceDescription::GetAttribute serviceType enum $type]
set a(description) $description
if {[catch {set oid [ServiceDescription::Insert a]} result]} {
DbObject::Rollback
error "demoDb::ServiceDescriptionInsert had problems: $result"
}
incr cnt
}
DbObject::Commit
}
# -----------------------------------
# STANDARD SETUP FOR TCL EXAMPLE SCRIPTS
# Setup a unique name for this test instance
set PROCNAME TableTest
set SUFFIX [join [list [exec hostname] [pid] ] {.}]
set TESTPROC [format "%s.%s" $PROCNAME $SUFFIX]
#Setup a database connection
set dbuser tle
set dbpass tle123
if {[catch {
puts "Making Database Connection"
DbObject::Connect $dbuser $dbpass
puts "Creating the entityObject Table"
demoDb::entityObjectConstruct
puts "Insert contents into the entityObject Table"
demoDb::entityObjectInsert
puts "Creating the ManagedObj Table"
demoDb::ManagedObjConstruct
puts "Creating the Building Table"
demoDb::BuildingConstruct
puts "Creating the Service Table"
demoDb::ServiceConstruct
puts "Creating the BuildingService Table"
demoDb::BuildingServiceConstruct
puts "Creating the ServiceDescription Table"
demoDb::ServiceDescriptionConstruct
puts "Insert static data into the ServiceDescription Table"
demoDb::ServiceDescriptionInsert
} result]} {error "demoConstruction: $result: $sybmsg(msgtext)" }