common.database package

Submodules

common.database.ClassCache module

Definition for a class cache and the class cache itself

class common.database.ClassCache.ClassCache

Bases: dict

Dictionary that maps a Python class to any value based on its __name__

has_key(item)

common.database.Context module

The Astro-WISE Context

The Context contains all properties that can be used to filter large amounts of data in the Astro-WISE database.

common.database.ContextFilebased module

class common.database.ContextFilebased.Context

Bases: object

set_project(project_name)

common.database.ContextMySQL module

The Astro-WISE Context

The Context contains all properties that can be used to filter large amounts of data in the Astro-WISE database. It also handles the methods to set_project() (change project in session_current table), set_privileges() (change privileges in session_current so users VIEW different data). It also handles the ‘delete’ method, which calls a stored procedure that really just negates the privilegs column in a data table.

class common.database.ContextMySQL.Context

Bases: object

The singleton Context definition.

delete(obj, verbose=True, commit=False, delete_config=False)

python interface for deleting an object in the DB, switches : verbose - be verbose commit - database commit delete_config - delete also config dependencies

makes sure object is valid before calling _delete, checks for no dependencies.

get_chips()

Oracle code (7Oct2011), not currently being used by MySQL Return names of all Chips of the current project

get_chips_for_instrument(instrument)

Oracle code (7Oct2011), not currently being used by MySQL Return names of all Chips for the given instrument name

get_current_privileges()

Return the active privileges

get_current_project()

Return the project that is currently active

get_filters()

Return names and mag_ids for all Filters of the current project

get_filters_for_instrument(instrument)

Oracle code (7Oct2011), not currently being used by MySQL Return names and mag_ids of all Filters for the igven instrument name

get_instruments()

Oracle code (7Oct2011), not currently being used by MySQL Return names of all instruments of the current project

get_projects(all=False)

Oracle code (7Oct2011), not currently being used by MySQL Return all projects and their definitions that are available to the current user

get_users_for_project(projectname)

Oracle code (7Oct2011), not currently being used by MySQL Return username, userid and usertype for all users that belong to a project.

migrate(obj, targetprojectname, verbose=False)

Oracle code (7Oct2011), not currently being used by MySQL

publish(obj, privileges=0, commit=False, verbose=True)

Publish the object; update the privileges of the object to the given privileges (when set) or raise the privileges with one (when not set) Publishing is done recursively

set(**kwargs)
set_privileges(privileges)

Set the privileges, every created object will have this privileges

set_project(name, privileges=1)

set the project given by name, and optional the privileges

unset(*args)
unset_project()

Oracle (7Oct2011) code, not currently being called by MySQL

update_attribute(obj, attr_name, new_value)

call PL/SQL code for updating the attribue of the object

update_is_valid(obj, new_is_valid)

update the is_valid flag of the given object to the new value

update_privileges(obj, new_privileges)

update the privileges of the given object to the new value

update_quality_flags(obj, new_quality_flags)

bitwise OR the quality_flags of the given object with the given value bits which are already set will be ignored, bits cannot be unset

update_timestamp_end(obj, new_timestamp_end)

update the timestamp_end of the given object to the new value

update_timestamp_start(obj, new_timestamp_start)

update the timestamp_start of the given object to the new value

common.database.ContextMySQL.get_indent(level)

return indentation to plot for given (recursion) level

common.database.ContextMySQL.migrate_recursively(cursor, obj, targetprojectname, verbose=False)

Oracle code, that currently(7Oct2011), is not being used by MySQL

common.database.ContextMySQL.project__str__(self, *args, **kwargs)

common.database.ContextOracle module

The Astro-WISE Context

The Context contains all properties that can be used to filter large amounts of data in the Astro-WISE database.

class common.database.ContextOracle.Context

Bases: object

The singleton Context definition.

SSO_Request(valid_untill, application, origin)

Request a Single Sign On (SSO) ticket or token from the database

delete(objects, verbose=True, delete_config=False, commit=False)

python interface for deleting a single or multiple objects from the DB, the arguments :

objects - single object, or list of objects to delete verbose - be verbose commit - database commit delete_config - delete also config dependencies
get_chips()

Return names of all Chips of the current project

get_chips_for_instrument(instrument)

Return names of all Chips for the given instrument name

get_current_privileges()

Return the active privileges

get_current_project()

Return the project that is currently active

get_database_awsecurity_version()

return the version of the awsecurity package in the database

get_filters()

Return names and mag_ids for all Filters of the current project

get_filters_for_instrument(instrument)

Return names and mag_ids of all Filters for the igven instrument name

get_instruments()

Return names of all instruments of the current project

get_object_default_attrs(tablename, object_id)

Return the default attributes of the object; project, creator, privilegs. Even if the object has been deleted.

get_project_name(projectid)

Return the name of the project with project id

get_projects(all=False)

Return all projects and their definitions that are available to the current user

get_users_for_project(projectname)

Return username, userid and usertype for all users that belong to a project.

migrate(obj, targetprojectname, verbose=False)
publish(obj, privileges=0, commit=False, verbose=False)

Publish the object; update the privileges of the object to the given privileges (when set) or raise the privileges with one (when not set) Publishing is done recursively

set(**kwargs)
set_privileges(privileges)

Set the privileges, every created object will have this privileges

set_project(name, privileges=0)

set the project given by name, and optional the privileges

unset(*args)
unset_project()
update_attribute(obj, attr_name, new_value)

call PL/SQL code for updating the attribue of the object

update_desc_attribute(obj, attr_name, new_value)

call the PL/SQL procedure for updating the attribue of the object

update_is_valid(obj, new_is_valid)

update the is_valid flag of the given object to the new value

call PL/SQL code for updating the link attribue of the object

update_privileges(obj, new_privileges)

update the privileges of the given object to the new value

update_quality_flags(obj, new_quality_flags)

bitwise OR the quality_flags of the given object with the given value bits which are already set will be ignored, bits cannot be unset

update_timestamp_end(obj, new_timestamp_end)

update the timestamp_end of the given object to the new value

update_timestamp_start(obj, new_timestamp_start)

update the timestamp_start of the given object to the new value

exception common.database.ContextOracle.ContextError

Bases: Exception

Raised for Context errors

common.database.ContextOracle.get_indent(level)

return indentation to plot for given (recursion) level

common.database.ContextOracle.migrate_recursively(cursor, obj, targetprojectname, verbose=False)
common.database.ContextOracle.project__str__(self, *args, **kwargs)

common.database.ContextPostgreSQL module

common.database.DBFilebased module

Module DBFilebased.

class common.database.DBFilebased.DBFilebasedProxy

Bases: common.database.DBProxy.DBProxy

commit(other)

Commit a persistent object and all the objects that it references.

commit() stores persistent Python objects in the database that:

  1. For which the commit() method is called.
  2. That is referenced by an object for which commit() is called and for which the state has changed.
  3. That is referenced by an object as defined in 2) and for which the state has changed.

A commit() also defines transaction boundaries in that it succeeds only if all the referenced objects that take part in the commit() are stored successfully. If any of the referenced objects cannot be stored, then none of the objects are stored.

gc_transient(other)

Called by the DBObject destructor __del__()

get_instance(cls, *args, **kwargs)

Instantiate an object

Arguments:
tp – the class of the object to be instantiated *args – the constructor argments **kwargs – the constructor keyword arguments

This method should return a reference to a a new or existing instance. This method should ensure that the instance has a _desc attribute, which should be a dictionary. The object should also have an attribute _dirty, which is initially 0

persists(other)

Returns whether an object is persistent or not.

register_class(cls)

Register a new class with the database

Arguments:
cls – the class to be registered with the database

This method is called when a Persistent class is defined. It can be used to compare the newly created class definition with the existing definition in the database. The return value of this method is not checked. Use exceptions when class registration is unsucessfull.

class common.database.DBFilebased.filebasedoidtype(raw)

Bases: common.database.DBMeta.oidtype

binary()

common.database.DBFilebasedSelect module

The beginnings of an implementation for Logical Expression objects

These objects should be used by the database to build queries

class common.database.DBFilebasedSelect.ItemRef(prop, index)

Bases: object

class common.database.DBFilebasedSelect.LinkRef(prop, attr)

Bases: object

class common.database.DBFilebasedSelect.Select(lhs, operator, rhs)

Bases: object

next()

Python 2 compatibility

class common.database.DBFilebasedSelect.SelectAND(lhs, operator, rhs)

Bases: common.database.DBFilebasedSelect.Select

class common.database.DBFilebasedSelect.SelectOR(lhs, operator, rhs)

Bases: common.database.DBFilebasedSelect.Select

common.database.DBFilebasedSelect.instantiate_object(typeid, oid)

common.database.DBMain module

DBMain

This module provides the common interface to the persistence facilties implemented through DBMeta and DBProxy. This module provides:

persistent
A factory function (defined in DBMeta) used to qualify persistent attributes in persistent objects
DBObject
A root object for a hierarchy of persistent objects
class common.database.DBMain.DBObject

Bases: object

The root object of a persistent class hierarchy

DBObject is the root object of the persistant class hierarchy used by the pipeline. New persistent classes should be derived from DBObject or a decendant of DBObject.

A persistent class encapsulates a number of persistent attributes. To mark an attribute “attr” as persistent, the class definition should include something like:

class Myclass(DBObject):
attr = persistent(“A docstring for the attribute”,
attribute_type, attribute_default)

See persistent to see how various types of persistent attributes should be defined.

XXX Futher explanation of using persistent objects.

