org.opensubsystems.inventory.persist.db
Class CategoryDatabaseSchema

java.lang.Object
  extended by org.opensubsystems.core.persist.db.DatabaseSchemaImpl
      extended by org.opensubsystems.core.persist.db.ModifiableDatabaseSchemaImpl
          extended by org.opensubsystems.patterns.listdata.persist.db.impl.ModifiableListDatabaseSchemaImpl
              extended by org.opensubsystems.inventory.persist.db.CategoryDatabaseSchema
All Implemented Interfaces:
org.opensubsystems.core.persist.db.DatabaseOperations, org.opensubsystems.core.persist.db.DatabaseSchema, org.opensubsystems.core.persist.db.ModifiableDatabaseSchema, org.opensubsystems.patterns.listdata.persist.db.ListDatabaseSchema
Direct Known Subclasses:
DB2CategoryDatabaseSchema, HsqlDBCategoryDatabaseSchema, MSSQLCategoryDatabaseSchema, MySQLCategoryDatabaseSchema, OracleCategoryDatabaseSchema, PostgreSQLCategoryDatabaseSchema, SapDBCategoryDatabaseSchema, SybaseCategoryDatabaseSchema

public abstract class CategoryDatabaseSchema
extends org.opensubsystems.patterns.listdata.persist.db.impl.ModifiableListDatabaseSchemaImpl

Database specific operations related to persistence of categories.

Version:
$Id: CategoryDatabaseSchema.java,v 1.22 2007/01/12 06:19:45 bastafidli Exp $
Author:
Martin Cerba
Code reviewer:
Miro Halas
Code reviewed:
1.10 2006/01/07 01:30:18 jlegeny

Field Summary
static int CATEGORY_DESCRIPTION_MAXLENGTH
          Maximal length of category description.
static int[] CATEGORY_MANDATORY_RETRIEVE_COLUMNS
          Columns which always have to be retrieved from the database
static int CATEGORY_NAME_MAXLENGTH
          Maximal length of category name.
static java.lang.String CATEGORY_SCHEMA_NAME
          Name identifies this schema in the database.
static int CATEGORY_SCHEMA_VERSION
          Version of this schema in the database.
static int[] CATEGORY_SORT_COLUMNS
          Static variable for array of all columns codes that can be used for sorting.
 
Fields inherited from class org.opensubsystems.patterns.listdata.persist.db.impl.ModifiableListDatabaseSchemaImpl
m_mapFilterableColumns, m_mapListableTableNames, m_mapMandatoryRetrieveColumns, m_mapSortableColumns
 
Fields inherited from class org.opensubsystems.core.persist.db.ModifiableDatabaseSchemaImpl
m_mapModifiableTableNames
 
Fields inherited from class org.opensubsystems.core.persist.db.DatabaseSchemaImpl
DATABASE_SCHEMA_PREFIX, DATABASE_SCHEMA_PREFIX_DEFAULT, m_arrDependentSchemas, m_bIsInDomain, m_iSchemaVersion, m_strSchemaName, NL
 
Fields inherited from interface org.opensubsystems.core.persist.db.DatabaseOperations
DBOP_DELETE, DBOP_INSERT, DBOP_SELECT, DBOP_UPDATE
 
Constructor Summary
CategoryDatabaseSchema()
          Default constructor.
 
Method Summary
 void createListIndexes(java.sql.Connection cntDBConnection)
          Method creates specified LST indexes used for speeding up retrieving data into the list.
 int delete(java.sql.Connection dbConnection, int iId, int iDomainId)
          Delete category with specified id.
