Person val = new Person(key, Integer.toString(key));
Person obj = new Person(1, "Joe");
/** * Tested API: * <ul> * <li>{@link IgniteClient#query(SqlFieldsQuery)}</li> * </ul> */ @Test public void testSql() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { client.query( new SqlFieldsQuery(String.format( "CREATE TABLE IF NOT EXISTS Person (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"", Person.class.getName() )).setSchema("PUBLIC") ).getAll(); int key = 1; Person val = new Person(key, "Person 1"); client.query(new SqlFieldsQuery( "INSERT INTO Person(id, name) VALUES(?, ?)" ).setArgs(val.getId(), val.getName()).setSchema("PUBLIC")) .getAll(); Object cachedName = client.query( new SqlFieldsQuery("SELECT name from Person WHERE id=?").setArgs(key).setSchema("PUBLIC") ).getAll().iterator().next().iterator().next(); assertEquals(val.getName(), cachedName); } }
/** * Unmarshalling schema-less Ignite binary objects into Java static types. */ @Test public void testUnmarshalSchemalessIgniteBinaries() throws Exception { int key = 1; Person val = new Person(key, "Joe"); try (Ignite srv = Ignition.start(Config.getServerConfiguration())) { // Add an entry directly to the Ignite server. This stores a schema-less object in the cache and // does not register schema in the client's metadata cache. srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val); try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) { ClientCache<Integer, Person> cache = client.cache(Config.DEFAULT_CACHE_NAME); Person cachedVal = cache.get(key); assertEquals(val, cachedVal); } } }
/** * Reading schema-less Ignite Binary object. */ @Test public void testReadingSchemalessIgniteBinaries() throws Exception { int key = 1; Person val = new Person(key, "Joe"); try (Ignite srv = Ignition.start(Config.getServerConfiguration())) { // Add an entry directly to the Ignite server. This stores a schema-less object in the cache and // does not register schema in the client's metadata cache. srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val); try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) { ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary(); BinaryObject cachedVal = cache.get(key); assertEquals(val.getId(), cachedVal.field("id")); assertEquals(val.getName(), cachedVal.field("name")); } } }