ca.sqlpower.architect
Class SQLIndex

java.lang.Object
  extended by ca.sqlpower.architect.SQLObject
      extended by ca.sqlpower.architect.SQLIndex
All Implemented Interfaces:
java.io.Serializable

public class SQLIndex
extends SQLObject

The SQLIndex class represents an index on a table in a relational database.

Author:
fuerth
See Also:
Serialized Form

Nested Class Summary
static class SQLIndex.AscendDescend
          An enumeration to define if a column in an index should be ordered in ascending order, descending order, or it should be left undefined.
 class SQLIndex.Column
          A simple placeholder for a column.
 
Field Summary
static java.lang.String INDEX_TYPE_DESCRIPTOR
          This is the property name in the PL.ini file that will indicate what Index types are supported for any specific database.
static java.lang.String RS_INDEX_TYPE_COL
          This is the name of the column that will be augmented by the custom JDBC wrappers to represent index type;
 java.lang.String type
          This is the index type
 
Fields inherited from class ca.sqlpower.architect.SQLObject
children, magicDisableCount, populated, undoEventListeners
 
Constructor Summary
SQLIndex()
           
SQLIndex(SQLIndex oldIndex)
          Copy constructor for a sql index
SQLIndex(java.lang.String name, boolean unique, java.lang.String qualifier, java.lang.String type, java.lang.String filter)
           
 
Method Summary
protected  void addChildImpl(int index, SQLObject newChild)
          All other addChild() methods call this one.
 void addIndexColumn(SQLColumn col1, SQLIndex.AscendDescend aOrD)
           
 boolean allowsChildren()
          Indices are associated with one or more table columns.
 void cleanUp()
          This method is used to clean up the index when it no longer has any children.
 SQLIndex.Column getChild(int index)
          Overriden to narrow return type.
 java.util.List<SQLIndex.Column> getChildren()
          Overriden to narrow return type.
 java.lang.Class<? extends SQLObject> getChildType()
           
static SQLIndex getDerivedInstance(SQLIndex source, SQLTable parentTable)
          Returns a copy of a SQLIndex from a given SQLIndex in a parent SQLTable.
 java.lang.String getFilterCondition()
           
 SQLTable.Folder<SQLIndex> getParent()
          Returns the table folder that owns this index.
 SQLTable getParentTable()
          Returns this index's parent table, or null if this index is not attached to a parent table.
 java.lang.String getQualifier()
           
 java.lang.String getShortDisplayName()
          Returns a short string that should be displayed to the user for representing this SQLObject as a label.
 java.lang.String getType()
           
 boolean isClustered()
           
 boolean isPopulated()
          Tells if this object has already been filled with children, or if that operation is still pending.
 boolean isPrimaryKeyIndex()
           
 boolean isUnique()
           
 void makeColumnsLike(SQLIndex index)
          Make this index's columns look like the columns in index
protected  void populate()
          Indices are populated when first created, so populate is a no-op.
protected  SQLObject removeImpl(int index)
          The implementation that all remove methods delegate to.
 void setClustered(boolean value)
           
 void setFilterCondition(java.lang.String filterCondition)
           
protected  void setParent(SQLObject parent)
          Updates this index's parent reference, and attaches a listener to the columns folder of the new parent's parent table.
 void setParent(SQLTable.Folder<SQLIndex> parent)
           
 void setPrimaryKeyIndex(boolean isPrimaryKey)
          Updates whether this index is a primary key set this index as primary key index and remove any old primary key if isPrimaryKey is true.
 void setQualifier(java.lang.String qualifier)
           
 void setType(java.lang.String type)
           
 void setUnique(boolean unique)
           
 java.lang.String toString()
           
 
Methods inherited from class ca.sqlpower.architect.SQLObject
addChild, addChild, addSQLObjectListener, addSQLObjectPreEventListener, addUndoEventListener, endCompoundEdit, fireDbChildInserted, fireDbChildPreRemove, fireDbChildRemoved, fireDbChildrenInserted, fireDbChildrenPreRemove, fireDbChildrenRemoved, fireDbObjectChanged, fireDbStructureChanged, getChildByName, getChildByNameIgnoreCase, getChildCount, getIndexOfChildByName, getName, getPhysicalName, getSQLObjectListeners, getSQLObjectPreEventListeners, getUndoEventListeners, isMagicEnabled, removeChild, removeChild, removeSQLObjectListener, removeSQLObjectPreEventListener, removeUndoEventListener, setMagicEnabled, setName, setPhysicalName, setPopulated, startCompoundEdit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INDEX_TYPE_DESCRIPTOR

public static java.lang.String INDEX_TYPE_DESCRIPTOR
This is the property name in the PL.ini file that will indicate what Index types are supported for any specific database.


type

public java.lang.String type
This is the index type


RS_INDEX_TYPE_COL

public static java.lang.String RS_INDEX_TYPE_COL
This is the name of the column that will be augmented by the custom JDBC wrappers to represent index type;

Constructor Detail

SQLIndex

