Skip to main content
Previous section   Next section

Inserting an Object

Here is standard Java code that uses Java Projections to create a new PERSON record and store it in Caché. In detail, the code does the following:
  1. Uses the Java projection constructor to create a new projection, PERSON, instance. This simultaneously creates a new instance of MVFILE.PERSON in Caché. Note that the constructor takes an open CacheDatabase instance as an argument.
  2. Uses the Java projection's setter methods to assign values to its properties. A Java projection contains a setter for each of the public properties of the corresponding Caché class.
  3. Uses the Java projection's save method to save the corresponding Caché object.

PERSON person = new PERSON(db);
person.setItemId("10");
person.setName("DOE,JOHN");
person.setAge("55");
person.setHair("BLOND");
List<String> phoneList = person.getPhone();
phoneList.add("111-222-3333");
phoneList.add("222-333-4444");
person.save();
Please note that the above code sets the ItemId to 10 before saving. This value must be unique in the database. If your database already has an MVFILE.PERSON record with ItemId value 10, please adjust the value in the sample code accordingly.
Note:
The above code is contained in AddPerson.java. This file is in <cachesys>\Dev\tutorials\mv. Executing the Java Examples contains step-by-step instructions for executing this code.
Previous section   Next section