as_dict(seqnr=1, dependency_name='', dictionary=None, allow_lazy_typed_list=False)

Method much like the info method, but returns a dictionary.

Dictionary looks like:
{‘<classname>.<property1_name>.<property2_name>’: value,
‘<classname>.<property2_name>.<property3_name>’: value}

Problem: infinite loops for cold/flat dependencies. It seems a maximum recursion depth limits the problem.

commit()

Commits object including objects that are referenced and have been changed.

If this object refers to other persistent object a commit() ensures that

  1. ALL changes to the object and referred objects are made persistent.

2. NONE of the changed object and referred objects are made persistent. Under normal circumstances only the first thing should ever happen. If the second case occurs it is almost certainly because of some bug in the routine that implements the DBProxy interface.

copy_persistent_properties(other)

Copy the persistent properties of this DBObject to another one.

dbproxy = <common.database.DBOracle.DBOracleProxy object>
get_creator()

Returns the name of the user who created this object.

classmethod get_inverse_properties(props=None)

return all inverse properties that are all the properties that point to this class

get_persistent()
get_project()

Returns the name of the project to which this object belongs.

info(level=0, doc=False, hidden=False, _indent=0, _printclass=True)

Print the values of all persistent properties of the object.

level : level of introspection doc : display docstrings for attributes hidden : print hidden attributes _indent : internal parameter used for formatting _printclass : internal parameter used for formatting

inverse_objects(max_results=1000)

Iterate through and return all objects that use the current object max_results The maximum number of objects returned per query

inverse_query()

go through all inverse properties to see if this object is used

object_id

The object identifier

The object identifier is an attribute shared by all persistent instances. It is the prime key, by which object identity is established

persists()

Returns whether an object is already made persistent or transient.

pickle_id = None
recommit()

Commits changes to an object, without following links.

classmethod select_all()

method returns Select object without query arguments

common.database.DBMain.unpickle(cls, pickle_id, object_id, state, transients)

The unpickler function for DBObject objects

This function is used to make sure that upon unpickling goes through the normal calling mechanism. This ensures that only one object or each object_id exists.

Pickling saves obj._desc and unpickling overwrites obj._desc

common.database.DBMainMySQL module

common.database.DBMeta module

DBMeta.py

Implements: DBObjectMeta – The metaclass for persistent objects. persistent – A factory object for persistent attributes. inline – A factory object for persistent attributes which should be inlined.

class common.database.DBMeta.DBMixin

Bases: object

A baseclass for mixin classes containing persistent properties

The persistent object hierarchy does not support multiple inheritance of persistent classes. (The reason is that not all backend support multiple inheritance natively). You can derive a persistent class from more than one base class, but only the first baseclass can be itself a persistent class.

In order to be able to define multiple base classes containing persistent properties, it is possible to define persistent properties in classes deriving from DBMixin. For example:

class Base(DBObject):
base_prop = persistent(…)
class Mixin(DBMixin):
mixin_prop = persistent(…)
class Derived(Base, Mixin):

defines a class Derived with two persistent properties, Derived behaves as if multiple inheritance applies. However, note that Mixin itself is not a persistent class, specifically:

m = Mixin()

does not result in a persistent object, and selections like

Mixin.mixin_prop == 1

will result in an attribute error. Note, however, that

Derived.mixin_prop == 1

is a valid selection.

classmethod get_persistent_attributes()

return a list of persistent attributes

class common.database.DBMeta.DBObjectMeta

Bases: type

This is the metaclass for persistent classes

Provides:
__new__ – manages class construction __call__ – manages object instantiation
get_persistent_bases()

Return a tuple of persistent bases

get_persistent_desc_lists()
get_persistent_descs()
get_persistent_properties()

Return a list of persistent attribute names

is_root()

Tells whether this class is the root of a persistent hierarchy

register()

Register a class with its database

Called automatically by __new__ to register the newly created class with its database.

class common.database.DBMeta.inline(*args)

Bases: common.database.DBMeta.persistent

Factory for inline attributes.

An `inline’ attribute behaves like a `persistent’ attribute. It is intended to give the database engine a hint that a complex attribute (i.e. a persistent class) can be stored together with the other persistent attributes of that class. The default behaviour for a complex persistent attribute is to store the value of the attribute separately and refer to it from the containing object.

It is up to the database implementation to honour this optimisation hint or not.

class common.database.DBMeta.oidmetatype

Bases: type

Metatype for object identifier type.

class common.database.DBMeta.oidtype

Bases: object

Object Identifier Type

The “object_id” attribute of persistent objects is of this type. It is the responsibility of the DBProxy interface implementor to inherit from this type. The inheriting type should at least define a constructor and for “object_id”s that are raw values or structures in the DBProxy interface implementation it is recommended to define __str__() for debugging purposes.

class common.database.DBMeta.persistent(*args)

Bases: object

Factory for persistent attributes.

A perstistent class normally encapsulates a number of persistent attributes. To mark an attribute ‘attr’ as persistent, the class definition should include something like:

class Object(object):

__metaclass__ DBObjectMeta attr = persistent(‘A docstring for the attribute [None]’,

attribute_type, attribute_default)

Note the units definition in the docstring: [None]. This should be set to None if the attribute_type is an object as the proper units should be defined in the persistent properties of that object. It should also be None if there are no intrinsic units, and to the appropriate units otherwise. Please follow examples throughout the code for uniform syntax.

If attribute_type is a subclass of Object, then the attribute will be a link, else the attribute will be a descriptor. If the attribute_default is a list, then the attribute will be an array of objects of that type. If persistent has only a string argument, then the attribute is assumed to be a link to an object of the same type as the class it is defined in. Hence:

