ca.sqlpower.architect
Class SQLDatabase

java.lang.Object
  extended by ca.sqlpower.architect.SQLObject
      extended by ca.sqlpower.architect.SQLDatabase
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener

public class SQLDatabase
extends SQLObject
implements java.io.Serializable, java.beans.PropertyChangeListener

See Also:
Serialized Form

Field Summary
 
Fields inherited from class ca.sqlpower.architect.SQLObject
children, magicDisableCount, populated, undoEventListeners
 
Constructor Summary
SQLDatabase()
          Constructor for non-JDBC connected instances.
SQLDatabase(ca.sqlpower.sql.SPDataSource dataSource)
          Constructor for instances that connect to a real database by JDBC.
 
Method Summary
 boolean allowsChildren()
          Returns true if and only if this object can have child SQLObjects.
 void disconnect()
          Closes all connections and other resources that were allocated by the connect() method.
 SQLCatalog getCatalogByName(java.lang.String catalogName)
           
 java.lang.Class<? extends SQLObject> getChildType()
           
 java.sql.Connection getConnection()
          Returns a JDBC connection to the backing database, if there is one.
 ca.sqlpower.sql.SPDataSource getDataSource()
          Gets the value of dataSource
 int getMaxActiveConnections()
          Returns the maximum number of active connections that this database has ever opened.
 java.lang.String getName()
          This is the name of the object.
 SQLObject getParent()
          SQLDatabase objects don't have parents.
 SQLSchema getSchemaByName(java.lang.String schemaName)
          Searches for the named schema as a direct child of this database, or as a child of any catalog of this database.
 java.lang.String getShortDisplayName()
          Returns a short string that should be displayed to the user for representing this SQLObject as a label.
 SQLTable getTableByName(java.lang.String tableName)
           
 SQLTable getTableByName(java.lang.String catalogName, java.lang.String schemaName, java.lang.String tableName)
          Searches this database's list of tables for one with the given name, ignoring case because SQL isn't (usually) case sensitive.
 java.util.List<SQLTable> getTables()
          Recursively searches this database for SQLTable descendants, compiles a list of those that were found, and returns that list.
 boolean isCatalogContainer()
          Determines whether this SQL object is a container for catalog
 boolean isConnected()
           
 boolean isPlayPenDatabase()
           
 boolean isSchemaContainer()
          Determines whether this SQL object is a container for schemas
 void populate()
          Causes this SQLObject to load its children (if any exist).
 void propertyChange(java.beans.PropertyChangeEvent e)
          Listens for changes in DBCS properties, and resets this SQLDatabase if a critical property (url, driver, username) changes.
protected  void reset()
          Removes all children, closes and discards the JDBC connection.
 void setDataSource(ca.sqlpower.sql.SPDataSource argDataSource)
          Sets the value of dataSource
 void setName(java.lang.String argName)
          Sets the data source name if the data source is not null
protected  void setParent(SQLObject newParent)
          Parents call this on their children to update parent pointers during addChild and removeChild requests.
 void setPlayPenDatabase(boolean v)
           
 java.lang.String toString()
           
 
Methods inherited from class ca.sqlpower.architect.SQLObject
addChild, addChild, addChildImpl, addSQLObjectListener, addSQLObjectPreEventListener, addUndoEventListener, endCompoundEdit, fireDbChildInserted, fireDbChildPreRemove, fireDbChildRemoved, fireDbChildrenInserted, fireDbChildrenPreRemove, fireDbChildrenRemoved, fireDbObjectChanged, fireDbStructureChanged, getChild, getChildByName, getChildByNameIgnoreCase, getChildCount, getChildren, getIndexOfChildByName, getPhysicalName, getSQLObjectListeners, getSQLObjectPreEventListeners, getUndoEventListeners, isMagicEnabled, isPopulated, removeChild, removeChild, removeImpl, removeSQLObjectListener, removeSQLObjectPreEventListener, removeUndoEventListener, setMagicEnabled, setPhysicalName, setPopulated, startCompoundEdit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SQLDatabase

public SQLDatabase(ca.sqlpower.sql.SPDataSource dataSource)
Constructor for instances that connect to a real database by JDBC.


SQLDatabase

public SQLDatabase()
Constructor for non-JDBC connected instances.

Method Detail

isConnected

public boolean isConnected()

populate

public void populate()
              throws ArchitectException
Description copied from class: SQLObject
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.

