Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions data/src/cls/Person.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Purpose: This class stores information about traders. The Hibernate.Trade refers to this class for the detail of trader.

Class Demo.Person Extends %Persistent
{

Property FirstName As %String;

Property LastName As %String;

Property Phonenumber As %String;

Property Trades As array Of Hibernate.Trade [ SqlFieldName = Trade ];

}
53 changes: 53 additions & 0 deletions data/src/cls/Stock.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// PURPOSE: This class stores information about stocks. It also contains the function to load one year of stock data.

Class Demo.Stock Extends %Persistent
{

Property TransDate As %Date;

Index TDX On TransDate;

Property StockOpen As %Numeric(SCALE = 4);

Property High As %Numeric(SCALE = 4);

Property Low As %Numeric(SCALE = 4);

Property StockClose As %Numeric(SCALE = 4);

Property Volume As %Integer;

Property Name As %String;

Index NameX On Name [ Type = bitmap ];

ClassMethod LoadData(FileLocation As %String = "/tmp/irisupdate/all_stocks_1yr.csv") As %String
{
set status = $$$OK

try {
set stream = ##class(%Stream.FileCharacter).%New()
set sc = stream.LinkToFile(FileLocation)
set line = stream.ReadLine() //don't use headers for anything
while 'stream.AtEnd {
set line = stream.ReadLine()
set stock = ##class(Demo.Stock).%New()
set stock.TransDate = $zdateh($piece(line,",",1))
set stock.StockOpen = $piece(line,",",2)
set stock.High = $piece(line,",",3)
set stock.Low = $piece(line,",",4)
set stock.StockClose = $piece(line,",",5)
set stock.Volume = $piece(line,",",6)
set stock.Name = $zstrip($piece(line,",",7),"*C")
set status = stock.%Save()
}
} catch sc {
write "In Catch block",!
write "error code: ",sc.Code,!
write "error location: ",sc.Location,!
write "error data:",$LISTGET(sc.Data,2),!
}
quit status
}

}
18 changes: 18 additions & 0 deletions data/src/cls/Trade.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// PURPOSE: This class stores information about stocks used for connecting to InterSystems with Java Hibernate.

Class Hibernate.Trade Extends %Library.Persistent
{

Property stockName As %Library.String(MAXLEN = 10000);

Property purchaseDate As %Library.Date;

Property purchasePrice As %Library.Decimal;

Property shares As %Library.Integer;

Property trader As Demo.Person;

ForeignKey traderKey(trader) References Demo.Person() [ OnDelete = cascade ];

}