update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -0,0 +1,26 @@
|
|||
Class Serialize.Employee Extends %SerialObject
|
||||
{
|
||||
|
||||
Method %OnNew(ByRef pId As %Integer = 0, pDepartment As %String, pName As %String) As %Status
|
||||
{
|
||||
Do ..IDSet(pId)
|
||||
Set pId=pId+1
|
||||
Do ..DepartmentSet(pDepartment)
|
||||
Do ..NameSet(pName)
|
||||
Quit $$$OK
|
||||
}
|
||||
|
||||
Method Print()
|
||||
{
|
||||
Write "[", ..%ClassName(), "]", !
|
||||
Write "- ID: "_..IDGet(), !
|
||||
Write "- Name: "_..NameGet(), !
|
||||
Write "- Department: "_..DepartmentGet(), !
|
||||
Quit
|
||||
}
|
||||
|
||||
Property ID As %Integer [ Private ];
|
||||
Property Name As %String [ Private ];
|
||||
Property Department As %String [ Private ];
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
Class Serialize.Worker Extends Employee
|
||||
{
|
||||
|
||||
Method %OnNew(ByRef pId As %Integer = 0, pDepartment As %String, pName As %String, pHourlyPay As %Numeric) As %Status
|
||||
{
|
||||
Do ..HourlyPaySet(pHourlyPay)
|
||||
Quit ##super(.pId, pDepartment, pName)
|
||||
}
|
||||
|
||||
Method Print()
|
||||
{
|
||||
Do ##super()
|
||||
Write "- Hourly Pay: ", $FNumber(..HourlyPayGet(), ",", 2), !
|
||||
Quit
|
||||
}
|
||||
|
||||
Method HourlyPaySet(pHourlyPay As %Numeric) As %Status [ ServerOnly = 1 ]
|
||||
{
|
||||
Set i%HourlyPay=$Select(pHourlyPay<0: 0, 1: pHourlyPay)
|
||||
Quit $$$OK
|
||||
}
|
||||
|
||||
Property HourlyPay As %Numeric [ Private ];
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
Class Serialize.Example Extends %SerialObject
|
||||
{
|
||||
|
||||
ClassMethod Main()
|
||||
{
|
||||
Do ..Save("/temp/objects.dat")
|
||||
Do ..Load("/temp/objects.dat")
|
||||
Quit
|
||||
}
|
||||
|
||||
ClassMethod Save(pFilename As %String)
|
||||
{
|
||||
// creating objects of base class
|
||||
Set emp1 = ##class(Employee).%New(.id, "Maintenance", "Fritz Schmalstieg")
|
||||
Set emp2 = ##class(Employee).%New(.id, "Maintenance", "John Berry")
|
||||
Set emp3 = ##class(Employee).%New(.id, "Repair", "Pawel Lichatschow")
|
||||
Set emp4 = ##class(Employee).%New(.id, "IT", "Marian Niculescu")
|
||||
|
||||
// creating objects of derived class
|
||||
Set worker1 = ##class(Worker).%New(.id, "Maintenance", "Laurent Le Chef", 20)
|
||||
Set worker2 = ##class(Worker).%New(.id, "IT", "Srinivan Taraman", 55.35)
|
||||
|
||||
// put objects into collections
|
||||
Set example = ..%New()
|
||||
Set sc = example.Employees.Insert(emp1)
|
||||
Set sc = example.Employees.Insert(emp2)
|
||||
Set sc = example.Employees.Insert(emp3)
|
||||
Set sc = example.Employees.Insert(emp4)
|
||||
Set sc = example.Workers.Insert(worker1)
|
||||
Set sc = example.Workers.Insert(worker2)
|
||||
|
||||
// serialize the data and save to a file
|
||||
Set sc=example.%GetSwizzleObject(,.oid)
|
||||
Set fs=##class(%Stream.FileBinary).%New()
|
||||
Set fs.Filename=pFilename
|
||||
Set sc=fs.Write(oid)
|
||||
Set sc=fs.%Save()
|
||||
Quit
|
||||
}
|
||||
|
||||
ClassMethod Load(pFilename As %String)
|
||||
{
|
||||
// read serialized data from file
|
||||
Set fs=##class(%Stream.FileBinary).%New()
|
||||
Set fs.Filename=pFilename
|
||||
Set oid=fs.Read(.len, .sc)
|
||||
|
||||
// open the example object
|
||||
Set example = ..%Open(oid,, .sc)
|
||||
Do example.Employees.GetAt(1).Print()
|
||||
Do example.Employees.GetAt(3).Print()
|
||||
Do example.Workers.GetAt(2).Print()
|
||||
Quit
|
||||
}
|
||||
|
||||
Property Employees As list Of Employee;
|
||||
Property Workers As list Of Worker;
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue