Revision: 3572
Author: [email protected]
Date: Mon May 31 08:31:06 2010
Log: NEW - bug 2824: Profiling sets the parent pointer of new TableProfileResult objects to null
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2824

The parent pointer of the copy used in profiling is now pointing at an empty profiler with the correct UUID to keep the parent pointer correct when persisting the changes to the profile object.
http://code.google.com/p/power-architect/source/detail?r=3572

Modified:
 /trunk/regress/ca/sqlpower/architect/profile/TableProfileResultTest.java
/trunk/src/main/java/ca/sqlpower/architect/profile/AbstractTableProfileCreator.java

=======================================
--- /trunk/regress/ca/sqlpower/architect/profile/TableProfileResultTest.java Thu Feb 18 07:51:21 2010 +++ /trunk/regress/ca/sqlpower/architect/profile/TableProfileResultTest.java Mon May 31 08:31:06 2010
@@ -19,11 +19,15 @@

 package ca.sqlpower.architect.profile;

+import ca.sqlpower.architect.ArchitectSession;
+import ca.sqlpower.architect.ArchitectSessionContextImpl;
+import ca.sqlpower.architect.ArchitectSessionImpl;
 import ca.sqlpower.architect.util.ArchitectNewValueMaker;
 import ca.sqlpower.object.PersistedSPObjectTest;
 import ca.sqlpower.object.SPObject;
 import ca.sqlpower.sql.DataSourceCollection;
 import ca.sqlpower.sql.SPDataSource;
+import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.testutil.NewValueMaker;

 public class TableProfileResultTest extends PersistedSPObjectTest {
@@ -37,6 +41,7 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
+
         tpr = (TableProfileResult) new ArchitectNewValueMaker(
getRootObject(), getPLIni()).makeNewValue(TableProfileResult.class, null, "");
     }
@@ -56,5 +61,27 @@
             DataSourceCollection<SPDataSource> dsCollection) {
         return new ArchitectNewValueMaker(root, dsCollection);
     }
+
+    /**
+     * Regression test to ensure profiling a table does not null out the
+     * profile's parent pointer.
+     */
+    public void testParentSetCorrectly() throws Exception {
+ sqlx("Create table testProfileParent (col1 varchar(50), col2 varchar(50))");
+        SQLTable testTable = db.getTableByName("testProfileParent");
+        testTable.populate();
+        assertNotNull(testTable);
+        assertEquals(2, testTable.getColumns().size());
+
+ ArchitectSession session = new ArchitectSessionImpl(new ArchitectSessionContextImpl(), "testing session");
+        ProfileManager pm = new ProfileManagerImpl();
+        session.getWorkspace().setProfileManager(pm);
+        session.getWorkspace().getRootObject().addDatabase(db, 0);
+        TableProfileResult tpr = pm.createProfile(testTable);
+
+        assertEquals(pm, tpr.getParent());
+        assertTrue(tpr.getCreateStartTime() >= 0);
+        assertTrue(tpr.getCreateEndTime() >= 1);
+    }

 }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/AbstractTableProfileCreator.java Wed Apr 14 09:10:02 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/AbstractTableProfileCreator.java Mon May 31 08:31:06 2010
@@ -54,6 +54,11 @@
         //Setting the profile result UUID to match which allows the
         //persister to update the actual tpr at the end.
         tpr.setUUID(actualTPR.getUUID());
+        //Need to do the same for the parent pointer but do not want
+        //to attach it to the actual profile manager.
+        ProfileManager backgroundPM = new ProfileManagerImpl();
+        backgroundPM.setUUID(actualTPR.getParent().getUUID());
+        tpr.setParent(backgroundPM);

         MonitorableImpl pm = (MonitorableImpl) tpr.getProgressMonitor();
         try {

Reply via email to