" *****************************************************************************************************
*
*  delobj.txt
*
*   This examples shows how to delete Types from the database
*
*
******************************************************************************************************"


| aModel aTextDisplay anOrb aCourse  courseType oodb|
aTextDisplay := TextWindow  windowLabeled: 'LPC Brokers - deleting objects'
                           frame: (0 @ 0 corner: 500 @ 500).
aTextDisplay cr. 
 
aModel := LPCModel getName: #LpcSample.
courseType :=aModel typeNamed: #Course.

anOrb := LPCObjectRequestBroker new.
anOrb driverConnectWindow: aTextDisplay.

"set the model's orb it will be used by all type defined in the model
unless overidden"
aModel orb: anOrb.

"set autoCommit to be true"
anOrb autoCommit: true.

"retrieve our course"
aCourse := anOrb lookUpForKeyValue: #('ODB')  withType: courseType.

" mark the course for delete"
aCourse markDeleted.

" delete it from the database"
aCourse saveToDatabase.

"check that it has been deleted"
courses := anOrb lookUpAllWithType: courseType.
courses do: [ :each | aTextDisplay nextPutAll: each asString ; cr ].


anOrb disconnect.
 