public SQLIndex(java.lang.String name,
                boolean unique,
                java.lang.String qualifier,
                java.lang.String type,
                java.lang.String filter)

SQLIndex

public SQLIndex()

SQLIndex

public SQLIndex(SQLIndex oldIndex)
         throws ArchitectException
Copy constructor for a sql index

Parameters:
oldIndex -
Throws:
ArchitectException
Method Detail

allowsChildren

public boolean allowsChildren()
Indices are associated with one or more table columns. The children of this index represent those columns, and the order in which the index applies to them.

Specified by:
allowsChildren in class SQLObject

getChildType

public java.lang.Class<? extends SQLObject> getChildType()
Specified by:
getChildType in class SQLObject

getChild

public SQLIndex.Column getChild(int index)
                         throws ArchitectException
Overriden to narrow return type.

Overrides:
getChild in class SQLObject
Throws:
ArchitectException

getChildren

public java.util.List<SQLIndex.Column> getChildren()
                                            throws ArchitectException
Overriden to narrow return type.

Overrides:
getChildren in class SQLObject
Throws:
ArchitectException

getParent

public SQLTable.Folder<SQLIndex> getParent()
Returns the table folder that owns this index.

Specified by:
getParent in class SQLObject

getParentTable

public SQLTable getParentTable()
Returns this index's parent table, or null if this index is not attached to a parent table.


getShortDisplayName

public java.lang.String getShortDisplayName()
Description copied from class: SQLObject
Returns a short string that should be displayed to the user for representing this SQLObject as a label.

Specified by:
getShortDisplayName in class SQLObject

populate

protected void populate()
                 throws ArchitectException
Indices are populated when first created, so populate is a no-op.

Specified by:
populate in class SQLObject
Throws:
ArchitectException

isPopulated

public boolean isPopulated()
Description copied from class: SQLObject
Tells if this object has already been filled with children, or if that operation is still pending.

Overrides:
isPopulated in class SQLObject

setParent

protected void setParent(SQLObject parent)
Updates this index's parent reference, and attaches a listener to the columns folder of the new parent's parent table.

Specified by:
setParent in class SQLObject
Parameters:
parent - The new parent. Must be null or a SQLTable.Folder instance. If it's a folder, it must already have a parent table.
Throws:
java.lang.IllegalStateException - if the given parent is non-null and does not itself have a parent table.

cleanUp

public void cleanUp()
This method is used to clean up the index when it no longer has any children.


removeImpl

protected SQLObject removeImpl(int index)
Description copied from class: SQLObject
The implementation that all remove methods delegate to. If you want to override the behaviour of removeChild, override this method.

Overrides:
removeImpl in class SQLObject

addChildImpl

protected void addChildImpl(int index,
                            SQLObject newChild)
                     throws ArchitectException
Description copied from class: SQLObject
All other addChild() methods call this one. If you want to override the addChild behaviour, override this method only.

Overrides:
addChildImpl in class SQLObject
Parameters:
index - The index that the new child will have
newChild - The new child to add (must be same type as all other children)
Throws:
ArchitectException - If you try to add a child of a different type than the existing children.

getFilterCondition

public java.lang.String getFilterCondition()

setFilterCondition

public void setFilterCondition(java.lang.String filterCondition)

getQualifier

public java.lang.String getQualifier()

setQualifier

public void setQualifier(java.lang.String qualifier)

getType

public java.lang.String getType()

setType

public void setType(java.lang.String type)

isUnique

public boolean isUnique()

isClustered

public boolean isClustered()

setUnique

public void setUnique(boolean unique)

setClustered

public void setClustered(boolean value)

setParent

public void setParent(SQLTable.Folder<SQLIndex> parent)

isPrimaryKeyIndex

public boolean isPrimaryKeyIndex()

setPrimaryKeyIndex

public void setPrimaryKeyIndex(boolean isPrimaryKey)
                        throws ArchitectException
Updates whether this index is a primary key set this index as primary key index and remove any old primary key if isPrimaryKey is true. Otherwise, sets primaryKeyIndex to false and removes it from its parent table.

Parameters:
isPrimaryKey -
Throws:
ArchitectException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addIndexColumn

public void addIndexColumn(SQLColumn col1,
                           SQLIndex.AscendDescend aOrD)
                    throws ArchitectException
Throws:
ArchitectException

getDerivedInstance

public static SQLIndex getDerivedInstance(SQLIndex source,
                                          SQLTable parentTable)
                                   throws ArchitectException
Returns a copy of a SQLIndex from a given SQLIndex in a parent SQLTable. This appears to be mainly used for creating a SQLIndex for a copied table in the playpen when importing tables from a source database as part of the reverse engineering feature.

Parameters:
source - The source SQLIndex to copy
parentTable - The parent SQLTable of the source SQLIndex
Returns:
A copy of the given source SQLIndex.
Throws:
ArchitectException

makeColumnsLike

public void makeColumnsLike(SQLIndex index)
                     throws ArchitectException
Make this index's columns look like the columns in index

Parameters:
index - The index who's columns are what we want in this index
Throws:
ArchitectException


Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca