Index: openacs.org-dev/packages/acs-core-docs/www/xml/developers-guide/objects.xml =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/acs-core-docs/www/xml/developers-guide/objects.xml,v diff -u -r1.1.1.1 -r1.1.1.2 --- openacs.org-dev/packages/acs-core-docs/www/xml/developers-guide/objects.xml 9 Jul 2002 17:34:57 -0000 1.1.1.1 +++ openacs.org-dev/packages/acs-core-docs/www/xml/developers-guide/objects.xml 11 Aug 2002 00:42:49 -0000 1.1.1.2 @@ -2,7 +2,7 @@ OpenACS &version; Data Models and the Object System -By Pete Su +By Pete Su Overview @@ -20,13 +20,13 @@ create table notes ( - note_id integer primary key, - owner_id integer references users(user_id), - creation_user references(user_id) not null, - creation_date date not null, - last_modified date not null, - title varchar(255) not null, - body varchar(1024) + note_id integer primary key, + owner_id integer references users(user_id), + creation_user references(user_id) not null, + creation_date date not null, + last_modified date not null, + title varchar(255) not null, + body varchar(1024) ) @@ -43,15 +43,15 @@ Define access control policies on notes. Attach user comments on notes. -Allows users to define custom fields to store on their notes. +Allow users to define custom fields to store on their notes. Automatically generate input forms or output displays for notes. Allow other applications to use notes in ways we don't know of yet. In OpenACS &version;, the key to enabling these types of services on your application data is to take advantage of the Object System. The first -question anyone asks is usually "Just what are objects, and what do +question, then, is "Just what are objects, and what do you use them for anyway?". The short answer: objects are anything represented in the application's data model that will need to be managed by any central service in OpenACS &version;, or that may be reusable in @@ -65,7 +65,7 @@ To make use of the object system, you as the application developer have to write your data model in a way that is slightly more complex -than before. What you get for this extra work includes: +than in the ACS 3.x days. What you get for this extra work includes: The lets you @@ -95,10 +95,10 @@ -For our example Notes application, to hook into the object system we +In order to hook our Notes application into the object system, we make some calls to use our notes table as the basis for a new object type. Object types are analogous to classes in -programming languages such as C++ and Java. For example, in Java a +programming languages such as C++ and Java. In Java, a class defines a set of attributes that store data and a set of methods that run code. In OpenACS &version;, we use one or more Oracle tables to store the data attributes, and we define a PL/SQL package to hold procedures to @@ -107,20 +107,21 @@ The object type itself is described using data in the -acs_object_types and acs_attributes tables, -which plays a role similar to the data dictionary in Oracle. As in -Java, object types can inherit attributes from a parent type, so the -type system forms a hierarchy. Unlike Java, Oracle does not support -this inheritance transparently, so we have to make sure we add our own -bookkeeping code to keep everything consistent. Given all of this, -below you'll find the code needed to describe a new object type called -notes in your system. +acs_object_types and +acs_attributes tables, which play a role +similar to the data dictionary in Oracle. As in Java, object types can +inherit attributes from a parent type, so the type system forms a +hierarchy. Unlike Java, Oracle does not support this inheritance +transparently, so we have to make sure we add our own bookkeeping code to +keep everything consistent. Below you'll find the code needed to describe a +new object type called notes in your +system. Fire up your text editor and open the -ROOT/packages/notes/sql/notes-create.sql file created -during the earlier created the package. Then, do the following: +ROOT/packages/notes/sql/oracle/notes-create.sql (ROOT/packages/notes/sql/postgresql/notes-create.sql for the PG version) file created +when we created the package. Then, do the following: @@ -160,7 +161,7 @@ -Now add entries to the acs_attributes table to describe +Add entries to the acs_attributes table to describe the data attributes of the new type. This data can eventually be used to do things like automatically generate user interfaces to manipulate the notes table, though that functionality isn't yet @@ -218,23 +219,23 @@ create table notes ( - note_id integer references acs_objects(object_id) primary key, - owner_id integer references users(user_id), - title varchar(255) not null, - body varchar(1024) + note_id integer references acs_objects(object_id) primary key, + owner_id integer references users(user_id), + title varchar(255) not null, + body varchar(1024) ) -Again, the usual creation_date and +The usual creation_date and modified_date columns are absent since they already exist in acs_objects. Also, note the constraint we have added to reference the acs_objects table, which makes clear that since note is a subtype of acs_object, every row in the notes table must have a corresponding row in the acs_objects table. This is the fundamental means by which -we model inheritance; it guarantees that any services developed that +we model inheritance; it guarantees that any services that use the acs_objects table to find objects will transparently find any objects that are instances of any subtype of acs_objects. @@ -409,7 +410,7 @@ When to Use Objects -While it is generally hard to give general design advice without +While it is hard to give general design advice without knowing anything about a particular application, you should follow the following rule of thumb when deciding when to hook part of your data model to the object system: @@ -555,3 +556,8 @@ +