This file contains hidden or 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 QueryCriteria positionCriteria = new QueryCriteria("position", QueryCriteriaOperator.EQUAL, "QB"); | |
final QueryCriteria passingCriteria = new QueryCriteria("stats.passingYards", QueryCriteriaOperator.LESS_THAN, 1500); | |
final QueryCriteria compoundCriteria = positionCriteria.and(passingCriteria); | |
Query query = new Query(Player.class, compoundCriteria); |
This file contains hidden or 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 EntityDescriptor entityDescriptor = persistenceManager.getContext().getDescriptorForEntity(Payment.class, ""); | |
final IndexDescriptor indexDescriptor = entityDescriptor.getIndexes().get("notes"); | |
final IndexController indexController = persistenceManager.getContext().getIndexController(indexDescriptor); | |
indexController.rebuild(); |
This file contains hidden or 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 Query indexedQuery = new Query(Invoice.class, new QueryCriteria("dueDate", QueryCriteriaOperator.EQUAL, parseDate("04-01-2016"))); | |
final List<Invoice> invoices = persistenceManager.executeQuery(indexedQuery); | |
// First pass may not give you 2 results since the index could still be rebuilding. After it is done re-indexing you should have 2 results. | |
assert invoices.size() == 2; |
This file contains hidden or 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 Query nonIndexedQuery = new Query(Invoice.class, new QueryCriteria("amount", QueryCriteriaOperator.EQUAL, 44.32)); | |
List<Payment> payments = persistenceManager.executeQuery(nonIndexedQuery); | |
// See that we still get results by doing the full table scan. | |
assert payments.size() == 2; |
This file contains hidden or 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 Payment extends ManagedEntity implements IManagedEntity | |
{ | |
@Attribute | |
@Identifier | |
protected long paymentId; | |
@Relationship(type = RelationshipType.MANY_TO_ONE, | |
inverse = "payments", | |
inverseClass = Invoice.class) |
This file contains hidden or 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 Invoice myLatestInvoice = (Invoice)persistenceManager.findById(Invoice.class, 1l); | |
// This used to be a single entity and now it is a list of payments since the relationship has changed from a One To One | |
// to a One To Many. This is also handled by the light weight migration. | |
List<Payment> paymentList = myLatestInvoice.getPayments(); | |
// What previously was a one to one relationship should have the existing record in the set. | |
assert paymentList.size() == 1; | |
assert paymentList.get(0).getPaymentId() == 1; |
This file contains hidden or 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
@Relationship(type = RelationshipType.ONE_TO_MANY, | |
inverse = "invoice", | |
inverseClass = Payment.class, | |
cascadePolicy = CascadePolicy.SAVE, | |
fetchPolicy = FetchPolicy.EAGER) | |
protected List<Payment> payments; |
This file contains hidden or 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
@Relationship(type = RelationshipType.MANY_TO_ONE, | |
inverse = "payments", | |
inverseClass = Invoice.class) | |
protected Invoice invoice; |
This file contains hidden or 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
// 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; | |
// This example creates a new account and attempts to save it without an identifier. | |
Account account2 = new Account(); | |
persistenceManager.saveEntity(account2); | |
// The account ID was not auto incremented. | |
// This is because we removed the generator from the @Identifier annotation. |
This file contains hidden or 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
List<Player> inactivePlayers = manager.executeQuery(query); | |
// There should only be one inactivePlayer: Calvin Johnson | |
for (final Player player : inactivePlayers) | |
{ | |
System.out.println(player.getFirstName() + " " + player.getLastName() + " is not active."); | |
} | |
manager.executeDelete(query); |