Building (3Building)

NAME SYNOPSIS DESCRIPTION IMPLEMENTATION NOTES WARNINGS SEE ALSO AUTHORS

NAME

Building - This object is derived from ManagedObj and holds the generic information for all buildings.

SYNOPSIS

Building
Base: ManagedObj
oid
dt
buildingName
location
comment
buildingNumber
type residential, industrial, professional
certificateOfOccupancy yes, no

Namespace Procedure Constructors

BuildingInit  {}  

Standard Public Interface

Building::Create { objRef {selectList} }
Building::ArrayCopy { objRef {selectList} } : objList
Building::Query { objRef {where} {order} }
Building::Next { objRef } : 1(Success), 0(Failure)
Building::Insert { objRef } : oid
Building::Update { objRef }
Building::Delete { objRef }
Building::Refresh { objRef } : 1(Success), 0(Failure)
Building::Retrieve { oid objRef {selectList} } : 1(Success), 0(Failure)
Building::GetAttribute { {attribute} {property} {enumTagList} } : results - See documentation
Building::ContainedList { containerOid {selectList} } : objList
Building::Value { oid attr {value} } : value
Building::InsertUpdate { objRef {attr value} ... } : oid
Building::MdtRetrieve { oid objRef } : 1(Success), 0(Failure)
Building::RetrieveObjBy { {attr value} ... } : objList
Building::RetrieveOidBy { {attr value} ... } : oidList
Building::UpdateWhere { objref {attr value} ... } : oidList
Building::DeleteWhere { {attr value} ... }
Building::Count { attr {attr value} ... } : count
Building::Container { oid objRef } : 1(Success), 0(failure)
Building::GetListOf { attr { attr value} ... } : valueList

Public Interface


None

 

DESCRIPTION

BuildingInit

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

IMPLEMENTATION

  namespace eval Building {
   variable this
   variable attr

   variable oid
   variable dt
   variable buildingName
   variable location
   variable comment
   variable type
   variable buildingNumber
   variable certificateOfOccupancy

   #Insure the base class is initialized
   ManagedObjInit

   #Insure contained classes are initialized
   BuildingServiceInit

   #The directives
   #This is a derived class, so a join is needed with the base class
   #The from clause specifies the tables and aliases to be read in order from base to derived.
   #table specifies the derived table name and the alias
   #class specifies the namespace
   #where specifies the join constraint
   #hierarchy specifies the order of tables to be written from base to derived.

   set this(from) "ManagedObj m, Building b"
   set this(table) "Building b"
   set this(class) Building
   set this(containedClass) [list Service]
   set this(container) ManagedObj
   set this(where) "m.oid = b.managedObjOid"
   set this(hierarchy) [list ManagedObj $this(class)]
   #Import the Base class attributes
   array set attr [ManagedObj::GetAttribute]
   #the oid in the Building table has a column name, managedObjOid
   #It is not an identity but a foreign key
   lappend this(attrs) oid
   set oid(type) Integer
   set oid(key) Foreign
   set oid(column) {b.managedObjOid}
   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) dt
   set dt(type) Text
   set dt(column) {b.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) buildingName
   set buildingName(column) {b.buildingName}
   set buildingName(defWidth) 25
   set buildingName(default) {}
   set buildingName(label) {(a,A - z,Z); 25 characters max}
   set buildingName(table) $this(class)
   set buildingName(type) Text
   set attr(buildingName) [array get buildingName]
   lappend this(attrs) location
   set location(type) Text
   set location(column) {b.location}
   set location(table) $this(class)
   set location(label) {(a,A - z,Z); 50 characters max}
   set location(defWidth) 50
   set location(default) {}
   set attr(location) [array get location]
    
   lappend this(attrs) comment
   set comment(type) Text
   set comment(column) {b.comment}
   set comment(table) $this(class)
   set comment(label) {(a,A - z,Z); 255 characters max}
   set comment(defWidth) 255
   set comment(default) {}
   set attr(comment) [array get comment]
 
   lappend this(attrs) type
   set type(type) EnumText
   set type(column) {b.type}
   set type(enum) {residential {R: Residential} professional {P: Professional} industrial {I: Industrial} }
   set type(table) $this(class)
   set type(defWidth) [Entity::EnumMax $type(enum)]
   set type(label) {}
   set type(default) {R: Residential}
   set attr(type) [array get type]
   lappend this(attrs) certificateOfOccupancy
   set certificateOfOccupancy(type) EnumText
   set certificateOfOccupancy(column) {b.certificateOfOccupancy}
   set certificateOfOccupancy(enum) { no {N: No} yes {Y: Yes}}
   set certificateOfOccupancy(table) $this(class)
   set certificateOfOccupancy(label) {}
   set certificateOfOccupancy(defWidth) [Entity::EnumMax $certificateOfOccupancy(enum)]
   set certificateOfOccupancy(default) {N: No}
   set attr(certificateOfOccupancy) [array get certificateOfOccupancy]
   lappend this(attrs) buildingNumber
   set buildingNumber(type) Integer
   set buildingNumber(column) {b.buildingNumber}
   set buildingNumber(table) $this(class)
   set buildingNumber(defWidth) 10
   set buildingNumber(label) {(0 - 9); 10 characters max}
   set buildingNumber(default) 1
   set attr(buildingNumber) [array get buildingNumber]
   set this(attrs) [union $this(attrs) $ManagedObj::this(attrs)]
}

