docs.intersystems.com
MultiValue Quick Start Tutorial
Retrieving an Object
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Search:    

Here is standard Java code that uses Java projections to display the data for a PERSON record stored in Caché. In detail, the code does the following:

  1. Opens an instance of the Java Projection class PERSON. This class is the Java projection for the Caché MVFILE.PERSON class. Each projection for a persistent Caché class has an open method. The method opens an instance of the Java projection in the Java code and the corresponding Caché object in Caché. The method takes both the Caché object ID for the instance and an open CacheDatabase instance as arguments.
  2. Uses the projection's getter methods to retrieve the property values from the projection and Caché object. A Java projection contains a getter method for each public property in the corresponding Caché class.
  3. Displays each of the elements in the MVFILE.PERSON PHONE array. A Java projection represents an array property using java.util.List.
  PERSON person = (PERSON)PERSON.open(db, new Id(id));
  System.out.printf("Name: %s %n",person.getName());
  System.out.printf("Age: %s %n",person.getAge());
  System.out.printf("Hair: %s %n",person.getHair());
                
  System.out.println("Phones: ");
  List phoneList = person.getPhone();
  for (Object number: phoneList)
       System.out.println(number);
                
 System.out.println("###################################");  
 
Note:
The above code is contained in DisplayPersons.java. This file is in <cachesys>\Dev\tutorials\mv. Executing the Java Examples contains step-by-step instructions for executing this code.


Send us comments on this page
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA