Skip to content

Instantly share code, notes, and snippets.

View cosbor11's full-sized avatar
🤓
always coding

Chris Osborn cosbor11

🤓
always coding
View GitHub Profile
@cosbor11
cosbor11 / Main.java
Created April 7, 2016 03:39
Create test data to outline how data is stored in different partitions
// 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);
@cosbor11
cosbor11 / Main.java
Created April 7, 2016 03:40
Query partitioned data
// 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);
@cosbor11
cosbor11 / Main.java
Created April 7, 2016 03:42
Find record by id in 2 different partitions
// 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()));
@cosbor11
cosbor11 / BeverageEffect.java
Last active April 7, 2016 04:12
Create an entity to model the effects of a beverage including event listeners.
@Entity
public class BeverageEffects extends ManagedEntity implements IManagedEntity
{
public BeverageEffects()
{
}
protected Beverage beverage;
@cosbor11
cosbor11 / Beverage.java
Created April 7, 2016 03:46
A set of constants that outline the effects of a beverage
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;
@cosbor11
cosbor11 / BeverageEffect.java
Created April 7, 2016 03:48
Add event lifecycle methods to the BeverageEffect entity
// Event lifecycle listeners
@PostInsert
private void beforeInsert()
{
this.description = this.beverage.getPreConsumption();
}
@PostUpdate
private void postUpdate()
{
@cosbor11
cosbor11 / Main.java
Created April 7, 2016 03:49
Manipulate a BeverageEffect in order to observe its lifecycle behavior
// 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()));
@cosbor11
cosbor11 / pom.xml
Created May 6, 2016 17:33
Add Spring dependencies within your maven configuration pom
<dependencies>
<dependency>
<groupId>com.onyxdevtools</groupId>
<artifactId>onyx-database</artifactId>
<version>${onyx-database.version}</version>
</dependency>
<!-- Spring framework -->
<dependency>
<groupId>org.springframework</groupId>
@cosbor11
cosbor11 / MeetingApplicationConfiguration.java
Created May 6, 2016 17:34
Spring Configuration file including connection to Onyx Database
@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
@cosbor11
cosbor11 / MeetingController.java
Created May 6, 2016 17:35
Create a Spring Controller and Autowire the PersistenceManager
@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