Search in sources :

Example 96 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class CacheClientBinaryQueryExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     */
public static void main(String[] args) {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Binary objects cache query example started.");
        CacheConfiguration<Integer, Organization> orgCacheCfg = new CacheConfiguration<>();
        orgCacheCfg.setCacheMode(CacheMode.PARTITIONED);
        orgCacheCfg.setName(ORGANIZATION_CACHE_NAME);
        orgCacheCfg.setQueryEntities(Arrays.asList(createOrganizationQueryEntity()));
        CacheConfiguration<EmployeeKey, Employee> employeeCacheCfg = new CacheConfiguration<>();
        employeeCacheCfg.setCacheMode(CacheMode.PARTITIONED);
        employeeCacheCfg.setName(EMPLOYEE_CACHE_NAME);
        employeeCacheCfg.setQueryEntities(Arrays.asList(createEmployeeQueryEntity()));
        try (IgniteCache<Integer, Organization> orgCache = ignite.getOrCreateCache(orgCacheCfg);
            IgniteCache<EmployeeKey, Employee> employeeCache = ignite.getOrCreateCache(employeeCacheCfg)) {
            if (ignite.cluster().forDataNodes(orgCache.getName()).nodes().isEmpty()) {
                System.out.println();
                System.out.println(">>> This example requires remote cache nodes to be started.");
                System.out.println(">>> Please start at least 1 remote cache node.");
                System.out.println(">>> Refer to example's javadoc for details on configuration.");
                System.out.println();
                return;
            }
            // Populate cache with sample data entries.
            populateCache(orgCache, employeeCache);
            // Get cache that will work with binary objects.
            IgniteCache<BinaryObject, BinaryObject> binaryCache = employeeCache.withKeepBinary();
            // Run SQL query example.
            sqlQuery(binaryCache);
            // Run SQL query with join example.
            sqlJoinQuery(binaryCache);
            // Run SQL fields query example.
            sqlFieldsQuery(binaryCache);
            // Run full text query example.
            textQuery(binaryCache);
            System.out.println();
        } finally {
            // Delete caches with their content completely.
            ignite.destroyCache(ORGANIZATION_CACHE_NAME);
            ignite.destroyCache(EMPLOYEE_CACHE_NAME);
        }
    }
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Employee(org.apache.ignite.examples.model.Employee) EmployeeKey(org.apache.ignite.examples.model.EmployeeKey) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 97 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class ComputeClientTask method split.

/** {@inheritDoc} */
@Override
protected Collection<? extends ComputeJob> split(int gridSize, Collection<BinaryObject> arg) {
    Collection<ComputeClientJob> jobs = new ArrayList<>();
    Collection<BinaryObject> employees = new ArrayList<>();
    // create a job for each batch.
    for (BinaryObject employee : arg) {
        employees.add(employee);
        if (employees.size() == 3) {
            jobs.add(new ComputeClientJob(employees));
            employees = new ArrayList<>(3);
        }
    }
    if (!employees.isEmpty())
        jobs.add(new ComputeClientJob(employees));
    return jobs;
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) ArrayList(java.util.ArrayList)

Example 98 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class CacheClientBinaryPutGetExample method putGetAllBinary.

/**
     * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations,
     * getting values in binary format, without de-serializing it.
     *
     * @param cache Cache.
     */
