ca.sqlpower.architect
Class SQLObject

java.lang.Object
  extended by ca.sqlpower.architect.SQLObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
SQLCatalog, SQLColumn, SQLDatabase, SQLExceptionNode, SQLIndex, SQLIndex.Column, SQLObjectRoot, SQLRelationship, SQLRelationship.ColumnMapping, SQLSchema, SQLSequence, SQLTable, SQLTable.Folder

public abstract class SQLObject
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
protected  java.util.List children
          The children of this SQLObject (if not applicable, set to Collections.EMPTY_LIST in your constructor).
protected  int magicDisableCount
          When this counter is > 0, the fireXXX methods will ignore secondary changes.
protected  boolean populated
           
protected  java.util.LinkedList<UndoCompoundEventListener> undoEventListeners
          The list of SQLObject property change event listeners used for undo
 
Constructor Summary
SQLObject()
           
 
Method Summary
 void addChild(int index, SQLObject newChild)
          Adds the given SQLObject to this SQLObject at index.
 void addChild(SQLObject newChild)
          Adds the given SQLObject to this SQLObject at the end of the child list by calling addChild(int,SQLObject).
protected  void addChildImpl(int index, SQLObject newChild)
          All other addChild() methods call this one.
 void addSQLObjectListener(SQLObjectListener l)
           
 void addSQLObjectPreEventListener(SQLObjectPreEventListener l)
           
 void addUndoEventListener(UndoCompoundEventListener l)
           
abstract  boolean allowsChildren()
          Returns true if and only if this object can have child SQLObjects.
 void endCompoundEdit(java.lang.String message)
           
protected  void fireDbChildInserted(int newIndex, SQLObject newChild)
           
protected  boolean fireDbChildPreRemove(int oldIndex, SQLObject oldChild)
          Convenience method for fireDbChildrenPreRemove(int[], List) when there is only one child being removed.
protected  void fireDbChildRemoved(int oldIndex, SQLObject oldChild)
           
protected  void fireDbChildrenInserted(int[] newIndices, java.util.List newChildren)
           
protected  boolean fireDbChildrenPreRemove(int[] oldIndices, java.util.List oldChildren)
          Fires a pre-remove event, and returns the status of whether or not the operation should proceed.
protected  void fireDbChildrenRemoved(int[] oldIndices, java.util.List oldChildren)
           
