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 / DeleteQueryExample.java
Created July 5, 2016 14:46
re-execute query to verify they were deleted
inactivePlayers = manager.executeQuery(query);
System.out.println("There are " + inactivePlayers.size() + " inactive players now."); // should be zero
@cosbor11
cosbor11 / DeleteQueryExample.java
Created July 5, 2016 14:33
execute delete query
manager.executeDelete(query);
@cosbor11
cosbor11 / DeleteQueryExample.java
Created July 5, 2016 14:30
Create a delete query and critiera
final QueryCriteria criteria = new QueryCriteria("active", QueryCriteriaOperator.EQUAL, false);
final Query query = new Query(Player.class, criteria);
@cosbor11
cosbor11 / Main.java
Created July 5, 2016 14:28
Main executable class to seed data to showcase the model update examples
public static void main(String[] args) throws EntityException{
// Create a database and its connection
PersistenceManagerFactory factory = new EmbeddedPersistenceManagerFactory(); //1
factory.setCredentials("onyx", "SavingDataisFun!"); //2
String pathToOnyxDB = System.getProperty("user.home")
+ File.separatorChar + ".onyxdb"
+ File.separatorChar + "sandbox"
@cosbor11
cosbor11 / Main.java
Created July 5, 2016 13:43
Reconnect to the updated database.
// Create a database and its connection
PersistenceManagerFactory factory = new EmbeddedPersistenceManagerFactory(); //1
factory.setCredentials("onyx", "SavingDataisFun!"); //2
String pathToOnyxDB = System.getProperty("user.home")
+ File.separatorChar + ".onyxdb"
+ File.separatorChar + "sandbox"
+ File.separatorChar +"model-update-db.oxd";
factory.setDatabaseLocation(pathToOnyxDB); //3
@cosbor11
cosbor11 / Main.java
Created July 5, 2016 13:42
Showcase how the Account entity has been changed including added and removed attributes
// Fetch an account. Notice that the id is now a long rather than an integer.
Account account = (Account)persistenceManager.findById(Account.class, 1l);
assert account.getAccountId() == 1l;
// The Account Name is a new field and is now persistable.
// This demonstrates that we can now take
// advantage of the new field.
account.setAccountName("Utility Bill");
persistenceManager.saveEntity(account);
@cosbor11
cosbor11 / Account.java
Created July 5, 2016 13:40
Account entity model updates
@Entity
public class Account extends ManagedEntity implements IManagedEntity
{
// Note, I have changed the type of the accountId from an int to a long. Also the generator was removed.
@Attribute
@Identifier
protected long accountId;
// Note, I have added the Account Holder's Name attribute
@Attribute
@cosbor11
cosbor11 / Main.java
Created July 5, 2016 13:38
Seed data before updating the model to show the effects of a lightweight migration
Account account = new Account();
account.setAccountName("Timbob's Lawn Care");
account.setBalanceDue(55.43f);
Invoice marchLawnInvoice = new Invoice();
marchLawnInvoice.setDueDate(parseDate("04-01-2016"));
marchLawnInvoice.setInvoiceDate(parseDate("03-01-2016"));
marchLawnInvoice.setNotes("Why did we need to mow your lawn. Its basically a dirt field.");
marchLawnInvoice.setInvoiceId(1l);
marchLawnInvoice.setAmount(44.32);
@cosbor11
cosbor11 / Payment.java
Created July 5, 2016 13:36
Payment entity before model updates
@Entity
public class Payment extends ManagedEntity implements IManagedEntity
{
@Attribute
@Identifier
protected long paymentId;
@Relationship(type = RelationshipType.ONE_TO_ONE,
inverse = "payments",
inverseClass = Invoice.class)
@cosbor11
cosbor11 / Invoice.java
Created July 5, 2016 13:35
Invoice entity before the model updates
@Entity
public class Invoice extends ManagedEntity implements IManagedEntity
{
@Attribute
@Identifier
protected Long invoiceId;
@Attribute
protected Date invoiceDate;