class ClassA(Object):
a = persistent(‘’, int, 0) b = persistent(‘’, float, []) c = persistent(‘’, str, [‘A’, ‘B’, ‘C’])
class ClassB(Object):
e = persistent(‘’, ClassA, (ClassA, (), {}) f = persistent(‘’, ClassA, []) g = persistent(‘’)

defines two persistent classes. ClassA defines three persistent attributes: ‘a’ is an int, ‘b’ is an array of floats, with an empty default, ‘c’ is an array of strings with a three element default. ClassB defines three links: ‘e’ is a link to an instance of ClassA, ‘f’ is a array of links to instances of A (default empty), snd ‘g’ is a link to another instance of ClassB

ClassB illustrates a special property of links. They can be represented by tuples (type, tuple, dict), which, when accessed, will result in a new instance type(*tuple, **dict). Instantiatiaton is lazy. Hence.

inst = ClassB() print inst.e

will only result in instantiation of a new ClassA() when attribute ‘e’ is accessed.

Note that persistent properties are inherited. So

class ClassC(ClassA):
h = persistent(‘’, ClassB, None)

defines a new persistent object, with four perssitent attributes (‘a’, ‘b’, ‘c’, ‘h’).

To implement versioning of object the following mechanism is used

A class that defines a method ‘update’ that accepts an argument, may be used as follows:

class A(DBObject):

prev = persistent(‘Previous version’) # link to own type def update(self, previous):

self.prev = previous

‘update’ will be called when an instance of a referring class updates a ref to an instance of A. i.e:

class B(DBObject):
ref = persistent(‘’,.A, None)

b = B() a1 = A() a2 = A()

b.ref = a1 b.ref = a2 # calls a2.update(a1)

will lead to:

b.ref.prev is a1

Implementation note:

The persistent class itself is just a container used to mark an attribute as persistent. persistent’s constructor arguments are passed by DBObjectMeta.__new__ to DBProperties.property_factory, to build a persistent_property object

common.database.DBMetaMySQL module

DBMeta.py

Implements: DBObjectMeta – The metaclass for persistent objects. persistent – A factory object for persistent attributes. inline – A factory object for persistent attributes which should be inlined.

For MySQL oidtype(long) now inherits a long type, as MySQL OBJECT_IDs are Python long types. There is very little difference between the MySQL and Oracle implementation here, except the imports, and class definitions ():

prop = DBPropertiesMySQL.inline_list_property(key, prop_type, prop_default, doc)
class common.database.DBMetaMySQL.DBMixin

Bases: object

A baseclass for mixin classes containing persistent properties

The persistent object hierarchy does not support multiple inheritance of persistent classes. (The reason is that not all backend support multiple inheritance natively). You can derive a persistent class from more than one base class, but only the first baseclass can be itself a persistent class.

In order to be able to define multiple base classes containing persistent properties, it is possible to define persistent properties in classes deriving from DBMixin. For example:

class Base(DBObject):
base_prop = persistent(…)
class Mixin(DBMixin):
mixin_prop = persistent(…)
class Derived(Base, Mixin):

defines a class Derived with two persistent properties, Derived behaves as if multiple inheritance applies. However, note that Mixin itself is not a persistent class, specifically:

m = Mixin()

does not result in a persistent object, and selections like

Mixin.mixin_prop == 1

will result in an attribute error. Note, however, that

Derived.mixin_prop == 1

is a valid selection.

classmethod get_persistent_attributes()

return a list of persistent attributes

class common.database.DBMetaMySQL.DBObjectMeta

Bases: type

This is the metaclass for persistent classes

Provides:
__new__ – manages class construction __call__ – manages object instantiation
get_persistent_bases()

Return a tuple of persistent bases

get_persistent_desc_lists()
get_persistent_descs()
get_persistent_properties()

Return a list of persistent attribute names

is_root()

Tells whether this class is the root of a persistent hierarchy

register()

Register a class with its database

Called automatically by __new__ to register the newly created class with its database.

class common.database.DBMetaMySQL.inline(*args)

Bases: common.database.DBMetaMySQL.persistent

Factory for inline attributes.

An `inline’ attribute behaves like a `persistent’ attribute. It is intended to give the database engine a hint that a complex attribute (i.e. a persistent class) can be stored together with the other persistent attributes of that class. The default behaviour for a complex persistent attribute is to store the value of the attribute separately and refer to it from the containing object.

It is up to the database implementation to honour this optimisation hint or not.

class common.database.DBMetaMySQL.oidmetatype

Bases: type

Metatype for object identifier type.

class common.database.DBMetaMySQL.oidtype

Bases: common.util.types.long

Object Identifier Type

The “object_id” attribute of persistent objects is of this type. It is the responsibility of the DBProxy interface implementor to inherit from this type. The inheriting type should at least define a constructor and for “object_id”s that are raw values or structures in the DBProxy interface implementation it is recommended to define __str__() for debugging purposes.

class common.database.DBMetaMySQL.persistent(*args)

Bases: object

Factory for persistent attributes.

A perstistent class normally encapsulates a number of persistent attributes. To mark an attribute ‘attr’ as persistent, the class definition should include something like:

class Object(object):

__metaclass__ DBObjectMeta attr = persistent(‘A docstring for the attribute [None]’,

attribute_type, attribute_default)

Note the units definition in the docstring: [None]. This should be set to None if the attribute_type is an object as the proper units should be defined in the persistent properties of that object. It should also be None if there are no intrinsic units, and to the appropriate units otherwise. Please follow examples throughout the code for uniform syntax.

If attribute_type is a subclass of Object, then the attribute will be a link, else the attribute will be a descriptor. If the attribute_default is a list, then the attribute will be an array of objects of that type. If persistent has only a string argument, then the attribute is assumed to be a link to an object of the same type as the class it is defined in. Hence:

class ClassA(Object):
a = persistent(‘’, int, 0) b = persistent(‘’, float, []) c = persistent(‘’, str, [‘A’, ‘B’, ‘C’])
class ClassB(Object):
e = persistent(‘’, ClassA, (ClassA, (), {}) f = persistent(‘’, ClassA, []) g = persistent(‘’)

defines two persistent classes. ClassA defines three persistent attributes: ‘a’ is an int, ‘b’ is an array of floats, with an empty default, ‘c’ is an array of strings with a three element default. ClassB defines three links: ‘e’ is a link to an instance of ClassA, ‘f’ is a array of links to instances of A (default empty), snd ‘g’ is a link to another instance of ClassB

ClassB illustrates a special property of links. They can be represented by tuples (type, tuple, dict), which, when accessed, will result in a new instance type(*tuple, **dict). Instantiatiaton is lazy. Hence.

inst = ClassB() print inst.e

will only result in instantiation of a new ClassA() when attribute ‘e’ is accessed.

Note that persistent properties are inherited. So

class ClassC(ClassA):
h = persistent(‘’, ClassB, None)

defines a new persistent object, with four perssitent attributes (‘a’, ‘b’, ‘c’, ‘h’).

To implement versioning of object the following mechanism is used

A class that defines a method ‘update’ that accepts an argument, may be used as follows:

class A(DBObject):

prev = persistent(‘Previous version’) # link to own type def update(self, previous):

self.prev = previous

‘update’ will be called when an instance of a referring class updates a ref to an instance of A. i.e:

class B(DBObject):
ref = persistent(‘’,.A, None)

b = B() a1 = A() a2 = A()

b.ref = a1 b.ref = a2 # calls a2.update(a1)

will lead to:

b.ref.prev is a1

Implementation note:

The persistent class itself is just a container used to mark an attribute as persistent. persistent’s constructor arguments are passed by DBObjectMeta.__new__ to DBPropertiesMySQL.property_factory, to build a persistent_property object

common.database.DBMySQL module

Module DBMySQL, was Module DBProxy.

DBProxy provides an instance of the database interface needed by the DBMeta.DBObjectMeta. This class with call register_flattable, which creates the DDL for a Table and table links and comments. insert_into_flattable builds a DML statement to insert data into a table via a stored procedure.

class common.database.DBMySQL.DBMySQLProxy

Bases: common.database.DBProxy.DBProxy

commit(other)

Commit a persistent object and all the objects that it references.

commit() stores persistent Python objects in the database that:

  1. For which the commit() method is called.
  2. That is referenced by an object for which commit() is called and for which the state has changed.
  3. That is referenced by an object as defined in 2) and for which the state has changed.

A commit() also defines transaction boundaries in that it succeeds only if all the referenced objects that take part in the commit() are stored successfully. If any of the referenced objects cannot be stored, then none of the objects are stored.

gc_transient(other)

Called by the DBObject destructor __del__()

get_instance(cls, *args, **kwargs)

Instantiate an object

Arguments:
tp – the class of the object to be instantiated *args – the constructor argments **kwargs – the constructor keyword arguments

This method should return a reference to a a new or existing instance. This method should ensure that the instance has a _desc attribute, which should be a dictionary. The object should also have an attribute _dirty, which is initially 0

persists()

Returns whether an object is persistent or not.

register_class(cls)

Register a new class with the database

Arguments:
cls – the class to be registered with the database

This method is called when a Persistent class is defined. It can be used to compare the newly created class definition with the existing definition in the database. The return value of this method is not checked. Use exceptions when class registration is unsucessfull.

common.database.DBMySQL.OBJECTID_UNIQUE_STRING(cls)

not being used in current(7Oct2011) MySQL implementataion

common.database.DBMySQL.check_consistency_with_database(aclass)

Checks if the current Python definition of the class is the same as the definition in the database

common.database.DBMySQL.commitDatabase(other)

commits any updates/inserts that have been called by stored procedures

common.database.DBMySQL.existsTABLE(cls)

returns bolean True if table has been created, or the tablename

common.database.DBMySQL.fetch_inline_from_database(other, object_id)

fetches a row from a database. not sure if this is currently (7Oct2011) being used by MySQL

common.database.DBMySQL.insert_desc_into_database(cursor, object_id, prop, items)

ORACLE method. this method has not been rewritten for MySQL

common.database.DBMySQL.insert_inline_into_database(cursor, object_id, prop, other)

ORACLE method. this method has not been rewritten for MySQL

common.database.DBMySQL.insert_into_flattable(other)

inserts data into the DB using a insert_proc_tablename stored procedure

link table (i.e. Table1$Table2) only has OBJECT_ID,POSITION,COLUMN_VALUE,COLUMN_VALUE$ So insert_proc_table$table(OBJECT_ID,POSITION,COLUMN_VALUE,COLUMN_VALUE$) calls the MySQL insert_proc_tablename procedure to insert data.

common.database.DBMySQL.register_flattable(aclass)

This method is called when a table is created in the database. It creates the DDL for a table (._ddltable()), for any nested/link objects or lists (._ddlnested), and creates the table comments in ._ddlcomment() ._ddlnestedcomment().

common.database.DBMySQL.rowsInTable(tablename)

not being used in current(7Oct2011) MySQL implementataion

common.database.DBMySQLSelect module

The beginnings of an implementation for Logical Expression objects

These objects should be used by the database to build queries

Reformatted for MySQL start 6 June 2011

There are some Oracle specific bits of code remaining.

class common.database.DBMySQLSelect.LinkRef(prop, attr)

Bases: object

like(other)
class common.database.DBMySQLSelect.Select(lhs, operator, rhs)

Bases: object

add_clause(operator, other_clause, other_param)

add the other_clause (and param) to self

current_mydb_only()

Only show mydb data of the current project. So do not show the mydb data of other projects ! But show all other visible data.

get_rows(getJustObjectID=False)

get the rows for this Select object. The lhs,rhs,operatore have been assigned in the Select.__init__. For MySQL the columns names are determined from the information_schema.columns table. returns a list where each element is a dictionary of each row in the table.

get_sql(select=None, rownum=0)

Get the sql from the query, default SELECT arguments are the type and object_id, use select argument to extend the rownum argument adds a where limit on the number of rows returned

max(attribute)

Return the item in a query for which “attribute” is largest.

min(attribute)

Return the item in a query for which “attribute” is smallest.

order_by(attribute)

Order the result of a query by increasing value of “attribute”.

order_by_desc(attribute)

Order the result of a query by increasing value of “attribute”.

privileges_only(privileges=0)

limit the query to the given privileges

project_favourite()

Prefer project owned data over data from other projects.

project_only(project=None)

Filter the objects specific to the given project (name/id) or the current project.

public_data_only(public=True)

Limit the query to public data (when True) or private data when public is False

public_project_only(public=True, ids=[])

Limit the query to public projects (when public is True) or private projects when public is False or to the given project ids

user_only(user=None)

Filter the objects to the given user (name/id) or current user

vo_only(use_world=False)

Filter VO objects

common.database.DBMySQLSelect.escape_orderby_clause(clause)
common.database.DBMySQLSelect.get_row_class(tablename, oid)

‘this is called by instantiate object to get an linked class

common.database.DBMySQLSelect.get_row_list(tablename, oid)

given a tablename and an object_id=oid, get that row from the VIEW. currently only called by instantiate object, when making an attribute linked from that object.

common.database.DBMySQLSelect.getalltables()

returns all tables in database

common.database.DBMySQLSelect.instantiate_object(rows)

given a row returned from a query (called by get_rows()). makes an instance of an object, assigns attributes, sets the database cache of instantiated objects, and makes any linked objects.

common.database.DBMySQLSelect.mangle(anidentifier)

MySQL 5.5 can have long table names. OLD: Oracle identifiers can not be longer than 31 characters

common.database.DBMySQLSelect.sqlname(name)
common.database.DBMySQLSelect.viewname(aclass)

common.database.DBOracle module

Module DBOracle.

DBOracle implements the DBProxy database interface needed by the DBMeta.DBObjectMeta for usage with Oracle 9i.

exception common.database.DBOracle.DBOracleError

Bases: Exception

class common.database.DBOracle.DBOracleProxy

Bases: common.database.DBProxy.DBProxy

commit(other)
fetch_from_database(cls, object_id)
gc_transient(other, *args, **kwargs)
get_instance(cls, *args, **kwargs)

Instantiate an object

Arguments:
tp – the class of the object to be instantiated *args – the constructor argments **kwargs – the constructor keyword arguments

This method should return a reference to a a new or existing instance. This method should ensure that the instance has a _desc attribute which should be a dictionary.

insert_or_update(other)
persists(other)
register_class(aclass)

Register a new class with the database

Arguments:
aclass – the class to be registered with the database

This method is called when a Persistent class is defined. It can be used to compare the newly created class definition with the existing definition in the database. The return value of this method is not checked. Use exceptions when class registration is unsuccessfull.

subtypes = {}
tabnames = {}
update(other)
update_database(other)
common.database.DBOracle.check_consistency_with_database(aclass)

Checks if the current Python definition of the class is the same as the definition in the database

common.database.DBOracle.existsTABLE(tablename)
common.database.DBOracle.fetch_inline_from_database(cls, object_id)
common.database.DBOracle.insert_desc_into_database(cursor, object_id, prop, items)
common.database.DBOracle.insert_inline_into_database(cursor, object_id, prop, other)
common.database.DBOracle.insert_into_flattable(other)
common.database.DBOracle.qstrip(s)
common.database.DBOracle.register_flattable(aclass)

common.database.DBOracleSelect module

The beginnings of an implementation for Logical Expression objects

These objects should be used by the database to build queries

class common.database.DBOracleSelect.LinkRef(prop, attr)

Bases: object

contains(other)
like(other)
class common.database.DBOracleSelect.Select(lhs, operator, rhs)

Bases: object

add_clause(operator, other_clause, other_param)

add the other_clause (and param) to self

copy()

Return coyp of self

current_mydb_only()

Only show mydb data of the current project. So do not show the mydb data of other projects ! But do show all other visible data.

get_input_sizes()
get_rows()

Generate query and return all object_id’s The Environment can contain directives to adjust the query, if so a copy of self is made and used

get_sql(select=None, rownum=0)

Get the sql from the query, default SELECT arguments are the type and object_id, use select argument to extend the rownum argument adds a where limit on the number of rows returned

max(attribute)

Return the item in a query for which “attribute” is largest.

min(attribute)

Return the item in a query for which “attribute” is smallest.

not_all_mydb()

Only show mydb data of the current project. So do not show the mydb data of other projects ! But do show all other visible data.

order_by(attribute)

Order the result of a query by increasing value of “attribute”.

order_by_desc(attribute)

Order the result of a query by decreasing value of “attribute”.

privileges_only(privileges=0)

limit the query to the given privileges

project_favourite()

Prefer project owned data over data from other projects.

project_only(project=None)

Filter the objects specific to the given project (name/id) or the current project.

public_data_only(public=True)

Limit the query to public data (when True) or private data when public is False

public_project_only(public=True, ids=[])

Limit the query to public projects (when public is True) or private projects when public is False or to the given project ids

user_only(user=None)

Filter the objects to the given user (name/id) or current user

vo_only()

Limit query to VO objects, so privileges 5

world_only()

Limit query to world objects, so privileges 4

common.database.DBOracleSelect.escape_orderby_clause(clause)
common.database.DBOracleSelect.instantiate_object(typeid, oid)
common.database.DBOracleSelect.sqlname(name)
common.database.DBOracleSelect.viewname(aclass)

common.database.DBPostgreSQL module

common.database.DBPostgreSQLSelect module

The beginnings of an implementation for Logical Expression objects

These objects should be used by the database to build queries

class common.database.DBPostgreSQLSelect.LinkRef(prop, attr)

Bases: object

like(other)
class common.database.DBPostgreSQLSelect.Select(lhs, operator, rhs)

Bases: object

add_clause(operator, other_clause, other_param)

add the other_clause (and param) to self

copy()

Return coyp of self

current_mydb_only()

Only show mydb data of the current project. So do not show the mydb data of other projects ! But do show all other visible data.

get_input_sizes()
get_rows()

Generate query and return all object_id’s The Environment can contain directives to adjust the query, if so a copy of self is made and used

get_sql(select=None, rownum=0)

Get the sql from the query, default SELECT arguments are the type and object_id, use select argument to extend the rownum argument adds a where limit on the number of rows returned

max(attribute)

Return the item in a query for which “attribute” is largest.

min(attribute)

Return the item in a query for which “attribute” is smallest.

not_all_mydb()

Only show mydb data of the current project. So do not show the mydb data of other projects ! But do show all other visible data.

order_by(attribute)

Order the result of a query by increasing value of “attribute”.

order_by_desc(attribute)

Order the result of a query by decreasing value of “attribute”.

privileges_only(privileges=0)

limit the query to the given privileges

project_favourite()

Prefer project owned data over data from other projects.

project_only(project=None)

Filter the objects specific to the given project (name/id) or the current project.

public_data_only(public=True)

Limit the query to public data (when True) or private data when public is False

public_project_only(public=True, ids=None)

Limit the query to public projects (when public is True) or private projects when public is False or to the given project ids

user_only(user=None)

Filter the objects to the given user (name/id) or current user

vo_only()

Limit query to VO objects, so privileges 5

world_only()

Limit query to world objects, so privileges 4

common.database.DBPostgreSQLSelect.escape_orderby_clause(clause)
common.database.DBPostgreSQLSelect.instantiate_object(typeid, oid)
common.database.DBPostgreSQLSelect.sqlname(name)
common.database.DBPostgreSQLSelect.viewname(aclass)

common.database.DBProperties module

Implementation for persistent properties

This module defines the following classes

persistent_property
+- desc_property +- link_property +- desc_list_property +- link_list_property +- self_link_property +- objectlist_property

This module also defines a number of helper classes to define getter and setters (through callable instances) for each property

class common.database.DBProperties.desc_list_property(attribute, prop_type, default, doc)

Bases: common.database.DBProperties.persistent_property

contains(other)
is_absent = True
class common.database.DBProperties.desc_property(attribute, prop_type, default, doc)

Bases: common.database.DBProperties.persistent_property

is_absent = False
like(pattern, format='YYYY-MM-DD')
class common.database.DBProperties.inline_list_property(attribute, prop_type, default, doc)

Bases: common.database.DBProperties.link_list_property

Inline list properties have an identical interface to link_list properties. The database backend may provide a different (optimised) implementation separately.

class common.database.DBProperties.inline_property(attribute, prop_type, default, doc)

Bases: common.database.DBProperties.link_property

Inline properties have an identical interface to link_properties. The database backend may provide a different (optimised) implementation separately.

Bases: common.database.DBProperties.persistent_property

returns query which searches the link_list for the other

Bases: common.database.DBProperties.persistent_property

class common.database.DBProperties.objectlist_property(attribute, doc, params)

Bases: common.database.DBProperties.persistent_property

is_absent = True
class common.database.DBProperties.persistent_property(attribute, prop_type, default, getter, setter, doc)

Bases: property

get_persistent_properties()
like(pattern)
common.database.DBProperties.property_factory(*args)

A factory function for the different types of properties

Based on the argument signature this method returns an instance of:
desc_property link_property desc_list_property link_list_property self_link_property

Bases: common.database.DBProperties.persistent_property

common.database.DBPropertiesMySQL module

Implementation for persistent properties

This module defines the following classes

persistent_property
+- desc_property +- link_property +- desc_list_property +- link_list_property +- self_link_property +- objectlist_property

This module also defines a number of helper classes to define getter and setters (through callable instances) for each property

There is little difference between the MySQL vs. Oracle version. The imports at the beginning must import MySQL modules.

class common.database.DBPropertiesMySQL.desc_list_property(attribute, prop_type, default, doc)

Bases: common.database.DBPropertiesMySQL.persistent_property

contains(other)
is_absent = True
class common.database.DBPropertiesMySQL.desc_property(attribute, prop_type, default, doc)

Bases: common.database.DBPropertiesMySQL.persistent_property

is_absent = False
like(pattern, format='YYYY-MM-DD')
class common.database.DBPropertiesMySQL.inline_list_property(attribute, prop_type, default, doc)

Bases: common.database.DBPropertiesMySQL.link_list_property

Inline list properties have an identical interface to link_list properties. The database backend may provide a different (optimised) implementation separately.

class common.database.DBPropertiesMySQL.inline_property(attribute, prop_type, default, doc)

Bases: common.database.DBPropertiesMySQL.link_property

Inline properties have an identical interface to link_properties. The database backend may provide a different (optimised) implementation separately.

Bases: common.database.DBPropertiesMySQL.persistent_property

returns query which searches the link_list for the other

Bases: common.database.DBPropertiesMySQL.persistent_property

class common.database.DBPropertiesMySQL.objectlist_property(attribute, doc, params)

Bases: common.database.DBPropertiesMySQL.persistent_property

is_absent = True
class common.database.DBPropertiesMySQL.persistent_property(attribute, prop_type, default, getter, setter, doc)

Bases: property

get_persistent_properties()
like(pattern)
common.database.DBPropertiesMySQL.property_factory(*args)

A factory function for the different types of properties

Based on the argument signature this method returns an instance of:
desc_property link_property desc_list_property link_list_property self_link_property

Bases: common.database.DBPropertiesMySQL.persistent_property

common.database.DBProxy module

Module DBProxy.

DBProxy provides an instance of the database interface needed by the DBMeta.DBObjectMeta.

class common.database.DBProxy.DBProxy

Bases: object

commit(other)

Commit a persistent object and all the objects that it references.

commit() stores persistent Python objects in the database that:

  1. For which the commit() method is called.
  2. That is referenced by an object for which commit() is called and for which the state has changed.
  3. That is referenced by an object as defined in 2) and for which the state has changed.

