com.altair.hwm.database.dbmodel
Class HWMClass

java.lang.Object
  extended by com.altair.hwm.database.dbmodel.HWMClass
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.beans.VetoableChangeListener, java.util.EventListener
Direct Known Subclasses:
HWMRelationClass

public class HWMClass
extends java.lang.Object
implements java.beans.VetoableChangeListener, java.beans.PropertyChangeListener

Title: HWMClass

Description: This class represents the class objects created in the data model

Company: Altair Engineering, Inc.


Field Summary
static java.lang.String HWM_UNIQUE_ID
          The mandatory attrib's name which is the uniquely generated ID
static int MANDATORY_ATTRIB_COUNT
          The number of mandatory attributes in a class
static java.lang.String PROP_CLASS_ATTRIB
          The name of the property (attrib to display) which when changed, an event is fired
static java.lang.String PROP_CLASS_ATTRIB_ADD
          The name of the property (attribute added) which when added, an event is fired
static java.lang.String PROP_CLASS_ATTRIB_DEL
          The name of the property (attribute removed) which when removed, an event is fired
static java.lang.String PROP_CLASS_CONST
          The name of the property (constraints) which when changed, an event is fired
static java.lang.String PROP_CLASS_DISPLAY
          The name of the property (display name) which when changed, an event is fired
static java.lang.String PROP_CLASS_NAME
          The name of the property (class name) which when changed, an event is fired
 
Method Summary
 HWMAttribute AddAttribute(java.lang.String strAttribName)
          Add a attribute to the class
 long AddData(java.util.Hashtable hashNameToValue)
          Adds a record to the table
 HWMForeignAttribute AddForeignAttribute(java.lang.String strName, HWMAttribute hwmAttrib)
          Add a foreign attribute to the class
 void addPropertyChangeListener(java.beans.PropertyChangeListener propChangeListener)
          Add property change listener
 void addVetoableChangeListener(java.beans.VetoableChangeListener vetoableListener)
          Add vetoable change listener
 void Export(org.jdom.Element elemClass)
          Creates XML element representation of this class
 HWMAttribute GetAttribute(java.lang.String strAttribName)
          Gets the attribute with the given name
 int GetAttributeCount()
          Gets the number of attributes
 java.util.Vector GetAttributes()
          Gets all the attributes in the class.
 HWMClassConstraints GetConstraints()
          Gets the constraints for this class.
 java.sql.ResultSet GetData()
          Gets all the instances/records in this class/table
 java.sql.ResultSet GetData(java.util.Hashtable hashNameToValue)
          Gets all the instances/records in this class/table given the values for the certain attribs
 java.sql.ResultSet GetData(java.lang.String strAttribName, java.lang.Object objValue)
          Gets all the instances/records in this class/table where the value for the given attrib - strAttribName is strValue
 HWMDBModel GetDataModel()
          Returns the data model to which this class belongs to
 java.lang.String GetDisplayName()
          Gets the display name of the class
 java.util.Vector GetForeignAttributes()
          Gets all the foreign attributes
 java.lang.String GetName()
          Gets the name of the class
 java.lang.String GetPrimaryAttribute()
          Gets the primary attribute's name in the class.
 java.util.Vector GetRelatedClasses()
          Gets all the related classes
 java.lang.String GetSQLRepresentation(HWMDatabaseInfo hwmDBInfo)
          Returns a string which represents this class in the database.
 void Import(org.jdom.Element elemClass)
          Recreates the class
 void Init()
          Init creates the required attributes
 boolean IsEditable()
          returns a flag indicating if this class can be edited
 boolean IsRelated(HWMClass hwmClass)
          Returns true if there is an attribute from the given class present in this class
 boolean IsVisible()
          returns a flag indicating if this class should be visible in the view of the datamodel i.e.
 void propertyChange(java.beans.PropertyChangeEvent propChangeEvt)
          This event is fired whenever a class is deleted.
 void RemoveAttribute(java.lang.String strAttribName)
          Removes a attribute from the class
 void RemoveData(java.util.Hashtable hashNameToValue)
          Removes records from the table
 void removePropertyChangeListener(java.beans.PropertyChangeListener propChangeListener)
          Remove property change listener
 void removeVetoableChangeListener(java.beans.VetoableChangeListener vetoableListener)
          Remove vetoable change listener
 void Resolve()
          Resolves the foreign attribs and constraints.
 void SetDisplayName(java.lang.String strDisplayName)
          Sets the display name of the class
 void SetEditable(boolean bEditable)
          Sets the flag indicating if this class can be edited
 void SetName(java.lang.String strName)
          Sets the name of the class
 void SetVisible(boolean bVisible)
          Sets the flag indicating if this class should be visible in the view of the datamodel i.e.
 java.lang.String toString()
          Returns the name for this attribute
 void UpdateData(java.util.Hashtable hashNameToValues, java.util.Hashtable hashNameaToValWhereCond)
          Updates the records in the table which match the conditions in the vector.
 void vetoableChange(java.beans.PropertyChangeEvent propChangeEvt)
          This event is fired whenever an attrib name is changed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MANDATORY_ATTRIB_COUNT

