Hi Igniters,
I'm wondering if a SQL update statement must be different when used from
a ThinClient? It doesn't seem to have any effect for me, nor does it
output an error.
For the below code I get this output:
Row: [1, Foo, 2]
Row: [2, Bar, 4]
Row: [1, Foo, 3]
Row: [2, Bar, 5]
Row: [1, Foo, 3]
Row: [2, Bar, 5]
Row: [1, Foo, 3]
Row: [2, Bar, 5]
But expected should be (difference marked in red):
Row: [1, Foo, 2]
Row: [2, Bar, 4]
Row: [1, Foo, 3]
Row: [2, Bar, 5]
Row: [1, Foo, 3]
Row: [2, Bar, 5]
Row: [1, Foo, 4]
Row: [2, Bar, 6]
Code:
public class TestThinClientSQL
{
static class Person implements Serializable
{
@QuerySqlField
private String name;
@QuerySqlField
private int age;
public Person withName(String name)
{
this.name = name;
return this;
}
public Person withAge(int age)
{
this.age = age;
return this;
}
}
public static void main(String[] args)
{
try (Ignite igniteServer = Ignition.start())
{
CacheConfiguration<Long, Person> cacheCfg = new
CacheConfiguration<Long, Person>().setName("Person");
cacheCfg.setIndexedTypes(Long.class, Person.class);
IgniteCache<Long, Person> personCache =
igniteServer.createCache(cacheCfg);
personCache.put(1L, new Person().withName("Foo").withAge(2));
personCache.put(2L, new Person().withName("Bar").withAge(4));
showContent(personCache);
updateAge(personCache);
showContent(personCache);
IgniteClient thinClient =
Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"));
ClientCache<Long, Person> personCacheThin =
thinClient.cache("Person");
showContent(personCacheThin);
updateAge(personCacheThin);
showContent(personCacheThin);
}
}
private static void updateAge(IgniteCache<Long, Person> personCache)
{
SqlFieldsQuery query = new SqlFieldsQuery("UPDATE Person SET
age=age+1");
personCache.query(query);
}
private static void showContent(IgniteCache<Long, Person> personCache)
{
SqlFieldsQuery query = new SqlFieldsQuery("SELECT
_key, name, age FROM Person");
FieldsQueryCursor<List<?>> cursor = personCache.query(query);
cursor.getAll().forEach(ROW -> System.out.println("Row: " + ROW));
}
private static void updateAge(ClientCache<Long, Person> personCache)
{
SqlFieldsQuery query = new SqlFieldsQuery("UPDATE Person SET
age=age+1");
personCache.query(query);
}
private static void showContent(ClientCache<Long, Person> personCache)
{
SqlFieldsQuery query = new SqlFieldsQuery("SELECT
_key, name, age FROM Person");
FieldsQueryCursor<List<?>> cursor = personCache.query(query);
cursor.getAll().forEach(ROW -> System.out.println("Row: " + ROW));
}
}