A commit() also defines transaction boundaries in that it succeeds only if all the referenced objects that take part in the commit() are stored successfully. If any of the referenced objects cannot be stored, then none of the objects are stored.

gc_transient(other)

Called by the DBObject destructor __del__()

get_instance(cls, *args, **kwargs)

Instantiate an object

Arguments:
tp – the class of the object to be instantiated *args – the constructor argments **kwargs – the constructor keyword arguments

This method should return a reference to a a new or existing instance. This method should ensure that the instance has a _desc attribute, which should be a dictionary. The object should also have an attribute _dirty, which is initially 0

persists(other)

Returns whether an object is persistent or not.

register_class(cls)

Register a new class with the database

Arguments:
cls – the class to be registered with the database

This method is called when a Persistent class is defined. It can be used to compare the newly created class definition with the existing definition in the database. The return value of this method is not checked. Use exceptions when class registration is unsucessfull.

common.database.DBProxyFactory module

common.database.DBSelect module

The beginnings of an implementation for Logical Expression objects

These objects should be used by the database to build queries

common.database.DataObject module

objects with an associated data file

class common.database.DataObject.DataObject(pathname='', **kw)

Bases: common.database.DBMain.DBObject

A peristent object with associated data.

DataObject is the root class for persistent objects that also have an associated data file, for example: fits images (BaseFrame), or LDAC cats (Catalog).

