use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class CacheQueryBuildValueTest method testBuilderAndQuery.
/**
* @throws Exception If failed.
*/
public void testBuilderAndQuery() throws Exception {
Ignite node = ignite(0);
final IgniteCache<Object, Object> cache = node.cache(DEFAULT_CACHE_NAME);
IgniteBinary binary = node.binary();
BinaryObjectBuilder builder = binary.builder(TestBuilderValue.class.getName());
cache.put(0, builder.build());
builder.setField("iVal", 1);
cache.put(1, builder.build());
List<Cache.Entry<Object, Object>> entries = cache.query(new SqlQuery<>(TestBuilderValue.class, "true")).getAll();
assertEquals(2, entries.size());
}
use of org.apache.ignite.IgniteBinary in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method testEnumObjectQuery.
/**
* JUnit.
*
* @throws Exception In case of error.
*/
public void testEnumObjectQuery() throws Exception {
final IgniteCache<Long, EnumObject> cache = jcache(Long.class, EnumObject.class);
for (long i = 0; i < 50; i++) cache.put(i, new EnumObject(i, i % 2 == 0 ? EnumType.TYPE_A : EnumType.TYPE_B));
assertEnumQry("type = ?", EnumType.TYPE_A, EnumType.TYPE_A, cache, 25);
assertEnumQry("type > ?", EnumType.TYPE_A, EnumType.TYPE_B, cache, 25);
assertEnumQry("type < ?", EnumType.TYPE_B, EnumType.TYPE_A, cache, 25);
assertEnumQry("type != ?", EnumType.TYPE_B, EnumType.TYPE_A, cache, 25);
assertEmptyEnumQry("type = ?", null, cache);
assertEmptyEnumQry("type > ?", EnumType.TYPE_B, cache);
assertEmptyEnumQry("type < ?", EnumType.TYPE_A, cache);
cache.put(50L, new EnumObject(50, null));
assertNoArgEnumQry("type is null", null, cache, 1);
assertAnyResTypeEnumQry("type is not null", cache, 50);
// Additional tests for binary enums.
IgniteBinary binary = ignite().binary();
if (binary != null) {
assertEnumQry("type = ?", binaryEnum(binary, EnumType.TYPE_A), EnumType.TYPE_A, cache, 25);
assertEnumQry("type > ?", binaryEnum(binary, EnumType.TYPE_A), EnumType.TYPE_B, cache, 25);
assertEnumQry("type < ?", binaryEnum(binary, EnumType.TYPE_B), EnumType.TYPE_A, cache, 25);
assertEnumQry("type != ?", binaryEnum(binary, EnumType.TYPE_B), EnumType.TYPE_A, cache, 25);
assertEmptyEnumQry("type > ?", binaryEnum(binary, EnumType.TYPE_B), cache);
assertEmptyEnumQry("type < ?", binaryEnum(binary, EnumType.TYPE_A), cache);
}
}
Aggregations