The Virtual Brain Project

Table Of Contents

Previous topic

db_update_scripts Package

Next topic

transient Package

This Page

storage Package

This is just a shortcut, in order to make all DAO functions accessible from a single point, in an uniform manner, without supplementary name space. We want DAO functions to be separated in multiple files, because they are too many to easily follow.



Empty class, build only for inheriting from all DAO classes.

session = < object at 0x7f375af503d0>


DAO operations related to generic DataTypes are defined here.




compute_bursts_disk_size(*args, **kwargs)[source]

SUM the disk_size of all data types generated by each requested burst Do not count DataType Groups as those already include the size of the entities inside the group. :returns a map from burst id to disk size

count_all_datatypes(*args, **kwargs)[source]

Gives you the count of all the datatypes currently stored by TVB. Is used by the file storage update manager to upgrade from version to the next.

count_datatypes(*args, **kwargs)[source]
count_datatypes_generated_from(*args, **kwargs)[source]

Returns a count of all the datatypes that were generated by an operation having as input the datatype ginen by ‘datatype_gid’

count_datatypes_in_burst(*args, **kwargs)[source]

Returns the number of DataTypes from the specified DataTypeGroup ID.

count_datatypes_in_group(*args, **kwargs)[source]

Returns the number of DataTypes from the specified DataTypeGroup ID.

get_all_datatypes(*args, **kwargs)[source]

Return a list with all of the datatypes currently available in TVB. Is used by the file storage update manager to upgrade from version to the next.

  • page_start – the index from which to start adding datatypes to the result list
  • page_size – maximum number of entities to retrieve
get_data_in_project(*args, **kwargs)[source]

Get all the DataTypes for a given project, including Linked Entities and DataType Groups.

  • visibility_filter – when not None, will filter by DataTye fields
  • filter_value – when not None, will filter with ilike multiple DataType string attributes
get_datatype_by_gid(*args, **kwargs)[source]

Retrieve a DataType DB reference by a global identifier.

get_datatype_details(*args, **kwargs)[source]

Returns the details for the dataType with the given GID.

get_datatype_group_by_gid(*args, **kwargs)[source]

Returns the DataTypeGroup with the specified gid.

get_datatype_group_disk_size(*args, **kwargs)[source]

Return the size of all the DataTypes from this datatype group.

get_datatype_in_group(*args, **kwargs)[source]

Return a list of id-s of the DataTypes in the given dt group.

get_datatypegroup_by_op_group_id(*args, **kwargs)[source]

Returns the DataTypeGroup corresponding to a certain OperationGroup.

get_datatypes_for_range(*args, **kwargs)[source]

Retrieve from DB, DataTypes resulted after executing a specific range operation.

get_datatypes_from_datatype_group(*args, **kwargs)[source]

Retrieve all datatype which are part from the given datatype group.

get_datatypes_in_project(*args, **kwargs)[source]

Get all the DataTypes for a given project with no other filter apart from the projectId

get_disk_size_for_operation(*args, **kwargs)[source]

Return the disk size for the operation by summing over the disk space of the resulting DataTypes.

get_last_data_with_uid(*args, **kwargs)[source]

Retrieve the last dataType ID witch has UDI field as the passed parameter, or None if nothing found.

get_linked_datatypes_in_project(*args, **kwargs)[source]

Return a list of datatypes linked into this project :param project_id: the id of the project

Get the links to a specific datatype

get_selections_for_project(*args, **kwargs)[source]

Get available selections for a given project and data type.

get_stored_pse_filters(*args, **kwargs)[source]
Returns:Stored PSE filters for a given DatTypeGroup or None
get_summary_for_group(*args, **kwargs)[source]

:return (disk_size SUM, subject)

get_values_of_datatype(*args, **kwargs)[source]

Retrieve a list of dataTypes matching a filter inside a project. :returns: (results, total_count) maximum page_end rows are returned, to avoid endless time when loading a page

is_datatype_group(*args, **kwargs)[source]

Used to check if the DataType with the specified GID is a DataTypeGroup.

session = < object at 0x7f375af503d0>
set_datatype_visibility(*args, **kwargs)[source]

Sets the dataType visibility. If the given dataType is a dataTypeGroup or it is part of a dataType group than this method will set the visibility for each dataType from this group.

try_load_last_entity_of_type(*args, **kwargs)[source]


