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
| // Create a call log for area code (555) | |
| CellPhone myPhoneNumber = new CellPhone(); | |
| myPhoneNumber.setCellPhoneNumber("(555) 303-2322"); | |
| myPhoneNumber.setAreaCode(555); | |
| manager.saveEntity(myPhoneNumber); | |
| CallLog callToMom = new CallLog(); | |
| callToMom.setDestinationNumber("(555) 323-2222"); | |
| callToMom.setNSAListening(true); | |
| callToMom.setCallFrom(myPhoneNumber); |
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
| // Create a query that includes the partition and flag for whether the NSA is listening | |
| // Area Code is partitioned and isNSAListening is indexed. This should be an optimized query | |
| QueryCriteria nsaListeningCriteria = new QueryCriteria( | |
| "isNSAListening", QueryCriteriaOperator.EQUAL, true); | |
| Query query = new Query(CallLog.class, nsaListeningCriteria); | |
| query.setPartition(555); | |
| List<CallLog> nsaIsWastingThereTimeListeningTo = manager.executeQuery(query); | |
| assertTrue("NSA is only listening to 1 call in area code 555", nsaIsWastingThereTimeListeningTo.size() == 1); |
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
| // Use Find By ID in Partition to fetch a call log within a partition | |
| CallLog callLogInAreaCode555 = (CallLog) manager.findByIdInPartition(CallLog.class, 1, 555); | |
| CallLog callLogInAreaCode123 = (CallLog) manager.findByIdInPartition(CallLog.class, 1, 123); | |
| // Make sure the CallLog(s) are 2 different entities. | |
| assertTrue("The Destination Number should be different for each CallLog!", !callLogInAreaCode123.getDestinationNumber().equals(callLogInAreaCode555.getDestinationNumber())); |
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
| @Entity | |
| public class BeverageEffects extends ManagedEntity implements IManagedEntity | |
| { | |
| public BeverageEffects() | |
| { | |
| } | |
| protected Beverage beverage; |
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
| public enum Beverage | |
| { | |
| BEER("Im feeling dangerous", "Lets makeout on a plane and annoy the people around me!", "Hold my hair back"), | |
| WATER("Soooo thirsty", "Satisfied", "I gotta pee"), | |
| COFFEE("Very Sleepy", "Bouncing off the walls", "Zzzzzzzzzz"); | |
| protected String preConsumption; | |
| protected String duringConsumption; |
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
| // Event lifecycle listeners | |
| @PostInsert | |
| private void beforeInsert() | |
| { | |
| this.description = this.beverage.getPreConsumption(); | |
| } | |
| @PostUpdate | |
| private void postUpdate() | |
| { |
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
| // Define a beverage effect | |
| BeverageEffects effectsOfWater = new BeverageEffects(Beverage.WATER); | |
| // Observe the behavior of the pre insert listener | |
| manager.saveEntity(effectsOfWater); | |
| assertTrue("After saving the behavior entity, the effects should be thirsty", effectsOfWater.getDescription().equals(Beverage.WATER.getPreConsumption())); | |
| // Observe the behavior of the pre update listener | |
| manager.saveEntity(effectsOfWater); | |
| assertTrue("After updating the behavior entity, the effects should be satisfied", effectsOfWater.getDescription().equals(Beverage.WATER.getDuringConsumption())); |
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
| <dependencies> | |
| <dependency> | |
| <groupId>com.onyxdevtools</groupId> | |
| <artifactId>onyx-database</artifactId> | |
| <version>${onyx-database.version}</version> | |
| </dependency> | |
| <!-- Spring framework --> | |
| <dependency> | |
| <groupId>org.springframework</groupId> |
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
| @Configuration | |
| public class MeetingApplicationConfiguration | |
| { | |
| /** | |
| * Persistence Manager factory. This determines your database connection. This would have the same usage if | |
| * you were connecting to an embedded or remote database. The only difference would be the factory type. | |
| * | |
| * @return Initialized Persistence Manager Factory | |
| */ | |
| @Bean |
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
| @Controller | |
| public class MeetingController | |
| { | |
| // Persistence Manager injected by spring | |
| @Autowired | |
| protected PersistenceManager persistenceManager; | |
| /** | |
| * Simple method used to encapsulate the saving of a meeting. | |
| * @param meeting Meeting to persist |