TableConstruct(3MO)

NAME SYNOPSIS DESCRIPTION IMPLEMENTATION NOTES WARNINGS SEE ALSO AUTHORS

NAME

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.

SYNOPSIS

Public Interface

proc demoDb::entityObjectConstruct {}

proc demoDb::entityObjectInsert {}

proc demoDb::ManagedObjConstruct {}

proc demoDb::BuildingConstruct {}

proc demoDb::ServiceConstruct {}

proc demoDb::BuildingServiceConstruct {}

proc demoDb::ServiceDescriptionConstruct {}

proc demoDb::ServiceDescriptionInsert {}

DESCRIPTION

entityObjectConstruct

This procedure creates the entityObject Table

Inputs: None
Outputs: None
Returns: None

entityObjectInsert

This procedure inserts all of the known entities for siWisql.

Inputs: None
Outputs: None
Returns: None

ManagedObjConstruct

This procedure creates the ManagedObj Table

Inputs: None
Outputs: None
Returns: None

BuildingConstruct

This procedure creates the Building Table

Inputs: None
Outputs: None
Returns: None

ServiceConstruct

This procedure creates the Service Table

Inputs: None
Outputs: None
Returns: None

BuildingServiceConstruct

This procedure creates the BuildingService Table

Inputs: None
Outputs: None
Returns: None

ServiceDescriptionConstruct

This procedure creates the ServiceDescription Table

Inputs: None
Outputs: None
Returns: None

IMPLEMENTATION

namespace eval demoDb {}

demoDb::entityObjectConstruct

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"} 
}

demoDb::entityObjectInsert

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
   }
}

demoDb::ManagedObjConstruct

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"} 
}

demoDb::BuildingConstruct

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"} 
}

demoDb::ServiceConstruct

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"} 
}

demoDb::BuildingServiceConstruct

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"} 
}

demoDb::ServiceDescriptionConstruct

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"} 
}

demoDb::ServiceDescriptionInsert

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 
}

EXAMPLES

# -----------------------------------
#  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)" }

NOTES

WARNINGS

SEE ALSO

DbObject.htm


AUTHORS

by Timothy L. Eshelman