You will learn how to
- Add persistency to a class instances by subclassing SDActiveRecord
- Save and retrieve objects
- Prevent saving of an object if invalid
- Hook into records life cycle for cascade saving
- Use HelpSystem from Torsten Bergmann to browse API documentation
See also:
Download screencast (800x600): .mpeg 18.8 MB, .mov 27.9 MB
Voice recorded by Christoph Budzinski.
This is the first screencast with subtitles, I hope you like it :). Download the subtitle file (SubRip format).
Load the source code:
Gofer new
squeaksource: 'SandstoneDb';
package: 'SandstoneDb';
squeaksource: 'Pharocasts';
package: 'SandstoneDbIntro';
load.Load HelpSystem:
Gofer new
squeaksource: 'MetacelloRepository';
package: 'ConfigurationOfHelpSystem';
load.
(Smalltalk at:#ConfigurationOfHelpSystem) project latestVersion load
If you'd like to avoid restarting the image when you create subclasses, you can just run
ReplyDeleteSDCheckPointer startUp: true.
This is what happens at image startup that ensures all the directories exist and reloads the database.
Also, just FYI, you don't need to make all biz objects active records, had the tweets just been an Object subclass, they would have been save with the Person in the same file as the Person atomically. Of course, then the only way to get the tweets would be through the person, since it'd be the aggregate root for that aggregate object cluster.
Anyway, nice screencast.
Thanks for this clarification !
ReplyDeleteMeanwhile I also created a ConfigurationOfSandstoneDb
ReplyDeleteGreat!
ReplyDeleteHow do you load the ConfigurationOfSandstoneDb?
ReplyDeleteI loaded it in Monticello but am not sure what command to issue.
Thank You,
Jonathan
You can load ConfigurationOfSandstoneDb with Monticello Browser, in MetacelloRepository on SqueakSource.
ReplyDeleteAn easier way is to use Gofer. In a workspace evaluate:
Gofer new
squeaksource: 'MetacelloRepository';
package: 'ConfigurationOfSandstoneDb';
load.
Then load SandstoneDb:
ConfigurationOfSandstoneDb
project latestVersion load.
ConfigurationOfSandstoneDb (LT 4)is out of date. Loading it triggers a dependency warning (missing Complex class).
ReplyDeleteTry:
ReplyDeleteGofer it
squeaksource: 'SandstoneDb';
package: 'SandstoneDb';
load
Hello,
ReplyDeleteI am not able to play with sandstone db since i have issues with database creation. After I save and leave the image db is not created. I have tried with pharo 1.1 and 1.2.1 image on OSX (Snow leopard) without success. Is maybe sandstone db not working any more in pharo under OSX.
Thanks in advance,
Boštjan
@Bostjan: From Ramon: It should be working now if you grab the latest version, I updated the config this morning. The last version got broken because another package stole the #startUp: method with an override in SandstoneDb causing me to publish a version without it; it'd cause the symptoms he's describing.
ReplyDeleteI was trying to migrate a simple image-based persistence app into Sandstone, so I just recompiled my biz objects to be subclasses of SDActiveRecord, but of course the objects I want to save are already created and "floating" in the image, so when I try to save them I get an error as many instvars haven't been initialized upon creating these objects (as they were already there).
ReplyDeleteIs there a way to automatically do this?
Thanks!
Bernat.
from Ramon Leon: http://forum.world.st/Fwd-Pharocasts-New-comment-on-SandstoneDb-simple-ActiveRecord-style-persistence-tp3495252p3495252.html
ReplyDeleteMy general approach would be this sequence of steps, let's assume his
class is called Person in collection var name people.
If Person has an initialize method, rename it to initializeOld.
Change superclass of Person to SDActiveRecord.
Person warmUp. to setup the store for this new class.
people do: [:e | e initialize ] to invoke active records initialize
setting up it's necessary inst vars and marking all people as new
rename Person>>initializeOld back to Person>>initialize.
people do: [:e | e save ]
Migration complete.