protected  void fireDbObjectChanged(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
           
 void fireDbStructureChanged()
          Notifies listeners that a major change has occurred at or under this node.
 SQLObject getChild(int index)
           
 SQLObject getChildByName(java.lang.String name)
          Returns the first child (in the sequence of the getChildren() list) which has the given name (case sensitive).
 SQLObject getChildByNameIgnoreCase(java.lang.String name)
          Returns the first child (in the sequence of the getChildren() list) which has the given name (case insensitive).
 int getChildCount()
           
 java.util.List getChildren()
          Returns an unmodifiable view of the child list.
abstract  java.lang.Class<? extends SQLObject> getChildType()
           
 int getIndexOfChildByName(java.lang.String name)
          Returns the index of the named child, or -1 if there is no child with that name.
 java.lang.String getName()
          This is the name of the object.
abstract  SQLObject getParent()
          Returns the parent of this SQLObject or null if it is a root object such as SQLDatabase.
 java.lang.String getPhysicalName()
          when the logical name is an illegal identifier in the target database, generate a legal name store it here.
abstract  java.lang.String getShortDisplayName()
          Returns a short string that should be displayed to the user for representing this SQLObject as a label.
 java.util.List<SQLObjectListener> getSQLObjectListeners()
           
 java.util.List<SQLObjectPreEventListener> getSQLObjectPreEventListeners()
           
 java.util.LinkedList<UndoCompoundEventListener> getUndoEventListeners()
           
 boolean isMagicEnabled()
           
 boolean isPopulated()
          Tells if this object has already been filled with children, or if that operation is still pending.
protected abstract  void populate()
          Causes this SQLObject to load its children (if any exist).
 SQLObject removeChild(int index)
          This implementation calls .
 boolean removeChild(SQLObject child)
          This method is implemented in terms of removeImpl(int).
protected  SQLObject removeImpl(int index)
          The implementation that all remove methods delegate to.
 void removeSQLObjectListener(SQLObjectListener l)
           
 void removeSQLObjectPreEventListener(SQLObjectPreEventListener l)
           
 void removeUndoEventListener(UndoCompoundEventListener l)
           
 void setMagicEnabled(boolean enable)
           
 void setName(java.lang.String argName)
          Sets the value of sql object name
protected abstract  void setParent(SQLObject parent)
          Parents call this on their children to update parent pointers during addChild and removeChild requests.
 void setPhysicalName(java.lang.String argName)
           
 void setPopulated(boolean v)
          Lets outside users modify the internal flag that says whether or not the list of child objects has already been loaded from the source database.
 void startCompoundEdit(java.lang.String message)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

populated

protected boolean populated

children

protected java.util.List children
The children of this SQLObject (if not applicable, set to Collections.EMPTY_LIST in your constructor).


magicDisableCount

protected int magicDisableCount
When this counter is > 0, the fireXXX methods will ignore secondary changes.


undoEventListeners

protected java.util.LinkedList<UndoCompoundEventListener> undoEventListeners
The list of SQLObject property change event listeners used for undo

Constructor Detail

SQLObject

public SQLObject()
Method Detail

setMagicEnabled

public void setMagicEnabled(boolean enable)

isMagicEnabled

public boolean isMagicEnabled()

getName

public java.lang.String getName()
This is the name of the object. For tables, it returns the table name; for catalogs, the catalog name, and so on.


setName

public void setName(java.lang.String argName)
Sets the value of sql object name

Parameters:
argName - Value to assign to this.name

getPhysicalName

public final java.lang.String getPhysicalName()
when the logical name is an illegal identifier in the target database, generate a legal name store it here. Some SQLObject classes do not need to implement this, so the method is declared concrete, and passes through to getName() by default. SQLObject subclasses that use this idea should override this class to return the physicalName and then pass through to the getName method if one is not found.

there is no good reason why this is final, but there is no good reason to override it at this time.


setPhysicalName

public final void setPhysicalName(java.lang.String argName)

getParent

public abstract SQLObject getParent()
Returns the parent of this SQLObject or null if it is a root object such as SQLDatabase.


setParent

protected abstract void setParent(SQLObject parent)
Parents call this on their children to update parent pointers during addChild and removeChild requests.


populate

protected abstract void populate()
                          throws ArchitectException
Causes this SQLObject to load its children (if any exist). This method will be called lots of times, so track whether or not you need to do anything and return right away whenever possible.

Throws:
ArchitectException

getShortDisplayName

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


isPopulated

public boolean isPopulated()
Tells if this object has already been filled with children, or if that operation is still pending.


setPopulated

public void setPopulated(boolean v)
Lets outside users modify the internal flag that says whether or not the list of child objects has already been loaded from the source database. Users of this SQLObject hierarchies should not normally call this method, but it needs to be public for the SwingUIProject load implementation.


allowsChildren

public abstract boolean allowsChildren()
Returns true if and only if this object can have child SQLObjects. Your implementation of this method must not cause JDBC activity, or the lazy loading properties of your SQLObjects will be wasted! Typically, you will implement this with a hardcoded "return true" or "return false" depending on object type.


getChildren

public java.util.List getChildren()
                           throws ArchitectException
Returns an unmodifiable view of the child list. All list members will be SQLObject subclasses (SQLTable, SQLRelationship, SQLColumn, etc.) which are directly contained within this SQLObject.

Throws:
ArchitectException

getChild

public SQLObject getChild(int index)
                   throws ArchitectException
Throws:
ArchitectException

getChildCount

public int getChildCount()
                  throws ArchitectException
Throws:
ArchitectException

addChildImpl

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

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.

addChild

public void addChild(int index,
                     SQLObject newChild)
              throws ArchitectException
Adds the given SQLObject to this SQLObject at index. Causes a DBChildrenInserted event. If you want to override the behaviour of addChild, override this method.

Throws:
ArchitectException
ArchitectException

addChild

public void addChild(SQLObject newChild)
              throws ArchitectException
Adds the given SQLObject to this SQLObject at the end of the child list by calling addChild(int,SQLObject). Causes a DBChildrenInserted event. If you want to override the behaviour of addChild, do not override this method.

Throws:
ArchitectException
ArchitectException
java.lang.Exception

removeChild

public SQLObject removeChild(int index)
This implementation calls .


removeChild

public boolean removeChild(SQLObject child)
This method is implemented in terms of removeImpl(int).


removeImpl

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


getSQLObjectListeners

public java.util.List<SQLObjectListener> getSQLObjectListeners()

addSQLObjectListener

public void addSQLObjectListener(SQLObjectListener l)

removeSQLObjectListener

public void removeSQLObjectListener(SQLObjectListener l)

fireDbChildrenInserted

protected void fireDbChildrenInserted(int[] newIndices,
                                      java.util.List newChildren)

fireDbChildInserted

protected void fireDbChildInserted(int newIndex,
                                   SQLObject newChild)

fireDbChildrenRemoved

protected void fireDbChildrenRemoved(int[] oldIndices,
                                     java.util.List oldChildren)

fireDbChildRemoved

protected void fireDbChildRemoved(int oldIndex,
                                  SQLObject oldChild)

fireDbObjectChanged

protected void fireDbObjectChanged(java.lang.String propertyName,
                                   java.lang.Object oldValue,
                                   java.lang.Object newValue)

fireDbStructureChanged

public void fireDbStructureChanged()
Notifies listeners that a major change has occurred at or under this node.

Note: This method is public because the PlayPen's Objects-Adder cleanup method needs to generate these notifications. That kind of code should be in this package instead.


getSQLObjectPreEventListeners

public java.util.List<SQLObjectPreEventListener> getSQLObjectPreEventListeners()
Returns:
An immutable copy of the list of SQLObject pre-event listeners

addSQLObjectPreEventListener

public void addSQLObjectPreEventListener(SQLObjectPreEventListener l)

removeSQLObjectPreEventListener

public void removeSQLObjectPreEventListener(SQLObjectPreEventListener l)

fireDbChildrenPreRemove

protected boolean fireDbChildrenPreRemove(int[] oldIndices,
                                          java.util.List oldChildren)
Fires a pre-remove event, and returns the status of whether or not the operation should proceed.

Parameters:
oldIndices - The child indices that might be removed
oldChildren - The children that might be removed
Returns:
True if the operation should proceed; false if it should not.

fireDbChildPreRemove

protected boolean fireDbChildPreRemove(int oldIndex,
                                       SQLObject oldChild)
Convenience method for fireDbChildrenPreRemove(int[], List) when there is only one child being removed.

Parameters:
oldIndex - The index of the child to be removed
oldChild - The child to be removed

getChildType

public abstract java.lang.Class<? extends SQLObject> getChildType()

addUndoEventListener

public void addUndoEventListener(UndoCompoundEventListener l)

removeUndoEventListener

public void removeUndoEventListener(UndoCompoundEventListener l)

startCompoundEdit

public void startCompoundEdit(java.lang.String message)

endCompoundEdit

public void endCompoundEdit(java.lang.String message)

getUndoEventListeners

public java.util.LinkedList<UndoCompoundEventListener> getUndoEventListeners()

getChildByName

public SQLObject getChildByName(java.lang.String name)
                         throws ArchitectException
Returns the first child (in the sequence of the getChildren() list) which has the given name (case sensitive).

Parameters:
name - The name of the child to look for (case sensitive).
Returns:
The first child with the given name, or null if there is no such child.
Throws:
ArchitectException - If the moon is waxing gibbous.

getChildByNameIgnoreCase

public SQLObject getChildByNameIgnoreCase(java.lang.String name)
                                   throws ArchitectException
Returns the first child (in the sequence of the getChildren() list) which has the given name (case insensitive).

Parameters:
name - The name of the child to look for (case insensitive).
Returns:
The first child with the given name, or null if there is no such child.
Throws:
ArchitectException - If the moon is waxing gibbous.

getIndexOfChildByName

public int getIndexOfChildByName(java.lang.String name)
                          throws ArchitectException
Returns the index of the named child, or -1 if there is no child with that name.

Parameters:
name - The name of the child to look for (case sensitive)
Returns:
The index of the named child in the child list, or -1 if there is no such child.
Throws:
ArchitectException - if the child list can't be populated


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