org.opensubsystems.core.persist.db
Class DatabaseSchemaImpl

java.lang.Object
  extended by org.opensubsystems.core.persist.db.DatabaseSchemaImpl
All Implemented Interfaces:
DatabaseOperations, DatabaseSchema
Direct Known Subclasses:
ModifiableDatabaseSchemaImpl, VersionedDatabaseSchema

public abstract class DatabaseSchemaImpl
extends java.lang.Object
implements DatabaseSchema, DatabaseOperations

Base class implementation for database schemas that provides the common functionality needed by all schemas that allow to read data from the tables managed by this schema.

Version:
$Id: DatabaseSchemaImpl.java,v 1.25 2007/01/10 05:11:33 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.16 2006/07/21 22:47:52 jlegeny

Field Summary
static java.lang.String DATABASE_SCHEMA_PREFIX
          Name of the property that can specify default prefix to use for database objects.
static java.lang.String DATABASE_SCHEMA_PREFIX_DEFAULT
          Default prefix to use for database objects.
protected  DatabaseSchema[] m_arrDependentSchemas
          Array of dependent schemas.
protected  boolean m_bIsInDomain
          Flag signaling if object is in domain.
protected  int m_iSchemaVersion
          Version of the schema.
protected  java.lang.String m_strSchemaName
          Name of the schema.
static java.lang.String NL
          New line constant which should be used when creating any table or stored procedure in the database.
 
Fields inherited from interface org.opensubsystems.core.persist.db.DatabaseOperations
DBOP_DELETE, DBOP_INSERT, DBOP_SELECT, DBOP_UPDATE
 
Constructor Summary
DatabaseSchemaImpl(DatabaseSchema[] arrDependentSchemas, java.lang.String strSchemaName, int iSchemaVersion, boolean bIsInDomain)
          Constructor allowing to specify attributes for database schema that doesn't provide any operations that would modify any of the tables it is accessing.
 
Method Summary
 DatabaseSchema[] getDependentSchemas()
          Get list of database schemas which this schema depends on.
 java.lang.String[] getJoinFromWhere(java.util.List conditions, int[] columns)
          Create SQL query fragments, which can be used to create database join between multiple database tables.
 java.lang.String getName()
          Get the name of this database schema.
protected  java.lang.String[] getOwnerColumnNames()
          Deprecated.  
static java.lang.String getSchemaPrefix()
          Get prefix which should be used to construct database objects.
 int getVersion()
          Get the current (most recent) version of database schema.
 void handleSQLException(java.sql.SQLException exc, java.sql.Connection dbConnection, int iOperationType, int iDataType, java.lang.Object data)
          Handle SQL Exception caused by some database operations.
 boolean isExistingIndex(java.lang.String strIndexName)
          Check if index with the specified name exists within this schema.
 boolean isInDomain()
          Check if the the data object belongs to a domain or not.
 void upgrade(java.sql.Connection cntDBConnection, java.lang.String strUserName, int iOriginalVersion)
          Upgrade the schema.
protected  void upgradeView(java.sql.Connection cntDBConnection, java.lang.String strUserName, int iOriginalVersion, java.lang.String strViewName)
          Upgrade the view by dropping it and recreating it again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensubsystems.core.persist.db.DatabaseSchema
create
 

Field Detail

DATABASE_SCHEMA_PREFIX

public static final java.lang.String DATABASE_SCHEMA_PREFIX
Name of the property that can specify default prefix to use for database objects.

See Also:
Constant Field Values

DATABASE_SCHEMA_PREFIX_DEFAULT

public static final java.lang.String DATABASE_SCHEMA_PREFIX_DEFAULT
Default prefix to use for database objects.

See Also:
Constant Field Values

NL

public static final java.lang.String NL
New line constant which should be used when creating any table or stored procedure in the database. We can reverse engineer them from database e.g. using CaseStudio but if they do not contain new lines then they appear as single long string and it is impossible to find out what has changed.

See Also:
Constant Field Values

m_arrDependentSchemas

protected DatabaseSchema[] m_arrDependentSchemas
Array of dependent schemas.


m_strSchemaName

protected java.lang.String m_strSchemaName
Name of the schema.


m_iSchemaVersion

protected int m_iSchemaVersion
Version of the schema.


m_bIsInDomain

protected boolean m_bIsInDomain
Flag signaling if object is in domain.

Constructor Detail

DatabaseSchemaImpl

public DatabaseSchemaImpl(DatabaseSchema[] arrDependentSchemas,
                          java.lang.String strSchemaName,
                          int iSchemaVersion,
                          boolean bIsInDomain)
                   throws OSSException
Constructor allowing to specify attributes for database schema that doesn't provide any operations that would modify any of the tables it is accessing.