Specified by:
populate in class SQLObject
Throws:
ArchitectException

getCatalogByName

public SQLCatalog getCatalogByName(java.lang.String catalogName)
                            throws ArchitectException
Throws:
ArchitectException

getSchemaByName

public SQLSchema getSchemaByName(java.lang.String schemaName)
                          throws ArchitectException
Searches for the named schema as a direct child of this database, or as a child of any catalog of this database.

Note: there may be more than one schema with the given name, if your RDBMS supports catalogs. In that case, use SQLCatalog.getSchemaByName(java.lang.String) or write another version of this method that return an array of SQLSchema.

Returns:
the first SQLSchema whose name matches the given schema name.
Throws:
ArchitectException

getTableByName

public SQLTable getTableByName(java.lang.String tableName)
                        throws ArchitectException
Throws:
ArchitectException

getTableByName

public SQLTable getTableByName(java.lang.String catalogName,
                               java.lang.String schemaName,
                               java.lang.String tableName)
                        throws ArchitectException
Searches this database's list of tables for one with the given name, ignoring case because SQL isn't (usually) case sensitive.

Parameters:
catalogName - The name of the catalog to search, or null if you want to search all catalogs.
schemaName - The name of the schema to search (in this database or in the given catalog) or null to search all schemas.
tableName - The name of the table to look for (null is not allowed).
Returns:
the first SQLTable with the given name, or null if no such table exists.
Throws:
ArchitectException

getParent

public SQLObject getParent()
SQLDatabase objects don't have parents.

Specified by:
getParent in class SQLObject
Returns:
null

setParent

protected void setParent(SQLObject newParent)
Description copied from class: SQLObject
Parents call this on their children to update parent pointers during addChild and removeChild requests.

Specified by:
setParent in class SQLObject

getName

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

Overrides:
getName in class SQLObject

setName

public void setName(java.lang.String argName)
Sets the data source name if the data source is not null

Overrides:
setName in class SQLObject
Parameters:
argName - Value to assign to this.name

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

allowsChildren

public boolean allowsChildren()
Description copied from class: SQLObject
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.

Specified by:
allowsChildren in class SQLObject

isCatalogContainer

public boolean isCatalogContainer()
                           throws ArchitectException
Determines whether this SQL object is a container for catalog

Returns:
true (the default) if there are no children; false if the first child is not of type SQLCatlog.
Throws:
ArchitectException

isSchemaContainer

public boolean isSchemaContainer()
                          throws ArchitectException
Determines whether this SQL object is a container for schemas

Returns:
true (the default) if there are no children; false if the first child is not of type SQLSchema.
Throws:
ArchitectException

getTables

public java.util.List<SQLTable> getTables()
                                   throws ArchitectException
Recursively searches this database for SQLTable descendants, compiles a list of those that were found, and returns that list.

WARNING: Calling this method will populate the entire database! Think carefully about using it on lazy-loading source databases (it is safe to use on the playpen database).

Returns:
the value of tables
Throws:
ArchitectException

getDataSource

public ca.sqlpower.sql.SPDataSource getDataSource()
Gets the value of dataSource

Returns:
the value of dataSource

setDataSource

public void setDataSource(ca.sqlpower.sql.SPDataSource argDataSource)
Sets the value of dataSource

Parameters:
argDataSource - Value to assign to this.dataSource

setPlayPenDatabase

public void setPlayPenDatabase(boolean v)

isPlayPenDatabase

public boolean isPlayPenDatabase()

reset

protected void reset()
Removes all children, closes and discards the JDBC connection. Unless playPenDatabase is true


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Listens for changes in DBCS properties, and resets this SQLDatabase if a critical property (url, driver, username) changes.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getConnection

public java.sql.Connection getConnection()
                                  throws ArchitectException
Returns a JDBC connection to the backing database, if there is one. The connection that you get will be yours and only yours until you call close() on it. To maximize efficiency of the pool, try to call close() as soon as you are done with the connection.

Returns:
an open connection if this database has a valid dataSource; null if this is a dummy database (such as the playpen instance).
Throws:
ArchitectException

toString

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

disconnect

public void disconnect()
Closes all connections and other resources that were allocated by the connect() method. Logs, but does not propogate, SQL exceptions.


getChildType

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

getMaxActiveConnections

public int getMaxActiveConnections()
Returns the maximum number of active connections that this database has ever opened.

Returns:
Maximum number of active connections ever opened.


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