Note that the full pathname separates into a filename which is persistent and a filepath, which is not persistent. This is because it is expected that the pathname is only meaningfull on the site where a process is running.

commit()

The commit method is overloaded to give a warning when a DataObject is committed without being stored. However this warning is only triggered when the unstored object itself is committed. The warning is not raised when the commit is performed recursively by committing an object with an unstored object as a dependency because the commit is performed recursively in the metaclass.

derive_hash()

Apply hashing function to the contents of the file that is part of this object.

The SHA hashing function is used to calculate a hash value of the contents of this DataObject. The hash value is returned as a hexadecimal string.

exists()

Test is the file existsts localy. See the is_on_dataserver and locate functions below to check whether files exist on the storage.

filename

The name of the associated file [None]

filepath = './'
get_canonical_name(processlevel='')

Returns the canonical name of a DataObject. This function is used by the set_filename function and should be overloaded in derived classes.

globalname

The name used to store and retrieve file to and from Storage [None]

is_on_dataserver(local=True, remote=True)

Checks if file is accessable on the dataserver.

local: check for file on local dataserver(s)

remote: check for file on remote dataserver(s)

NOTE: A return of False does NOT imply the file is not on any
dataserver! It is simply not on any accessable dataserver.
is_stored()
localname = ''
locate(local=True, remote=True)

See common/net/ds/client.py (Data_IO.locateit).

local: check for file on local dataserver(s)

remote: check for file on remote dataserver(s)

Returns a list of strings describing all dataservers where the file is located as well as a few properties of the file, i.e.

[‘ip=…,port=…,path=…,size=…,mdate=…,
‘ip=…,port=…,path=?,size=?,mdate=?’]

Question marks indicate that this dataserver is not reachable.

name_insert_suffix(suffix)
name_replace_suffix(suffix)
name_with_new_suffix(suffix)
object_id

The object identifier

The object identifier is an attribute shared by all persistent instances. It is the prime key, by which object identity is established

pathname
release()
retrieve()

Retrieves the file from storage.

set_filename(filename='', filepath='', processlevel='')

Specify a filename for this DataObject or use the default filename.

This method is used to set the filename attribute of a DataObject. If called without a filename, the filename is set to the canonical name. Classes that are derived from DataObject are expected to define a method get_canonical_name() that returns the name for an instance of that class. This is mandatory for CalFiles (or files that are store()d on the data server) and optional for other files.

set_process_parameters_from_dict(pars={})

pars is a dictionary of the type e.g.: {‘BiasFrame.process_params.SIGMA_CLIP’:8}

set_stored()
set_user_config(pars={})
storage = <common.net.ds.client.Storage object>
store()

Stores the file on storage.

store_with_hash_as_name(prefix='', suffix='fits')

Name the file after the hash value of the file and store it.

First the hash value of the file is calculated. The pathname of the dataobject is renamed to the hash value with the given suffix appended. Then the file is stored.

common.database.Database module

Module Database

Defines singleton database instance and provides an instance that can be used to connect to a database.

common.database.DatabaseFilebased module

class common.database.DatabaseFilebased.DatabaseFilebased

Bases: common.database.DatabaseInterface.DatabaseInterface

common.database.DatabaseInterface module

class common.database.DatabaseInterface.DatabaseInterface

Bases: object

The singleton Database definition.

classmethod awschema()

return the database schema, determined by the environment or else username

clear_all_state()

Clear all state from the database object (connections, object cache) This should be used when a child process is spawned

clear_objcache()

clear the object cache for the current thread

commit()

Commit changes made during transaction.

connect(profile=None)

Connect to the profiled database.

connected()

returns the connection if connected otherwise None

connections = {}
cursor()

Create a cursor using the currently connected database.

del_objcache(obj_id)

remove the object (obj) with object_id from the cache

disconnect()

Disconnect the currently connected database.

execute_create(query, *args)
execute_grant(query, *args)
execute_insert(query, *args)
execute_procedure(query, *args)
execute_select(query, *args, **kwargs)
execute_select_assoc(query, *args, **kwargs)

Returns a list of dictionaries whose keys are the names of the selected columns.

execute_update(query, *args)
classmethod expand_dbname(dbname)

Expands the dbname to dbname/dbname, if needed

get_all_projects(init=False)

return a dictionary coupling project ids to project names set init to force an initialization of the dictionary

get_all_users(init=False)

return a dictionary coupling all user ids to user names set init to force an initialization of the dictionary

get_column_comments()
get_current_privileges()

Return the active privileges

get_current_project()

Return the project that is currently active using the context

get_datamodel_namespace()
get_dbid()

Return DBID that uniquely identifies an Oracle database.

get_derived_classes(class_name)

get all the derived class names from the given class

classmethod get_identity(username, password, dbname)

return the identity string for the connection

get_object_cache()

get or make the object cache for the current thread

get_table_comments()
get_threadid()

get the identifier which couples the DB connection to the thread

get_userid()

get the user id

invalidate_objects()

Invalidate objects that should not be visible because the project or privileges have been changed. The invalidated objects will be removed from the cache.

objcache(object_id)

get the object with object_id from the cache

object_caches = {}
projects = {}
rollback()

Undo changes made during transaction.

set_all_projects()

fill the projects dictionary

set_all_users()

fill the users dictionary

set_datamodel_namespace(p_namespace_name)
set_default_datamodel_namespace()
set_objcache(obj_id, obj)

place the object (obj) with object_id in the cache

set_privileges(privileges)

Set the privileges, every created object will have this privileges

set_project(name, privileges=0)

Set the current project

sso_authorize(ticket, sso_application='')

Authorize using the SSO ticket. The sso_application argument overrides the one in the Environment. Return whether the authorize succeeded; True or False.

test_login(dbname=None, username=None, password=None)

test the username and password by logging in dbname

username()

returns the username of the current connection

users = {}
exception common.database.DatabaseInterface.InvalidOIDError

Bases: Exception

Raised for object_id == OIDNONE

common.database.DatabaseMySQL module

Module Database

Defines singleton database instance and provides an instance that can be used to connect to a database.

For MySQL the connect statement will connect (through MySQLdb) using information in the $HOME/.awe/Environment.cfg file, calls the insert_data_proc procedure which inserts information into the session_current table, and “set sql_mode=’ANSI_QUOTES’”.

IMPORTANT: For MySQL, the connect() method calls the “call insert_data_proc()” which inserts the session data, user, privileges, and project into the session_current table. The information in this table is join in VIEWs. So VIEWs will not work if call insert_data_proc() is not called.

class common.database.DatabaseMySQL.DatabaseMySQL

Bases: common.database.DatabaseInterface.DatabaseInterface

The singleton Database definition.

classmethod awschema()

return the database schema, determined by the environment or else username

clear_objcache()

clear the object cache for the current thread

commit()

Commit changes made during transaction.

connect()

Connect to the profiled database.

connected()

returns the connection if connected otherwise None

connections = {}
cursor()

Create a cursor using the currently connected database.

del_objcache(obj_id_tablename)

remove the object (obj) with object_id from the cache JP: for MySQL obj_id = object_id +::+tablename b/c in MySQL unique id only for table

disconnect()

Disconnect the currently connected database.

