Revision: 3490
Author: mo.jeff
Date: Mon May 3 16:11:03 2010
Log: ASSIGNED - bug 2682: Implement Save/Load to XML with User Defined Types
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2682
Modified the xml saving and loading process so that it refers to column
types by the UUID of the user defined type. Also allowed old files to be
loaded by using the jdbc type and find the corresponding user defined type
and use that.
TODO:
* Gracefully handle loading a project file that contains a type with a UUID
that doesn't exist in the system.
http://code.google.com/p/power-architect/source/detail?r=3490
Modified:
/trunk/regress/ca/sqlpower/architect/StubArchitectSession.java
/trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
/trunk/src/main/java/ca/sqlpower/architect/ArchitectSession.java
/trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java
/trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
=======================================
--- /trunk/regress/ca/sqlpower/architect/StubArchitectSession.java Tue Apr
20 15:12:12 2010
+++ /trunk/regress/ca/sqlpower/architect/StubArchitectSession.java Mon May
3 16:11:03 2010
@@ -170,4 +170,13 @@
return null;
}
-}
+ public UserDefinedSQLType findSQLTypeByUUID(String uuid) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public UserDefinedSQLType findSQLTypeByJDBCType(int type) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
=======================================
--- /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Tue
Apr 20 15:12:12 2010
+++ /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Mon
May 3 16:11:03 2010
@@ -205,5 +205,14 @@
// TODO Auto-generated method stub
return null;
}
-
-}
+
+ public UserDefinedSQLType findSQLTypeByUUID(String uuid) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public UserDefinedSQLType findSQLTypeByJDBCType(int type) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
=======================================
---
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Mon May 3 15:55:22 2010
+++
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Mon May 3 16:11:03 2010
@@ -472,4 +472,24 @@
list.add(testType2);
return list;
}
-}
+
+ public UserDefinedSQLType findSQLTypeByUUID(String uuid) {
+ if (testType1.getUUID().equals(uuid)) {
+ return testType1;
+ } else if (testType2.getUUID().equals(uuid)) {
+ return testType2;
+ } else {
+ return null;
+ }
+ }
+
+ public UserDefinedSQLType findSQLTypeByJDBCType(int type) {
+ if (testType1.getType() == type) {
+ return testType1;
+ } else if (testType2.getType() == type) {
+ return testType2;
+ } else {
+ return null;
+ }
+ }
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectSession.java Tue
Apr 20 15:12:12 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectSession.java Mon
May 3 16:11:03 2010
@@ -19,6 +19,7 @@
package ca.sqlpower.architect;
import java.beans.PropertyChangeListener;
+import java.sql.Types;
import java.util.List;
import ca.sqlpower.architect.ddl.DDLGenerator;
@@ -139,4 +140,27 @@
* Returns a list of {...@link UserDefinedSQLType} defined in this
session.
*/
public List<UserDefinedSQLType> getSQLTypes();
-}
+
+ /**
+ * Searches the session for a {...@link UserDefinedSQLType} with the given
+ * UUID.
+ *
+ * @param uuid
+ * The UUID of the desired {...@link UserDefinedSQLType}.
+ * @return Returns a {...@link UserDefinedSQLType} with the given UUID if
it
+ * exists in this session. If not, then it will return null.
+ */
+ public UserDefinedSQLType findSQLTypeByUUID(String uuid);
+
+ /**
+ * Searches the session for a {...@link UserDefinedSQLType} with the
given int
+ * that represents a value from {...@link java.sql.Types}.
+ *
+ * @param uuid
+ * The {...@link Types} value of the {...@link
UserDefinedSQLType}
+ * desired.
+ * @return Returns a {...@link UserDefinedSQLType} with the given type if
one
+ * exists in this session. If not, then it will return null.
+ */
+ public UserDefinedSQLType findSQLTypeByJDBCType(int type);
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java
Tue Apr 20 15:12:12 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java
Mon May 3 16:11:03 2010
@@ -255,5 +255,25 @@
public List<UserDefinedSQLType> getSQLTypes() {
return getDataSources().getSQLTypes();
}
+
+ public UserDefinedSQLType findSQLTypeByUUID(String uuid) {
+ List<UserDefinedSQLType> types = getSQLTypes();
+ for (UserDefinedSQLType type : types) {
+ if (type.getUUID().equals(uuid)) {
+ return type;
+ }
+ }
+ return null;
+ }
+
+ public UserDefinedSQLType findSQLTypeByJDBCType(int jdbcType) {
+ List<UserDefinedSQLType> types = getSQLTypes();
+ for (UserDefinedSQLType type : types) {
+ if (type.getType() == jdbcType) {
+ return type;
+ }
+ }
+ return null;
+ }
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java Wed Mar
10 08:21:50 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java Mon May
3 16:11:03 2010
@@ -62,6 +62,7 @@
import ca.sqlpower.sqlobject.SQLRelationship;
import ca.sqlpower.sqlobject.SQLSchema;
import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
import ca.sqlpower.sqlobject.SQLIndex.AscendDescend;
import ca.sqlpower.sqlobject.SQLIndex.Column;
import ca.sqlpower.sqlobject.SQLRelationship.Deferrability;
@@ -709,6 +710,22 @@
if (sourceId != null) {
col.setSourceColumn((SQLColumn)
sqlObjectLoadIdMap.get(sourceId));
}
+
+ String sqlTypeUUID =
attributes.getValue("userDefinedTypeUUID");
+ UserDefinedSQLType sqlType;
+
+ // If sqlTypeUUID isn't in the file, probably because it's
from an older version...
+ if (sqlTypeUUID == null) {
+ String type = attributes.getValue("type");
+ int jdbcType = Integer.valueOf(type);
+ sqlType = session.findSQLTypeByJDBCType(jdbcType);
+ } else {
+ sqlType = session.findSQLTypeByUUID(sqlTypeUUID);
+ }
+
+ // TODO: Handle gracefully if sqlType is null, in which case,
the
+ // user is probably loading a project from another user or
server.
+ col.getUserDefinedSQLType().setUpstreamType(sqlType);
LoadSQLObjectAttributes(col, attributes);
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Fri Apr 23 14:24:33 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Mon May 3 16:11:03 2010
@@ -1217,4 +1217,12 @@
public List<UserDefinedSQLType> getSQLTypes() {
return delegateSession.getSQLTypes();
}
-}
+
+ public UserDefinedSQLType findSQLTypeByUUID(String uuid) {
+ return delegateSession.findSQLTypeByUUID(uuid);
+ }
+
+ public UserDefinedSQLType findSQLTypeByJDBCType(int type) {
+ return delegateSession.findSQLTypeByJDBCType(type);
+ }
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
Wed Apr 14 07:49:36 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
Mon May 3 16:11:03 2010
@@ -198,8 +198,7 @@
in.reset();
super.load(in, dataSources);
- }
- finally {
+ } finally {
getSession().getUndoManager().setLoading(false);
uin.forceClose();
}
@@ -1307,6 +1306,10 @@
if (sourceCol != null) {
propNames.put("source-column-ref",
sqlObjectSaveIdMap.get(sourceCol)); //$NON-NLS-1$
}
+ UserDefinedSQLType userDefinedSQLType = ((SQLColumn)
o).getUserDefinedSQLType();
+ if (userDefinedSQLType.getUpstreamType() != null) {
+ propNames.put("userDefinedTypeUUID",
userDefinedSQLType.getUpstreamType().getUUID());
+ }
propNames.put("type", new Integer(((SQLColumn) o).getType()));
//$NON-NLS-1$
propNames.put("sourceDataTypeName", ((SQLColumn)
o).getSourceDataTypeName()); //$NON-NLS-1$
propNames.put("scale", new Integer(((SQLColumn)
o).getScale())); //$NON-NLS-1$