This file contains 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
final CookBook cookBook = new CookBook(); | |
cookBook.setTitle("Onyx's House of Yummy"); | |
final Recipe cupOfNoodle = new Recipe(); | |
cupOfNoodle.setContent("Cup of Noodle"); | |
cupOfNoodle.setDetails("Open lid, add water, put powder stuff in and microwave until it boils over and makes a mess in your microwave."); | |
List<Recipe> recipees = new ArrayList<>(); | |
recipees.add(cupOfNoodle); | |
cookBook.setRecipes(recipees); |
This file contains 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
PersistenceManagerFactory persistenceManagerFactory = new CacheManagerFactory(); | |
try { | |
persistenceManagerFactory.initialize(); | |
} catch (InitializationException e) { | |
Log.e(TAG, "Cannot initialize Persistence Manager Factory"); | |
} | |
PersistenceManager persistenceManager = persistenceManagerFactory.getPersistenceManager(); |
This file contains 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 Recipe extends ManagedEntity | |
{ | |
@Attribute | |
@Identifier(generator = IdentifierGenerator.SEQUENCE) | |
private long recipeId; | |
@Attribute | |
private String content; |
This file contains 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
repositories { | |
mavenCentral() | |
} | |
... | |
dependencies { | |
compile 'com.onyxdevtools:onyx-android:1.3.0' | |
} |
This file contains 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
apply plugin: 'com.android.application' | |
repositories { | |
mavenCentral() | |
mavenLocal() | |
} | |
android { | |
compileSdkVersion 25 | |
buildToolsVersion "25.0.0" |
This file contains 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
// Remove the change listener when done | |
manager.removeChangeListener(hallOfFameQuarterBackQuery); |
This file contains 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
// Add some data to see how the change listener reacts | |
Player tomBrady = new Player(); | |
tomBrady.setFirstName("Tom"); | |
tomBrady.setLastName("Brady"); | |
tomBrady.setPosition("QB"); | |
tomBrady.setHallOfFame(true); | |
// On Item Added should be fired | |
manager.saveEntity(tomBrady); |
This file contains 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
// Execute the query to register the change listener | |
manager.executeQuery(hallOfFameQuarterBackQuery); |
This file contains 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 Change listener for query | |
hallOfFameQuarterBackQuery.setChangeListener(new QueryListener<Player>() { | |
@Override | |
public void onItemUpdated(Player item) { | |
System.out.println("Player " + item.getFirstName() + " " + item.getLastName() + " has been updated!"); | |
} | |
@Override | |
public void onItemAdded(Player item) { | |
System.out.println("Player " + item.getFirstName() + " " + item.getLastName() + " has been added!"); |
This file contains 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 critiera to match position = QB & isHallOfFame = true | |
QueryCriteria hallOfFameQuarterbackCriteria = new QueryCriteria("position", QueryCriteriaOperator.EQUAL, "QB") | |
.and(new QueryCriteria("isHallOfFame", QueryCriteriaOperator.EQUAL, true)); | |
final Query hallOfFameQuarterBackQuery = new Query(Player.class, hallOfFameQuarterbackCriteria); |
NewerOlder