| NAME | SYNOPSIS | DESCRIPTION | IMPLEMENTATION | NOTES | WARNINGS | SEE ALSO | AUTHORS |
Service - This object is derived from ManagedObj and holds the generic information for all Services
| Service Base: ManagedObj |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Namespace Procedure Constructors
Standard Public Interface
Specific Public Interface
Public InterfaceNone |
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.
This procedure inserts a Service record into the database. A serviceName or serviceDescriptionOid must be provided within the objref; a reference to the applicable table must be provided. It links to the ServiceDescription Table by validating the given reference table oid for the table or obtaining the table oid from the given refernce table name. If the given table oid or name is not balid, an error will be displayed and the insert will terminate; no insert entry will be made in the DB.
namespace eval Service {
variable this
variable attr
variable oid
variable dt
variable owner
variable serviceDescriptionOid
variable hours
#Insure the base class is initialized
ManagedObjInit
#Insure the referenced class is initialized
ServiceDescriptionInit
#Insure the contained classes are initialized
#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, Service s, ServiceDescription sd}
set this(table) "Service s"
set this(class) Service
set this(containedClass) {}
set this(container) ManagedObj
set this(where) "m.oid = s.managedObjOid and s.serviceDescriptionOid = sd.oid"
#Make ServiceDescription read-only
set this(hierarchy) [list ManagedObj $this(class)]
#Import the 'refers to' class attribute
array set attr [ServiceDescription::GetAttribute]
#Import the base class attributes
array set attr [ManagedObj::GetAttribute]
lappend this(attrs) oid
set oid(type) Integer
set oid(key) Foreign
set oid(column) {s.managedObjOid}
set oid(table) $this(class)
set oid(defWidth) 9
set oid(label) {}
set oid(default) {}
set attr(oid) [array get oid]
lappend this(attrs) dt
set dt(type) Text
set dt(column) {s.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) owner
set owner(type) Text
set owner(table) $this(class)
set owner(label) {(a,A - z,Z); 50 characters max}
set owner(column) {s.owner}
set owner(defWidth) 50
set owner(default) {}
set attr(owner) [array get owner]
lappend this(attrs) serviceDescriptionOid
set serviceDescriptionOid(type) Integer
set serviceDescriptionOid(column) {s.serviceDescriptionOid}
set serviceDescriptionOid(table) $this(class)
set serviceDescriptionOid(defWidth) 9
set serviceDescriptionOid(label) {}
set serviceDescriptionOid(default) {}
set attr(serviceDescriptionOid) [array get serviceDescriptionOid]
lappend this(attrs) hours
set hours(type) Text
set hours(column) {s.hours}
set hours(table) $this(class)
set hours(label) {(a,A - z,Z, 0-9, -, :); 255 characters max}
set hours(defWidth) 255
set hours(default) {9:00 am - 5:00 pm}
set attr(hours) [array get hours]
set this(attrs) [union $this(attrs) $ManagedObj::this(attrs)]
set this(attrs) [union $this(attrs) $ServiceDescription::this(attrs)]
}
#Create the standard member functions, but only once
EntityCreate $Service::this(class)
EntityQuery $Service::this(class)
EntityNext $Service::this(class)
EntityInsert $Service::this(class)
EntityUpdate $Service::this(class)
EntityDelete $Service::this(class)
EntityRefresh $Service::this(class)
EntityGetAttribute $Service::this(class)
EntityRetrieve $Service::this(class)
EntityContainedList $Service::this(class)
EntityArrayCopy $Service::this(class)
EntityValue $Service::this(class)
EntityInsertUpdate $Service::this(class)
EntityMdtRetrieve $Service::this(class)
EntityRetrieveObjBy $Service::this(class)
EntityRetrieveOidBy $Service::this(class)
EntityUpdateWhere $Service::this(class)
EntityDeleteWhere $Service::this(class)
EntityContainer $Service::this(class)
EntityCount $Service::this(class)
EntityGetListOf $Service::this(class)
proc ServiceInit { {db DbObject} {connection 1} } {
set Service::this(DbObject) $db
set Service::this(inst) $connection
return
}
proc Service::Insert {objref {class Service}} {
upvar $objref obj
upvar #0 $class\::this this
#Test if ServiceDescriptionOid or serviceName are provided and valid
if {[ string match $obj(serviceDescriptionOid) {} ]} {
#See if serviceName was provided
if {[ string match $obj(serviceName) {} ]} {
error "$this(class)::Insert failed. Object reference doesn't contain a ServiceDescriptionOid or serviceName."
} else {
#validate serviceName and obtain ServiceDescriptionOid
set serviceOid [ServiceDecription::RetrieveOidBy serviceName $obj(serviceName)]
if {[ string match $serviceOid {} ]} {
error "$this(class)::Insert failed. The provided serviceName \"$obj(serviceName)\" is not valid"
} else {
set obj(serviceDescriptionOid) $serviceOid
}
} else {
#validate the serviceDescriptionOid
if { ![ServiceDescription::Count * oid $obj(serviceDescriptionOid)] } {
error "$this(class)::Insert failed. The provided serviceDescriptionOid is not valid."
}
}
#Insert into Database
return [Entity::Insert $this(class) obj]
}
# STANDARD SETUP FOR TCL EXAMPLE SCRIPTS
# Setup a unique name for this test instance
set PROCNAME ServiceTest
set SUFFIX [join [list [exec hostname] [pid] ] {.}]
set TESTPROC [format "%s.%s" $PROCNAME $SUFFIX]
#Setup a database connection
global handle scriptName
set scriptName Service
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 SYBurkel
puts "Initializing the Service Entity"
ServiceInit
puts "Creating Service objects a, b"
Service::Create a
Service::Create b
DbObject::Begin
puts "Testing insert of object a"
if [catch {set oid [Service::Insert a]} result] {
puts $result
DbObject::Rollback
exit
}
puts "Insert ok, oid: $oid"
puts "Testing Query"
if [catch {Service::Query b "s.managedObjOid = $oid"} result] {
puts $result
DbOject::Rollback
exit
}
puts "Retrieving and loading object b"
if [catch {set rtn [Service::Next b]} result] {
puts $result
DbOject::Rollback
exit
}
puts "Refreshing object a"
if [catch {set rtn [Service::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(owner) tle
if [catch {Service::Update a} result] {
puts $result
DbOject::Rollback
exit
}
puts "Refreshing object b"
if [catch {set rtn [Service::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 {Service::Delete b} result] {
puts $result
DbObject::Rollback
exit
}
DbObject::Commit
puts "Service test Passed!"
DbObject::Close
by Timothy L. Eshelman & Susan Pringle