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 / SortingAndPagingExample.java
Created July 14, 2016 15:11
Query for the first page (rows 0-9, records 1-10)
final List<Player> page1 = manager.executeQuery(query);
@cosbor11
cosbor11 / SortingAndPagingExample.java
Created July 14, 2016 15:09
Set the firstRow and maxResults to Implement Paging
query.setFirstRow(0);
query.setMaxResults(10);
@cosbor11
cosbor11 / SortingAndPagingExample.java
Created July 14, 2016 15:05
Create a Query using the QueryOrders
final Query query = new Query(Player.class, queryOrders);
@cosbor11
cosbor11 / SortingAndPagingExample.java
Created July 14, 2016 15:03
Create a list of QueryOrders
final List<QueryOrder> queryOrders = Arrays.asList(new QueryOrder("lastName", true), new QueryOrder("firstName", true));
@cosbor11
cosbor11 / ManualMigrationDemo.java
Created July 13, 2016 03:02
Use the Stream API to iterate through all the records and perform a migration
persistenceManager.stream(accountQuery, (QueryMapStream) (o, internalPersistenceManager) -> {
Map accountMap = (Map)o;
try {
// Ensure the property still exists within the data.
if(accountMap.containsKey("balanceDue"))
{
double balanceDue = (double) accountMap.get("balanceDue");
// This field has been updated to long in the new data model but, the old data model persisted it as an int. So, that is the reason why we cast it as an integer.
@cosbor11
cosbor11 / ManualMigrationDemo.java
Created July 13, 2016 03:01
Define a query designed to retrieve all accounts.
final Query accountQuery = new Query(Account.class, new QueryCriteria("accountId", QueryCriteriaOperator.NOT_NULL));
@cosbor11
cosbor11 / UpdateQueryExample.java
Created July 12, 2016 15:46
Re-execute to confirm that entites were updated
final List<Player> qbs = manager.executeQuery(query);
for (final Player qb : qbs)
{
System.out.println(qb.getFirstName() + " " + qb.getLastName() + ": active=" + qb.getActive());
}
@cosbor11
cosbor11 / UpdateQueryExample.java
Created July 12, 2016 15:42
Invoke executeUpdate
final Query updateQuery = new Query(Player.class, compoundCriteria, updateActiveToFalse);
manager.executeUpdate(updateQuery);
@cosbor11
cosbor11 / UpdateQueryExample.java
Created July 12, 2016 15:36
Create an AttributeUpdate
AttributeUpdate updateActiveToFalse = new AttributeUpdate("active", false);
@cosbor11
cosbor11 / UpdateQueryExample.java
Created July 12, 2016 15:33
query for qbs and print each one
final List<Player> players = manager.executeQuery(query);
for (final Player qb : players)
{
System.out.println(qb.getFirstName() + " " + qb.getLastName() + ": active=" + qb.getActive());
}