public static final int MANDATORY_ATTRIB_COUNT
The number of mandatory attributes in a class

See Also:
Constant Field Values

PROP_CLASS_NAME

public static final java.lang.String PROP_CLASS_NAME
The name of the property (class name) which when changed, an event is fired

See Also:
Constant Field Values

PROP_CLASS_DISPLAY

public static final java.lang.String PROP_CLASS_DISPLAY
The name of the property (display name) which when changed, an event is fired

See Also:
Constant Field Values

PROP_CLASS_ATTRIB

public static final java.lang.String PROP_CLASS_ATTRIB
The name of the property (attrib to display) which when changed, an event is fired

See Also:
Constant Field Values

PROP_CLASS_CONST

public static final java.lang.String PROP_CLASS_CONST
The name of the property (constraints) which when changed, an event is fired

See Also:
Constant Field Values

PROP_CLASS_ATTRIB_ADD

public static final java.lang.String PROP_CLASS_ATTRIB_ADD
The name of the property (attribute added) which when added, an event is fired

See Also:
Constant Field Values

PROP_CLASS_ATTRIB_DEL

public static final java.lang.String PROP_CLASS_ATTRIB_DEL
The name of the property (attribute removed) which when removed, an event is fired

See Also:
Constant Field Values

HWM_UNIQUE_ID

public static final java.lang.String HWM_UNIQUE_ID
The mandatory attrib's name which is the uniquely generated ID

See Also:
Constant Field Values
Method Detail

Init

public void Init()
          throws java.lang.Exception
Init creates the required attributes

Throws:
java.lang.Exception

GetDataModel

public HWMDBModel GetDataModel()
Returns the data model to which this class belongs to

Returns:
HWMDBModel The data model to which this class belongs to

GetName

public java.lang.String GetName()
Gets the name of the class

Returns:
String Name of this class.

SetName

public void SetName(java.lang.String strName)
             throws java.beans.PropertyVetoException
Sets the name of the class

Parameters:
strName - Name of this class.
Throws:
java.beans.PropertyVetoException - The exception thrown if a class with similar name already exists

GetDisplayName

public java.lang.String GetDisplayName()
Gets the display name of the class

Returns:
String Display name for this class.

SetDisplayName

public void SetDisplayName(java.lang.String strDisplayName)
Sets the display name of the class

Parameters:
strDisplayName - Display name of this class.

IsEditable

public boolean IsEditable()
returns a flag indicating if this class can be edited

Returns:
boolean If true, it can be edited else not

SetEditable

public void SetEditable(boolean bEditable)
Sets the flag indicating if this class can be edited

Parameters:
bEditable - If true, it can be edited else not

IsVisible

public boolean IsVisible()
returns a flag indicating if this class should be visible in the view of the datamodel i.e. DBCreator

Returns:
boolean If true, it is visible else not

SetVisible

public void SetVisible(boolean bVisible)
Sets the flag indicating if this class should be visible in the view of the datamodel i.e. DBCreator

Parameters:
bVisible - If true, it is visible else not

GetPrimaryAttribute

public java.lang.String GetPrimaryAttribute()
Gets the primary attribute's name in the class.

Returns:
String Primary attribute's name in this class.

GetConstraints

public HWMClassConstraints GetConstraints()
Gets the constraints for this class.

Returns:
HWMClassConstraints constraints for this class.

GetAttributeCount

public int GetAttributeCount()
Gets the number of attributes

Returns:
int The number of attributes present.

GetAttribute

public HWMAttribute GetAttribute(java.lang.String strAttribName)
Gets the attribute with the given name

Returns:
strAttribName The name of the attribute. Returns null if the attribute with given name is not present

GetAttributes

public java.util.Vector GetAttributes()
Gets all the attributes in the class.

Returns:
Vector Returns a vector of all the attributes in the class.

AddAttribute

public HWMAttribute AddAttribute(java.lang.String strAttribName)
                          throws java.lang.Exception
Add a attribute to the class

Parameters:
strAttribName - The name of the attribute that should be added to this class
Returns:
HWMAttribute The newly created attribute *
Throws:
java.lang.Exception - If a class with given name already exists, an exception is thrown

AddForeignAttribute

public HWMForeignAttribute AddForeignAttribute(java.lang.String strName,
                                               HWMAttribute hwmAttrib)
                                        throws java.lang.Exception
Add a foreign attribute to the class

Parameters:
strName - The name for the fgn attribute
hwmAttrib - An attribute to be contained in this class
Returns:
HWMForeignAttribute Always returns null
Throws:
java.lang.Exception - If a class with given name already exists, an exception is thrown

RemoveAttribute

public void RemoveAttribute(java.lang.String strAttribName)
                     throws java.lang.Exception
Removes a attribute from the class

Parameters:
strAttribName - The name of the attribute to be removed
Throws:
java.lang.Exception

GetData

public java.sql.ResultSet GetData()
                           throws java.lang.Exception
Gets all the instances/records in this class/table

Returns:
ResultSet The data from the query
Throws:
java.lang.Exception - If query fails

