" *****************************************************************************************************
*
*  newobj.txt
*
*   This examples shows how to store new objects in the database
*
*
******************************************************************************************************"


| aModel aTextDisplay anOrb aCourse  courseType oodb|
aTextDisplay := TextWindow  windowLabeled: 'LPC Brokers - creating new 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.

"create a new course"
aCourse := LPCObject newType: courseType. 


" sets its attributes "
aCourse course: 'ODB' ;
               hours: 3 ;
               credit: 1 ;
               description: 'Object databases for the masses'.

" store it in the database"
aCourse saveToDatabase.

"let's make sure it is stored"
oodb := anOrb lookUpForKeyValue: #('ODB')  withType: courseType.

aTextDisplay
      nextPutAll: 'Course: ', oodb course asString; cr
    ; nextPutAll: 'Hours: ', oodb hours asString; cr
    ; nextPutAll: 'Credit: ', oodb credit asString; cr
    ; nextPutAll: 'Description: ' , oodb description asString; cr .


anOrb disconnect.
 