execute_SQL(query)
execute_create(query, *args)
execute_grant(query, *args)
execute_insert(query, *args)
execute_procedure(query, *args)
execute_select(query, *args)
get_all_projects(init=False)

return a dictionary coupling project ids to project names set init to force an initialization of the dictionary

get_all_users(init=False)

return a dictionary coupling all user ids to user names set init to force an initialization of the dictionary

get_column_comments()
get_current_privileges()

Return the active privileges

get_current_project()

Return the project that is currently active using the context

get_dbid()

Return DBID that uniquely identifies an Oracle database.

get_derived_classes(class_name)

get all the derived class names from the given class

get_object_cache()

get or make the object cache for the current thread JP: for MySQL obj_id = object_id +::+tablename b/c in MySQL unique id only for table

get_table_comments()
get_userid()

get the user id

invalidate_objects()

Invalidate objects that should not be visible because the project or privileges have been changed. The invalidated objects will be removed from the cache.

objcache(obj_id_tablename)

get the object with object_id from the cache JP: for MySQL obj_id = object_id +::+tablename b/c in MySQL unique id only for table

object_caches = {}
projects = {}
rollback()

Undo changes made during transaction.

setANSIQUOTES()

Used to set special character recognition. used when creating tables such as TESTA*OBJECTLIST_ATTRIBUTE

set_all_projects()

fill the projects dictionary

set_all_users()

fill the users dictionary

set_objcache(obj_id_tablename, obj)

place the object (obj) with object_id in the cache JP: for MySQL obj_id = object_id +::+tablename b/c in MySQL unique id only for table

set_privileges(privileges)

Set the privileges, every created object will have this privileges

set_project(name, privileges=1)

Set the current project.

test_login(dbname=None, username=None, password=None)

test the username and password by logging in dbname

username()

returns the username of the current connection

users = {}

common.database.DatabaseOracle module

class common.database.DatabaseOracle.DatabaseOracle

Bases: common.database.DatabaseInterface.DatabaseInterface

The singleton Database definition.

assert_qualified_sql_name(name)

assert that the given (sql) name is qualified, for example to check a column name for more information see sys.dbms_assert.qualified_sql_name

assert_sql_object_name(name)

assert that the given (object) name is valid, for example to check a table name for more information see sys.dbms_assert.sql_object_name

classmethod awschema()

return the database schema, determined by the environment or else username

clear_all_state()

Clear all state from the database object (connections, object cache) This should be used when a child process is spawned

clear_objcache()

clear the object cache for the current thread

commit()

Commit changes made during transaction.

connect(profile=None)

Connect to the profiled database.

connected()

returns the connection if connected otherwise None

connections = {140440255924032: <cx_Oracle.Connection to AWANONYMOUS@db.astro.rug.astro-wise.org/db.astro.rug.astro-wise.org>}
cursor()

Create a cursor using the currently connected database.

default_arraysize = 50
del_objcache(obj_id)

remove the object (obj) with object_id from the cache

disconnect()

Disconnect the currently connected database.

execute_create(query, *args)
execute_grant(query, *args)
execute_insert(query, *args)
execute_procedure(query, *args, **kwargs)
execute_select(query, *args, **kwargs)
execute_update(query, *args)
classmethod expand_dbname(dbname)

Expands the dbname to dbname/dbname, if needed

get_all_projects(init=False)

return a dictionary coupling project ids to project names set init to force an initialization of the dictionary

get_all_users(init=False)

return a dictionary coupling all user ids to user names set init to force an initialization of the dictionary

get_column_comments()
get_current_privileges()

Return the active privileges

get_current_project()

Return the project that is currently active using the context

get_dbid()

Return DBID that uniquely identifies an Oracle database.

get_derived_classes(class_name)

get all the derived class names from the given class

classmethod get_identity(username, password, dbname)

return the identity string for the connection

get_object_cache()

get or make the object cache for the current thread

get_oracle_version()
get_table_comments()
get_userid()

get the user id from the AWCONTEXT

invalidate_objects()

Invalidate objects that should not be visible because the project or privileges have been changed. The invalidated objects will be removed from the cache.

objcache(object_id)

get the object with object_id from the cache

object_caches = {140440255924032: <WeakValueDictionary at 0x7fbaa3bbd5f8>}
projects

return a dictionary coupling project ids to project names set init to force an initialization of the dictionary

rollback()

Undo changes made during transaction.

set_all_projects()

fill the projects dictionary

set_all_users()

fill the users dictionary

set_objcache(obj_id, obj)

place the object (obj) with object_id in the cache

set_privileges(privileges)

Set the privileges, every created object will have this privileges

set_project(name, privileges=0)

Set the current project

sso_authorize(ticket, sso_application='')

Authorize using the SSO ticket, the sso_application argument overrides the one in the Environment

sso_authorize_enabled()

Does the database support Authorization with an SSO ticket ?

test_login(dbname=None, username=None, password=None)

test if the username / password can login to the database with dbname return the connection or an Exception should be raised do NOT use this method to create a regular database connection

update_cache(*args, **kwargs)

updates the cache, which keeps track of which classes/tables were imported

username()

returns the username of the current connection

users

return a dictionary coupling all user ids to user names set init to force an initialization of the dictionary

common.database.DatabasePostgreSQL module

common.database.Evolution module

common.database.Evolution.addattributes(classdef, *attrnames)
common.database.Evolution.addclass(classdef)
common.database.Evolution.addcolumns(classdef, *attrnames)
common.database.Evolution.addcomments(classdef, *attrnames, **kwargs)

Generate SQL to add comments for the given class and attribute (names)

common.database.Evolution.addnested(classdef, *attrnames)
common.database.Evolution.dropclass(classdef)
common.database.Evolution.dropcolumns(classdef, *attrnames)
common.database.Evolution.generate()

generate SQL for all added or removed attributes

common.database.Evolution.renamecolumns(classdef, *attrnames)
common.database.Evolution.showquery(query)

common.database.MySQLsupport module

Module MySQLsupport.

This module contains support functions used by the DBOracle module to convert persistent classes and attributes from Python to MySQL and vice versa.

MySQL 5.5 allows table and columns names longer than 30 characters. So that restriction has been removed. 20Jan2012 JPizagno

class common.database.MySQLsupport.ColumnDefinition(tablename, columnname, propname, attrname, attrtype, columntype, attrdoc)

Bases: object

Contains all information about a column.

This class exposes the following attributes: tablename - name of the table in the database to which this column belongs. columnname - name of the column in the database. columntype - SQL type of the column in the database. propname - type of the property: desc_property, link_property, etc. attrname - Python name of the persistent attribute that defines this column. attrtype - Python type of the persistent attribute that defines this column. attrdoc - Python documentation of the persistent attribute that defines this column. attrunit - Unit of the attribute (taken from the attrdoc)

is_inline()
show()
sqlattrname()
sqlattrtype()
sqldeclaration()
sqlviewattrname()
common.database.MySQLsupport.ObjectListAttribute(aproperty)
class common.database.MySQLsupport.PropertyDict(aclass)

Bases: dict

has_key(key)
objectlisttypevalues()
subtypevalues()
class common.database.MySQLsupport.Sequence

Bases: object

add_desc(attribute, value)
alias()
columns()
objectlist()
params()
parnum()
setters()
values()
common.database.MySQLsupport.add_sql_for_property(aproperty, **kwargs)
common.database.MySQLsupport.arraytype(aproperty)
common.database.MySQLsupport.augment_dbmetaobject()
common.database.MySQLsupport.augment_properties()
common.database.MySQLsupport.convert_objectlist_type(prop, type_name)

used by Oracle, not currently (7Oct2011) used by MySQL

common.database.MySQLsupport.datetimeconvert(value)
common.database.MySQLsupport.definingclass(aproperty)
common.database.MySQLsupport.descSQL(aproperty)
common.database.MySQLsupport.desclistSQL(aproperty)
common.database.MySQLsupport.get_arguments_for_select(cls)

used by Oracle, not currently (7Oct2011) used by MySQL

common.database.MySQLsupport.lendet(arg)
common.database.MySQLsupport.linkSQL(aproperty)
common.database.MySQLsupport.linklistSQL(aproperty)
common.database.MySQLsupport.mangle(anidentifier)

MySQL does NOT use this convention to fit in with Oracle implementation: Oracle identifiers can not be longer than 31 characters. MySQL 5.5 can have tables and columns with really long names

class common.database.MySQLsupport.mysqloidtype(raw)

Bases: common.database.DBMetaMySQL.oidtype

mysqloidtype is a class for the Oracle OBJECT_ID. Used for example in DBMySQL.insert_into_flattable when object_id is return. object has type mysqloidtype(object_id_returned) assigned to the object.object_id.

binary()
common.database.MySQLsupport.python2odbc(value)
common.database.MySQLsupport.selflinkSQL(aproperty)
common.database.MySQLsupport.sqlname(name)
common.database.MySQLsupport.sqltype(pythontype)

Returns the corresponding SQL type for a given Python type

common.database.MySQLsupport.sqltypename(identifier)
common.database.MySQLsupport.typename(aclass)
common.database.MySQLsupport.update_cache(self, *args, **kwargs)

updates the cache, which keeps track of which classes/tables were imported

common.database.MySQLsupport.viewname(aclass)

common.database.PostgreSQLsupport module

common.database.Security module

Creates packages and context in Oracle to support Astro-WISE Contexts.

common.database.SecurityFilebased module

Define the necessary functions to support Context for a filebased backend.

common.database.SecurityMySQL module

Creates packages and context in MySQL to support Astro-WISE Contexts.

