PersistStore* OpenPersistStore(
ConstStringZ lssPath,
EOpenMode openMode = OM_OPEN_ALWAYS,
const PersistStoreSettings& settings = PersistStoreSettings())
Create a new PersistStore or open an existing PersistStore using the given PersistStoreSettings. Throws exceptions on failure.
If the EOpenMode openMode requires that the LSS exists yet it doesn't or requires there is no store with that name existing and yet one does exist, a FileException will be thrown.
A FileException may also be thrown if the file could not be written to or read from when required.
Never returns nullptr.
This example creates a new store, adds a PSpace to the store and adds a root object to the PSpace
The store is opened with EOpenMode OM_CREATE_ALWAYS which means it will overwrite any existing store having the same name.
PersistStore* store = OpenPersistStore("my_persiststore_path", OM_CREATE_ALWAYS);
PSpace* pspace = OpenPSpace(store, "my_pspace_name");
CSpace* cspace = GetCSpace(pspace);
SetThreadPtr<PSpace>(pspace);
SetThreadPtr<CSpace>(cspace);
// This block defines the scope of the CSpaceTxn
{
CSpaceTxn txn;
MyRootObject* obj = $new MyRootObject;
AddRoot(pspace, "my_root_object", obj);
}
Close(pspace);
Close(store);
The above code is not exception safe, there is a requirement to call Close() on the PersistStore and the PSpace when exceptions are thrown.
There is an RAII class named AutoCloser2 which should be used to ensure this is done:
AutoCloser2<PersistStore> store( OpenPersistStore("my_persiststore_path", OM_CREATE_ALWAYS) );
AutoCloser2<PSpace> pspace( OpenPSpace(store, "my_pspace_name") );
CSpace* cspace = GetCSpace(pspace);
SetThreadPtr<PSpace>(pspace);
SetThreadPtr<CSpace>(cspace);
// This block defines the scope of the CSpaceTxn
{
CSpaceTxn txn;
MyRootObject* obj = $new MyRootObject;
AddRoot(pspace, "my_root_object", obj);
}