/** * Query all purchases made at a specific store for 3 specific products. This query uses * cross-cache joins between {@link DimStore}, {@link DimProduct} objects stored in {@code * 'replicated'} cache and {@link FactPurchase} objects stored in {@code 'partitioned'} cache. * * @throws IgniteException If failed. */ private static void queryProductPurchases() { IgniteCache<Integer, FactPurchase> factCache = Ignition.ignite().cache(PARTITIONED_CACHE_NAME); // All purchases for certain product made at store2. // ================================================= DimProduct p1 = rand(dataProduct.values()); DimProduct p2 = rand(dataProduct.values()); DimProduct p3 = rand(dataProduct.values()); System.out.println( "IDs of products [p1=" + p1.getId() + ", p2=" + p2.getId() + ", p3=" + p3.getId() + ']'); // Create cross cache query to get all purchases made at store2 // for specified products. QueryCursor<Cache.Entry<Integer, FactPurchase>> prodPurchases = factCache.query( new SqlQuery( FactPurchase.class, "from \"" + REPLICATED_CACHE_NAME + "\".DimStore, \"" + REPLICATED_CACHE_NAME + "\".DimProduct, " + "\"" + PARTITIONED_CACHE_NAME + "\".FactPurchase " + "where DimStore.id=FactPurchase.storeId and DimProduct.id=FactPurchase.productId " + "and DimStore.name=? and DimProduct.id in(?, ?, ?)") .setArgs("Store2", p1.getId(), p2.getId(), p3.getId())); printQueryResults( "All purchases made at store2 for 3 specific products:", prodPurchases.getAll()); }
/** * Populate cache with {@code 'facts'}, which in our case are {@link FactPurchase} objects. * * @param factCache Cache to populate. * @throws IgniteException If failed. */ private static void populateFacts(Cache<Integer, FactPurchase> factCache) throws IgniteException { for (int i = 0; i < 100; i++) { int id = idGen++; DimStore store = rand(dataStore.values()); DimProduct prod = rand(dataProduct.values()); factCache.put(id, new FactPurchase(id, prod.getId(), store.getId(), (i + 1))); } }
/** * @param springCfgPath Spring configuration file path. * @return Grid configuration. * @throws Exception If failed. */ protected static IgniteConfiguration loadConfiguration(String springCfgPath) throws Exception { URL url; try { url = new URL(springCfgPath); } catch (MalformedURLException e) { url = IgniteUtils.resolveIgniteUrl(springCfgPath); if (url == null) throw new IgniteCheckedException( "Spring XML configuration path is invalid: " + springCfgPath + ". Note that this path should be either absolute or a relative local file system path, " + "relative to META-INF in classpath or valid URL to IGNITE_HOME.", e); } GenericApplicationContext springCtx; try { springCtx = new GenericApplicationContext(); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url)); springCtx.refresh(); } catch (BeansException e) { throw new Exception( "Failed to instantiate Spring XML application context [springUrl=" + url + ", err=" + e.getMessage() + ']', e); } Map<String, IgniteConfiguration> cfgMap; try { cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); } catch (BeansException e) { throw new Exception( "Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null || cfgMap.isEmpty()) throw new Exception("Failed to find ignite configuration in: " + url); return cfgMap.values().iterator().next(); }
/** * @param cls Component class. * @param <T> Component type. * @return Component class instance or {@code null} if no one plugin override this component. */ public <T> T createComponent(Class<T> cls) { for (PluginProvider plugin : plugins.values()) { PluginContext ctx = pluginContextForProvider(plugin); T comp = (T) plugin.createComponent(ctx, cls); if (comp != null) return comp; } return null; }
/** Print plugins information. */ private void ackPluginsInfo() { U.quietAndInfo(log, "Configured plugins:"); if (plugins.isEmpty()) { U.quietAndInfo(log, " ^-- None"); U.quietAndInfo(log, ""); } else { for (PluginProvider plugin : plugins.values()) { U.quietAndInfo(log, " ^-- " + plugin.name() + " " + plugin.version()); U.quietAndInfo(log, " ^-- " + plugin.copyright()); U.quietAndInfo(log, ""); } } }
/** @return All plugin providers. */ public Collection<PluginProvider> allProviders() { return plugins.values(); }