When you open a database you need some way of accessing the objects it contains. An AllSet contains all objects of a given class. PTXX declares an AllSet for each persistent class it encounters. You can step through an AllSet sequentially or perform value-based and identity-based queries on it. For instance, if you have Jets in your database you can use the JetAllSet to find the first jet, or you can perform queries on the JetAllSet to find jets with particular characteristics.
This chapter documents the functions for PtAllSet. When PTXX finds a persistent class declaration, it creates a new class to manage the AllSets for that persistent class. The new AllSet class that PTXX generates is derived from PtAllSet. These generated functions are usually the ones you will use.
For instance, JetAllSet is derived from PtAllSet, but it uses only Jet pointers and Jet ondemands, not PtObject pointers or PtOndemand. For instance, PtAllSet has this function:
For the Jet class, PTXX generates the following function, substituting a Jet pointer for the PtObject pointer:
Please read the chapter "Sets" for general guidelines on declaring and programming with sets. Set declaration syntax is explained in the chapter "The PTXX Precompiler."
PtAllSets are derived from PtObjectSet, and most of the methods you will use are documented more completely under PtObjectSet. Looking for the Get() function? It is a PtObjectSet function, and is documented there.
Files to include | Class declaration | Base class |
poet.hxx | ptallset.hxx | PtObjectSet |
constructor | PtAllSet(PtBase* pb = 0); |
destructor | virtual ~PtAllSet(); |
Append* | virtual int Append(PtObject* pObj, int do_remember); |
Assign | virtual void Assign(PtBase* Base); |
BeginCriticalSection | virtual void BeginCriticalSection(); |
Clear* | virtual int Clear(); |
Delete* | virtual int Delete(); |
EndCriticalSection | virtual void EndCriticalSection(); |
FindKey | virtual int FindKey(PtTypeId, void* arg, dwPtDWord numarritems); |
GetClassId | virtual PtClassId& GetClassId() = 0; |
GetCurrentPos* | virtual long GetCurrentPos(); |
GetDescId | virtual PtClassId& GetDescId() = 0; |
GetNum | virtual dwPtDWord GetNum(); |
Insert* | virtual int Insert(PtObject* pObj, int do_remember = 1); |
IsAssigned | bPtBool IsAssigned(); |
Lock | virtual int Lock(PtLockSpec* pSpec=0); |
Make | static PtAllSet* Make(PtBase *, const PtString& ClassName); |
Put | virtual int Put(PtOnDemand& Ond); |
Query | virtual int Query(PtQuery*, PtObjectSet* Result,PtLockSpec* plk = 0, PtWatchSpec* pwatch = 0); |
Search | inline int Search(PtObject *&pObj, PtSrchSpec *pSSpec, PtCmpOp GetDir, short SSpecNum=1, PtLockSpec *pLS = 0, PtWatchSpec * pWS = 0); |
Seek | virtual int Seek(long offset, PtSeekMode mode); |
SetFilter | virtual int SetFilter(PtQuery*, bPtBool UseCurrentIndex = PtFALSE); |
SetReadAhead | virtual int SetReadAhead(wPtWord); |
SortBy | int SortBy(const PtString& Membername, PtSortOp sop=PtASCENDING); |
SortByIndex | int SortByIndex(const PtString& IndexName, PtSortOp sop=PtASCENDING); |
Unget | virtual int Unget(PtObject* pObj, PtLockSpec* plk = 0, PtWatchSpec* pwatch = 0); |
Unlock | virtual int Unlock(PtLockSpec* pSpec=0); |
UnsetFilter | virtual int UnsetFilter(); |
UnsetWatch | virtual int UnsetWatch(PtWatchSpec* pSpec=0); |
Watch | virtual int Watch(PtWatchSpec* pSpec=0); |
* Dummy function, always returns an error.
- PtAllSet::PtAllSet(PtBase* pb = 0)
Constructor for PtAllSet. If you do not pass the PtBase* parameter then you must use Assign() to assign the AllSet to a database before you use it.
PtBase* | The database to which the AllSet should be assigned |
- virtual PtAllSet::~PtAllSet()
- virtual int PtAllSet::Append(PtObject * pObj, int) virtual int PtAllSet::Append(PtOnDemand &Ond)
Dummy function. Always returns ERR_PT_ILLEGAL_USE. You can not add elements to an AllSet using Append. Instead, use the object's Store() method.
- virtual void PtAllSet::Assign(PtBase* pBase)
Assigns the AllSet to a given database. This function assumes that the PtBase pointer is valid, and does not return an error. If this pointer is invalid, this will cause problems when the AllSet tries to access the database.
PtBase* | The database to which the AllSet should be assigned |
- virtual void PtAllSet::BeginCriticalSection()
Enters a critical section local to this object. If the critical section is already in use by a different thread, the function blocks until the other thread calls EndCriticalSection().
This function can be used to serialize access if you are using the same PtAllSet object in different threads simultaneously and you need to call more than one function sequentially. You do not need to call this function if you are using different PtAllSet objects in every thread.
- virtual int PtAllSet::Clear()
Dummy function. Always returns ERR_PT_ILLEGAL_USE. You can not clear an AllSet. You must delete elements individually.
- virtual int PtAllSet::Delete()
Dummy function. Always returns ERR_PT_ILLEGAL_USE. To delete an object from an AllSet, use the object's Delete() method.
- virtual void PtAllSet::EndCriticalSection()
Leaves a critical section local to this AllSet object. After that other threads are able to enter the critical section again.
- virtual int PtAllSet::FindKey(PtTypeId id, void* key, dwPtDWord numArrayItems)
Sets the current position to the first entry at or above the specified key. FindKey() allows you to position quickly to a particular value in a sorted AllSet. It is like positioning using Find(), but instead of positioning to an object with a particular object identity, it positions to an object with a particular indexed value. For instance, if you have an AllSet which is sorted by Name, you could use FindKey() to position to the first entry starting with the name "Marissa". FindKey() is very useful for implementing incremental searches.
PtTypeId id | Type manager ID for the data type |
void* key | Pointer to the data for the key |
dwPtDWord numArrayItems | Number of array items. If the type is not an array, use 1. For arrays, use the dimension of the array. |
ERR_PT_KEY_NOT_FOUND | Key not found |
0 | Success |
To use FindKey(), you must first use PtAllSet:: SortByIndex() or PtAllSet:: SortBy() to set a sort order for the AllSet, and the data for your key must have the same type as the index used to sort the AllSet. If the index is a compound index, the data for the key must match the first field in the index, and positioning will be based on the first field.
If the item is found, FindKey() positions to the item. If it is not found, FindKey() returns ERR_PT_KEY_NOT_FOUND and positions just previous to the next greater value. To position to the next greater value, do a Seek() or a Get() with the seek parameters 1 and PtCURRENT. Suppose you have a class called Person which has an index on Person:: Name:
In your program, you can take a PersonAllSet, sort it by the name index, and position to the first person whose name is greater than or equal to Marissa:
// The current position is now at the first entry greater than // or equal to Marissa
Wildcards are not supported.
Comparision is limited to the significance of the index being used index. Compound indexes always return ERR_PT_KEY_NOT_FOUND, because they cannot be fully qualified in the argument.
The later two limitations do not apply to PtAllSet::Search().
- virtual PtClassId& PtAllSet::GetClassId()
Returns the PtClassId for the set type itself. For instance, if this set is a PersonAllSet then it would return the PtClassId for PersonAllSet.
- virtual dword PtAllSet::GetCurrentPos()
Dummy function. Always returns ERR_PT_ILLEGAL_USE. GetCurrentPos() works for PtObjectSets, but not for PtAllSets. Since you often change the position within an AllSet without doing a Seek(), AllSets can not easily return an absolute position - you can use filters to position based on values, or you can access AllSets using indexes in various sort orders, and these indexes are updated every time you do a Store() or Delete(). Therefore, we can not easily put absolute position numbers in our index entries.
- virtual PtClassId& PtAllSet::GetDescId()
Returns the PtClassId for the class contained in the set. For instance, if this set was declared like this:
Then it would return the PtClassId for Person. Since sets are polymorphic, the set may contain any object which belongs to a class derived from Person, e.g. Firemen, Programmers, and Morticians.
- virtual dwPtDWord PtAllSet::GetNum()
Returns the number of objects in the AllSet.
If you are in a transaction, this will include objects added using a Store() during the transaction and exclude objects deleted with Delete() during the transaction.
PtAllSet:: GetNum() does not work for a filtered set. There is no way to determine the number of matching items without reading through the set.
>= 0 | The number of objects in the AllSet |
ERR_PT_NOT_ASSIGNED | The AllSet has not been assigned to a database. |
ERR_PT_NOT_OPENED | The AllSet has been assigned, but the database is not open. |
- virtual int PtAllSet::Insert(PtObject* pObj, int); virtual int PtAllSet::Insert(PtOnDemand& Ond)
Dummy function. Always returns ERR_PT_ILLEGAL_USE. The only way to add elements to an AllSet is to use the object's Store() method.
- virtual int PtBool PtAllSet::IsAssigned()
Returns a non-zero value if the PtAllSet has been assigned to a database.
- virtual int PtAllSet::Lock(PtLockSpec * pSpec=0)
Locks all the objects in the AllSet. This is the same as PtObjectSet:: Lock(), but the depth mode in the PtLockSpec must always be PtFLAT. Any other depth mode results in an error return without locking any objects. Although locks for objects stack, locks for AllSets do not stack. You may set more than one lock for an AllSet, but no two locks may have the same lock mode and depth.
Locking is an all-or-nothing affair. If POET can not lock all the objects in the set, the whole Lock() will fail without locking anything.
0 | Success |
ERR_PT_ILLEGAL_PARAMETER | Your lock's depth mode must be PtFLAT |
ERR_PT_OBJECT_LOCKED | You do not have permission to lock at least one object; someone else has locked it. |
ERR_PT_NO_DEFAULT | You tried to lock using the default lock, but there is no default lock. |
ERR_PT_OBJECT_ALREADY_LOCKED | An identical lock has already been placed on this AllSet |
ERR_PT_NOT_ASSIGNED | The AllSet has not been assigned to a database. |
ERR_PT_NOT_OPENED | The AllSet has been assigned, but the database is not open. |
- static PtAllSet* Make(PtBase*, const PtString & ClassName)
Creates an object of class PtAllSet which contains all objects of the given class class. If no class with the given name was registered inside the POET dictionary, the function returns a null-pointer.
- virtual int PtAllSet::Put(PtObject* pObj, int) virtual int PtAllSet::Put(PtOnDemand& odObj)
Dummy function. Always returns an error. You can not replace an element in an AllSet directly.
- virtual int PtAllSet::Query(PtQuery*, PtObjectSet* Result, PtLockSpec* plk = 0, PtWatchSpec* pwatch = 0)
This function does the same thing as PtObjectSet:: Query(), and is documented in the PtObjectSet class.
- inline int Search(PtObject *&pObj, PtSrchSpec *pSSpec, PtCmpOp GetDir, short SSpecNum=1, PtLockSpec *pLS = 0, PtWatchSpec * pWS = 0)
Retrieves one object from the AllSet. The search criteria is passed as an argument. You can specify one criteriona for each part of a component index.
PtObject *&pObj | Pointer to object, which has to be retreived |
PtSrchSpec *pSSpec | Address of search criteria. This can be an array of descriptions if a compound index is used. |
PtCmpOp GetDir | Specifies the comparision that is made to pSSpec. Allowed values are: PtLT, PtLTE, PtEQ, PtGTE, PtGT. A value of zero determines, that only a positioning with PtEQ is done and no object is returned. |
short SSpecNum | Number of array items. If the type is not an array, use 1. For arrays, use the dimension of the array. |
PtLockSpec *pLS | Specifies the lockmode which is applied to the object before it is returned. |
PtWatchSpec * pWS | Specifies the watchmode which is applied to the object before it is returned. |
0 | Success |
ERR_PT_KEY_NOT_FOUND | Key not found |
ERR_PT_OBJECT_LOCKED | The searched object could not be locked, because it is locked by a different client. |
Wildcards are not supported.
- virtual int PtAllSet::Seek(long offset, PtSeekMode mode)
Sets the current position of the AllSet. When reading objects from the AllSet, it is usually best not to call Seek() explicitly; instead, call Get() with the seek parameters.
offset | offset within the set |
mode | PtSTART, PtCURRENT, or PtEND |
ERR_PT_RANGE | You are trying to position past the beginning or end of the set. |
ERR_PT_NOT_ASSIGNED | The AllSet has not been assigned to a database. |
ERR_PT_NOT_OPENED | The AllSet has been assigned, but the database is not open. |
- virtual int PtAllSet::SetFilter(PtQuery* Query, bool UseCurrentIndex = PtFALSE)
Installs the query specification as a filter. When you retrieve an item from a filtered AllSet, you only see the items which satisfy the query conditions that you specified in the filter. In other words, the AllSet acts as though it were the result set for the query, but instead of performing the query all at once, POET finds each item as you read it from the filtered set. The PtQuery may not contain a SortBy clause. Except for this, you can use any query specification, including nested query specifications. Filters do not nest. An AllSet may only have one filter at a given time. Queries on filtered sets currently ignore the filter entirely and act as though the filter had never been set.
If you have used SortByIndex() to set an order, you can decide if the filter should maintain this sort order. Set the parameter UseCurrentIndex to PtTRUE if you want to keep the sort order. Note, however, that this sort order may force POET to use a sub-optimal search strategy. In general, use this only when you are searching based on the same member or members that you want to sort by.
PtAllSet:: GetNum() does not work for a filtered set. There is no way to determine the number of matching items without reading through the set.
- virtual int PtAllSet::SetReadAhead(word count)
Specifies the size of a read-ahead cache which POET will use when reading items for a particular set. It is particularly useful for writing browsers. Note: locks and watches are applied when the object is read using Get(), not when it is read into the cache, so you should be very careful if you use this for applications where you need concurrency control or distributed objects.
- int PtAllSet::SortBy( const PtString& Membername, PtSortOp sop=PtASCENDING) int PtAllSet::SortBy( PtSortOp sop=PtASCENDING )
Choose an indexed data member to determine the sort order of the AllSet. This function is less useful than SortByIndex(), which is the function you probably want to be using for new development.
By default, AllSets are sorted in ascending order using the surrogate, which is equivalent to sorting the objects by the order in which they were first assigned to the database. You can use any index to set a different order. For instance, if you want to access objects sorted by name and your object has a member called LastName then you can set the sort order like this:
You can reverse this sort order by using PtDESCENDING:
The second form of the function does not specify a member name - the surrogate index is implied:
If the sort order is PtASCENDING, SortBy() seeks to the beginning of the set. If the sort order is PtDESCENDING, SortBy() seeks to the end of the set.
const PtString& IndexMembername | The name of the index Member to use |
PtSortOp sop | PtASCENDING or PtDESCENDING |
0 | Successful completion |
ERR_PT_NO_INDEX | This member is not indexed |
ERR_PT_NOT_ASSIGNED | The AllSet is not assigned to a database |
ERR_PT_NOT_OPENED | The AllSet is assigned, but the database is not open. |
- int PtAllSet::SortByIndex( const PtString& IndexName, PtSortOp sop=PtASCENDING)
Chooses an index to determine the sort order of the AllSet. SortByIndex() does not actually sort the AllSet, it merely uses the sort order defined by the index. By default, AllSets use the surrogate index, which is equivalent to sorting the objects by the order in which they were first assigned to the database. You can use any index to set a different order. If the sort order is PtASCENDING, SortByIndex() also seeks to the beginning of the set. If the sort order is PtDESCENDING, SortByIndex() seeks to the end of the set.
const PtString& IndexName | The name of the index to use |
PtSortOp sop | PtASCENDING or PtDESCENDING |
0 | Successful completion |
ERR_PT_NO_INDEX | The index does not exist for this AllSet |
ERR_PT_NOT_ASSIGNED | The AllSet is not assigned to a database |
ERR_PT_NOT_OPENED | The AllSet is assigned, but the database is not open. |
If the Person class has an index called TelephoneBookOrderIX then you can set this as the sort order like this:
- virtual int PtAllSet::Unget(PtObject* pObj, PtLockSpec* plk = 0,PtWatchSpec* pwatch = 0 ) virtual int PtAllSet::Unget(PtOnDemand& odObj, PtLockSpec* plk = 0,PtWatchSpec* pwatch = 0) virtual int PtAllSet::Unget(PtObject* pObj, PtLockSpec* plk = 0,PtWatchSpec* pwatch = 0 )
Frees up resources allocated by Get(). .
If you specify only the first parameter, Unget() decrements the link count and removes it from RAM if the resulting link count is zero. If you specify a PtLockSpec or a PtWatchSpec, this should match the PtLockSpec or PtWatchSpec used by the corresponding Get() function; Unget() will then remove the lock or the watch. Future versions of POET may do more. If you want to keep an object in memory you can call the object's Remember() method before calling Unget():
PtObject* pObj PtOnDemand& odObj | The object being returned to the set |
PtLockSpec* plk = 0 | A lock to remove from the object |
PtWatchSpec* pw = 0 | A watch to remove from the object |
0 | Link count went to zero, object was deleted |
>0 | Resulting link count |
- virtual int PtAllSet::Unlock(PtLockSpec * pSpec=0)
Unlock the objects in the AllSet. This is the same as PtObjectSet:: Unlock(), but the depth mode in the PtLockSpec must always be PtFLAT.
0 | Success |
ERR_PT_ILLEGAL_PARAMETER | Your lock's depth mode must be PtFLAT |
ERR_PT_OBJECT_LOCKED | You do not have permission to lock at least one object; someone else has locked it. |
ERR_PT_NO_DEFAULT | You tried to lock using the default lock, but there is no default lock. |
ERR_PT_NOT_LOCKED | The AllSet was not locked in the first place. |
ERR_PT_NOT_ASSIGNED | The AllSet has not been assigned to a database. |
ERR_PT_NOT_OPENED | The AllSet has been assigned, but the database is not open. |
- virtual int PtAllSet::UnsetFilter()
Removes the current filter from the AllSet.
- virtual int PtAllSet::UnsetWatch ( PtWatchSpec * pSpec=0)
Unsets a watch on the objects in the AllSet. This is the same as PtObjectSet:: UnsetWatch(), but the depth mode in the PtWatchSpec must always be PtFLAT.
0 | Success |
ERR_PT_ILLEGAL_PARAMETER | Your watch's depth mode must be PtFLAT |
ERR_PT_NO_DEFAULT | You tried to watch using the default watch, but there is no default watch. |
ERR_PT_OBJECT_NOT _WATCHED | There is no watch on this AllSet. |
ERR_PT_NOT_ASSIGNED | The AllSet has not been assigned to a database. |
ERR_PT_NOT_OPENED | The AllSet has been assigned, but the database is not open. |
- virtual int PtAllSet::Watch(PtWatchSpec * pSpec=0)
Sets a watch on the objects in the AllSet. This is the same as PtObjectSet:: Watch(), but the depth mode in the PtWatchSpec must always be PtFLAT. Any other depth mode results in an error return without setting any watches.
If you are testing for stores, note that PtWATCH_STORE and PtWATCH_UPDATE do not detect when a new object is added to the AllSet. Use PtWATCH_INSERT for this.
If you set a watch on an AllSet, it is not triggered if an object belongs to the same class that the AllSet holds; it is not triggered by objects whose class is derived from it. Therefore, if you want a watch to apply to derived classes, you must also set the watch for the AllSets associated with the derived classes.
0 | Success |
ERR_PT_ILLEGAL_PARAMETER | Your watch's depth mode must be PtFLAT |
ERR_PT_NO_DEFAULT | You tried to watch using the default watch, but there is no default watch. |
ERR_PT_OBJECT_ALREADY_ WATCHED | An identical watch has already been placed on this AllSet |
ERR_PT_NOT_ASSIGNED | The AllSet has not been assigned to a database. |
ERR_PT_NOT_OPENED | The AllSet has been assigned, but the database is not open. |
Copyright (c) 1996 POET Software, Inc. All rights reserved. Reproduction in whole or in part in any form or medium without the express permission of POET Software, Inc. is prohibited.