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
/**
* IBAction for saving a person. This will create a save request with a new
*/
- (IBAction) savePerson:(id)sender
{
// Create a new Person
Person *person = [Person new];
[person setFirstName:@"Bob"];
[person setLastName:@"Sanchez"];
@cosbor11
cosbor11 / Person.java
Created October 23, 2015 07:06
onyx web person entity
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
{
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
@cosbor11
cosbor11 / Actor.java
Created January 22, 2016 03:53
Entity Definition of an Actor
@Entity
public class Actor
{
@Attribute
@Identifier(generator = IdentifierGenerator.SEQUENCE)
protected long actorId;
@Attribute
protected String actorFirstName;
@cosbor11
cosbor11 / Movie.java
Created January 22, 2016 03:55
Entity Definition of a Movie declaring a To Many relationship to actors
@Entity
public class Movie
{
@Identifier(generator = IdentifierGenerator.SEQUENCE)
@Attribute
protected long movieId;
@Attribute
protected String title;
@cosbor11
cosbor11 / Main.java
Last active January 22, 2016 04:38
Save movies with many to many relationship to actors
// Define Harrison Ford Actor
Actor harrisonFordActor = new Actor();
harrisonFordActor.setFirstName("Harrison");
harrisonFordActor.setLastName("Ford");
// Define Mark Hamill Actor
Actor markHamillActor = new Actor();
markHamillActor.setFirstName("Mark");
markHamillActor.setLastName("Hamill");
@cosbor11
cosbor11 / Main.java
Created January 22, 2016 04:28
Hydrate Harrison Ford Actor
harrisonFordActor = persistenceManager.find(harrisonFordActor);
persistenceManager.initialize(harrisonFordActor, "movies");
System.out.println("Harrison Ford has been in "
+ harrisonFordActor.getMovies().size()
+ " movies including "
+ harrisonFordActor.getMovies().get(0).getTitle()
+ " and "
+ harrisonFordActor.getMovies().get(1).getTitle()
+ "!");
@cosbor11
cosbor11 / Movie.java
Created March 27, 2016 05:33
Define a movie
@Entity
public class Movie extends ManagedEntity implements IManagedEntity
{
@Identifier(generator = IdentifierGenerator.SEQUENCE)
@Attribute
public int movieId;
@Attribute
public String title;
@cosbor11
cosbor11 / CascadeDeferExample.java
Created March 27, 2016 05:35
Create test data for movie and actor entities
// Populate the movie data with actors //1
Movie starWarsMovie = new Movie();
starWarsMovie.title = "Star Wars, A new Hope";
ArrayList<Actor> actors = new ArrayList<>();
Actor markHamil = new Actor();
markHamil.actorId = 1;
markHamil.firstName = "Mark";
markHamil.lastName = "Hamil";
@cosbor11
cosbor11 / CascadeDeferExample.java
Created March 27, 2016 05:37
Verify the actors were not associated to the movie
// The Persistence Manager did not save the actors and associated it to the movie //2
Movie starWarsAfterSave1 = (Movie) manager.findById(Movie.class, starWarsMovie.movieId);
manager.initialize(starWarsAfterSave1, "actors");
if(starWarsAfterSave1.actors.size() == 0) {
System.out.println("Actors have NOT been associated yet");
}