Search in sources :

Example 11 with IgniteBinary

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());
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 12 with IgniteBinary

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);
    }
}
Also used : IgniteBinary(org.apache.ignite.IgniteBinary)

Aggregations

IgniteBinary (org.apache.ignite.IgniteBinary)12 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)8 Ignite (org.apache.ignite.Ignite)7 BinaryObject (org.apache.ignite.binary.BinaryObject)5 HashSet (java.util.HashSet)2 BinaryType (org.apache.ignite.binary.BinaryType)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)2 ConcurrentHashSet (org.eclipse.jetty.util.ConcurrentHashSet)2 ResultSet (java.sql.ResultSet)1 Collection (java.util.Collection)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SqlQuery (org.apache.ignite.cache.query.SqlQuery)1 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)1 Transaction (org.apache.ignite.transactions.Transaction)1