Created on Jan 15, 2013


Bases: exceptions.Exception

Base class for all TVB storage exceptions.



Exception raised in case you have any faulty access to a transaction.



Nested transactions are not supported unless in testing.


DAO operations related to Algorithms and User Operations are defined here.




compute_disk_size_for_started_ops(*args, **kwargs)[source]

Get all the disk space that should be reserved for the started operations of this user.

count_resulted_datatypes(*args, **kwargs)[source]

Returns the number of resulted datatypes from the specified operation.

filter_category(*args, **kwargs)[source]

Retrieve category with given id

get_adapters_from_categories(*args, **kwargs)[source]

Retrieve a list of stored adapters in the given categories.

get_algorithm_by_id(*args, **kwargs)[source]
get_algorithm_by_module(*args, **kwargs)[source]
get_algorithm_categories(*args, **kwargs)[source]

Retrieve all existent categories of Algorithms.

get_all_operations_for_uploaders(*args, **kwargs)[source]

Returns all finished upload operations.

get_applicable_adapters(*args, **kwargs)[source]

Retrieve a list of algorithms in a given list of categories with a given dataType classes as required input.

get_category_by_id(*args, **kwargs)[source]

Retrieve category with given id

get_figure_count(*args, **kwargs)[source]

Used to generate sequential image names.

get_figures_for_operation(*args, **kwargs)[source]

Retrieve Figure entities, resulted after executing an operation.

get_filtered_operations(*args, **kwargs)[source]
  • project_id – current project ID
  • filter_chain – instance of FilterChain
  • is_count – when True, return a number, otherwise the list of operation entities

:return a list of filtered operation in current project, page by page, or the total count for them.

get_launchable_categories(*args, **kwargs)[source]

Retrieve algorithm categories which can be launched on right-click (optionally filter visualizers)

get_operation_by_gid(*args, **kwargs)[source]

Retrieve OPERATION entity for a given gid.

get_operation_by_id(*args, **kwargs)[source]

Retrieve OPERATION entity for a given Identifier.

get_operation_numbers(*args, **kwargs)[source]

Count total number of operations started for current project.

get_operation_process_for_operation(*args, **kwargs)[source]

Get the OperationProcessIdentifier for this operation id.

get_operationgroup_by_gid(*args, **kwargs)[source]

Retrieve by GID

get_operationgroup_by_id(*args, **kwargs)[source]

Retrieve by ID

get_operations_for_datatype(*args, **kwargs)[source]

Returns all the operations which uses as an input parameter the dataType with the specified GID. If the flag only_relevant is True than only the relevant operations will be returned.

If only_in_groups is True than this method will return only the operations that are part from an operation group, otherwise it will return only the operations that are NOT part of an operation group.

get_operations_for_datatype_group(*args, **kwargs)[source]

Returns all the operations which uses as an input parameter a datatype from the given DataTypeGroup. If the flag only_relevant is True than only the relevant operations will be returned.

If only_in_groups is True than this method will return only the operations that are part from an operation group, otherwise it will return only the operations that are NOT part of an operation group.

get_operations_in_burst(*args, **kwargs)[source]

Return a list with all the operations generated by a given burst. These need to be removed when the burst is deleted. :param: is_count When True, a counter of the filtered operations is returned.

get_operations_in_group(*args, **kwargs)[source]

Retrieve OPERATION entities for a given group.

get_previews(*args, **kwargs)[source]

This method returns a tuple of 2 elements. The first element represents a dictionary of form {‘$session_name’: [list_of_figures]}. This dictionary contains data only for the selected self.session. If the selected session is ‘all_sessions’ than it will contain data for all the sessions. The second element of the returned tuple is a dictionary of form {‘$session_name’: $no_of_figures_in_this_session, ...}. This dictionary contains information about all the sessions.

selected_session_name - represents the name of the session for which you
want to obtain the stored figures.
get_raw_categories(*args, **kwargs)[source]

Retrieve categories with raw_input = true

get_results_for_operation(*args, **kwargs)[source]

Retrieve DataTypes entities, resulted after executing an operation.

get_uploader_categories(*args, **kwargs)[source]

Retrieve categories with raw_input = true

get_visualisers_categories(*args, **kwargs)[source]

Retrieve categories with display = true

is_upload_operation(*args, **kwargs)[source]

