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);
}
}
}
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;
}
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);
}
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");
}
}
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);
}
}
Aggregations