#Create the standard member functions, but only once
EntityCreate $Building::this(class)
EntityQuery $Building::this(class)
EntityNext $Building::this(class)
EntityInsert $Building::this(class)
EntityUpdate $Building::this(class)
EntityDelete $Building::this(class)
EntityRefresh $Building::this(class)
EntityGetAttribute $Building::this(class)
EntityRetrieve $Building::this(class)
EntityContainedList $Building::this(class)
EntityArrayCopy $Building::this(class)
EntityValue $Building::this(class)
EntityInsertUpdate $Building::this(class)
EntityMdtRetrieve $Building::this(class)
EntityRetrieveObjBy $Building::this(class)
EntityRetrieveOidBy $Building::this(class)
EntityUpdateWhere $Building::this(class)
EntityDeleteWhere $Building::this(class)
EntityContainer $Building::this(class)
EntityCount $Building::this(class)
EntityGetListOf $Building::this(class)

BuildingInit

proc BuildingInit { {db DbObject} {connection 1} } {
   set Building::this(DbObject) $db
   set Building::this(inst) $connection
   return
}

EXAMPLES

#  STANDARD SETUP FOR TCL EXAMPLE SCRIPTS
#  Setup a unique name for this test instance

set PROCNAME BuildingTest
set SUFFIX [join [list [exec hostname] [pid] ] {.}]
set TESTPROC [format "%s.%s" $PROCNAME $SUFFIX]
#Setup a database connection
global handle scriptName
set scriptName Building
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]
# Setup the Log Server and Notification Server connections

puts "Making Database Connection"
DbObject::Connect tle tle123

puts "Initializing the Building Entity"
BuildingInit

puts "Creating Building objects a, b"
Building::Create a
Building::Create b

DbObject::Begin
puts "Testing insert of object a"
if [catch {set oid [Building::Insert a]} result] {
     puts $result
     DbObject::Rollback
     exit
}
puts "Insert ok, oid: $oid"

puts "Testing Query"

if [catch {Building::Query b "b.managedObjOid = $oid"} result] {
     puts $result
     DbOject::Rollback
     exit
}

puts "Retrieving and loading object b"

if [catch {set rtn [Building::Next b]} result] {
     puts $result
     DbOject::Rollback
     exit
}

puts "Refreshing object a"

if [catch {set rtn [Building::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(buildingNumber) 32
if [catch {Building::Update a} result] {
     puts $result
     DbOject::Rollback
     exit
}


puts "Refreshing object b"

if [catch {set rtn [Building::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 {Building::Delete b} result] {
     puts $result
     DbObject::Rollback
     exit
}
DbObject::Commit

puts "Building test Passed!"

DbObject::Close

NOTES

WARNINGS

SEE ALSO

Entity.htm

MO.htm

DbObject.htm


AUTHORS

by Timothy L. Eshelman