use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method testEqEmptyStringEmbedded.
public void testEqEmptyStringEmbedded() {
UserHS user = new UserHS();
user.setId(1);
user.setName("test name");
user.setSurname("test surname");
user.setGender(User.Gender.MALE);
user.setNotes("1234567890");
cache.put(1, user);
QueryFactory qf = org.infinispan.query.Search.getQueryFactory(cache);
Query<User> q = qf.create("FROM " + UserHS.class.getName() + " WHERE name = ''");
List<User> list = q.execute().list();
assertTrue(list.isEmpty());
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method testRemoteQueryForEmbeddedEntryOnNonIndexedField.
public void testRemoteQueryForEmbeddedEntryOnNonIndexedField() {
UserHS user = new UserHS();
user.setId(1);
user.setName("test name");
user.setSurname("test surname");
user.setGender(User.Gender.MALE);
user.setNotes("1234567890");
cache.put(1, user);
// get user back from remote cache via query and check its attributes
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> query = qf.create("FROM sample_bank_account.User WHERE notes LIKE '%567%'");
List<User> list = query.execute().list();
assertNotNull(list);
assertEquals(1, list.size());
assertNotNull(list.get(0));
assertEquals(UserPB.class, list.get(0).getClass());
assertEquals(1, list.get(0).getId());
assertEquals("1234567890", list.get(0).getNotes());
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedRemoteInteropQueryTest method testEqEmptyStringRemote.
public void testEqEmptyStringRemote() {
UserHS user = new UserHS();
user.setId(1);
user.setName("test name");
user.setSurname("test surname");
user.setGender(User.Gender.MALE);
user.setNotes("1234567890");
cache.put(1, user);
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> q = qf.create("FROM sample_bank_account.User WHERE name = ''");
List<User> list = q.execute().list();
assertTrue(list.isEmpty());
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedUserMarshaller method readFrom.
@Override
public UserHS readFrom(ProtoStreamReader reader) throws IOException {
int id = reader.readInt("id");
Set<Integer> accountIds = reader.readCollection("accountIds", new HashSet<>(), Integer.class);
// Read them out of order. It still works but logs a warning!
String surname = reader.readString("surname");
String name = reader.readString("name");
String salutation = reader.readString("salutation");
List<Address> addresses = reader.readCollection("addresses", new ArrayList<>(), AddressHS.class);
Integer age = reader.readInt("age");
User.Gender gender = reader.readEnum("gender", User.Gender.class);
String notes = reader.readString("notes");
Instant creationDate = reader.readInstant("creationDate");
Instant passwordExpirationDate = reader.readInstant("passwordExpirationDate");
UserHS user = new UserHS();
user.setId(id);
user.setAccountIds(accountIds);
user.setName(name);
user.setSurname(surname);
user.setSalutation(salutation);
user.setAge(age);
user.setGender(gender);
user.setAddresses(addresses);
user.setNotes(notes);
user.setCreationDate(creationDate);
user.setPasswordExpirationDate(passwordExpirationDate);
return user;
}
use of org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS in project infinispan by infinispan.
the class EmbeddedQueryEngineTest method init.
@BeforeClass(alwaysRun = true)
protected void init() throws Exception {
qe = new QueryEngine<>(cache(0).getAdvancedCache(), true);
// create the test objects
User user1 = new UserHS();
user1.setId(1);
user1.setName("John");
user1.setSurname("Doe");
user1.setGender(User.Gender.MALE);
user1.setAge(22);
user1.setAccountIds(new HashSet<>(Arrays.asList(1, 2)));
user1.setNotes("Lorem ipsum dolor sit amet");
Address address1 = new AddressHS();
address1.setStreet("Main Street");
address1.setPostCode("X1234");
user1.setAddresses(Collections.singletonList(address1));
User user2 = new UserHS();
user2.setId(2);
user2.setName("Spider");
user2.setSurname("Man");
user2.setGender(User.Gender.MALE);
user2.setAge(44);
user2.setAccountIds(Collections.singleton(3));
Address address2 = new AddressHS();
address2.setStreet("Old Street");
address2.setPostCode("Y12");
Address address3 = new AddressHS();
address3.setStreet("Bond Street");
address3.setPostCode("ZZ");
user2.setAddresses(Arrays.asList(address2, address3));
User user3 = new UserHS();
user3.setId(3);
user3.setName("Spider");
user3.setSurname("Woman");
user3.setGender(User.Gender.FEMALE);
user3.setAccountIds(Collections.emptySet());
Account account1 = new AccountHS();
account1.setId(1);
account1.setDescription("John Doe's first bank account");
account1.setCreationDate(makeDate("2013-01-03"));
Account account2 = new AccountHS();
account2.setId(2);
account2.setDescription("John Doe's second bank account");
account2.setCreationDate(makeDate("2013-01-04"));
Account account3 = new AccountHS();
account3.setId(3);
account3.setCreationDate(makeDate("2013-01-20"));
Transaction transaction0 = new TransactionHS();
transaction0.setId(0);
transaction0.setDescription("Birthday present");
transaction0.setAccountId(1);
transaction0.setAmount(1800);
transaction0.setDate(makeDate("2012-09-07"));
transaction0.setDebit(false);
transaction0.setValid(true);
Transaction transaction1 = new TransactionHS();
transaction1.setId(1);
transaction1.setDescription("Feb. rent payment");
transaction1.setAccountId(1);
transaction1.setAmount(1500);
transaction1.setDate(makeDate("2013-01-05"));
transaction1.setDebit(true);
transaction1.setValid(true);
Transaction transaction2 = new TransactionHS();
transaction2.setId(2);
transaction2.setDescription("Starbucks");
transaction2.setAccountId(1);
transaction2.setAmount(23);
transaction2.setDate(makeDate("2013-01-09"));
transaction2.setDebit(true);
transaction2.setValid(true);
Transaction transaction3 = new TransactionHS();
transaction3.setId(3);
transaction3.setDescription("Hotel");
transaction3.setAccountId(2);
transaction3.setAmount(45);
transaction3.setDate(makeDate("2013-02-27"));
transaction3.setDebit(true);
transaction3.setValid(true);
Transaction transaction4 = new TransactionHS();
transaction4.setId(4);
transaction4.setDescription("Last january");
transaction4.setAccountId(2);
transaction4.setAmount(95);
transaction4.setDate(makeDate("2013-01-31"));
transaction4.setDebit(true);
transaction4.setValid(true);
Transaction transaction5 = new TransactionHS();
transaction5.setId(5);
transaction5.setDescription("Popcorn");
transaction5.setAccountId(2);
transaction5.setAmount(5);
transaction5.setDate(makeDate("2013-01-01"));
transaction5.setDebit(true);
transaction5.setValid(true);
// persist and index the test objects
// we put all of them in the same cache for the sake of simplicity
cache(0).put("user_" + user1.getId(), user1);
cache(0).put("user_" + user2.getId(), user2);
cache(0).put("user_" + user3.getId(), user3);
cache(0).put("account_" + account1.getId(), account1);
cache(0).put("account_" + account2.getId(), account2);
cache(0).put("account_" + account3.getId(), account3);
cache(0).put("transaction_" + transaction0.getId(), transaction0);
cache(0).put("transaction_" + transaction1.getId(), transaction1);
cache(0).put("transaction_" + transaction2.getId(), transaction2);
cache(0).put("transaction_" + transaction3.getId(), transaction3);
cache(0).put("transaction_" + transaction4.getId(), transaction4);
cache(0).put("transaction_" + transaction5.getId(), transaction5);
for (int i = 0; i < 50; i++) {
Transaction transaction = new TransactionHS();
transaction.setId(50 + i);
transaction.setDescription("Expensive shoes " + i);
transaction.setAccountId(2);
transaction.setAmount(100 + i);
transaction.setDate(makeDate("2013-08-20"));
transaction.setDebit(true);
transaction.setValid(true);
cache(0).put("transaction_" + transaction.getId(), transaction);
}
// this value should be ignored gracefully
cache(0).put("dummy", "a primitive value cannot be queried");
cache(0).put("notIndexed1", new NotIndexed("testing 123"));
cache(0).put("notIndexed2", new NotIndexed("xyz"));
cache(0).put("entity1", new TheEntity("test value 1", new TheEntity.TheEmbeddedEntity("test embedded value 1")));
cache(0).put("entity2", new TheEntity("test value 2", new TheEntity.TheEmbeddedEntity("test embedded value 2")));
cache(0).put("book1", new Book("Java Performance: The Definitive Guide", "O'Reilly Media", new Author("Scott", "Oaks"), "Still, it turns out that every day, I think about GC performance, or the\n" + "performance of the JVM compiler, or how to get the best performance from Java Enterprise Edition APIs."));
cache(0).put("book2", new Book("Functional Programming for Java Developers", "O'Reilly Media", new Author("Dean", "Wampler"), "Why should a Java developer learn about functional programming (FP)? After all, hasn’t\n" + "functional programming been safely hidden in academia for decades? Isn’t object-\n" + "oriented programming (OOP) all we really need?"));
cache(0).put("book3", new Book("The Java ® Virtual Machine Specification Java SE 8 Edition", "Oracle", new Author("Tim", "Lindholm"), "The Java SE 8 Edition of The Java Virtual Machine Specification incorporates all the changes that have " + "been made to the Java Virtual Machine since the Java SE 7 Edition in 2011. In addition, numerous " + "corrections and clarifications have been made to align with popular implementations of the Java Virtual Machine."));
}
Aggregations