25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Object Persistence<br />

For example:<br />

// Open person "1"<br />

Set person = ##class(Sample.Person).%OpenId(1)<br />

Write "Original value: ",person.Name,!<br />

// modify the object<br />

Set person.Name = "Black,Jimmy Carl"<br />

Write "Modified value: ",person.Name,!<br />

// Now see what value is on disk<br />

Set id = person.%Id()<br />

&sql(SELECT Name INTO :name<br />

FROM Sample.Person WHERE %ID = :id)<br />

Write "Disk value: ",name,!<br />

12.2.3 Deleting <strong>Objects</strong><br />

The Persistence Interface includes several methods for deleting objects from the database.<br />

12.2.3.1 The %DeleteId Method<br />

The %DeleteId method deletes a an object that is stored within a database:<br />

Set sc = ##class(MyApp.MyClass).%DeleteId(id)<br />

%DeleteId returns a %Status value indicating whether the object was deleted or not.<br />

If present, %DeleteId will call the %OnDelete callback method before deleting the object.<br />

%OnDelete returns a %Status value; if %OnDelete returns an error value, then the object<br />

will not be deleted, the current transaction is rolled back, and %DeleteId returns an error<br />

value.<br />

Note that the %DeleteId method is a class method and has no effect on any object instances<br />

that may be in memory.<br />

12.2.3.2 The %DeleteExtent Method<br />

The %DeleteExtent method deletes every object (and subclass of object) within its extent.<br />

Specifically it iterates the entire extent of objects and then invokes the %DeleteId method<br />

on each instance.<br />

12.2.3.3 The %KillExtent Method<br />

The %KillExtent method directly deletes the globals used to store an extent of objects. It<br />

does not invoke the %DeleteId method and performs no referential integrity actions. This<br />

method is simply intended to serve as a help to developers during the development process.<br />

106 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!