GetData

public java.sql.ResultSet GetData(java.lang.String strAttribName,
                                  java.lang.Object objValue)
                           throws java.sql.SQLException,
                                  java.lang.Exception
Gets all the instances/records in this class/table where the value for the given attrib - strAttribName is strValue

Parameters:
strAttribName - The name of the attribute
objValue - The value of the attribute
Returns:
ResultSet The data from the query
Throws:
java.lang.Exception - If query fails
java.sql.SQLException

GetData

public java.sql.ResultSet GetData(java.util.Hashtable hashNameToValue)
                           throws java.lang.Exception
Gets all the instances/records in this class/table given the values for the certain attribs

Parameters:
hashNameToValue - The hashtable contains the attrib name-value pair using which a query is built. The "and" relation is used here.
Returns:
ResultSet The data from the query
Throws:
java.lang.Exception - If query fails

AddData

public long AddData(java.util.Hashtable hashNameToValue)
             throws java.lang.Exception
Adds a record to the table

Parameters:
hashNameToValue - The hashtable contains the attrib name-value pair to be added.
Returns:
long The auto generated id (if the value for HWM_ID was not passed)... else the result should be ignored
Throws:
java.lang.Exception - If hashNameToValue is null or has no elements in it.

UpdateData

public void UpdateData(java.util.Hashtable hashNameToValues,
                       java.util.Hashtable hashNameaToValWhereCond)
                throws java.lang.Exception
Updates the records in the table which match the conditions in the vector. The vector will contain name value pairs to be used and "AND" is used as the condition if there are more than one name-value pair

Parameters:
hashNameToValues - The hashtable contains the attrib name-value pair to be added.
hashNameaToValWhereCond - The hashtable contains the attrib name-value which forms the where condition
Throws:
java.lang.Exception - If hashNameToValue is null or has no elements in it.

RemoveData

public void RemoveData(java.util.Hashtable hashNameToValue)
                throws java.lang.Exception
Removes records from the table

Parameters:
hashNameToValue - The hashtable contains the attrib name-value pair to be removed. The "and" relation is used between the attribs
Throws:
java.lang.Exception - If hashNameToValue is null or has no elements in it.

GetForeignAttributes

public java.util.Vector GetForeignAttributes()
Gets all the foreign attributes

Returns:
Vector Vector of foreign attributes present in this class

GetRelatedClasses

public java.util.Vector GetRelatedClasses()
Gets all the related classes

Returns:
Vector Vector of classes to which the fgn attributes belong

IsRelated

public boolean IsRelated(HWMClass hwmClass)
Returns true if there is an attribute from the given class present in this class

Parameters:
hwmClass - The class to check for
Returns:
boolean true if there is an attribute from the given class present in this class

GetSQLRepresentation

public java.lang.String GetSQLRepresentation(HWMDatabaseInfo hwmDBInfo)
                                      throws java.sql.SQLException
Returns a string which represents this class in the database. This string can be used as the SQL command to create a table which will represent this class.

Parameters:
hwmDBInfo - The DB information required to convert the class to SQL string
Returns:
String The SQL representation for this class.
Throws:
java.sql.SQLException

Export

public void Export(org.jdom.Element elemClass)
Creates XML element representation of this class

Parameters:
elemClass - The element representing this class

Import

public void Import(org.jdom.Element elemClass)
            throws java.lang.Exception
Recreates the class

Parameters:
elemDM - The element representing this class
Throws:
java.lang.Exception

Resolve

public void Resolve()
             throws java.lang.Exception
Resolves the foreign attribs and constraints.

Throws:
java.lang.Exception

toString

public java.lang.String toString()
Returns the name for this attribute

Overrides:
toString in class java.lang.Object
Returns:
String The namefor this attribute

vetoableChange

public void vetoableChange(java.beans.PropertyChangeEvent propChangeEvt)
                    throws java.beans.PropertyVetoException
This event is fired whenever an attrib name is changed. Check if the name clashes with anyother attribute's name within the same class. If it does then throw an exception.

Specified by:
vetoableChange in interface java.beans.VetoableChangeListener
Parameters:
propChangeEvt - The property change event object
Throws:
java.beans.PropertyVetoException - The exception is thrown when the attribute's name clashes with someother attribute's name

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent propChangeEvt)
This event is fired whenever a class is deleted. Check if any attribs are present from that class. If so... then delete them

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
propChangeEvt - The property change event object

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener propChangeListener)
Add property change listener

Parameters:
propChangeListener - The listener for property change events fired by this class

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener propChangeListener)
Remove property change listener

Parameters:
propChangeListener - The listener to be removed

addVetoableChangeListener

public void addVetoableChangeListener(java.beans.VetoableChangeListener vetoableListener)
Add vetoable change listener

Parameters:
vetoableChangeListener - The listener for vetoable change events fired by this class

removeVetoableChangeListener

public void removeVetoableChangeListener(java.beans.VetoableChangeListener vetoableListener)
Remove vetoable change listener

Parameters:
vetoableListener - The listener to be removed