2.17.2: 2011-06-17

net.sf.basedb.core
Class VirtualDb

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<D>
      extended by net.sf.basedb.core.ChildItem<VirtualDbData>
          extended by net.sf.basedb.core.VirtualDb
All Implemented Interfaces:
AccessControlled, Identifiable

public class VirtualDb
extends ChildItem<VirtualDbData>

A virtual database represents the set of tables in the dynamic database used by a single experiment to store it's analysed data.

This class is not intended to be exposed to client applications. It is only used internally to handle the creation and deletion of the tables in the dynamic database.

The names of the dynamic tables depends on the ID of this object. The name is generated by the VirtualTable enumeration.

Version:
2.0
Author:
Nicklas
See Also:
VirtualTable, VirtualColumn
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Field Summary
private static boolean debugSqlEnabled
          So we don't always have to call logSql.debug()
private static Logger logSql
          Log all SQL statements.
static Item TYPE
          The type of item represented by this class.
 
Constructor Summary
VirtualDb(VirtualDbData data)
          Creates a new experiment item from the given data.
 
Method Summary
(package private)  void createTables(VirtualTable... tables)
          Create the real database tables for this virtual database.
(package private)  int deleteAllCubeData(short cubeNo)
          Delete all analysed data for the specified data cube.
(package private)  int deleteAllCubeExtraValueData(short cubeNo, short extraNo, VirtualTable extraTable)
          Delete all extra value data for the specified extra value type in the specified data cube.
(package private)  int deleteAllCubeFilterData(short cubeNo, short filterNo)
          Delete all analysed data for the specified filter in the specified data cube.
(package private)  int deleteAllCubeLayerData(short cubeNo, short layerNo)
          Delete all analysed data for the specified layer in the specified data cube.
private  void dropAllTables()
          Drop all real database tables in this virtual database.
(package private) static VirtualDb getById(DbControl dc, int id)
          Get a VirtualDb item when you know the id.
 short getCubes()
          Get the number of DataCube:s in this virtual database.
 Experiment getExperiment()
          Get the experiment this set of tables stores data for.
 short getMappings()
          Get the number of DataCubeMapping:s in this virtual database.
(package private) static VirtualDb getNew(DbControl dc)
          Create a new DynamicTables item.
(package private)  short getNextCubeNo()
          Generate the next available cube number.
(package private)  Permission getPermissionForWriteDeleteAndCreate()
          USE permission is enough to be able to manage virtual db.
 RawDataType getRawDataType()
          Get the raw data type the experiment uses for the raw data.
(package private)  SharedData getSharedParent()
          Get the experiment.
 Item getType()
          Get the type of item represented by the object.
 boolean hasTable(VirtualTable table)
          Check if a real database table for this virtual database exists.
(package private)  DataCube newDataCube()
          Create a new data cube in this virtual database.
(package private)  void onAfterCommit(Transactional.Action action)
          Remove all dynamic tables if action == Action.DELETE
 
Methods inherited from class net.sf.basedb.core.ChildItem
getPluginPermissions, initPermissions
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logSql

private static final Logger logSql
Log all SQL statements.


debugSqlEnabled

private static final boolean debugSqlEnabled
So we don't always have to call logSql.debug()


TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.VIRTUALDB, getType()
Constructor Detail

VirtualDb

VirtualDb(VirtualDbData data)
Creates a new experiment item from the given data.

Parameters:
data - the data
Method Detail

getNew

static VirtualDb getNew(DbControl dc)
                 throws BaseException
Create a new DynamicTables item.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
Returns:
The new DynamicTables item
Throws:
BaseException - If there is an error

getById

static VirtualDb getById(DbControl dc,
                         int id)
                  throws ItemNotFoundException,
                         PermissionDeniedException,
                         BaseException
Get a VirtualDb item when you know the id.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The id of the item to load
Returns:
The VirtualDb item
Throws:
ItemNotFoundException - If an item with the specified id is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item

onAfterCommit

void onAfterCommit(Transactional.Action action)
Remove all dynamic tables if action == Action.DELETE

Overrides:
onAfterCommit in class BasicItem<VirtualDbData>
See Also:
Transactional, Core API overview - Transaction handling, Coding rules and guidelines for item classes

