- SEE ALSO
WE::DB::Obj - object database for the WE_Framework
$objdb = WE::DB::Obj->new($root, $db_file); $objdb = $root->ObjDB;
new creates a new database reference object (and, if the database does not exist, also the physical database). Usually called only from WE::DB (see there). Parameters are: the
$root object (a
WE::DB object) and the filename for the underlying database (here, it is
In the optional arguments, further options can be specified:
- -serializer => $serializer
The type of the serializer, e.g.
Data::Dumper(the default) or
- -db => $db
The type of the database (dbm) implementation, e.g.
DB_File(the default) or
GDBM_File. Note that other databases than
GDBM_Filehave length restrictions, making them unsuitable for using with
WE::DB::Obj. However, the CPAN module
MLDBM::Sync::SDBM_Fileworkaround the deficiency of the 1K size limit in the standard
- -locking => $bool
True, if locking should be used. XXX For now, only 0 and 1 can be used, but this should probably be changed to use shared and exclusive locks.
By default, there is no locking. If locking is enabled and the database type is
DB_File::Lockwill be used. For other database types, no locking is implemented.
- -readonly => $bool
Open the database read-only. This is the same as specifying O_RDONLY. By default it is opened read-write and the database is created if necessary (O_RDWR|O_CREAT).
- -writeonly => $bool
If true, then a database will not be created if necessary. This is the same as specifying O_RDWR.
- -connect => $bool
If true, connects to the database while constructing the object. Otherwise the connection will be made automatically before each operation. Also, the methods connect and disconnect can be used for connecting and disconnecting from the database.
Normally, long running processes (servers or mod_perl processes) should specify -connect => 0 and use the auto-connection feature or manually connect()/disconnect(). So database changes are propagated immediately.
The default of the -connect option is true.
Called automatically. Destroys the tied database handle.
Please see also WE::DB::ObjBase for inherited methods.
Initialize the database to hold meta data like _root_object or _next_id. Usually called only from
Delete all database contents
Return the root object.
Return true if the object with id
$objidis the root object.
Increment and get the next free id. The internal id counter is always incremented, regardless whether the new id will be used or not.
Only get the next free id, without incrementing it.
Create a new internal stored object.
Store the internal stored object.
Store the object. Please note that there is a difference between a stored object (holding additional data like children, parents etc.) and the mere object.
Get a stored object.
Get an object by id.
Return true if the object exists. Parameter is the object id.
Return a list of the children ids of this object. If the object does not exist or the object has not children, return an empty list.
Like children_ids, but return parent ids instead.
Like children_ids, but return version ids instead.
Find links with the $target_id as target.
Remove the given parent link from the object. If there is no parent link anymore, remove the whole object.
Remaining arguments are passed to the remove method (see there).
Link an object to a folder. This can be used to create multiple links. It is possible to create multiple links from one object to another --- this behaviour may change XXX. See also "BUGS".
- remove($object_id, %args)
Remove the object $obj_id and all links to this object uncoditionally.
If -links => "unhandled" is specified, then links to this object won't get removed. This is dangerous, and needs an additional we_fsck run afterwards. This option is useful if a mass-delete should be done.
Insert a document. The following arguments should be given:
-content: a string to the content or -file: the filename for the content -parent: the id of the parent
Other arguments will be used as attributes for the object, e.g. -ContentType will be used as the ContentType attribute and -Title as the title attribute. Note that these attributes are typically starting with an uppercase letter.
Return the generated object.
Insert a folder. The following arguments should be given:
-parent: the id of the parent
Return the generated object.
- insert($object, %args)
General method for inserting objects. You will mostly use either insert_doc or insert_folder.
-parentfor parent object.
Return the generated object.
Get the content for the given object.
- replace_content($object_id, $content)
Replace the content of an existing object. Return the object itself.
Flushes all changes, so they are visible to other processes. This is done automatically on end of the program or if the object is destroyed.
Replace the given object. Argument is an object. This object should contain the valid id. Return the object itself.
- is_ancestor($object_id, $ancestor_id)
Return true if $ancestor_id is an ancestor of $object_id.
- copy($object_id, $folder_id, %args)
Copies the object identified by $object_id to the folder identified by $folder_id. Both the object metadata and the content are copied. Folders are copied by default recursively. To only copy the folder object, use
-recursive => 0in the %args parameter hash.
Return the copied object. If there is a recursive copy, then return a list of copied objects. In this list, the first object is the copied top folder. In scalar context, always return only the first (or only) copied object.
Version information is never copied (yet).
- ci($object_id, %args)
Check in the current version of the object with id
$object_id. You can use additional parameters:
- -log => $log_message
Specify a log message for this version (recommended).
-commentis an alias for
- -number => $version_number
Normally, the version number is just incremented (e.g. from 1.0 to 1.1). If you like, you can specify another version number. There are no checks for valid version numbers (that is, you can specify more than one number, invalid formatted version numbers etc).
-versionis an alias for
- -trimold => $number_of_versions
If set to a value greater 0, then delete old versions. Set $number_of_versions specify the number of versions you want to keep. With -trimold => 1, all but the newest version will be wiped out.
Return the checked-in objects. The original object is set to not dirty.
- trim_old_versions($object_id, [ -trimold => $number | -all => 1 ])
Trim the last
$numberversions of object
-allis used instead, then trim all old versions.
-trimoldare mutually exclusive.
- co($object_id [, -version => $version_number])
Check out the object with the version number
$version_number. If version number is not given, then check out the latest version. If the version number is not given and there are no versions at all, then an exception will be thrown. Please note that a check out will override the current object, so you probably should do a
cifirst. No locking is done (yet).
- move($object_id, $parent_id, %args)
Move the object with
$object_idand linked to the parent
$parent_idto another position or destination. If
undef, then the first found parent is used. If there are multiple parents, then it is better to specify the right one. The
%argsportion may look like this:
- -destination => $folder_id
Move the object to another folder. You can also use
-targetas an alias for
- -after => $after_object_id
Leave the object in the same folder, but move it after the object with the id
$after_object_id. If there is no such object in the folder, then an exception is raised.
- -before => $before_object_id
-after, but move the object before the specified object.
- -to => "begin" | "end"
Move the object to the beginning or end of the folder. For "begin", you can also use "first" and for "end", you can use "last".
Return nothing. On error an exception will be raised.
Dump object structure as a string. Possible options:
- -root => $object_id
Specify another object to start dumping from. If not specified, start dumping from root object.
- -versions => $bool
If true, then version information is also dumped.
- -attributes => $bool
If true, then attribute information is also dumped.
- -children => $bool
Recurse into children. This is by default true.
- -callback => $sub
A reference to a callback which can dump additional code. The subroutine will get the following key-value pairs as arguments:
The subroutine should return a string. See
we_dumpscript for an example.
Get the minimum and maximum depth of the object. There are multiple depths, because the object can be in multiple parents with different depths.
($min_depth, $max_depth) = $objdb->depth($obj_id);
The default path separator is "/".
- pathname2id($pathname [, $parent_obj])
Return the object id for the matching "pathname". There are no real pathnames in the WE_Framework, so a dummy pathname is constructed by the titles (english, if there are multiple).
PATH_SEPis used as the path separator.
$parent_objis given as a object, then the given pathname should be only a partial path starting from this parent object.
undefif no object could be found.
- pathname($object_id [, $parent_obj, %args])
For the object
$object_id, the virtual pathname (as described in pathname2id) is returned.
$parent_objis given as a object, then the returned pathname is only a partial path starting from this parent object.
Possible key-values for %args:
Return recursive all folders and released children of the given folder
$folder_idas an array of objects.
Return the last released version for
$object_id. If there is no released version yet, return
Return true if the object $obj is active, that is, the release state is not inactive and TimeOpen/TimeExpire does not apply.
For some methods, there are cycle test missing. Therefore it is possible that methods cause endless loops, if links are causing cycle loops! Please think before using
Slaven Rezic - email@example.com