Symphony Framework
Symphony FileIO v3.2
Symphony Templates > Symphony FileIO v3.2
Template file name Symphony_FileIO_v3_2.tpl

The Symphony_FileIO (version 3.2) provides the ability to create a powerful repository based file handler class.

The generated class utilizes the base Symphony.Conductor.Data.FileIO class to provide a thread safe method of accessing a Synergy data file.

The resulting class provides methods to read, write, update, delete and store records within a file.  The class optionally allows you to define a Synergy IOHook class to provide IOHook capabilities (See IOHook class in the Synergy documentation).

It is recommended that your generated code from the Symphony_FileIO template is created into a project sub-folder called DataIO.
 CodeGen Template Tokens
Token Comments
NAMESPACE Define the namespace within which the generated class will be placed (-n option).
RPSDATAFILES Optionally define the repository main and text files, comma separated.
DATAFILENAME Override the standard <FILE_NAME> CodeGen token.  This can be a literal filename or the name of a static method/function that returns a computed filename.
MODELNAMESPACE
Define the namespace when the associated data object is define.
IOHOOKCLASS
Define the class name to assign as the IOHook class when opening the file.
 CodeGen Template Defines
Token Comments
DEFINED_ATTACH_IO_HOOKS If specified with the -define option then the IOHOOKCLASS token will be used to define the IOHook class to associate with the opened file.
 CodeGen Command Examples
Define repository files
set CUSTOMRPS=SYMPHONYRPS:rpsmain.ism,SYMPHONYRPS:rpstext.ism
codegen e -r -s PART -t Symphony_FileIO_v3_2 -o %ROOT%ControlLibrary\Data -n ControlLibrary.Data -ut MODELNAMESPACE=ControlLibrary.Data -ut RPSDATAFILES=CUSTOMRPS

 

Basic FileIO
codegen e -r -s PART -t Symphony_FileIO_v3_2 -o %ROOT%ControlLibrary\Data -n ControlLibrary.Data -ut MODELNAMESPACE=ControlLibrary.Data

 

Define alternate file name
codegen -e -r -s PART -t Symphony_FileIO_v3_2 -o %ROOT%ControlLibrary\Data -n ControlLibrary.Data -ut MODELNAMESPACE=ControlLibrary.Data  -ut DATAFILENAME='DATA:part_file.ism'

 

Define alternate file name at runtime
codegen -e -r -s RPS_STRUCTURE_NAME -t Symphony_FileIO_v3_2 -o folderName -n NameSpace -ut DATAFILENAME="%%MakeFileName('<FILE_NAME>')"

 

Define IO Hook class
codegen -e -r -s PART -t Symphony_FileIO_v3_2 -o %ROOT%ControlLibrary\JustTesting -n ControlLibrary.Data -ut MODELNAMESPACE=ControlLibrary.Data -define ATTACH_IO_HOOKS -ut IOHOOKCLASS=ControlLibrary.Data.ControlHooks

 Example
;;****************************************************************************
;; WARNING: This code was code generated. Any changes that you
;;          make to this code will be overwritten if the code is regenerated!
;;
;; Template author:    Richard C. Morris : RCP Consultants.
;;
;; Template Name:    Symphony Framework : SYMPHONY_FILEIO_V3_2.tpl
;;****************************************************************************

import System
import System.Collections.Generic
import System.Text

import Symphony.Core
import Symphony.Conductor.Model
import Symphony.Conductor.DataIO

import ControlLibrary.Data