This module creates the tables for AWEUSERS and AWEPROJECTS. For MySQL they control the values inserted into the session_current table, which is then used in the join in VIEWs of tables.

It does not currently work, as the connection to the MySQL database checks for AWEPROJECTS, which of course is not being created. So use the query strings below as guides, write them manually (without this script), and run them in batch mode using MySQL command line (or MySQL Workbench).

Example Script mode: – BEGIN script use myDB;

– set ANSI quotes SET sql_mode=’ANSI_QUOTES’;

– create AWE tables: CREATE TABLE AWEPROJECTS ( ID int PRIMARY KEY, NAME VARCHAR(79) UNIQUE , DESCRIPTION VARCHAR(2097) , INSTRUMENT VARCHAR(79) , DEFAULT_PRIVILEGES int); INSERT INTO AWEPROJECTS (ID,NAME,DESCRIPTION,DEFAULT_PRIVILEGES) values (4,’ALL’,’All public data for all instruments’,3); INSERT INTO AWEPROJECTS (ID,NAME,DESCRIPTION,DEFAULT_PRIVILEGES) values (3,’public’,’All public data for all instruments’,3); INSERT INTO AWEPROJECTS (ID,NAME,DESCRIPTION,DEFAULT_PRIVILEGES) values (2,’project’,’public and project’,2); INSERT INTO AWEPROJECTS (ID,NAME,DESCRIPTION,DEFAULT_PRIVILEGES) values (1,’user’,’public,project,user’,1); GRANT SELECT on AWEPROJECTS to ‘awJPIZAGNO’@’localhost’;

CREATE TABLE AWEPROJECTUSERS ( PROJECTID int , USERID int , USERTYPE int, UNIQUE (PROJECTID,USERID) ); insert into AWEPROJECTUSERS (PROJECTID,USERID,USERTYPE) values (1,1,1); insert into AWEPROJECTUSERS (PROJECTID,USERID,USERTYPE) values (2,2,1); GRANT SELECT on AWEPROJECTUSERS to ‘awJPIZAGNO’@’localhost’;

CREATE TABLE AWEUSERS ( USERNAME VARCHAR(100) PRIMARY KEY, USER_ID int UNIQUE , CREATED TIMESTAMP, FULLNAME VARCHAR(297) , EMAIL VARCHAR(297), PASSWORD VARCHAR(297) ); INSERT INTO AWEUSERS (USERNAME,USER_ID,CREATED,FULLNAME,EMAIL,PASSWORD) values (‘awJPIZAGNO@localhost’,1,CURRENT_TIMESTAMP(),’jim pizagno1’,’jim@gmail.com’,’pass1’); INSERT INTO AWEUSERS (USERNAME,USER_ID,CREATED,FULLNAME,EMAIL,PASSWORD) values (‘jpizagno2@localhost’,2,CURRENT_TIMESTAMP(),’jim pizagno2’,’jim2@gmail.com’,’pass2’); GRANT SELECT on AWEUSERS to ‘awJPIZAGNO’@’localhost’;

FLUSH PRIVILEGES; – END script

common.database.SecurityMySQL.add_project(projectid, projectname)

examples projectID,projectname = (4,’ALL’),(3,’public’),(2,’project’),(1,’user’)

common.database.SecurityMySQL.add_projectuser(projectid, userid, usertype)

called by add_user. all ints

common.database.SecurityMySQL.add_user(username, userid, projectid)

add user to AWEUSERS and project to AWEPROJECTUSERS

common.database.SecurityMySQL.create_table_aweprojects()
common.database.SecurityMySQL.create_table_aweprojectusers()
common.database.SecurityMySQL.create_table_aweusers()

common.database.SecurityOracle module

Creates packages and context in Oracle to support Astro-WISE Contexts.

common.database.SecurityOracle.add_grants(tablename)
common.database.SecurityOracle.add_policy(schema, tablename, policy_name, function)
common.database.SecurityOracle.create_awsecurity_body()
common.database.SecurityOracle.create_awsecurity_header()
common.database.SecurityOracle.create_logon_trigger()
common.database.SecurityOracle.create_table_aweallowedupdates()
common.database.SecurityOracle.create_table_aweprojects()
common.database.SecurityOracle.create_table_aweprojectusers()
common.database.SecurityOracle.create_table_aweusers()
common.database.SecurityOracle.create_trigger_before_insert(tablename)
common.database.SecurityOracle.create_trigger_before_update(tablename)
common.database.SecurityOracle.define_awsecurity_body(awsecurity)
common.database.SecurityOracle.define_awsecurity_header(awsecurity)

common.database.SecurityPostgreSQL module

Creates packages and context in PostgresSQL to support Astro-WISE Contexts.

This module creates the tables for AWEUSERS and AWEPROJECTS. For PostgreSQL they control the values inserted into the awecontet_sys table, which is then used in the join in VIEWs of tables.

class common.database.SecurityPostgreSQL.SecurityPackage

Bases: object

delete_object(p_object_type, p_object_id, p_outsideproject=0, p_project=0)
get_ref_count(p_object_type, p_object_id, p_outsideproject=0, p_project=0)
update_allowed(p_object_type, p_object_id)
update_attrebute(p_update_attr, p_class_dmlname, p_object_id, p_new_value, p_commit=True)
common.database.SecurityPostgreSQL.add_adminuser(p_schema, p_username, p_awesuperuser='N', p_commit=True)
common.database.SecurityPostgreSQL.add_grants_to_usersroles(p_parentschema, p_prefix, p_commit=True)
common.database.SecurityPostgreSQL.add_project(p_projectname, p_description='', p_default_provilages=2, p_instrument='', p_commit=True)
common.database.SecurityPostgreSQL.add_projectuser(p_schema, p_projectname, p_username, p_usertype=0, p_commit=True)
common.database.SecurityPostgreSQL.add_projectuser_idid(p_schema, p_projectid, p_userid, p_usertype=0, p_commit=True)
common.database.SecurityPostgreSQL.add_user(p_username, p_fullname='', p_email='', p_password='', p_readonly='N', p_commit=True)
common.database.SecurityPostgreSQL.create_all_awe_views(p_parentschema, p_commit=True)
common.database.SecurityPostgreSQL.create_awedatabasecontext()
common.database.SecurityPostgreSQL.create_generic_after_insert_trigger_function(p_commit=True)
common.database.SecurityPostgreSQL.create_generic_after_update_trigger_function(p_commit=True)
common.database.SecurityPostgreSQL.create_generic_before_insert_trigger_function(p_commit=True)
common.database.SecurityPostgreSQL.create_generic_before_update_trigger_function(p_commit=True)
common.database.SecurityPostgreSQL.create_global_awesequence(p_commit=True)
common.database.SecurityPostgreSQL.create_global_awesysguidsequence(p_commit=True)
common.database.SecurityPostgreSQL.create_now_utc_function(p_commit=True)
common.database.SecurityPostgreSQL.create_obj_delete(p_commit=True)
common.database.SecurityPostgreSQL.create_schema_objects_ref_table(p_schema, p_commit=True)
common.database.SecurityPostgreSQL.create_set_awecontext_fordb_function(p_commit=True)
common.database.SecurityPostgreSQL.create_table_aweadminusers(p_commit=True)
common.database.SecurityPostgreSQL.create_table_awecontext(p_commit=True)
common.database.SecurityPostgreSQL.create_table_aweinit(p_commit=True)
common.database.SecurityPostgreSQL.create_table_aweprojects(p_commit=True)
common.database.SecurityPostgreSQL.create_table_aweprojectusers(p_commit=True)
common.database.SecurityPostgreSQL.create_table_awesessions(p_commit=True)
common.database.SecurityPostgreSQL.create_table_aweusers(p_commit=True)
common.database.SecurityPostgreSQL.create_table_awevocabulary_classattr(p_commit=True)
common.database.SecurityPostgreSQL.create_table_awevocabulary_classes(p_commit=True)
common.database.SecurityPostgreSQL.create_table_awevocabulary_classes_prop(p_commit=True)
common.database.SecurityPostgreSQL.create_table_awevocabulary_classes_ref_table(p_commit=True)
common.database.SecurityPostgreSQL.create_table_awevocabulary_tablesviews(p_commit=True)
common.database.SecurityPostgreSQL.create_trigger_after_insert(tablename, p_commit=True)
common.database.SecurityPostgreSQL.create_trigger_after_update(tablename, p_commit=True)
common.database.SecurityPostgreSQL.create_trigger_before_insert(tablename, p_commit=True)
common.database.SecurityPostgreSQL.create_trigger_before_update(tablename, p_commit=True)
common.database.SecurityPostgreSQL.truncate_vocabulary(p_commit=True)

common.database.Sequence module

Sequences.

common.database.Sequence.create_sequence(seq_name)
common.database.Sequence.get_next_unique_identifier(seq_name=None)
common.database.Sequence.get_next_val_from_sequence(seq_name)
common.database.Sequence.get_sequence_offset()
common.database.Sequence.mk_seqname(seq_name)
common.database.Sequence.remove_sequence(seq_name)

common.database.SequenceFilebased module

Filebased implementation of a Sequence.

Function names are based on the Oracle Sequence.

The numbers produced by these sequences end with a 9 to distinguish them from the original Sequences.

TODO: - Make the sequence (somewhat) persistent? E.g. through a file? - Make the sequence unique? E.g. like a UUID instead of a sequence? - Ensure we use only meaningful identifiers instead of relying on