getSharedParent

SharedData getSharedParent()
Get the experiment.

Specified by:
getSharedParent in class ChildItem<VirtualDbData>
Returns:
The parent item

getPermissionForWriteDeleteAndCreate

Permission getPermissionForWriteDeleteAndCreate()
USE permission is enough to be able to manage virtual db.

Overrides:
getPermissionForWriteDeleteAndCreate in class ChildItem<VirtualDbData>

getRawDataType

public RawDataType getRawDataType()
Get the raw data type the experiment uses for the raw data.

Returns:
A RawDataType object

getExperiment

public Experiment getExperiment()
                         throws PermissionDeniedException,
                                BaseException
Get the experiment this set of tables stores data for.

Returns:
An Experiment object
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission to the experiment
BaseException - If there is another error

getCubes

public short getCubes()
Get the number of DataCube:s in this virtual database. Each new data cube increases this value with one.


getNextCubeNo

short getNextCubeNo()
              throws BaseException
Generate the next available cube number. This method will open a second transaction and update the getCubes() property by one.

Returns:
The next cube number
Throws:
BaseException

getMappings

public short getMappings()
Get the number of DataCubeMapping:s in this virtual database. Each new mapping increases this value with one.


newDataCube

DataCube newDataCube()
               throws PermissionDeniedException,
                      BaseException
Create a new data cube in this virtual database. The number of the new data cube will be one more than the current value of getCubes().

Throws:
PermissionDeniedException
BaseException

createTables

void createTables(VirtualTable... tables)
            throws BaseException
Create the real database tables for this virtual database. The table is created by first building a Hibernate mapping structure and then using Hibernate to generate the SQL that is needed.

Parameters:
tables - The tables to create
Throws:
BaseException
See Also:
HibernateUtil.createVirtualTable(VirtualDb, VirtualTable)

hasTable

public boolean hasTable(VirtualTable table)
                 throws BaseException
Check if a real database table for this virtual database exists.

Parameters:
table - The table to check
Returns:
TRUE if database table exists, FALSE otherwise
Throws:
BaseException - If there is some kind of error.
See Also:
HibernateUtil.virtualTableExists(VirtualDb, VirtualTable)

dropAllTables

private void dropAllTables()
                    throws BaseException
Drop all real database tables in this virtual database. The tables are deleted by first building a Hibernate mapping structure and then using Hibernate to generate the SQL that is needed.

Throws:
BaseException
See Also:
HibernateUtil.dropVirtualTable(VirtualDb, VirtualTable)

deleteAllCubeData

int deleteAllCubeData(short cubeNo)
                throws BaseException
Delete all analysed data for the specified data cube.

Parameters:
cubeNo - The number of the cube
Returns:
The number of deleted rows
Throws:
BaseException
See Also:
DataCube.onBeforeCommit(Transactional.Action)

deleteAllCubeLayerData

int deleteAllCubeLayerData(short cubeNo,
                           short layerNo)
                     throws BaseException
Delete all analysed data for the specified layer in the specified data cube.

Parameters:
cubeNo - The number of the cube
layerNo - The number of the layer
Returns:
The number of deleted rows
Throws:
BaseException
See Also:
DataCubeLayer.onBeforeCommit(Transactional.Action)

deleteAllCubeFilterData

int deleteAllCubeFilterData(short cubeNo,
                            short filterNo)
                      throws BaseException
Delete all analysed data for the specified filter in the specified data cube.

Parameters:
cubeNo - The number of the cube
filterNo - The number of the filter
Returns:
The number of deleted rows
Throws:
BaseException
See Also:
DataCubeFilter.onBeforeCommit(Transactional.Action)

deleteAllCubeExtraValueData

int deleteAllCubeExtraValueData(short cubeNo,
                                short extraNo,
                                VirtualTable extraTable)
                          throws BaseException
Delete all extra value data for the specified extra value type in the specified data cube.

Parameters:
cubeNo - The number of the cube
extraNo - The number of the extra value type
Returns:
The number of deleted rows
Throws:
BaseException
See Also:
DataCubeExtraValue.onBeforeCommit(Transactional.Action)

2.17.2: 2011-06-17