namespace ControlLibrary.Data

    ;;we will define a tag value, if we have tags defined for the structure


    public class Part_FileIO extends FileIO

        ;;; <summary>
        ;;;  Default constructor openes the data file in input mode
        ;;; </summary>
        public method Part_FileIO
            endparams
            parent(700)
        proc
            mOpenMode = FileOpenMode.Input
            openTheFile("SYMPHONYDATA:parts.ism", ^typeof(ControlLibrary.Data.Part_Data_IOHook))
        endmethod

        ;;; <summary>
        ;;;  Alternate constructor accepts the file open mode
        ;;; </summary>
        public method Part_FileIO
            in req openMode        ,FileOpenMode
            endparams
            parent(700)
        proc
            mOpenMode = openMode
            openTheFile("SYMPHONYDATA:parts.ism", ^typeof(ControlLibrary.Data.Part_Data_IOHook))
        endmethod

        protected override method checkInRange    ,boolean
            in req partArg        ,a
            endparams
            .include 'part' repository  , stack record = "part", end
        proc
            part = partArg
            ;;do any tag values
            .ifdef FILE_HAS_TAGS
            if (
            &    ) then
                mreturn true
            else
                mreturn false
            .endc
            ;;if we get here, we have no tag field!
            mreturn true
        endmethod
        
        ;;this fixes when you are using tags as filters.
        .ifdef QAWSEDRFTGYH
        .undefine QAWSEDRFTGYH
        .endc
        
        ;;this logic is only compiled if the structure has a tag value
        .ifdef FILE_HAS_TAGS

        ;;; <summary>
        ;;;  Read the first record from the file and assign the located record to a Symphony Data Object.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to propogate with the located data.</param>
        ;;; <remarks>
        ;;; The file will be read on the key index that was set by the last read operation, or the default of primary if no previous operation was performed.  The record will be locked if the file is opened in update mode and the record is successfully located.
        ;;; </remarks>
        public override method ReadFirstRecord    ,FileAccessResults
            in req dataObject            ,@DataObjectBase
            endparams

        proc
            dataObject.InitData()
            mreturn parent.ReadRecord(dataObject)

        endmethod

        ;;; <summary>
        ;;;  Read the first record from the file and assign the located record to a Symphony Data Object.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to propogate with the located data.</param>
        ;;; <remarks>
        ;;; The file will be read on the key index that was set by the last read operation, or the default of primary if no previous operation was performed.
        ;;; The record will not be locked.  To update the record you should use the UpdateRecordUsingGRFA method.
        ;;; </remarks>
        public override method ReadFirstRecord    ,FileAccessResults
            in req dataObject            ,@DataObjectBase
            in req noLock                ,Boolean
            endparams

        proc
            dataObject.InitData()
            mreturn parent.ReadRecord(dataObject, noLock)

        endmethod

        ;;; <summary>
        ;;;  Read the last record from the file and assign the located record to a Symphony Data Object.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to propogate with the located data.</param>
        ;;; <remarks>
        ;;; The file will be read on the key index that was set by the last read operation, or the default of primary if no previous operation was performed.  The record will be locked if the file is opened in update mode and the record is successfully located.
        ;;; </remarks>
        public override method ReadLastRecord    ,FileAccessResults
            in req dataObject            ,@DataObjectBase
            endparams

        proc
            dataObject.InitData()
            ((@Part_Data)dataObject).Id = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"

            parent.ReadRecord(dataObject, true)
            mreturn parent.ReadPrevRecord(dataObject)

        endmethod

        ;;; <summary>
        ;;;  Read the last record from the file and assign the located record to a Symphony Data Object.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to propogate with the located data.</param>
        ;;; <remarks>
        ;;; The file will be read on the key index that was set by the last read operation, or the default of primary if no previous operation was performed.
        ;;; The record will not be locked.  To update the record you should use the UpdateRecordUsingGRFA method.
        ;;; </remarks>
        public override method ReadLastRecord    ,FileAccessResults
            in req dataObject            ,@DataObjectBase
            in req noLock                ,Boolean
            endparams

            record
                far    ,FileAccessResults
            endrecord

        proc
            dataObject.InitData()
            ((@Part_Data)dataObject).Id = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"

            parent.ReadRecord(dataObject, true)
            mreturn parent.ReadPrevRecord(dataObject)

        endmethod

        ;;; <summary>
        ;;;  Read a record from the file and assign the located record to a Symphony Data Object.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to use as the key value and to propogate with the located data.</param>
        ;;; <remarks>
        ;;; Given the passed _DATAOBJECT_ the key value will be extracted.  This key value will then be used to locate the matching record in the file.  The file will be read on the primary key index.
        ;;; The record will be locked if the file is opened in update mode and the record is successfully located.
        ;;; </remarks>
        public override method ReadRecord    ,FileAccessResults
            in req dataObject        ,@DataObjectBase
            endparams

        proc
            mreturn parent.ReadRecord(dataObject)

        endmethod

        ;;; <summary>
        ;;;  Read a record from the file and assign the located record to a Symphony Data Object, but do not lock the record.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to use as the key value and to propogate with the located data.</param>
        ;;; <remarks>
        ;;; Given the passed _DATAOBJECT_ the key value will be extracted.  This key value will them be used to locate the matching record in the file.  The file will be read on the primary key index. The
        ;;; record will not be locked.  To subsequently perform an update, call the UpdateRecordUsingGRFA method.
        ;;; </remarks>
        public override method ReadRecord    ,FileAccessResults
            in req dataObject        ,@DataObjectBase
            in req noLock            ,Boolean
            endparams

        proc
            mreturn parent.ReadRecord(dataObject, noLock)

        endmethod

        ;;; <summary>
        ;;;  Update the currently locked record the file.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to use as the value and to update the locked record.</param>
        ;;; <remarks>
        ;;; Given the passed _DATAOBJECT_ the data will be extracted and used to update the currently locked record.
        ;;; </remarks>
        public override method UpdateRecord    ,FileAccessResults
            in req dataObject        ,@DataObjectBase
            endparams

        proc
            mreturn parent.UpdateRecord(dataObject)
        endmethod

        ;;; <summary>
        ;;;  Update the record to referecned by it's Global RFA.
        ;;; </summary>
        ;;; <param name="dataObject">The _DATAOBJECT_ to use as the value and to locate and updated the record.</param>
        ;;; <remarks>
        ;;; Given the passed _DATAOBJECT_ the data will be extracted and used to loate and update the record.
        ;;; </remarks>
        public override method UpdateRecordUsingGRFA    ,FileAccessResults
            in req dataObject                ,@DataObjectBase
            endparams

        proc
            mreturn parent.UpdateRecordUsingGRFA(dataObject)
        endmethod

        ;;; <summary>
        ;;;  Create a new record within the data files.
        ;;; </summary>
        ;;; <remarks>
        ;;; The passed-in _DATAOBJECT_ will will be created in the data files.
        ;;; </remarks>
        public override method CreateRecord    ,FileAccessResults
            in req dataObject        ,@DataObjectBase
            endparams

        proc
            mreturn parent.CreateRecord(dataObject)
        endmethod
        
        .ifdef FILE_HAS_TAGS
        .undefine FILE_HAS_TAGS
        .endc
        .endc
    endclass

endnamespace


See Also

Reference