Forum OpenACS Development: Re: Re: Re: xotcl object cache behavior?

Posted by Gustaf Neumann on
Stan, are you sure that 11395 is the item_id and not the revision_id? it can be easily confused, since the the entries in the class specific extension tables (such as xowiki_page or xowiki_object) are revision_ids and name page_id or object_id.

::Generic::CrItem instantiate loads the object from the database (or cache), bat this is only a partial initialization . btw, in the next version i'll get the package_id as well this way... i wanted to keep it mostly functioning with 5.1, but one should give user reasons to upgrade anyway...

Posted by Stan Kaufman on
Aha!! It *was* the revision_id. I mistakenly looked at the object_id -- and not the item_id -- in the xowiki_objectx view -- which was particularly stupid since the view provides a column named "item_id". Using the correct item_id now works without error.

Thanks again for your helpful explanations and ingenious code!

Posted by Stan Kaufman on
One last question on this: is there an API to find this root folder object's id -- which is the item_id as you pointed out? In the following snippet:

set package_id 11385
set xowiki_folder [::xowiki::Page require_folder -package_id $package_id -name "xowiki"]
set obj_id [db_string obi "select distinct item_id from xowiki_objectx where object_package_id = $package_id"]
set o [::xowiki::Package instantiate_page_from_id -item_id $obj_id]
$o volatile
$o set title "My New Title"
$o save

obj_id is found via the "select distinct" query -- which seems to me like a hack, but at that point we don't have a real object to introspect. Seems like a ::xowiki::Package proc get_root_folder_id {package_id} method would be useful -- or maybe it's already there by another name and I'm too dim to see. Many thanks, Gustaf, as always!

Posted by Stan Kaufman on
Ooops, I meant a ::xowiki::Package proc get_root_folder_object_id {package_id} method -- ie one that returns the id of the root folder's associated object.
Posted by Gustaf Neumann on
Stan, there are currently two approaches implemented to determine the folder_id (needed in different situations):
  1. In oder to determine the (root) folder_id from a package (e.g. in order to fetch xowiki pages from this folder)

    set Package [::xowiki::Package create ::$package_id]
    set folder_id [$Package folder_id]

  2. In order to determine the folder_id from a page:

    set folder_id [$page parent_id]
As said before, this describes the situatiton in the current release 0.34, it might change in the future (when e.g. subfolders are introduced, etc). i am currently working to make it easier to get the connection context (setting up package-id, user-id etc for e.g. testing) there will be calls to take care of these issues as well and setup the package objects etc. automatically). if someone reads this posting later, things might have changed.

It took me yesterday a couple of hours to find a bug where i had several code pieces with ::namespace:cmd (note the missing second colon), so i need some break or better glasses. i am currently finishing a ~1000 page book, and i am doing the xowiki stuff mostly as a recreational activity. On the 18th i am going on vacation, until then i try to finish up the pending things.

best regards

Posted by Stan Kaufman on
Gustaf, those steps return the folder_id -- but not the id of the folder's associated object -- which is what is needed to instantiate the object itself, as you explained earlier:

assume, you have a folder 16059, you might have
a folder object with the id 16068 and the name ::16059
The next two commands do create the object and show it to
you (you can run this from the shell).

::xowiki::Package instantiate_page_from_id -item_id 16068
::Serializer deepSerialize ::16068

Is there somewhere in the api that returns the id "16068" in your example? In any case, I see how to work around this for now, and I realize that you're actively working on all this. I really appreciate all your ongoing contributions! You are amazingly productive!

By the way, is your book entitled "Using XOTCL with OpenACS"? That would be a most excellent title! 😊

Posted by Gustaf Neumann on
sorry, i thought the question was to obtain the folder id, i misread your posting. There is not a big need for an api, since once a package is instantiated, the folder_object is as well. you just need the package_id to get all you want. here is, how you get the interesting ids:

set P [::xowiki::Package create ::$package_id]
set folder ::[$P folder_id]
set folder_id [$folder set folder_id]
set folder_item_id [$folder set item_id]
set folder_revision_id [$folder set revision_id]

btw, in the next release, you can do

$folder serialize

instead of the Serializer::...

The new code is stabilizing, and has some cool features. For example, i added some code to instantiate values from an sql query into an object. normally you get the return variables into the current scope of a function. In order to implement this, only one line was needed

::xotcl::Object instforward db_1row -objscope

db_1row is a forwarder applicable to all objects that makes the instance variables of an object to appear as local variables (the flag -objscope). So, if you do a

$obj db_1row query_name "select some_atts from ..."

the return variables are set as instance variables of the object. This is quite important for dynamic sql queries, where there is no control over the output variables, where it is quite easy to overwrite local variables. the standard set of db-commands allows already array output, but for oo style of code, the above variant is much more convenient and saves copying of values...

Posted by Stan Kaufman on
Gustaf, this is *brilliant*! Thanks again!