SourceForge.net Logo

Open-Commerce Logo

Database.DatabaseObject.DatabaseObject Class Reference

Inheritance diagram for Database.DatabaseObject.DatabaseObject:

SalePart.SalePart.SalePart SalePart.SalePart.SalePartLine SalePart.SaleOrder.SaleOrder

List of all members.

Public Member Functions

def __init__
def __getattribute__
def getParent
def setLocked
def setUnlocked
def isLocked
def addContent
def newRelation
def emptyRelation
def getRelationAllowedTypeName
def setRelationAllowedTypeName
def setRelation
def setRelationList
def getAllowedTypeNameForRelation
def getRelatedRelationObject
def getRelatedRelationObjectList
def getRelationObject
def getRelatedRelation
def getRelatedRelationList
def getRelation
def getRelationObjectList
def getRelationList
def setDatabaseEngine
def getDatabaseEngine
def storeObject
def removeProperty
def getPropertyList
def getRelationNameList
def replaceProperty
def addProperty
def newProperty
def getPropertyTitle
def setPropertyTitle
def setPropertyDescription
def getPropertyDescription
def getPropertyType
def controlDictionnaryIntegrity
def setTypeName
def getTypeName
def setObjectId
def getObjectId
def getPropertyDictionnary
def setPropertyDictionnary
def setPropertyValue
def getPropertyValue
def __str__

Public Attributes

 method_dict
 relation_method_dict
 relation
 relation_table
 locked

Static Public Attributes

dictionary relation = {}
dictionary relation_table = {}
tuple database_engine = property(getDatabaseEngine,setDatabaseEngine)
tuple type_name = property(getTypeName, setTypeName)
tuple object_id = property(getObjectId, setObjectId)
tuple property_dictionnary = property(getPropertyDictionnary, setPropertyDictionnary)


Detailed Description

DatabaseObject is the base of each Object intended to be store in Database

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)

Version:
0.02
Author:
Brice LEROY

Member Function Documentation

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

Parameters:
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
See also:
DatabaseObject.controlDictionnaryIntegrity

property_dictionnary

Exceptions:
TypeError property_dictionnary is not a dictionnary (hugh!)
Since:
0.01

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 :

Parameters:
name the called method/attribute
Exceptions:
AttributeError Method not found
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getParent (   self  ) 

Return parent object of current object

This method return object who's contain current object

Returns:
Parent object dict or None if doesn't exist
Since:
0.02

def Database.DatabaseObject.DatabaseObject.setLocked (   self  ) 

Lock current object

This method is use by database when you get object. It's not recommended to use manually, let database managed it

Returns:
boolean
See also:
isLocked
Since:
0.01

def Database.DatabaseObject.DatabaseObject.setUnlocked (   self  ) 

Unlock the current object

This method is used to unlock the object

Returns:
boolean
See also:
isLocked
Since:
0.01

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

Returns:
boolean
Since:
0.01

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.

Parameters:
database_object could be list, database_object or dict of object.
Returns:
nothing
Exceptions:
AddContentError Adding object to itself
Since:
0.02

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).

Parameters:
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")
Exceptions:
TypeError relation_name is not a string
TypeError relation_type_name is not a string or a tuple of string
Since:
0.01

def Database.DatabaseObject.DatabaseObject.emptyRelation (   self,
  name 
)

Clearing a relation set it to an empty dictionnary

Parameters:
name string name of the relation you want to clear
Exceptions:
KeyError Relation not found
TypeError name parameters is not a string
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelationAllowedTypeName (   self,
  relation_name 
)

Return list of allowed type for a given relation

Parameters:
relation_name Name of the relation for which you which to obtain allowed type name
Returns:
a list of allowed type like ("person","organisation")
Exceptions:
KeyError Given relation does not exist on current object
TypeError relation_name parameters is not a string
Since:
0.01

def Database.DatabaseObject.DatabaseObject.setRelationAllowedTypeName (   self,
  relation_name,
  allowed_type_name 
)

set list of allowed type for a given relation

Parameters:
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
Exceptions:
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
Since:
0.01

