Author: thomasobrien95
Date: Wed Jan 7 09:57:50 2009
New Revision: 2907
Modified:
trunk/src/ca/sqlpower/architect/SQLCatalog.java
trunk/src/ca/sqlpower/architect/SQLColumn.java
trunk/src/ca/sqlpower/architect/SQLDatabase.java
trunk/src/ca/sqlpower/architect/SQLObject.java
trunk/src/ca/sqlpower/architect/SQLSchema.java
trunk/src/ca/sqlpower/architect/SQLTable.java
Log:
Fix for bug 1733. The SQLObject now implements getParent and setParent as a
default for other classes. This way new classes do not have to define a
generic setter and getter.
Modified: trunk/src/ca/sqlpower/architect/SQLCatalog.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLCatalog.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLCatalog.java Wed Jan 7 09:57:50 2009
@@ -34,8 +34,6 @@
*/
public class SQLCatalog extends SQLObject {
private static Logger logger = Logger.getLogger(SQLCatalog.class);
- protected SQLObject parent;
-
/**
* The term used for catalogs in the native database system. In
@@ -52,7 +50,7 @@
}
public SQLCatalog(SQLDatabase parent, String name, boolean
startPopulated) {
- this.parent = parent;
+ setParent(parent);
setName(name);
this.children = new LinkedList();
this.nativeTerm = "catalog";
@@ -104,15 +102,6 @@
}
// ---------------------- SQLObject support ------------------------
-
- public SQLObject getParent() {
- return parent;
- }
-
- protected void setParent(SQLObject newParent) {
- parent = newParent;
- }
-
public String getShortDisplayName() {
return getName();
@@ -128,13 +117,13 @@
logger.debug("SQLCatalog: populate starting");
int oldSize = children.size();
- synchronized (parent) {
+ synchronized (getParent()) {
String oldCatalog = null;
Connection con = null;
ResultSet rs = null;
try {
- con = ((SQLDatabase) parent).getConnection();
+ con = ((SQLDatabase)
getParent()).getConnection();
DatabaseMetaData dbmd = con.getMetaData();
oldCatalog = con.getCatalog();
@@ -202,7 +191,7 @@
// ----------------- accessors and mutators -------------------
public SQLDatabase getParentDatabase() {
- return (SQLDatabase) parent;
+ return (SQLDatabase) getParent();
}
Modified: trunk/src/ca/sqlpower/architect/SQLColumn.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLColumn.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLColumn.java Wed Jan 7 09:57:50 2009
@@ -45,8 +45,6 @@
*/
protected SQLColumn sourceColumn;
- protected SQLObject parent;
-
/**
* Must be a type defined in java.sql.Types. Move to enum in 1.5
* (we hope!).
@@ -188,7 +186,7 @@
logger.debug("NEW COLUMN "+colName+"@"+hashCode()+" (null
parent)");
}
if (parentTable != null) {
- this.parent = parentTable.getColumnsFolder();
+ setParent(parentTable.getColumnsFolder());
}
this.setName(colName);
this.type = dataType;
@@ -237,7 +235,7 @@
logger.debug("derived instance SQLColumn constructor
invocation.");
SQLColumn c = new SQLColumn();
copyProperties(c, source);
- c.parent = addTo.getColumnsFolder();
+ c.setParent(addTo.getColumnsFolder());
if (source != null && ArchitectUtils.isInSameSession(c,
source)) {
c.sourceColumn = source;
} else {
@@ -438,10 +436,6 @@
return false;
}
- public SQLObject getParent() {
- return this.parent;
- }
-
// ------------------------- accessors and mutators
--------------------------
public SQLColumn getSourceColumn() {
@@ -631,8 +625,8 @@
* Returns the parent SQLTable object, which is actually a grandparent.
*/
public SQLTable getParentTable() {
- if (parent == null) return null;
- else return (SQLTable) parent.getParent();
+ if (getParent() == null) return null;
+ else return (SQLTable) getParent().getParent();
}
/**
@@ -641,8 +635,8 @@
* @param argParent Value to assign to this.parent
*/
protected void setParent(SQLObject argParent) {
- SQLObject oldParent = this.parent;
- this.parent = argParent;
+ SQLObject oldParent = getParent();
+ super.setParent(argParent);
fireDbObjectChanged("parent",oldParent,argParent);
}
@@ -751,7 +745,7 @@
this.primaryKeySeq = argPrimaryKeySeq;
fireDbObjectChanged("primaryKeySeq",oldPrimaryKeySeq,argPrimaryKeySeq);
- SQLObject p = parent;
+ SQLObject p = getParent();
if (p != null) {
try {
p.setMagicEnabled(false);
Modified: trunk/src/ca/sqlpower/architect/SQLDatabase.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLDatabase.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLDatabase.java Wed Jan 7 09:57:50
2009
@@ -67,8 +67,6 @@
*/
private int maxActiveConnections = 0;
- private SQLObject parent;
-
/**
* Constructor for instances that connect to a real database by JDBC.
*/
@@ -312,19 +310,6 @@
}
// ---------------------- SQLObject support ------------------------
-
- /**
- * SQLDatabase objects don't have parents.
- *
- * @return <code>null</code>
- */
- public SQLObject getParent() {
- return parent;
- }
-
- protected void setParent(SQLObject newParent) {
- parent = newParent;
- }
@Override
public String getName() {
Modified: trunk/src/ca/sqlpower/architect/SQLObject.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLObject.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLObject.java Wed Jan 7 09:57:50 2009
@@ -105,6 +105,12 @@
* then there was an exception the last time the children were attempted
to be accessed.
*/
private Throwable childrenInaccessibleReason = null;
+
+ /**
+ * The parent of this SQLObject. This may be null if it is
+ * a root object.
+ */
+ private SQLObject parent;
public synchronized void setMagicEnabled(boolean enable) {
if (magicDisableCount < 0) {
@@ -179,15 +185,19 @@
/**
* Returns the parent of this SQLObject or <code>null</code> if it
- * is a root object such as SQLDatabase.
+ * is a root object.
*/
- public abstract SQLObject getParent();
+ public SQLObject getParent() {
+ return parent;
+ }
/**
* Parents call this on their children to update parent pointers
* during addChild and removeChild requests.
*/
- protected abstract void setParent(SQLObject parent);
+ protected void setParent(SQLObject parent) {
+ this.parent = parent;
+ }
/**
* Causes this SQLObject to load its children through populateImpl (if
any exist).
Modified: trunk/src/ca/sqlpower/architect/SQLSchema.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLSchema.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLSchema.java Wed Jan 7 09:57:50 2009
@@ -34,7 +34,6 @@
*/
public class SQLSchema extends SQLObject {
private static final Logger logger = Logger.getLogger(SQLSchema.class);
- protected SQLObject parent;
protected String nativeTerm;
public SQLSchema(boolean populated) {
@@ -45,7 +44,7 @@
if (parent != null && !(parent instanceof SQLCatalog || parent
instanceof SQLDatabase)) {
throw new IllegalArgumentException("Parent to SQLSchema must be
SQLCatalog or SQLDatabase");
}
- this.parent = parent;
+ setParent(parent);
setName(name);
this.children = new LinkedList();
this.nativeTerm = "schema";
@@ -70,19 +69,10 @@
}
public boolean isParentTypeDatabase() {
- return (parent instanceof SQLDatabase);
+ return (getParent() instanceof SQLDatabase);
}
// ---------------------- SQLObject support ------------------------
-
- public SQLObject getParent() {
- return parent;
- }
-
- protected void setParent(SQLObject newParent) {
- parent = newParent;
- }
-
public String getShortDisplayName() {
return getName();
@@ -106,7 +96,7 @@
int oldSize = children.size();
- SQLObject tmp = parent;
+ SQLObject tmp = getParent();
while (tmp != null && (! (tmp instanceof SQLDatabase))) {
tmp = tmp.getParent();
}
@@ -120,10 +110,10 @@
con = parentDatabase.getConnection();
DatabaseMetaData dbmd = con.getMetaData();
- if ( parent instanceof SQLDatabase ) {
+ if ( getParent() instanceof SQLDatabase ) {
SQLTable.addTablesToTableContainer(this, dbmd, null,
getName());
- } else if ( parent instanceof SQLCatalog ) {
- SQLTable.addTablesToTableContainer(this, dbmd,
parent.getName(), getName());
+ } else if ( getParent() instanceof SQLCatalog )
{
+ SQLTable.addTablesToTableContainer(this, dbmd,
getParent().getName(), getName());
}
}
} catch (SQLException e) {
Modified: trunk/src/ca/sqlpower/architect/SQLTable.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLTable.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLTable.java Wed Jan 7 09:57:50 2009
@@ -40,7 +40,6 @@
private static Logger logger = Logger.getLogger(SQLTable.class);
- protected SQLObject parent;
protected String remarks="";
private String objectType;
protected String physicalPrimaryKeyName;
@@ -81,7 +80,7 @@
* Sets up the values for the new Table
*/
private void setup(SQLObject parent, String name, String remarks,
String objectType) {
- this.parent = parent;
+ super.setParent(parent);
super.setName(name); // this.setName will try to be far to fancy at
this point, and break stuff
this.remarks = remarks;
this.objectType = objectType;
@@ -807,17 +806,13 @@
// ---------------------- SQLObject support ------------------------
- public SQLObject getParent() {
- return parent;
- }
-
//TODO XXX Sql object should be doing this when we add generics
protected void setParent(SQLObject newParent) {
- logger.debug("Setting "+getName()+"'s parent to "+ newParent);
- if (parent == newParent) return;
- SQLObject oldVal = parent;
- parent = newParent;
- fireDbObjectChanged("parent",oldVal,parent);
+ logger.debug("Setting " + getName() + "'s parent to "+
newParent);
+ if (getParent() == newParent) return;
+ SQLObject oldVal = getParent();
+ super.setParent(newParent);
+ fireDbObjectChanged("parent", oldVal, getParent());
}
@@ -1084,7 +1079,7 @@
* @return the value of parentDatabase
*/
public SQLDatabase getParentDatabase() {
- SQLObject o = this.parent;
+ SQLObject o = getParent();
while (o != null && ! (o instanceof SQLDatabase)) {
o = o.getParent();
}
@@ -1105,7 +1100,7 @@
}
public SQLCatalog getCatalog() {
- SQLObject o = this.parent;
+ SQLObject o = getParent();
while (o != null && ! (o instanceof SQLCatalog)) {
o = o.getParent();
}
@@ -1126,7 +1121,7 @@
}
public SQLSchema getSchema() {
- SQLObject o = this.parent;
+ SQLObject o = getParent();
while (o != null && ! (o instanceof SQLSchema)) {
o = o.getParent();
}