Returns True only if the operation with the given gid is an upload operation.

load_figure(*args, **kwargs)[source]

Load a figure with all it’s lazy load fields to have all required info available.

session = < object at 0x7f375af503d0>
set_operation_and_group_visibility(*args, **kwargs)[source]

Sets the operation visibility.

If ‘is_operation_group’ is True than this method will change the visibility for all the operation from the OperationGroup with the GID field equal to ‘entity_gid’.

try_get_operation_by_id(*args, **kwargs)[source]

Try to call self.get_operation_by_id, but when operation was not found, instead of failing, return None. This could be called from situations like: stopping & removing op. A check for None is compulsory after this call!


DAO operation related to Users and Projects are defined here.




add_members_to_project(*args, **kwargs)[source]

Add link between Users and Project.

compute_user_generated_disk_size(*args, **kwargs)[source]

Do a SUM on DATA_TYPES table column DISK_SIZE, for the current user. :returns 0 when no DT are found, or SUM from DB.

count_projects_for_name(*args, **kwargs)[source]

Retrieve the number of projects with a given name currently in DB.

count_users_for_name(*args, **kwargs)[source]

Retrieve the number of users in DB for a given name.

delete_members_for_project(*args, **kwargs)[source]

Remove all linked user to current project.

delete_project(*args, **kwargs)[source]

Remove PROJECT entity by ID.

get_administrators(*args, **kwargs)[source]

Retrieve all users with Admin role

get_all_projects(*args, **kwargs)[source]

Retrieve all Project entities currently in the system. WARNING: use this wisely, as it might easily overflow the system.

get_all_users(*args, **kwargs)[source]

Retrieve all USERS in DB, except current user and system user.

:return link between a given DT and a given project id

get_linkable_projects_for_user(*args, **kwargs)[source]

Return all projects a given user can link some data given by a data_id to.

:return all links referring to a given project_id

get_members_of_project(*args, **kwargs)[source]

Retrieve USER entities with rights on current project.

get_project_by_gid(*args, **kwargs)[source]

Retrieve PROJECT entity for a given identifier. THROW SqlException when not found.

get_project_by_id(*args, **kwargs)[source]

Retrieve PROJECT entity for a given identifier. THROW SqlException when not found.

get_project_disk_size(*args, **kwargs)[source]

Do a SUM on DATA_TYPES table column DISK_SIZE, for the current project. :returns 0 when no DT are found, or SUM from DB.

get_project_for_operation(*args, **kwargs)[source]

Find parent project for current operation. THROW SqlException when not found.

get_projects_for_user(*args, **kwargs)[source]

Return all projects a given user can access (administrator or not).

get_system_user(*args, **kwargs)[source]

Retrieve System user from DB.

get_user_by_email(*args, **kwargs)[source]

Find a user by email address and name.

  • email – Valid email address string, to search for its exact match in DB
  • name_hint – string for a user’s name; to search with like in DB

None if none or more than one users matches the criteria.

get_user_by_id(*args, **kwargs)[source]

Retrieve USER entity by ID.

get_user_by_name(*args, **kwargs)[source]

Retrieve USER entity by name.

get_user_for_datatype(*args, **kwargs)[source]

Get the user who created a DT

session = < object at 0x7f375af503d0>


Base DAO behavior.


Bases: object


get_datatype_by_id(*args, **kwargs)[source]

Retrieve DataType entity by ID.

get_generic_entity(*args, **kwargs)[source]

Retrieve an entity of entity_type, filtered by select_field = filter_value.

logger = <logging.Logger object at 0x7f375af50b90>
remove_datatype(*args, **kwargs)[source]

When removing dataType, load fully so that sql-alchemy removes from all tables referenced.

remove_entity(*args, **kwargs)[source]

Find entity by Id and Type, end then remove it. Return True, when entity was removed successfully, of False when exception.

session = < object at 0x7f375af503d0>
store_entities(*args, **kwargs)[source]

Store in DB a list of generic entities.

store_entity(*args, **kwargs)[source]

Store in DB one generic entity.

session_maker, new_attributes)[source]

A meta-class factory that creates a meta-class which makes sure a list of decorators are applied to all it’s classes and also adds a dictionary of attributes.

  • decorator_functions – a list of functions. These will be applied as decorators to all methods from the class that uses the returned meta-class.
  • new_attributes – a dictionary of attribute_name & attribute_value pairs that will be added to the class that uses the returned meta-class