def Database.DatabaseObject.DatabaseObject.setRelation (   self,
  relation_name,
  database_object 
)

Setting a relation with another database_object

Parameters:
relation_name Name of the relation
database_object It could be a single/tuple of DatabaseObject or a dict like :
  • setRelation("my_relation",{'type_name':(1,2,3),'another type_name':2})
  • setRelation("my_relation",database_object)
  • setRelation("my_relation",(database_object,database_object))
Exceptions:
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
Since:
0.01

def Database.DatabaseObject.DatabaseObject.setRelationList (   self,
  relation_name,
  database_object 
)

set a relation with a list of object

Parameters:
relation_name name of the relation
database_object list of DatabaseObject or dictionnary of Database object reference
See also:
setRelation for list of possible exception
Since:
0.01

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.

Parameters:
relation_name name of the relation for wich you looking for allowed type name.
Returns:
list of allowed type name.
Exceptions:
KeyError current object does not have this relation.
TypeError you does not submit a string for relation_name parameter
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelatedRelationObject (   self,
  relation_name 
)

Return first related object found for given relation.

Parameters:
relation_name name of the relation for which you looking for related relation.
Returns:
the first DatabaseObject found for this related relation.

None if no related object is found.

See also:
getDictRangeSelection

Database.Database.getRelatedRelationForObject

Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelatedRelationObjectList (   self,
  relation_name,
  start = None,
  stop = None 
)

Return list of related object found for given relation.

Parameters:
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
Returns:
list of DatabaseObject found for this related relation.

None if no related object is found.

See also:
getDictRangeSelection

Database.Database.getRelatedRelationForObject

Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelationObject (   self,
  relation_name 
)

Return first found object for given relation

Parameters:
relation_name name of the relation
Returns:
DatabaseObject if at least on exist

None if no object was found

See also:
Database.Database.getObject
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelatedRelation (   self,
  relation_name 
)

Return first found related object for given relation

Parameters:
relation_name name of the relation
Returns:
dictionary like {"person":1}

None if no object was found

See also:
getDictRangeSelection

getRelatedRelationList

Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelatedRelationList (   self,
  relation_name 
)

Return list of related object for a given Relation

Parameters:
relation_name name of the relation
Returns:
dictionary of DatabaseObject references like {"person":(1,2),"organisation":(2,)}

None if nothing was found

See also:
Database.Database.getRelatedRelationForObject
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelation (   self,
  relation_name 
)

Return first found object id and type_name for a specified relation

Parameters:
relation_name name of the relation
Returns:
Dictionary like { "type_name" : 1 }

None if it does not exist object related to

Exceptions:
KeyError relation does not exist on currenct object
TypeError relation_name parameter is not a string
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelationObjectList (   self,
  relation_name,
  start = None,
  stop = None 
)

Return list of DatabaseObject for a given relation

Parameters:
relation_name name of the relation
start begining position on the list
stop ending position on the list
Returns:
List of DatabaseObject

None if nothing was found

See also:
getDictRangeSelection

Database.Database.getObjectList

Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelationList (   self,
  relation_name,
  start = None,
  stop = None 
)

Return a dictionnary of DatabaseObject reference for a given relation

Parameters:
relation_name name of the relation
start begining position on the list
stop ending position on the list
Returns:
dictionary of DatabaseObject references like {"person":(1,2),"organisation":(2,)}
Exceptions:
KeyError current object does not have this relation
TypeError relation_name parameter is not an string
See also:
getDictRangeSelection
Since:
0.01

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

Parameters:
database_engine Database that you which to use
Returns:
True if the database_engine is set

False if the database_engine is not accepted

See also:
storeObject

Database.Database.getRelatedList

getRelationObjectList

Since:
0.01

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

Returns:
Database instance used on this object
Since:
0.01

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.

Returns:
True if database_engine is able to store object

False if database_engine is not set

Since:
0.01

def Database.DatabaseObject.DatabaseObject.removeProperty (   self,
  name 
)

Remove a given property from the property dictionary

Parameters:
name name of the property you want to remove
Returns:
True if the property was removed

