|
Oak::DBIEntity - Class for DBI based entity classes |
Oak::DBIEntity - Class for DBI based entity classes
Base class for DBI based entity classes. This class can be used to automate the development of business applications, it implements automatic load and save of data with get and set methods, functions for listing the objects of a class, functions to handle the relationships and the constructor with a default interface to create new objects of a class.
This class is based on methods that will be overriden to specify the behavior of a class.
P.S.: Methods that are written with UpperCaseLetters are class methods and methods written with lower_case_letters are object methods.
Ex.:
{
User =>
[
["login","VARCHAR(40) NOT NULL DEFAULT ''"],
...
]
...
}
When implementing table-distributed classes (subclasses), remember that the primary keys of the tables MUST have the same name and value.
The value has no meaning and it is a hash to simplify lookup.
name_of_the_relationship =>
{
type => Relationship type, one of: 1-1, 1-N, N-1, N-N.
class => The class of the objects at the other side.
foreign_key => The field that maintain the relationship in this table.
other_foreign_key => The field that maintain the relationship in the other table
relation_table => Used in type N-N to specify the relationship table
on_delete => The name of a method in the current class that will be called
when trying to delete this object:
on_delete_cascade: Delete the objects at the other side (composition)
on_delete_restrict: Do not delete anything if there are objects at the other side
on_delete_set_null: Defines the foreign_key with a null value
default: Delete this entity and do nothing with the other objects
}
SetDBIIo(obj)Remember that a class variable will be set in this module, so, always you set an obj, remember to set undef after using it, else your dbi object will never be destroyed.
List($query)Count($query)Throws Oak::DBIEntity::Error::InvalidObject if the object already exists.
Throws Oak::DBIEntity::Error::InvalidObject if the object does not exist.
Throws Oak::Error::ParamsMissing if neighter create of primary key passed.
list_related($relationshipname,$query)In this method, the $query must not include the WHERE word.
Throws Oak::DBIEntity::Error::InexistentRelationship if an inexistent relationship is passed.
remove_relationship($relationshipname,$object)Throws Oak::DBIEntity::Error::InexistentRelationship if an inexistent relationship is passed.
Throws Oak::DBIEntity::Error::InvalidObject if the passed object is not associated with this object
add_relationship($relationshipname,$object)Throws Oak::DBIEntity::Error::InexistentRelationship if an inexistent relationship is passed.
This method will transverse the relationships, dispatching the on_delete methods. after this, it will delete itself.
The methods in this section can be specified in the on_delete attribute of a relationship.
on_delete_cascade($relationshipname)on_delete_restrict($relationshipname)on_delete_set_null($relationshipname)
Copyright (c) 2001 Daniel Ruoso <daniel@ruoso.com> Carlos Eduardo de Andrade Brasileiro <eduardo@oktiva.com.br> All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Oak::DBIEntity - Class for DBI based entity classes |