Database Object purpose an interface for object intended to stored. Each object intended to be stored in database should inherite from it and call DatabaseObject__init__() method. DatabaseObject permit to create relation between other DatabaseObject. DatabaseObject Generate dynamic method accessor for each property and each relation. Each accessor control data integrity. It also purpose storeObject() to store itself on database (but it should know Database before)
def Database.DatabaseObject.DatabaseObject.__init__ | ( | self, | ||
type_name, | ||||
property_dictionnary = None | ||||
) |
Initialise DatabaseObject with type_name
This method initialise object data and basic property like title and id. You can use a property_dictionnary in order to initialise object schema
type_name | Should be string, indicate name of object like organisation or person | |
property_dictionnary | It's a dictionnary property structure, __init__ will use it to directly add some property on object |
TypeError | property_dictionnary is not a dictionnary (hugh!) |
def Database.DatabaseObject.DatabaseObject.__getattribute__ | ( | self, | ||
name | ||||
) |
Dynamic accessor for property and relation surcharge
Allow to use dynamique method to access property ex. : if we declare current_date property it will permit to access this fonction through :
name | the called method/attribute |
AttributeError | Method not found |
def Database.DatabaseObject.DatabaseObject.getParent | ( | self | ) |
Return parent object of current object
This method return object who's contain current object
def Database.DatabaseObject.DatabaseObject.setLocked | ( | self | ) |
def Database.DatabaseObject.DatabaseObject.setUnlocked | ( | self | ) |
Unlock the current object
This method is used to unlock the object
def Database.DatabaseObject.DatabaseObject.isLocked | ( | self | ) |
To know if current object is locked
Define if this object is locked or not
WARNING : if you open an object with lock option self.locked property will not return true, but if someone open an already opened object, this property will return True
def Database.DatabaseObject.DatabaseObject.addContent | ( | self, | ||
database_object | ||||
) |
Adding a new content to the current Object
Adding a new content to the current Object. This object will be deleted if current object is deleted.
database_object | could be list, database_object or dict of object. |
AddContentError | Adding object to itself |
def Database.DatabaseObject.DatabaseObject.newRelation | ( | self, | ||
relation_name, | ||||
relation_type_name | ||||
) |
Adding a new relation and allowed type for it.
Adding a new type of relation for this object with another. relation_type_name define the type limit of this relation (like only with person or organisation type object).
relation_name | Name of the relation | |
relation_type_name | list of allowed type name, it could be a tuple of string or string like ("organisation","person") |
TypeError | relation_name is not a string | |
TypeError | relation_type_name is not a string or a tuple of string |
def Database.DatabaseObject.DatabaseObject.emptyRelation | ( | self, | ||
name | ||||
) |
Clearing a relation set it to an empty dictionnary
name | string name of the relation you want to clear |
KeyError | Relation not found | |
TypeError | name parameters is not a string |
def Database.DatabaseObject.DatabaseObject.getRelationAllowedTypeName | ( | self, | ||
relation_name | ||||
) |
Return list of allowed type for a given relation
relation_name | Name of the relation for which you which to obtain allowed type name |
KeyError | Given relation does not exist on current object | |
TypeError | relation_name parameters is not a string |
def Database.DatabaseObject.DatabaseObject.setRelationAllowedTypeName | ( | self, | ||
relation_name, | ||||
allowed_type_name | ||||
) |
set list of allowed type for a given relation
relation_name | Name of the relation for which you which to set allowed type name | |
allowed_type_name | list of type_name you wish to allow for relation |
KeyError | Given relation does not exist on current object | |
TypeError | relation_name parameters is not a string | |
TypeError | allowed_type_name parameters is not a string or a tuple composed by string |
def Database.DatabaseObject.DatabaseObject.setRelation | ( | self, | ||
relation_name, | ||||
database_object | ||||
) |
Setting a relation with another database_object
relation_name | Name of the relation | |
database_object | It could be a single/tuple of DatabaseObject or a dict like :
|
KeyError | database_object is an object and it has no Id | |
TypeError | Relation is not allowed for given object | |
TypeError | You does not submit list only composed by DatabaseObject | |
TypeError | Your object dictionnary has a non string key | |
TypeError | General incorrect dictionnary format | |
KeyError | Given relation does not exist on current object |
def Database.DatabaseObject.DatabaseObject.setRelationList | ( | self, | ||
relation_name, | ||||
database_object | ||||
) |
set a relation with a list of object
relation_name | name of the relation | |
database_object | list of DatabaseObject or dictionnary of Database object reference |
def Database.DatabaseObject.DatabaseObject.getAllowedTypeNameForRelation | ( | self, | ||
relation_name | ||||
) |
return allowed type for a relation in tuple format.
This method never return None because each relation should always have a list of allowed type.
relation_name | name of the relation for wich you looking for allowed type name. |
KeyError | current object does not have this relation. | |
TypeError | you does not submit a string for relation_name parameter |
def Database.DatabaseObject.DatabaseObject.getRelatedRelationObject | ( | self, | ||
relation_name | ||||
) |
Return first related object found for given relation.
relation_name | name of the relation for which you looking for related relation. |
None if no related object is found.
def Database.DatabaseObject.DatabaseObject.getRelatedRelationObjectList | ( | self, | ||
relation_name, | ||||
start = None , |
||||
stop = None | ||||
) |
Return list of related object found for given relation.
relation_name | name of the relation for which you looking for related relation. | |
start | begining position on the list | |
stop | ending position on the list |
None if no related object is found.
def Database.DatabaseObject.DatabaseObject.getRelationObject | ( | self, | ||
relation_name | ||||
) |
Return first found object for given relation
relation_name | name of the relation |
None if no object was found
def Database.DatabaseObject.DatabaseObject.getRelatedRelation | ( | self, | ||
relation_name | ||||
) |
Return first found related object for given relation
relation_name | name of the relation |
None if no object was found
def Database.DatabaseObject.DatabaseObject.getRelatedRelationList | ( | self, | ||
relation_name | ||||
) |
Return list of related object for a given Relation
relation_name | name of the relation |
None if nothing was found
def Database.DatabaseObject.DatabaseObject.getRelation | ( | self, | ||
relation_name | ||||
) |
Return first found object id and type_name for a specified relation
relation_name | name of the relation |
None if it does not exist object related to
KeyError | relation does not exist on currenct object | |
TypeError | relation_name parameter is not a string |
def Database.DatabaseObject.DatabaseObject.getRelationObjectList | ( | self, | ||
relation_name, | ||||
start = None , |
||||
stop = None | ||||
) |
Return list of DatabaseObject for a given relation
relation_name | name of the relation | |
start | begining position on the list | |
stop | ending position on the list |
None if nothing was found
def Database.DatabaseObject.DatabaseObject.getRelationList | ( | self, | ||
relation_name, | ||||
start = None , |
||||
stop = None | ||||
) |
Return a dictionnary of DatabaseObject reference for a given relation
relation_name | name of the relation | |
start | begining position on the list | |
stop | ending position on the list |
KeyError | current object does not have this relation | |
TypeError | relation_name parameter is not an string |
def Database.DatabaseObject.DatabaseObject.setDatabaseEngine | ( | self, | ||
database_engine | ||||
) |
Set the database engine which should be use to store object
This is usefull only for DatabaseObject method who need a database connector like related relation accessor and storeObject
database_engine | Database that you which to use |
False if the database_engine is not accepted
Database.Database.getRelatedList
def Database.DatabaseObject.DatabaseObject.getDatabaseEngine | ( | self | ) |
Return the database engine instance use on this object
Use it carefully, it could be dangerous to modify returned value
def Database.DatabaseObject.DatabaseObject.storeObject | ( | self | ) |
Store object on database
This method work only if the object know the database. To make it know, you could use setDatabaseEngine method.
False if database_engine is not set
def Database.DatabaseObject.DatabaseObject.removeProperty | ( | self, | ||
name | ||||
) |
Remove a given property from the property dictionary
name | name of the property you want to remove |
False if the property was not found on object
TypeError | the given name is not a string |
def Database.DatabaseObject.DatabaseObject.getPropertyList | ( | self | ) |
return the name list of property in dictionary
def Database.DatabaseObject.DatabaseObject.getRelationNameList | ( | self | ) |
return list of existing relation on object
list | of relation existing on object |
def Database.DatabaseObject.DatabaseObject.replaceProperty | ( | self, | ||
name, | ||||
property_type, | ||||
title = None , |
||||
description = None | ||||
) |
Replace a given property or create it if necessary
Each properties should be a strings
name | property name | |
property_type | type of the property (could be uint, int, float, string...) | |
title | title of object, you could just capitalize the property name | |
description | Description of the property |
TypeError | You does not submit an allowed type | |
TypeError | name parameter was not a string |
def Database.DatabaseObject.DatabaseObject.addProperty | ( | self, | ||
name, | ||||
property_type, | ||||
title = None , |
||||
description = None | ||||
) |
def Database.DatabaseObject.DatabaseObject.newProperty | ( | self, | ||
name, | ||||
property_type, | ||||
title = None , |
||||
description = None | ||||
) |
Adding a new Property
Each properties should be a strings Be care that it will not replace a property if it already exist the same property name in current object property dictionary
name | property name (it could only be composed by alphabetic char and "_") | |
property_type | type of the property (could be uint, int, float, string...) | |
title | title of object, you could just capitalize the property name | |
description | Description of the property |
TypeError | You does not submit an allowed type | |
TypeError | name parameter was not a string | |
TypeError | name was composed of illegal characters | |
KeyError | object contains a same property name |
def Database.DatabaseObject.DatabaseObject.getPropertyTitle | ( | self, | ||
name, | ||||
property_dictionnary = None , |
||||
default = None | ||||
) |
Return the property title like "First Name", "Age"...
You can submit a specific dictionary you want to ask it instead of object property dictionnary.
name | property name. | |
property_dictionnary | optional property dictionnary if you wand to work on it instead of current object property dictionnary. | |
default | default value you want to be return if no Title was defined on given property. |
KeyError | if the property does not exist on current object. | |
TypeError | if you do not submit string for name parameter. | |
TypeError | if you do not submit a dictionary for property_dictionnary parameter. |
def Database.DatabaseObject.DatabaseObject.setPropertyTitle | ( | self, | ||
name, | ||||
value | ||||
) |
Set the title of a given Property
name | name of the property which you ask to change the title | |
value | new title of the given property |
KeyError | if the property does not exist on current object. | |
TypeError | if you do not submit string for name parameter. | |
TypeError | if you do not submit string for value parameter. |
def Database.DatabaseObject.DatabaseObject.setPropertyDescription | ( | self, | ||
name, | ||||
value | ||||
) |
Set the description of a given Property
name | name of the property which you ask to change the description | |
value | new description of the given property |
KeyError | if the property does not exist on current object. | |
TypeError | if you do not submit string for name parameter. | |
TypeError | if you do not submit string for value parameter. |
def Database.DatabaseObject.DatabaseObject.getPropertyDescription | ( | self, | ||
name, | ||||
property_dictionnary = None , |
||||
default = None | ||||
) |
Return the property Descrition "Size of product"...
You can submit a specific dictionary you want to ask it instead of object property dictionnary.
name | property name. | |
property_dictionnary | optional property dictionnary if you wand to work on it instead of current object property dictionnary. | |
default | default value you want to be return if no description was defined on given property. |
KeyError | if the property does not exist on current object. | |
TypeError | if you do not submit string for name parameter. | |
TypeError | if you do not submit a dictionary for property_dictionnary parameter. |
def Database.DatabaseObject.DatabaseObject.getPropertyType | ( | self, | ||
name, | ||||
property_dictionnary = None , |
||||
default = None | ||||
) |
Return the property Type
You can submit a specific dictionary you want to ask it instead of object property dictionnary.
name | property name. | |
property_dictionnary | optional property dictionnary if you wand to work on it instead of current object property dictionnary. | |
default | default value you want to be return if no type was defined on given property. |
KeyError | if the property does not exist on current object. | |
TypeError | if you do not submit string for name parameter. | |
TypeError | if you do not submit a dictionary for property_dictionnary parameter. |
def Database.DatabaseObject.DatabaseObject.controlDictionnaryIntegrity | ( | self, | ||
property_dictionnary = None | ||||
) |
Make a control on property_dictionnary
Control each element in property dictionnary. You can control a dictionnary by passing it on parameter If an incoherence is found, TypeError exception will be raised.
A Property Dictionnary should be formed like this :
property_dictionnary = { "property_name" : { "title" : "Property Name", "type" : "string", "description" : "This is a sample string property"}, "another_property : { "title" : "Another Property", "type" : "int", "description" : "This is a sample integer property"}, }
property_dictionnary | optional, only if you want to controle another dictionnary |
TypeError | if an error is detected on Dictionnary |
def Database.DatabaseObject.DatabaseObject.setTypeName | ( | self, | ||
type_name | ||||
) |
set the type name of the object
Each object stored in database could be retrieve only with its type name and id.
type_name | type name of the current object (like "Person") |
TypeError | type_name is not a string |
def Database.DatabaseObject.DatabaseObject.getTypeName | ( | self | ) |
get the type name of the object
Each object stored in database could be retrieve only with its type name and id.
def Database.DatabaseObject.DatabaseObject.setObjectId | ( | self, | ||
ID | ||||
) |
Set the Id of current object
By default, new object has an ID = None.
WARNING : If you set manually the id of object database engine will try to replace object, not to store a new object.
ID | Object ID. |
TypeError | if you not submit an unsigned int or long value for ID parameter |
def Database.DatabaseObject.DatabaseObject.getObjectId | ( | self | ) |
Return current object ID
def Database.DatabaseObject.DatabaseObject.getPropertyDictionnary | ( | self | ) |
Return property dictionary of the current object
def Database.DatabaseObject.DatabaseObject.setPropertyDictionnary | ( | self, | ||
property_dictionnary | ||||
) |
set property dictionary of the current object
property_dictionnary | New property dictionnary you wish to use on current object |
TypeError | if the new Property could not be set because it was not correctly formated |
def Database.DatabaseObject.DatabaseObject.setPropertyValue | ( | self, | ||
name, | ||||
value | ||||
) |
Set value of property on the object
The value was cast to be an instance of the first item on correspondence list. The property should be an instance of the allowed type on correspondance list.
ex. : setProperty(name="first_name", value="Michel")
name | property name (key in property dictionary) | |
value | new value of the given property |
True if the property was set
TypeError | You give a unallowed value for the given property |
def Database.DatabaseObject.DatabaseObject.getPropertyValue | ( | self, | ||
name, | ||||
default = None | ||||
) |
return the property value stored for item 'name'.
name | name of the property | |
default | optional parameter returned if no value was not set on it |
KeyError | if the property 'name' does not exist. |
def Database.DatabaseObject.DatabaseObject.__str__ | ( | self | ) |
Return a string for the current object
Reimplemented in SalePart.SaleOrder.SaleOrder, SalePart.SalePart.SalePart, and SalePart.SalePart.SalePartLine.
dictionary Database.DatabaseObject.DatabaseObject.relation = {} [static] |
relation Dictionnary who store allowed relation
It have the form :
{ "relation_name" : ("allowed_type_name","allowed_type_name),...}
For example you can define a allowed relation subordination with person and organisation object by adding this a tuple :
self.relation["subordination"]=("organisation,"person")
dictionary Database.DatabaseObject.DatabaseObject.relation_table = {} [static] |
Dictonnary who store the relation with other object.
This complex dictionnary store each relation with other object with their id and type name. It should have the form :
{ "relation_name" : { "type_name":(id,id),"type_name":(id,)}, relation: {...}}
for example, if current object is related with subordination relation with organisation (id=2) and two persons (id 1,2) you should fine :
{...,"subordination":{"organisation":(2,),"person":(1,2)},...}
tuple Database.DatabaseObject.DatabaseObject.database_engine = property(getDatabaseEngine,setDatabaseEngine) [static] |
tuple Database.DatabaseObject.DatabaseObject.type_name = property(getTypeName, setTypeName) [static] |
tuple Database.DatabaseObject.DatabaseObject.object_id = property(getObjectId, setObjectId) [static] |
tuple Database.DatabaseObject.DatabaseObject.property_dictionnary = property(getPropertyDictionnary, setPropertyDictionnary) [static] |
Dictionnary who store all Property
Here are store each property. Each property was defined with an property_name , title, description and type. It should be defined like this :
property_dictionnary = { "property_name" : { "title" : "Property Name", "type" : "string", "description" : "This is a sample string property"}, "another_property : { "title" : "Another Property", "type" : "int", "description" : "This is a sample integer property"}, }
To know if object is already in use
Indicate if the current object is locked or not Usefull if you want to know if the object is already open by another user. Default is False, nobody is using it