This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PersistenceManager manager = factory.getPersistenceManager(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.onyxdevtools.quickstart.entities; | |
| import com.onyx.persistence.ManagedEntity; | |
| import com.onyx.persistence.annotations.*; | |
| import java.util.Date; | |
| @Entity | |
| public class Person extends ManagedEntity | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person person1 = new Person(); | |
| person1.setFirstName("John"); | |
| person1.setLastName("Elway"); | |
| person1.setDateCreated(new Date()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Attribute | |
| @Identifier(generator = IdentifierGenerator.SEQUENCE) | |
| private Integer id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| manager.saveEntity(person1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person retrievedPerson = (Person) manager.findById(Person.class, savedPerson.getId()); | |
| System.out.println("Person " + retrievedPerson.getId() + " saved successfully"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Random randomNumberGenerator = new Random(); | |
| Collection<RandomNumber> numbers = new LinkedList<>(); | |
| for(int i=0; i < 1000; i++){ | |
| RandomNumber number = new RandomNumber(); | |
| number.setNumber(randomNumberGenerator.nextInt(100)); | |
| numbers.add(number); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| manager.saveEntities(numbers); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Query query = new Query(); | |
| query.setEntityType(RandomNumber.class); | |
| List<RandomNumber> savedNumbers = manager.executeQuery(query); | |
| System.out.println(savedNumbers.size() + " random numbers saved"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person person1 = new Person(); | |
| person1.setFirstName("John"); | |
| person1.setLastName("Elway"); | |
| person1.setDateCreated(new Date()); | |
| Person savedPerson = (Person) manager.saveEntity(person1); |