Parameters:
arrDependentSchemas - - array of dependent schemas
strSchemaName - - name of the schema
iSchemaVersion - - version of the schema
bIsInDomain - - flag signaling if object is in domain
Throws:
OSSException - - an error has occured
Method Detail

upgrade

public void upgrade(java.sql.Connection cntDBConnection,
                    java.lang.String strUserName,
                    int iOriginalVersion)
             throws java.sql.SQLException
Upgrade the schema.

Specified by:
upgrade in interface DatabaseSchema
Parameters:
cntDBConnection - - valid connection to database
strUserName - - name of user who will be accessing this table
iOriginalVersion - - original version from which to upgrade
Throws:
java.sql.SQLException - - problem creating the database schema

getJoinFromWhere

public java.lang.String[] getJoinFromWhere(java.util.List conditions,
                                           int[] columns)
Create SQL query fragments, which can be used to create database join between multiple database tables. This is convenience implementation since most data objects do not cross multiple tables.

Parameters:
conditions - - list of DataConditions, which may represent search criterias in multiple tables which may need to be joined
columns - - columns we are trying to retrieve
Returns:
String[] - index 0 - comma separated tables to add to from - index 1 - join conditions to add to where using and - or null if no extra joins are necessary

isExistingIndex

public boolean isExistingIndex(java.lang.String strIndexName)
Check if index with the specified name exists within this schema. If this index exists it can be used for constructing querie to retrieve records. This is convenience implementation since most data objects do not need special indexes for their queries.

Parameters:
strIndexName - - name of the index existency of which we want to check
Returns:
boolean - true if the index with that name exists in this schema and can be used to speed up queries

getSchemaPrefix

public static java.lang.String getSchemaPrefix()
Get prefix which should be used to construct database objects.

Returns:
String - prefix to use for database objects.

upgradeView

protected void upgradeView(java.sql.Connection cntDBConnection,
                           java.lang.String strUserName,
                           int iOriginalVersion,
                           java.lang.String strViewName)
                    throws java.sql.SQLException,
                           OSSException
Upgrade the view by dropping it and recreating it again. Developer has to make sure that no view depends on it since the depending view will be dropped too. This method works if the schema contain only a single view.

Parameters:
cntDBConnection - - valid connection to database
strUserName - - name of user who will be accessing this table
iOriginalVersion - - original version from which to upgrade
strViewName - - view to upgrade
Throws:
java.sql.SQLException - - problem creating the database schema
OSSException - - problem creating the database schema

getOwnerColumnNames

protected final java.lang.String[] getOwnerColumnNames()
Deprecated. 

This method will return array of names of all columns which represents owner column. These columns will be checked for Current User Id in case of OWNED security data condition.

Returns:
String[] - array of Column Name which represents owner

isInDomain

public boolean isInDomain()
Check if the the data object belongs to a domain or not. If data object belongs to a domain, its table contains DOMAIN_ID column, which should be checked in generated SQL for this data type against the current call context domain. The assumption is that if the schema is managing multiple data objects and one of them is in domain then all of them are in domain (and vice versa) since it doesn't make sense for closely related data objects to do not exists in the same domain at the same time.

Specified by:
isInDomain in interface DatabaseSchema
Returns:
boolean - true if data object belongs to domain, false otherwise

getDependentSchemas

public DatabaseSchema[] getDependentSchemas()
                                     throws OSSException
Get list of database schemas which this schema depends on. These schemas will be created and initialized before this schema is initialized. This way if this schema has relationships (foreign keys, stored procedure access) with the other schemas, they are guaranteed to exist before this schema is created.

Specified by:
getDependentSchemas in interface DatabaseSchema
Returns:
DatabaseSchema[] - array of DatabaseSchema instances
Throws:
OSSException - - database cannot be started.

getName

public java.lang.String getName()
Get the name of this database schema.

Specified by:
getName in interface DatabaseSchema
Returns:
String - name which uniquely identifies this schema.

getVersion

public int getVersion()
Get the current (most recent) version of database schema.

Specified by:
getVersion in interface DatabaseSchema
Returns:
int - most current version of the schema

handleSQLException

public void handleSQLException(java.sql.SQLException exc,
                               java.sql.Connection dbConnection,
                               int iOperationType,
                               int iDataType,
                               java.lang.Object data)
                        throws OSSException
Handle SQL Exception caused by some database operations.

Specified by:
handleSQLException in interface DatabaseSchema
Parameters:
exc - - sql exception to be handled
dbConnection - - database connection used when the exception occured
iOperationType - - type of the operation that caused the exception, see DatabaseOperations for possible values
iDataType - - data type the data object represents (e.g if this is type user and data is Integer, that means it is id of user object). This is one of the DataConstant constants.
data - - data object the exception is handled for
Throws:
OSSException - - problem handling exception


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