pyswarm Documentation (http://pyswarm.sourceforge.net/)

2.5.  Running Your Application

2.5.1. Client-Specific Implementation Concepts
2.5.2. General Implementation Concepts
2.5.3. Mission achieved
[Important] Important

Advice is given to print at least the class diagram of the PetStore UML model so you can quickly reference the model while studying the code examples provided in this section.

In the current version of pyswarm your application is not provided as daemon or service. Assume a Python module that needs an object of our Adm component class. It needs to import the appropriate files, instances them, and calls the desired procedures. By doing so the Python modules of which your application consists are loaded and as soon as the client module finished its job our modules are disappearing again. There is no service running all the time in the background and waiting for calls like a daemon is used to do.

You can call special methods on collections, e.g. for counting:

                lCountA = addresses.count(oOp, None, None)
            

The method count() on a collection counts the objects found in the collection. The quantity returned is a long type. count() offers you two optional parameters to filter the collection, effecting the quantity that is count. Here both parameters are not set.

The first parameter after oOp is the classifier . Provide a string with the name of a sub-class of the opposite role's class to restrict which objects should be count. Since Address has a plenty of sub-classes, you can use one of them to classify the collection you want to count, e.g. 'Telephone' to get all associated Telephone objects counted, or 'ZipAddress' for all ZipAddress objects, which itself can be either GeoAddress or PoboxAddress objects. Example:

                lCountA = addresses.count(oOp, 'ZipAddress', None)
            

The last parameter is used for criteria. Provide a string with criteria filter as you probably know from SQL WHERE clauses. Thus you can filter all objects with a specific attribute value. If classifying ZipAddresses it could be counting all objects with the zipCode='11122'. Please note that we need to unmask ' and " characters with a backslash \.

                lCountA = addresses.count(oOp, 'ZipAddress', '\"zipCode\"=\'11122\'')
            

You can also use AND or OR combinations, also in conjunction with priorizing brackets, e.g "locationName"='Munich' AND ("zipCode"='11122' OR "zipCode"='222333')

You can also use UPPER( value ) or LOWER( value ) to compare values case-insensitive, e.g. LOWER("name")=LOWER('LinDA')

Another example worth to try out are LIKE comparisons, e.g. "subject" LIKE '%a' which applies to all entries where the subject value's last character is the lower character 'a'.

                lCountA = addresses.count(oOp, None, '\"subject\" LIKE \'%a\'')
            

According to the example with retrieving associated Address objects, but here Recipient objects:

                addressees = prime.getRecipientsOfAddressBook(oOp)
                lCountR = addressees.count(oOp)
            

Note that you can leave away the parameters if you don't need. But if you leave away strClassifier paremter, but want to use the criteria, you need to name the parameter. Try this:

                lCountR = addressees.count(oOp, strCriteria='\"name\" LIKE \'%a\'')
            

Dear reader, we are finished with this tutorial. pyswarm is in strong development and this tutorial is the first tutorial written for pyswarm. Nevertheless I hope that it was helpful for you.

Please also see Chapter 6, Community .

Thank you.

This document was created using the >e-novative> DocBook Environment (eDE)