The Kat's Work - Blog
Main | Blog | Registration | Login
Friday
2024-03-29
10:31 AM
Welcome Guest | RSS
Main » 2010 » December » 07



Just a qick update on the attempt to implement MVC in lotus script. Its going  pretty well, with a bear minimum of shouting to the gods of Coding to smite IBM down.

I quickly identified the benefit of replicating (stealing) the get/set methodology of other frame works. This way you can really control the business logic around setting particular field values. The downside? So many getters and setters…….

I think I will have to a some point write an eclipse plugin to generate these like it does for java. It also hasn’t helped I’ve taken the idea to include a clear method with the getters and setters. 50% more work, well done me. Unlike frameworks with a separate ui/database a lot of business logic in notes is to make the information display right in UI. So the clear functions are vital to maintain the functionality across the board. Some fields may be cleared by a document.replaceItemValue("field1”,””) while number fields need a 0 or custom functionality may require that clearing a field actually fills it with a default value. The addition of a clear function for all fields allows for tight control of this functionality.

I have also written a pretty nifty applications factory class that I will post at a later date.

Again here is a "brief example” of the Current Code this time focusing on Data access and Business Logic. Included is my master Entitymodel class. I have tried to make it a working example by removing all custom error handling. I apologise in advanced for anything I’ve missed/left in.

Public Class entityModel As entityCommons
    Private session As NotesSession
    Private document As NotesDocument
   
    Public Function atword(value As String, separator As String, occurance As Integer)
       
        Dim tmpString As String
        tmpString = value
        Dim i As Integer
        For i = 1 To occurance -1
                tmpString = Right(tmpString,Len(tmpString) - InStr(tmpString,separator))
        Next
        If(InStr(tmpstring,separator) > 0 )then
        tmpString = Left(tmpString,InStr(tmpString,separator)-1)
        End if
        atword = tmpString
       
    End Function
     
    Public Sub New()
        Set session = New NotesSession
       
    End Sub
   
   
    Public Sub save
       
        Call document.Save(True , False)
    End Sub
   
   
    Public Function getDocument() As NotesDocument
       
        Set getDocument = document
       
       
    End Function
   

    Private Function getItemValue(fieldName As String) As Variant
       
    getItemValue = document.Getitemvalue(fieldname)
       
    End Function

   
    Private Function setItemValue(fieldName As String,value As Variant)
           
        Call document.replaceItemValue(fieldName,value)
       
       
    End Function

   
   
    Private Function appendItemValue(fieldName As String,value As String, seperator As String)
                    Call document.replaceItemValue(fieldName,document.Getitemvalue(fieldname)(0) & seperator & value)
       
   
    End Function
   
   
    Private Function replaceItemValue(fieldName As String,value As String, seperator As String , element As Integer)
           
            Dim elements As Variant
            elements = Split(document.getItemValue(FieldName)(0),"#")
            elements(element) = value
        Call document.replaceItemValue(fieldName, Join(elements,"#"))
       
   
    End Function
   
   
   
    Private Function getItemValueElement(fieldname As String, seperator As String , element As Integer) As String
       
        getItemValueElement = atword(document.getItemValue(FieldName)(0),seperator,element)
       
   
    End Function
   
   
   

End Class

Public Class PersTable01Dao
    Private database As NotesDatabase
    Private view As NotesView
   
    Public Sub New()
   
       
        Set ApplicationFactory = New ApplicationFactory()
        Set database = ApplicationFactory.getApplication("Personnel - Tables", DATABASESTYPE)   
    End Sub
   
   
    Public Function getPersTable01(key As String) As PersTable01
        Set view = database.getView("PersTable03")
        Dim doc As NotesDocument

        Set doc = view.getDocumentByKey(key,true)   
        Dim PersTable01 As PersTable01
        Set PersTable01 = New PersTable01()
        Call PersTable01.setDocument(doc)
        Set getPersTable01 = PersTable01
       
    End Function
End Class

Public Class PersTable01 As entityModel
    Private database As NotesDatabase   
    Public Sub New(), entityModel()
       
       
       
    End Sub
   
   
   
    Public Sub newDocument(database As NotesDatabase)
        If database Is Nothing Then
            Set database = session.Currentdatabase
        End If
        Set document = database.CreateDocument
        document.form = "PersTable01"
    End Sub
   
    Public Sub setDocument(passedDocument As NotesDocument)
        Set document = passedDocument
       
    End Sub
   
   
    Public Function getTableEntry() As String
       
        getTableEntry =  getItemvalue("TableEntity")(0)       
    End Function
    Public Function getTable_User1() As String
       
        getTable_User1 =  getItemvalue("Table_User1")(0)       
    End Function
Public Function getTableEntry(value as string)
       
        Call setItemvalue("TableEntity”, value)       
    End Function
    Public Function getTable_User1() As String
       
        Call setItemvalue("Table_User1”, value)   
       
    End Function
Public Function clearTableEntry()
       
        Call setItemvalue("TableEntity”, "”)       
    End Function
    Public Function clearTable_User1() As String
       
        Call setItemvalue("Table_User1”, "No Value”)   
       
    End Function
    Private function onTableEntryChange()
        If(getTableEntry = "”) then
call    ClearTable_User1()
        End if
    End function
   
End Class
Views: 18057 | Added by: The_Kat | Date: 2010-12-07 | Comments (0)

Login form
Adverts
Search
Calendar
«  December 2010  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
262728293031
Entries archive
Site friends
  • Create your own site
  • Spree4.com
  • My Blog
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    spree4
    Copyright MyCorp © 2024
    Website builderuCoz