False if the property was not found on object

Exceptions:
TypeError the given name is not a string
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getPropertyList (   self  ) 

return the name list of property in dictionary

Returns:
tuple of property name on current object
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getRelationNameList (   self  ) 

return list of existing relation on object

Parameters:
list of relation existing on object
Since:
0.01

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

Parameters:
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
Exceptions:
TypeError You does not submit an allowed type
TypeError name parameter was not a string
Since:
0.01

def Database.DatabaseObject.DatabaseObject.addProperty (   self,
  name,
  property_type,
  title = None,
  description = None 
)

Adding a new Property

See also:
newProperty
Since:
0.01

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

Parameters:
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
Exceptions:
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
See also:
replaceProperty
Since:
0.01

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.

Parameters:
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.
Exceptions:
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.
Returns:
The title string of the property or default if not found
Since:
0.01

def Database.DatabaseObject.DatabaseObject.setPropertyTitle (   self,
  name,
  value 
)

Set the title of a given Property

Parameters:
name name of the property which you ask to change the title
value new title of the given property
Exceptions:
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.
Since:
0.01

def Database.DatabaseObject.DatabaseObject.setPropertyDescription (   self,
  name,
  value 
)

Set the description of a given Property

Parameters:
name name of the property which you ask to change the description
value new description of the given property
Exceptions:
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.
Since:
0.01

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.

Parameters:
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.
Exceptions:
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.
Returns:
The description string of the property or default if not found
Since:
0.01

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.

Parameters:
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.
Exceptions:
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.
Returns:
The type string of the property or default if not found
Since:
0.01

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"}, }

Parameters:
property_dictionnary optional, only if you want to controle another dictionnary
Exceptions:
TypeError if an error is detected on Dictionnary
Since:
0.01

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.

Parameters:
type_name type name of the current object (like "Person")
Exceptions:
TypeError type_name is not a string
Since:
0.01

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.

Returns:
type name (string) of the current object
Since:
0.01

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.

Parameters:
ID Object ID.
Exceptions:
TypeError if you not submit an unsigned int or long value for ID parameter
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getObjectId (   self  ) 

Return current object ID

Returns:
Object ID
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getPropertyDictionnary (   self  ) 

Return property dictionary of the current object

Returns:
property dictionary
Since:
0.01

def Database.DatabaseObject.DatabaseObject.setPropertyDictionnary (   self,
  property_dictionnary 
)

set property dictionary of the current object

Parameters:
property_dictionnary New property dictionnary you wish to use on current object
Returns:
Nothing
Exceptions:
TypeError if the new Property could not be set because it was not correctly formated
See also:
controlDictionnaryIntegrity
Since:
0.01

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")

Parameters:
name property name (key in property dictionary)
value new value of the given property
Returns:
False if property was not found on current object

True if the property was set

Exceptions:
TypeError You give a unallowed value for the given property
See also:
Database.Database.database_available_type_list_correspondence
Since:
0.01

def Database.DatabaseObject.DatabaseObject.getPropertyValue (   self,
  name,
  default = None 
)

return the property value stored for item 'name'.

Parameters:
name name of the property
default optional parameter returned if no value was not set on it
Exceptions:
KeyError if the property 'name' does not exist.
Since:
0.01

def Database.DatabaseObject.DatabaseObject.__str__ (   self  ) 

Return a string for the current object

Returns:
string
Since:
0.01

Reimplemented in SalePart.SaleOrder.SaleOrder, SalePart.SalePart.SalePart, and SalePart.SalePart.SalePartLine.


Member Data Documentation

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"}, }

See also:
controlDictionnaryIntegrity
Since:
0.01

Database.DatabaseObject.DatabaseObject.method_dict

Database.DatabaseObject.DatabaseObject.relation_method_dict

Database.DatabaseObject.DatabaseObject.relation

Database.DatabaseObject.DatabaseObject.relation_table

Database.DatabaseObject.DatabaseObject.locked

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


The documentation for this class was generated from the following file:
Generated on Sat Feb 16 09:03:02 2008 for OpenCommerce by  doxygen 1.5.3