I finished my participation in the Developing with InterSystems Objects and SQL with Joel Solon. The course is very nice and I will share with you some tips I got during this the training final day. Tips presented in the day 5:
- %SYSTEM package has general utiliy classes. Use $system.class.Help() to list the utilities. The main %SYSTEM classes are Encryption (industry encryption methods), OBJ to manage classes and objects, Security for security methods and SQL to use SQL language.
- IRIS allows validation to the properties and arguments using MINVAL and MAXVAL to integer, FORMAT to date and time, SCALE to decimal, MINLEN, MAXLEN, TRUNCATE, VALUELIST (restrict the input to a list of values) and PATTERN to string. Example: Method Print(name As %String(MAXLEN=50)).
- You can create new data type validations and convertions extending a datatype like %String and using DisplayToLogical() and LogicalToDisplay() to implement new behaviors. Is possible change the datatype parameter like the PATTERN parameter for change the validation of a string.
- IRIS uses -> operator to do implicit joins, example: select Country->States->County from Simple.Places. This joins 3 related tables.
- To create a reference between classes/tables use ForeignKey. Example: ForeignKey CountryFK(Country) References Simple.Country() [ OnDelete = setnull ]. There are the options setnull to set null to the otherside table/class, cascade to propagate the deletion, noaction to no action and setdefault to configure a default value to the reference.
- Use %ConstructClone() to do a clone of a object and its references.
- Use SqlComputeCode to the calculated fields. Example: (from IRIS documentation)
Property FullName As %String [ SqlComputeCode = {set {*}={FirstName}_" "_{LastName}}, SqlComputed ];
- Is possible automate tests using %UnitTest framework. Use %UnitTest.TestCase for defining test cases and %UnitTest.Manager for running a set of Test Cases. To see the results go to System Explorer > Tools > UnitTest Portal. See https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=TUNT.
- IRIS supports 2 type collections:
- List: key based on position starting in 1.
- Declaration: Property States as list of Simple.State.
- Get: country.States.GetAt(1)
- Insert: country.States.Insert(florida)
- Remove: country.States.RemoveAt(1)
- Count: country.States.Count()
- Clear: country.States.Clear()
- Next: country.States.GetNext(1) - to get item 2
- Loop: for i=1:1:country.States.Count() { write !, country.States.GetAt(i)
- Array: key based on associated value.
- Declaration: Property States as array of Simple.State.
- Get: country.States.GetAt("FL")
- Insert: country.States.SetAt(florida, "FL")
- Remove: country.States.RemoveAt("FL")
- Count: country.States.Count()
- Clear: country.States.Clear()
- Next: country.States.GetNext("FL") - to get item GA
- Loop: set state = "" for { set val = country.States.GetNext(.state) quit: (state = "") write !, val }
- List: key based on position starting in 1.
- To create relationships between classes, we have:
- Parent/Children: Relationship States as Simple.State [ cardinality = children, Inverse = Country ]. The otherside: Relationship Country as Simple.Country [ cardinality = parent, Inverse = Country ].
- One/Many: Relationship States as Simple.State [ cardinality = many, Inverse = Country ]. The otherside: Relationship Country as Simple.Country [ cardinality = one, Inverse = Country ].
- One-To-One and Many-to-Many are not supported. One-To-One may be simulated and Many-To-Many can be made using 2 Many-to-One to a relationship table.
- Stream is object that can contain amount of data larger than limit of regular properties, may store characters (%Stream.GlobalCharacter) or binary (%Stream.GlobalBinary) data. Use the following methods to read/write data:
- Write(text): write in the end of line;
- WriteLine(text): write to a new line;
- Clear(): clear the content of the stream;
- CopyFrom(stream): copy from a stream and overwrite the current content;
- Read(length): read characters limited to the length;
- ReadLine(length): read characters in the current line limited to the length;
- Rewind(): retorna para o início do stream;
- MoveToEnd(): move to end of stream.
- You can use triggers to do something before or after a CRUD event. Example: Trigger T1 [Event = INSERT, Time = AFTER, Order = 1, Foreach = row/object] { write your code }.
- The IRIS has some functions frequently used:
- $EXTRACT: get a substring - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fextract
- $FIND: get the position of a value passed as argument - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_ffind
- $LENGTH: get the size of a string or substring - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_flength
- $LIST: return/create a list of elements - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_flist
- $LISTDATA: return the element in the list by position - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_flistdata
- $LISTFIND: return the index of a element in the list - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_flistfind
- $LISTGET - get an element in the list - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_flistget
- $LISTLENGTH - get total of elements in the list - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_flistlength
- $PIECE - return or replace a substring using a delimiter - https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fpiece
The course was very nice and has a rich set of practical exercices. The course is important to preparation to IRIS developer certification too. See the course agenda in https://www.intersystems.com/support-learning/learning-services/classroom-learning/?course-view=course-schedule.
@11:
1:1 could be a degraded 1:N relationship or
by inheriting from a base class as mentioned earlier: "Employee Extends Person"
many-to-many can be covered as M:N relationship as I described in my article 3 years ago.
Thanks Cemper.
Point #11: one-to-one is not supported but can be imperfectly simulated. many-to-many is supported by combining one-to-many among 3 classes.
Oops! I posted this without noticing that Robert already handled this one!
Perfect! Thanks the contribution!
The interactive tutorials with exercises built into the documentation helped me a lot in my time:
Also included was a database "SAMPLES" (code and data) with examples for every taste. I often used it for performance testing.
In addition, in the <cachesys>\dev\ folder there were numerous demos with source code for various programming languages and connection technologies (С++, C#, Java, PHP, Python, ODBC, JDBC, ADO.NET, ActiveX, XEP, etc.):
Great tip, thanks!
I think Objects and Groovy are actually a bit similar...
I don't know if my idea is right or wrong, actually I write very little Objects.
Thank you for sharing your experience, It seems to be an enriching training