Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There's an easy solution to this, which is to split the queue that contains the data out into its own class. This may seem like unnecessary proliferation of classes, but it will help to keep the code clean, and instantiating classes is a very inexpensive operation , especially as compared to data database access. 

Here's my new class:

...

Have I mentioned how much I like having unit tests to fall back on? Refactoring is so much less stressful this way. 

Now I can pass just the link data to the persister class methods:

...

Code Block
SaveAndLoadData PROCEDURE  (*long addr)              ! Declare Procedure


ManytoMany                  CML_Data_ManyToManyLinks 
                            itemize(),pre()
RightRecordX                    equate
RightRecordY                    equate
RightRecordZ                    equate
                            end
Persister                   CML_Data_ManyToManyLinksPersisterForTPS
Filename                    cstring(500)

    CODE
    addr = address(UnitTestResult)
    BeginUnitTest('SaveAndLoadData')

    Filename = longpath() & '\CML_Data_ManyToManyLinksTests.tps'
    if exists(filename)
        remove(filename)
    end
    AssertThat(exists(filename),IsEqualTo(false),'Could not delete ' & filename)
   

    Persister.SetFilename(Filename)
    ManytoMany.Persister &= Persister
    ManyToMany.LeftRecordID = 1
    
    ManyToMany.SetLinkTo(RightRecordX)
    ManyToMany.SetLinkTo(RightRecordZ)
    AssertThat(ManyToMany.IsLinkedTo(RightRecordX),IsEqualTo(true), 'before save, record X should be linked')
    AssertThat(ManyToMany.IsLinkedTo(RightRecordY),IsEqualTo(false),'before save, record Y should not be linked')
    AssertThat(ManyToMany.IsLinkedTo(RightRecordZ),IsEqualTo(true), 'before save, record Z should be linked')
    
    ManyToMany.Save()
    ManyToMany.Reset()
    AssertThat(ManyToMany.IsLinkedTo(RightRecordX),IsEqualTo(false),'after reset, record X should not be linked')
    AssertThat(ManyToMany.IsLinkedTo(RightRecordY),IsEqualTo(false),'after reset, record Y should not be linked')
    AssertThat(ManyToMany.IsLinkedTo(RightRecordZ),IsEqualTo(false),'after reset, record Z should not be linked')
    
    ManytoMany.Load()
    
    AssertThat(ManyToMany.IsLinkedTo(RightRecordX),IsEqualTo(true), 'after load, record X should be linked')
    AssertThat(ManyToMany.IsLinkedTo(RightRecordY),IsEqualTo(false),'after load, record Y should not be linked')
    AssertThat(ManyToMany.IsLinkedTo(RightRecordZ),IsEqualTo(true), 'after load, record Z should be linked')

...