private static void putGetAllBinary(IgniteCache<Integer, Organization> cache) {
    // Create new Organization binary objects to store in cache.
    Organization org1 = new Organization(// Name.
    "Microsoft", // Address.
    new Address("1096 Eddy Street, San Francisco, CA", 94109), // Type.
    OrganizationType.PRIVATE, // Last update time.
    new Timestamp(System.currentTimeMillis()));
    Organization org2 = new Organization(// Name.
    "Red Cross", // Address.
    new Address("184 Fidler Drive, San Antonio, TX", 78205), // Type.
    OrganizationType.NON_PROFIT, // Last update time.
    new Timestamp(System.currentTimeMillis()));
    Map<Integer, Organization> map = new HashMap<>();
    map.put(1, org1);
    map.put(2, org2);
    // Put created data entries to cache.
    cache.putAll(map);
    // Get cache that will get values as binary objects.
    IgniteCache<Integer, BinaryObject> binaryCache = cache.withKeepBinary();
    // Get recently created organizations as binary objects.
    Map<Integer, BinaryObject> poMap = binaryCache.getAll(map.keySet());
    Collection<String> names = new ArrayList<>();
    // objects don't need to be fully deserialized).
    for (BinaryObject po : poMap.values()) names.add(po.<String>field("name"));
    System.out.println();
    System.out.println(">>> Retrieved organization names from binary objects: " + names);
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Address(org.apache.ignite.examples.model.Address) BinaryObject(org.apache.ignite.binary.BinaryObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp)

Example 99 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class IgnitePersistentStoreTest method blobBinaryLoadCacheTest.

/** */
@Test
public void blobBinaryLoadCacheTest() {
    Ignition.stopAll(true);
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/loadall_blob/ignite-config.xml")) {
        IgniteCache<Long, PojoPerson> personCache = ignite.getOrCreateCache("cache2");
        assert ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
        personCache.put(1L, new PojoPerson(1, "name"));
        assert personCache.withKeepBinary().get(1L) instanceof BinaryObject;
    }
    Ignition.stopAll(true);
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/loadall_blob/ignite-config.xml")) {
        IgniteCache<Long, PojoPerson> personCache = ignite.getOrCreateCache("cache2");
        personCache.loadCache(null, null);
        PojoPerson person = personCache.get(1L);
        LOGGER.info("loadCache tests passed");
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 100 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class GridCacheReturn method addEntryProcessResult.

/**
     * @param cctx Context.
     * @param key Key.
     * @param key0 Key value.
     * @param res Result.
     * @param err Error.
     * @param keepBinary Keep binary.
     */
@SuppressWarnings("unchecked")
public synchronized void addEntryProcessResult(GridCacheContext cctx, KeyCacheObject key, @Nullable Object key0, @Nullable Object res, @Nullable Exception err, boolean keepBinary) {
    assert v == null || v instanceof Map : v;
    assert key != null;
    assert res != null || err != null;
    invokeRes = true;
    if (loc) {
        HashMap<Object, EntryProcessorResult> resMap = (HashMap<Object, EntryProcessorResult>) v;
        if (resMap == null) {
            resMap = new HashMap<>();
            v = resMap;
        }
        CacheInvokeResult res0 = err == null ? CacheInvokeResult.fromResult(res) : CacheInvokeResult.fromError(err);
        Object resKey = key0 != null ? key0 : ((keepBinary && key instanceof BinaryObject) ? key : CU.value(key, cctx, true));
        resMap.put(resKey, res0);
    } else {
        assert v == null;
        assert cacheId == 0 || cacheId == cctx.cacheId();
        cacheId = cctx.cacheId();
        if (invokeResCol == null)
            invokeResCol = new ArrayList<>();
        CacheInvokeDirectResult res0 = err == null ? new CacheInvokeDirectResult(key, cctx.toCacheObject(res)) : new CacheInvokeDirectResult(key, err);
        invokeResCol.add(res0);
    }
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) BinaryObject(org.apache.ignite.binary.BinaryObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BinaryObject(org.apache.ignite.binary.BinaryObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)173 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)54 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)24 IgniteCache (org.apache.ignite.IgniteCache)21 Ignite (org.apache.ignite.Ignite)19 HashMap (java.util.HashMap)14 Map (java.util.Map)14 LinkedHashMap (java.util.LinkedHashMap)13 ArrayList (java.util.ArrayList)12 Cache (javax.cache.Cache)12 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 List (java.util.List)8 UUID (java.util.UUID)8 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)6 BinaryType (org.apache.ignite.binary.BinaryType)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 Transaction (org.apache.ignite.transactions.Transaction)6