a sequence. E.g. a data-lineage based hash.
class common.database.SequenceFilebased.Sequence(name, seed, iterator)

Bases: tuple

iterator

Alias for field number 2

name

Alias for field number 0

seed

Alias for field number 1

common.database.SequenceFilebased.create_sequence(seq_name)
common.database.SequenceFilebased.get_next_unique_identifier(seq_name=None)
common.database.SequenceFilebased.get_next_val_from_sequence(seq_name)
common.database.SequenceFilebased.get_sequence_offset()
common.database.SequenceFilebased.mk_seqname(seq_name)
common.database.SequenceFilebased.remove_sequence(seq_name)

common.database.Table module

Module Table

Defines a generalized table with convenient accessor methods.

class common.database.Table.Dict

Bases: dict

Dictionary with keys that can be accessed like attributes.

The Dict dictionary behave like a normal dictionary with one addition. Whenever an attribute of an instance of this class is retrieved, the value for the key that is equal to the name of that attribute is returned.

class common.database.Table.Table

Bases: object

Generalized table with convenient accessor methods.

Rows in a Table can be accessed by column name or column number.

get_column_number_for(key)
keys()

Return the names of the columns.

common.database.objectlist module

common.database.objectlist.convert_to_pythontype(sql_type)
common.database.objectlist.convert_to_pythontype_text(python_type)
common.database.objectlist.convert_to_sqltype(python_type)
common.database.objectlist.convert_typetext_to_fitstype(text)
common.database.objectlist.convert_typetext_to_pythontype(text)
common.database.objectlist.convert_typetext_to_pythontypefunc(text)
common.database.objectlist.mangle(anidentifier)

Oracle identifiers can not be longer than 31 characters

class common.database.objectlist.objectlist_type(params, table_name, supertype_name, subtype_name=None, params_ordered=None)

Bases: dict

extend(value)
fixate(attribute_dict)
class common.database.objectlist.objectlist_type_iterator(target)

Bases: object

next()

Python 2 compatibility

common.database.objectlist.objectlistname(aproperty)
common.database.objectlist.objectlisttablename(cls_name, attribute)
common.database.objectlist.objectlisttype(aproperty, number=None)
common.database.objectlist.qstrip(s)
common.database.objectlist.register_objecttype(supertype, attributes, ol_table_name)

common.database.objectlistMySQL module

This class defines a way to go from Python types to MySQL types. It still(7Oct2011) has Oracle-specific code, that has not yet been converted to MySQL

common.database.objectlistMySQL.convert_to_pythontype(sql_type)
common.database.objectlistMySQL.convert_to_pythontype_text(python_type)
common.database.objectlistMySQL.convert_to_sqltype(python_type)
common.database.objectlistMySQL.convert_typetext_to_fitstype(text)
common.database.objectlistMySQL.convert_typetext_to_pythontype(text)
common.database.objectlistMySQL.convert_typetext_to_pythontypefunc(text)
common.database.objectlistMySQL.mangle(anidentifier)

MySQL 5.5 allows long table column names. Oracle identifiers can not be longer than 31 characters

class common.database.objectlistMySQL.objectlist_type(params, table_name, supertype_name, subtype_name=None, params_ordered=None)

Bases: dict

extend(value)
fixate(attribute_dict)
class common.database.objectlistMySQL.objectlist_type_iterator(target)

Bases: object

next()

Python 2 compatibility

common.database.objectlistMySQL.objectlistname(aproperty)
common.database.objectlistMySQL.objectlisttablename(cls_name, attribute)
common.database.objectlistMySQL.objectlisttype(aproperty, number=None)
common.database.objectlistMySQL.qstrip(s)
common.database.objectlistMySQL.register_objecttype(supertype, attributes, ol_table_name)

common.database.oraclesupport module

Module oraclesupport.

This module contains support functions used by the DBOracle module to convert persistent classes and attributes from Python to Oracle and vice versa.

class common.database.oraclesupport.ColumnDefinition(tablename, columnname, propname, attrname, attrtype, columntype, attrdoc)

Bases: object

Contains all information about a column.

This class exposes the following attributes: tablename - name of the table in the database to which this column belongs. columnname - name of the column in the database. columntype - SQL type of the column in the database. propname - type of the property: desc_property, link_property, etc. attrname - Python name of the persistent attribute that defines this column. attrtype - Python type of the persistent attribute that defines this column. attrdoc - Python documentation of the persistent attribute that defines this column. attrunit - Unit of the attribute (taken from the attrdoc)

is_inline()
show()
sqlattrname()
sqlattrtype()
sqldeclaration()
sqlviewattrname()
common.database.oraclesupport.ObjectListAttribute(aproperty)
class common.database.oraclesupport.PropertyDict(aclass)

Bases: dict

has_key(key)
objectlisttypevalues()
subtypevalues()
class common.database.oraclesupport.Sequence

Bases: object

add_desc(attribute, value)
alias()
columns()
objectlist()
params()
parnum()
setters()
values()
common.database.oraclesupport.add_sql_for_property(aproperty, **kwargs)
common.database.oraclesupport.arraytype(aproperty)
common.database.oraclesupport.augment_dbmetaobject()
common.database.oraclesupport.augment_properties()
common.database.oraclesupport.convert_objectlist_type(prop, type_name)
common.database.oraclesupport.datetimeconvert(value)
common.database.oraclesupport.definingclass(aproperty)
common.database.oraclesupport.descSQL(aproperty)
common.database.oraclesupport.desclistSQL(aproperty)
common.database.oraclesupport.get_arguments_for_select(cls)
common.database.oraclesupport.lendet(arg)
common.database.oraclesupport.linkSQL(aproperty)
common.database.oraclesupport.linklistSQL(aproperty)
common.database.oraclesupport.mangle(anidentifier)

Oracle identifiers can not be longer than 31 characters

common.database.oraclesupport.mangle_left(anidentifier)

Oracle identifiers can not be longer than 31 characters

common.database.oraclesupport.mangle_right(anidentifier)

View column names should <= 30 characters and truncated at the end Truncation could lead to naming conflicts, for these cases we have the long attribute names translation dict

class common.database.oraclesupport.oracleoidtype(raw)

Bases: common.database.DBMeta.oidtype

binary()
unquote()
common.database.oraclesupport.python2odbc(value)
common.database.oraclesupport.selflinkSQL(aproperty)
common.database.oraclesupport.sqlname(name)
common.database.oraclesupport.sqltype(pythontype)

Returns the corresponding SQL type for a given Python type

common.database.oraclesupport.sqltypename(identifier)
common.database.oraclesupport.typename(aclass)
common.database.oraclesupport.update_cache(self, *args, **kwargs)
common.database.oraclesupport.viewname(aclass)

common.database.typed_list module

class common.database.typed_list.lazy_typed_list(item_type, items=[])

Bases: list

A list for which the items are either of the given type or a special tuple for lazy instantation.

Lazy instantiation takes a tuple (ob_type, ob_args, ob_kwargs) and returns ob_type(*ob_args, **ob_kwargs). Valid tuples that can be assigned to a lazy_typed_list satisfy issubclass(tup[0], item_type). Lzay instantiation is performed whenever the tuple is accessed through __getitem__.

append(item)
extend(other)
insert(index, item)
is_lazy_instance(item)
class common.database.typed_list.typed_list(item_type, items=[])

Bases: list

A list for which the items are of a given type

All items in a typed list satisfy isinstance(item, item_type)

append(item)
extend(other)
insert(index, item)

common.database.utilities module

Database utilities

common.database.utilities.print_tree(class_str, object_id, max_depth=1)

print_tree prints the given object and all its dependencies recursively to the given max_depth. Arguments :

class_str The class string (example BiasFrame) object_id The object id, (example CA75D91E44E0602BE0307D814C067B61) max_depth The maximum depth (optional)

Module contents

Database modules

This package contains the modules for the Persistent Object interface.

The modules DBMain, DBMeta, DBProperties, DBProxy and DBSelect together make it possible to mark Objects and their attributes as Persistent. The DBOracle module is an Oracle implementation of the DBProxy interface.

Usage

First make sure that you activate the right database engine or deactivate it if you don’t want to use a database. To use Oracle 10i add the following lines to the ~/.awe/Environment.cfg file:

database_engine        : oracle_10i
database_name          : yourdbmachine.yourdomain
database_user          : yourusername
database_password      : yourpasswordhere

If your ~/.awe/Environment.cfg does not exist or is still empty you’ll have to add a first line to define a global section, like:

[global]

and look at the documentation of the common.config.Environment module and the Environment.cfg file.

Warning

If your ~/.awe/Environment.cfg file contains a password make sure it is READ PROTECTED!!!

The user only needs to import DBObject and persistent() the DBMain module to derive a persistent class. The following import suffices:

from common.database.DBMain import DBObject, persistent

Here DBObject is the class that is to be used as the base class to derive persistent-capable classes from. The persistent() function is used to define attributes as persistent in a persistent-capable class.

Example

If this example is run with an appropriate database engine the creation of the instances results in the creation of an identical object in the database. That instance in the database will survive a Python session, whereas running the example without a database engine will create object that only exist as long as a Python session exists.

from common.database.DBMain import DBObject, persistent

class Person(DBObject):
    name = persistent('The name of a person', str, 'Jansen')
    age = persistent('The age of a person', int, 70)

jansen = Person()        # Create a persistent Person object
jansens = Person()       # Create another persistent Person object
jansens.name = 'Jansens' # Change the value of a string attribute
jansens.age = 71         # Change the value of an integer attribute