Package cjklib :: Module build :: Class DatabaseBuilder
[hide private]
[frames] | no frames]

Class DatabaseBuilder

source code

DatabaseBuilder provides the main class for building up a database for the cjklib package.

It contains all TableBuilder classes and a dependency graph to handle build requests.

Instance Methods [hide private]
 
__init__(self, databaseSettings={}, dbConnectInst=None, dataPath=[], quiet=False, rebuildDepending=True, rebuildExisting=True, noFail=False, prefer=[], additionalBuilders=[])
Constructs the DatabaseBuilder.
source code
 
setDataPath(self, dataPath)
Changes the data path.
source code
 
build(self, tables)
Builds the given tables.
source code
 
remove(self, tables)
Removes the given tables.
source code
bool
needsRebuild(self, tableName)
Returns true if either rebuild is turned on by default or we build into database and the table doesn't exist yet.
source code
list of str
getBuildDependentTables(self, tableNames)
Gets the name of the tables that needs to be built to resolve dependencies.
source code
list of str
getDependingTables(self, tableNames)
Gets the name of the tables that depend on the given tables to be built and are not included in the given set.
source code
list of str
getRebuiltDependingTables(self, tableNames)
Gets the name of the tables that depend on the given tables to be built and already exist, thus need to be rebuilt.
source code
list of classobj
getClassesInBuildOrder(self, tableNames)
Gets the build order for the given table names.
source code
list of str
getCurrentSupportedTables(self)
Gets names of tables supported by this instance of the database builder.
source code
boolean
isOptimizable(self)
Checks if the current database supports optimization.
source code
 
optimize(self)
Optimizes the current database.
source code
Static Methods [hide private]
list of classobj
getBuildDependencyOrder(tableBuilderClasses)
Create order in which the tables have to be created.
source code
dict
getTableBuilderClasses(preferClassSet=set([]), resolveConflicts=True, quiet=True, additionalBuilders=[])
Gets all classes in module that implement TableBuilder.
source code
list of str
getSupportedTables()
Gets names of supported tables.
source code
Method Details [hide private]

__init__(self, databaseSettings={}, dbConnectInst=None, dataPath=[], quiet=False, rebuildDepending=True, rebuildExisting=True, noFail=False, prefer=[], additionalBuilders=[])
(Constructor)

source code 

Constructs the DatabaseBuilder.

Parameters:
  • databaseSettings (dict) - dictionary holding the database options for the dbconnector module.
  • dbConnectInst (instance) - instance of a DatabaseConnector
  • dataPath (list of str) - optional list of paths to the data file(s)
  • quiet (bool) - if true no status information will be printed to stderr
  • rebuildDepending (bool) - if true existing tables that depend on updated tables will be dropped and built from scratch
  • rebuildExisting (bool) - if true existing tables will be dropped and built from scratch
  • noFail (bool) - if true build process won't terminate even if one table fails to build
  • prefer (list) - list of TableBuilder names to prefer in conflicting cases
  • additionalBuilders (list of classobj) - list of externally provided TableBuilders

setDataPath(self, dataPath)

source code 

Changes the data path.

Parameters:
  • dataPath (list of str) - list of paths to the data file(s)

build(self, tables)

source code 

Builds the given tables.

Parameters:
  • tables (list) - list of tables to build

remove(self, tables)

source code 

Removes the given tables.

Parameters:
  • tables (list) - list of tables to remove

needsRebuild(self, tableName)

source code 

Returns true if either rebuild is turned on by default or we build into database and the table doesn't exist yet.

Parameters:
Returns: bool
True, if table needs to be rebuilt

getBuildDependentTables(self, tableNames)

source code 

Gets the name of the tables that needs to be built to resolve dependencies.

Parameters:
  • tableNames (list of str) - list of tables to build
Returns: list of str
names of tables needed to resolve dependencies

getDependingTables(self, tableNames)

source code 

Gets the name of the tables that depend on the given tables to be built and are not included in the given set.

Dependencies depend on the choice of table builders and thus may vary.

Parameters:
  • tableNames (list of str) - list of tables
Returns: list of str
names of tables that depend on given tables

getRebuiltDependingTables(self, tableNames)

source code 

Gets the name of the tables that depend on the given tables to be built and already exist, thus need to be rebuilt.

Parameters:
  • tableNames (list of str) - list of tables
Returns: list of str
names of tables that need to be rebuilt because of dependencies

getClassesInBuildOrder(self, tableNames)

source code 

Gets the build order for the given table names.

Parameters:
  • tableNames (list of str) - list of names of tables to build
Returns: list of classobj
TableBuilders in build order

getBuildDependencyOrder(tableBuilderClasses)
Static Method

source code 

Create order in which the tables have to be created.

Parameters:
  • tableBuilderClasses (list of classobj) - list of TableBuilder classes
Returns: list of classobj
the given classes ordered in build dependency order

getTableBuilderClasses(preferClassSet=set([]), resolveConflicts=True, quiet=True, additionalBuilders=[])
Static Method

source code 

Gets all classes in module that implement TableBuilder.

Parameters:
  • preferClassSet (set of str) - set of TableBuilder names to prefer in conflicting cases, resolveConflicting must be True to take effect (default)
  • resolveConflicts (bool) - if true conflicting builders will be removed so that only one builder is left per Table.
  • quiet (bool) - if true no status information will be printed to stderr
  • additionalBuilders (list of classobj) - list of externally provided TableBuilders
Returns: dict
dictionary of all classes inheriting form TableBuilder that provide a table (i.d. non abstract implementations), with its name as key

getSupportedTables()
Static Method

source code 

Gets names of supported tables.

Returns: list of str
names of tables

getCurrentSupportedTables(self)

source code 

Gets names of tables supported by this instance of the database builder.

This list can have more entries then getSupportedTables() as additional external builders can be supplied on instantiation.

Returns: list of str
names of tables

isOptimizable(self)

source code 

Checks if the current database supports optimization.

Returns: boolean
True if optimizable, False otherwise

optimize(self)

source code 

Optimizes the current database.

Raises:
  • Exception - if database does not support optimization
  • OperationalError - if optimization failed