[Zope-dev] Q: Specialists, Racks, and ZCatalogs?

Johan Carlsson johanc@torped.se
Mon, 5 Feb 2001 09:13:07 +0100


> A Specialist manages objects that play a particular role in your =
application.
> You will usually have one Specialist for each role in your =
application; try
> listing all the roles, and what they do, and that's a good start for =
thinking
> about what specialists you need.

Hi Steve,
I'm a bit confused in regard to the roles.=20
What exactly is a role in this context?

At first I thought of a rola as "a role of an Actor", but
as you described it it's more like the role of the class
(GoPlayers)?

How should I look at roles in ZPatterns?

Regards,
Johan Carlsson


=20
> A Rack manages the storage for a particular class of objects.
> Therefore, you will have different racks for different classes
> of object. You will also have different racks for different
> ways of storing the same class of object.
>=20
> For example, let's say I have a Specialist "GoPlayers", which manages
> objects that represent people who play the board-game Go with other =
people.
>=20
> I have two implementation classes: AmateurGoPlayer and =
ProfessionalGoPlayer.
> Objects of these classes have exactly the same interface to the rest =
of the application.
> However, the implementation of some of the methods varies.
>=20
> So, I'll need two racks in my GoPlayers specialist: one for=20
> AmateurGoPlayers and one for ProfessionalGoPlayers.
>=20
> Let's complicate things by saying that I have the records for some=20
> ProfessionalGoPlayers in a relational database, but the rest of the=20
> ProfessionalGoPlayers are stored in the ZODB. All the AmateurGoPlayers =

> are stored in the ZODB.
>=20
> So, I need three Racks altogether:
>=20
>    AmateurGoPlayers (stored in ZODB)
>    ProGoPlayers_zodb (stored in ZODB)
>    ProGoPlayers_rdbms (from legacy rdbms)
>=20
> I'm indexing all the players that are stored in the ZODB using a=20
> ZCatalog called Catalog, in the GoPlayers specialist.
>=20
> Now, when I want to answer a query such as "return all go players =
called=20
> 'bill'", I need to do the following:
>=20
> * create a PythonScript in GoPlayers called list_players_by_name(name)
> * implement this method as follows:
>    - query the ZCatalog for players who have that name
>    - query the RDBMS using an SQL query for players who have that name
>    - return the union of the results of both queries
>=20
> In this scenario, I'd put the SkinScript to catalog AmateurGoPlayers =
in=20
> the AmateurGoPlayers rack, and likewise for the ProGoPlayers_zodb =
rack.
>=20
> I'm not indexing the players from the rdbms in a ZCatalog because, in=20
> this example, other systems external to Zope can independently update=20
> the RDBMS.
> If this wasn't the case, and the all changes to data in the RDBMS go=20
> through Zope, then I could put one set of cataloging skinscript as a=20
> data-plugin in the Specialist, and make the list_players_by_name(name) =

> method just return the results from a ZCatalog search.
>=20
> The rest of my application uses the interface provided by the=20
> Specialist, and can remain ignorant of where a particular GoPlayer's=20
> records are stored.
>=20
> Note that the specialist provides exactly the methods that the rest of =

> the application requires; ideally no more, and no fewer.
>=20
> Beware when returning results from a ZCatalog query that you are only=20
> returning Catalog Brains -- simple objects that record the meta-data=20
> archived when the original object was cataloged. Where speed of=20
> execution is not an issue, you should return a list of actual GoPlayer =

> objects rather than a list of CatalogBrains.
> An alternative is to return a list of string ids.
> Often, a better plan is to determine exactly what information is =
needed=20
> by the part of your application that requires the=20
> list_players_by_name(name) method call; then provide exactly that=20
> information.
>=20
> --
> Steve Alexander
> Software Engineer
> Cat-Box limited
> http://www.cat-box.net
>=20
>=20
>=20
>=20
>=20
>=20
>=20
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )
>=20