protected  int deleteList(java.sql.Connection dbConnection, java.util.List lstIds, int iDomainId, org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
          Delete all category records specified within the list.
protected  int deleteRecursiveCategories(java.sql.Connection dbConnection, java.util.List lstIds, int iDomainId, int iDeleted, org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
          Recursive delete all categories by IDs specified in the list.
 int deleteRoot(java.sql.Connection dbConnection, int iId, int iDomainId, org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
          Delete category and all its subcategories.
 int deleteRoots(java.sql.Connection dbConnection, int[] arrIds, int iDomainId, org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
          Delete multiple categories and its subcategories.
 java.lang.StringBuffer getColumns(boolean specific, int[] columns, java.lang.Object[] prefixes, java.lang.Object[] postfixes, java.lang.StringBuffer buffer)
          
protected  java.lang.String getDeleteCategoriesCascade(int[] arrIds, org.opensubsystems.patterns.listdata.data.SimpleRule secData)
          Get query to cascade delete more categories and all belonging subcategories.
 java.lang.String getDeleteCategoryById()
          Get query to delete particular category.
protected  java.lang.String getDeleteCategoryCascade(org.opensubsystems.patterns.listdata.data.SimpleRule secData)
          Get query to cascade delete category and all its subcategories.
 java.lang.String getInsertCategory()
          Method returns simple insert category query.
abstract  java.lang.String getInsertCategoryAndFetchGeneratedValues()
          Get query that inserts a category to the database and fetches database generated values such as the generated id and creation timestamp
 java.lang.String getSelectActualCategoryCount(int[] arrIds)
          Get query to retrieve count of categories which still exists.
 java.lang.String getSelectCategoryById(int[] columns)
          Get query to select category by ID.
 java.lang.String getSelectCategoryByParentIdAndName(int[] columns, int parentId)
          Get query to select category by parent ID and name.
 java.lang.String getSelectCategoryCount()
          Get number of subcategories for the specified category
protected  java.lang.String getSelectCategoryExist(Category cCategory)
          Get sql query to find out if specified category exists.
protected  java.util.List getSelectCategoryIDsForMoreParents(java.sql.Connection dbConnection, java.util.List lstParentIDs, int iDomainId)
          Get all category ids belonging to the specified parents.
protected  java.util.List getSelectCategoryIDsForParent(java.sql.Connection dbConnection, int iParentId, int iDomainId)
          Get all category ids belonging to the specified parent.
abstract  java.lang.String getUpdateCategoryAndFetchGeneratedValues()
          Get query that updates category in the database and fetches database generated values such as the updated modification timestamp
 void handleSQLException(java.sql.SQLException exc, java.sql.Connection dbConnection, int iOperationType, int iDataType, java.lang.Object data)
          
 
Methods inherited from class org.opensubsystems.patterns.listdata.persist.db.impl.ModifiableListDatabaseSchemaImpl
getFilterbleColumns, getMandatoryRetrieveColumns, getSelectList, getSortableColumns
 
Methods inherited from class org.opensubsystems.core.persist.db.ModifiableDatabaseSchemaImpl
deleteRelatedData, getModifiableTableNames
 
Methods inherited from class org.opensubsystems.core.persist.db.DatabaseSchemaImpl
getDependentSchemas, getJoinFromWhere, getName, getOwnerColumnNames, getSchemaPrefix, getVersion, isExistingIndex, isInDomain, upgrade, upgradeView
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensubsystems.patterns.listdata.persist.db.ListDatabaseSchema
getJoinFromWhere, isExistingIndex
 
Methods inherited from interface org.opensubsystems.core.persist.db.DatabaseSchema
create, getDependentSchemas, getName, getVersion, isInDomain, upgrade
 

Field Detail

CATEGORY_SCHEMA_NAME

public static final java.lang.String CATEGORY_SCHEMA_NAME
Name identifies this schema in the database.

See Also:
Constant Field Values

CATEGORY_SCHEMA_VERSION

public static final int CATEGORY_SCHEMA_VERSION
Version of this schema in the database.

See Also:
Constant Field Values

CATEGORY_MANDATORY_RETRIEVE_COLUMNS

public static final int[] CATEGORY_MANDATORY_RETRIEVE_COLUMNS
Columns which always have to be retrieved from the database


CATEGORY_SORT_COLUMNS

public static final int[] CATEGORY_SORT_COLUMNS
Static variable for array of all columns codes that can be used for sorting.


CATEGORY_NAME_MAXLENGTH

public static final int CATEGORY_NAME_MAXLENGTH
Maximal length of category name.

See Also:
Constant Field Values

CATEGORY_DESCRIPTION_MAXLENGTH

public static final int CATEGORY_DESCRIPTION_MAXLENGTH
Maximal length of category description.

See Also:
Constant Field Values
Constructor Detail

CategoryDatabaseSchema

public CategoryDatabaseSchema()
                       throws org.opensubsystems.core.error.OSSException
Default constructor.

Throws:
org.opensubsystems.core.error.OSSException - - error occured.
Method Detail

getInsertCategoryAndFetchGeneratedValues

public abstract java.lang.String getInsertCategoryAndFetchGeneratedValues()
                                                                   throws org.opensubsystems.core.error.OSSException
Get query that inserts a category to the database and fetches database generated values such as the generated id and creation timestamp

Returns:
String - query for simple insert or stored procedure call
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getUpdateCategoryAndFetchGeneratedValues

public abstract java.lang.String getUpdateCategoryAndFetchGeneratedValues()
                                                                   throws org.opensubsystems.core.error.OSSException
Get query that updates category in the database and fetches database generated values such as the updated modification timestamp

Returns:
String - query for simple update or stored procedure call
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getInsertCategory

public java.lang.String getInsertCategory()
                                   throws org.opensubsystems.core.error.OSSException
Method returns simple insert category query. This method is common for all databases and can be overwritten for each specific database schema.

Returns:
String - simple insert category query
Throws:
org.opensubsystems.core.error.OSSException - - exception during getting query

createListIndexes

public void createListIndexes(java.sql.Connection cntDBConnection)
                       throws java.sql.SQLException,
                              org.opensubsystems.core.error.OSSException
Method creates specified LST indexes used for speeding up retrieving data into the list.

Parameters:
cntDBConnection - - valid connection to database
Throws:
java.sql.SQLException - - problem creating the database schema
org.opensubsystems.core.error.OSSException - - problem creating the database schema

delete

public int delete(java.sql.Connection dbConnection,
                  int iId,
                  int iDomainId)
           throws org.opensubsystems.core.error.OSSException,
                  java.sql.SQLException
Delete category with specified id. This method doesn't attempt automatically delete all subcategories of the specified category and these will be also deleted only if the database supports cascade delete, if the database doesn't support cascade delete then an exception will occur.

Parameters:
dbConnection - - database connection
iId - - id of the category that have to be deleted together with all its subcategories
iDomainId - - domain id the deleted data belongs to
Returns:
int - number of deleted categories
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
java.sql.SQLException - - an error has occured

deleteRoot

public int deleteRoot(java.sql.Connection dbConnection,
                      int iId,
                      int iDomainId,
                      org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
               throws org.opensubsystems.core.error.OSSException,
                      java.sql.SQLException
Delete category and all its subcategories. This method should delete all subcategories of the specified category. These will be also deleted only if the database supports cascade delete, if the database doesn't support cascade delete this method should be overriden for specific database.

Parameters:
dbConnection - - database connection
iId - - data id that will be deleted
iDomainId - - domain id the deleted data belongs to
listSecurityData - - security data describing what data can be deleted
Returns:
int - number of deleted categories
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
java.sql.SQLException - - an error has occured

deleteRoots

public int deleteRoots(java.sql.Connection dbConnection,
                       int[] arrIds,
                       int iDomainId,
                       org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
                throws org.opensubsystems.core.error.OSSException,
                       java.sql.SQLException
Delete multiple categories and its subcategories. This method should delete all subcategories of the specified categories. These will be also deleted only if the database supports cascade delete, if the database doesn't support cascade delete this method should be overriden for specific database.

Parameters:
dbConnection - - database connection
arrIds - - array of data ids that will be deleted
iDomainId - - domain id the deleted data belongs to
listSecurityData - - security data describing what data can be deleted
Returns:
int - number of deleted categories
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
java.sql.SQLException - - an error has occured

getSelectCategoryById

public java.lang.String getSelectCategoryById(int[] columns)
                                       throws org.opensubsystems.core.error.OSSException
Get query to select category by ID.

Parameters:
columns - - columns to retrieve
Returns:
String - query
Throws:
org.opensubsystems.core.error.OSSException - - and error has occured

getSelectCategoryByParentIdAndName

public java.lang.String getSelectCategoryByParentIdAndName(int[] columns,
                                                           int parentId)
                                                    throws org.opensubsystems.core.error.OSSException
Get query to select category by parent ID and name.

Parameters:
columns - - list of columns to retrieve
parentId - - ID of the parent
Returns:
String - query
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getDeleteCategoryById

public java.lang.String getDeleteCategoryById()
Get query to delete particular category.

Returns:
String - query

getSelectCategoryCount

public java.lang.String getSelectCategoryCount()
                                        throws org.opensubsystems.core.error.OSSException
Get number of subcategories for the specified category

Returns:
String - query
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getSelectActualCategoryCount

public java.lang.String getSelectActualCategoryCount(int[] arrIds)
                                              throws org.opensubsystems.core.error.OSSException
Get query to retrieve count of categories which still exists.

Parameters:
arrIds - - array of category IDs
Returns:
String - query
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getColumns

public java.lang.StringBuffer getColumns(boolean specific,
                                         int[] columns,
                                         java.lang.Object[] prefixes,
                                         java.lang.Object[] postfixes,
                                         java.lang.StringBuffer buffer)
                                  throws org.opensubsystems.core.error.OSSException

Throws:
org.opensubsystems.core.error.OSSException

handleSQLException

public void handleSQLException(java.sql.SQLException exc,
                               java.sql.Connection dbConnection,
                               int iOperationType,
                               int iDataType,
                               java.lang.Object data)
                        throws org.opensubsystems.core.error.OSSException

Specified by:
handleSQLException in interface org.opensubsystems.core.persist.db.DatabaseSchema
Overrides:
handleSQLException in class org.opensubsystems.core.persist.db.ModifiableDatabaseSchemaImpl
Throws:
org.opensubsystems.core.error.OSSException

getSelectCategoryExist

protected java.lang.String getSelectCategoryExist(Category cCategory)
                                           throws org.opensubsystems.core.error.OSSException
Get sql query to find out if specified category exists.

Parameters:
cCategory - - category object
Returns:
String - constructed sql query
Throws:
org.opensubsystems.core.error.OSSException - - error occured during constructing query

getSelectCategoryIDsForParent

protected java.util.List getSelectCategoryIDsForParent(java.sql.Connection dbConnection,
                                                       int iParentId,
                                                       int iDomainId)
                                                throws org.opensubsystems.core.error.OSSException,
                                                       java.sql.SQLException
Get all category ids belonging to the specified parent. This method is used within the redefined deleteRoot() method within XXXCategoryDatabaseSchema. It is used to ensure manual cascade delete.

Parameters:
dbConnection - - database connection
iParentId - - ID of the parent
iDomainId - - domain ID the deleted data belongs to
Returns:
List - list of category IDs belonging to the parent ID
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
java.sql.SQLException - - an error has occured

getSelectCategoryIDsForMoreParents

protected java.util.List getSelectCategoryIDsForMoreParents(java.sql.Connection dbConnection,
                                                            java.util.List lstParentIDs,
                                                            int iDomainId)
                                                     throws org.opensubsystems.core.error.OSSException,
                                                            java.sql.SQLException
Get all category ids belonging to the specified parents. This method is used within the redefined delete() method within XXXCategoryDatabaseSchema. It is used to ensure manual cascade delete.

Parameters:
dbConnection - - database connection
lstParentIDs - - list of parent IDs
iDomainId - - domain ID the deleted data belongs to
Returns:
List - list of category IDs belonging to the parent ID
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
java.sql.SQLException - - an error has occured

getDeleteCategoryCascade

protected java.lang.String getDeleteCategoryCascade(org.opensubsystems.patterns.listdata.data.SimpleRule secData)
                                             throws org.opensubsystems.core.error.OSSException
Get query to cascade delete category and all its subcategories.

Parameters:
secData - - security data
Returns:
String - query
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getDeleteCategoriesCascade

protected java.lang.String getDeleteCategoriesCascade(int[] arrIds,
                                                      org.opensubsystems.patterns.listdata.data.SimpleRule secData)
                                               throws org.opensubsystems.core.error.OSSException
Get query to cascade delete more categories and all belonging subcategories. There will be alse chcecked rights

Parameters:
arrIds - - category ids that have to be deleted
secData - - security data
Returns:
String - query
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

deleteList

protected int deleteList(java.sql.Connection dbConnection,
                         java.util.List lstIds,
                         int iDomainId,
                         org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
                  throws org.opensubsystems.core.error.OSSException,
                         java.sql.SQLException
Delete all category records specified within the list.

Parameters:
dbConnection - - database connection
lstIds - - list of IDs that have to be deleted
iDomainId - - domain ID the deleted data belongs to
listSecurityData - - security data describing what data can be retrieved
Returns:
int - number of deleted categories
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
java.sql.SQLException - - an error has occured

deleteRecursiveCategories

protected int deleteRecursiveCategories(java.sql.Connection dbConnection,
                                        java.util.List lstIds,
                                        int iDomainId,
                                        int iDeleted,
                                        org.opensubsystems.patterns.listdata.data.SimpleRule listSecurityData)
                                 throws org.opensubsystems.core.error.OSSException,
                                        java.sql.SQLException
Recursive delete all categories by IDs specified in the list.

Parameters:
dbConnection - - database connection
lstIds - - list of data IDs that have to be deleted
iDomainId - - domain ID the deleted data belongs to
iDeleted - - number of alreade deleted items
listSecurityData - - security data describing what data can be retrieved
Returns:
int - number of deleted categories
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
java.sql.SQLException - - an error has occured


Copyright © 2003 - 2006 OpenSubsystems s.r.o.