alias of MetaClass*args, **kwargs)[source]

Called when a new instance is about to be created.


Bases: object

Helper class that holds a stack of SqlAlchemy’s session object and a counter that keeps track of how many transactions are opened.


Method called by all ‘add_session decorated methods. First check if there are any changes that needed to be committed but weren’t. Then either close the session if it’s not part of a transaction, or just expunge all objects otherwise.


Close a transaction. Make sure to commit beforehand so all changes are written to database. Then depending on if we are top level or not either close or expunge session.


Property just for ease of access. Current session will always be top of stack.


Create a new session. If we are part of a transaction we bind it to the parent session, otherwise just create a new session.


RollBack a transaction. If we are part of nested transaction - rollback everything up to top parent transaction.


Start a new transaction. If this is top level transaction just created new session. Otherwise depending if we support nested or not, either raise exception or create a session bound to parent one.[source]

Decorator that handles session related precautions before/after method call. Before each new method a session is created that will later on be closed/rolled back as necessary. This is intended to be used on all DAO methods[source]

Class decorator that makes sure only one instance of that class is ever returned.[source]

Decorator that makes sure that all DAO calls that will result from the decorated method will be encapsulated in a transaction that will be rolled back if any unexpected exceptions appear. This is intended to be used on service layer methods.


DAO layer for WorkFlow and Burst entities.



DAO layer for WorkFlow and Burst entities.

count_bursts_with_name(*args, **kwargs)[source]

Return the number of burst already named ‘custom_b%’ and NOT ‘custom_b%_%’ in current project.

get_all_datatypes_in_burst(*args, **kwargs)[source]

Get all dataTypes in burst, order by their creation, desc.

:param burst_id BurstConfiguration Identifier. :returns: list dataType GIDs or empty list.

get_available_portlets(*args, **kwargs)[source]

Get all the stored portlets form the db.

get_burst_by_id(*args, **kwargs)[source]

Get the BurstConfiguration entity with the given id

get_burst_for_operation_id(*args, **kwargs)[source]

Get the burst for which this operation was created.

get_bursts_for_project(*args, **kwargs)[source]

Get latest 50 BurstConfiguration entities for the current project

get_configured_portlets_for_id(*args, **kwargs)[source]

Get the workflow steps that were generated from the portlet given by portlet_id.

get_dynamic(*args, **kwargs)[source]
get_dynamic_by_name(*args, **kwargs)[source]
get_dynamics_for_user(*args, **kwargs)[source]
get_max_burst_id(*args, **kwargs)[source]

Return the maximum of the currently stored burst IDs to be used as the new burst name. This is not a thread-safe value, but we use it just for a label.

get_non_validated_entities(*args, **kwargs)[source]

Get a list of all categories, portlets and algorithm groups that were not found valid since the reference_time. Used in initializer on each start to filter out any entities that for some reason became invalid. :return tuple (list of entities to get invalidated) (list of entities to be removed)

get_portlet_by_id(*args, **kwargs)[source]

Given an portlet id retieve the portlet entity.

get_portlet_by_identifier(*args, **kwargs)[source]

Given an identifer retieve the portlet that corresponds to it.

get_visualization_steps(*args, **kwargs)[source]

Retrieve all the visualization steps for a workflow.

get_workflow_by_id(*args, **kwargs)[source]

“Returns the workflow instance with the given id

get_workflow_for_operation_id(*args, **kwargs)[source]

Get the workflow from which operation_id was generated.

get_workflow_step_by_step_index(*args, **kwargs)[source]
Returns:WorkflowStep entity or None.
get_workflow_step_for_operation(*args, **kwargs)[source]

Returns the executed workflow step from which resulted the operation with the given id ‘operation_id’. Returns None if there is no such executed workflow step.

get_workflow_steps(*args, **kwargs)[source]

Retrieve all the simulation/analyzers steps for a workflow.

get_workflow_steps_for_position(*args, **kwargs)[source]

Retrieve a list of analyzers corresponding to current cell in the portlets grid. Will be used for deciding the interface.

get_workflows_for_burst(*args, **kwargs)[source]

Returns all the workflows that were launched for this burst id

session = < object at 0x7f375af503d0>