http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicy.java new file mode 100644 index 0000000..dc070fe --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicy.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.eviction.lru; + +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.eviction.*; +import org.gridgain.grid.cache.*; +import org.jdk8.backport.*; +import org.jdk8.backport.ConcurrentLinkedDeque8.*; +import org.gridgain.grid.util.typedef.internal.*; + +import java.util.*; + +/** + * Eviction policy based on {@code Least Recently Used (LRU)} algorithm. This + * implementation is very efficient since it is lock-free and does not + * create any additional table-like data structures. The {@code LRU} ordering + * information is maintained by attaching ordering metadata to cache entries. + */ +public class GridCacheLruEvictionPolicy<K, V> implements GridCacheEvictionPolicy<K, V>, + GridCacheLruEvictionPolicyMBean { + /** Tag. */ + private final String meta = UUID.randomUUID().toString(); + + /** Maximum size. */ + private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE; + + /** Queue. */ + private final ConcurrentLinkedDeque8<GridCacheEntry<K, V>> queue = + new ConcurrentLinkedDeque8<>(); + + /** + * Constructs LRU eviction policy with all defaults. + */ + public GridCacheLruEvictionPolicy() { + // No-op. + } + + /** + * Constructs LRU eviction policy with maximum size. + * + * @param max Maximum allowed size of cache before entry will start getting evicted. + */ + public GridCacheLruEvictionPolicy(int max) { + A.ensure(max > 0, "max > 0"); + + this.max = max; + } + + /** + * Gets maximum allowed size of cache before entry will start getting evicted. + * + * @return Maximum allowed size of cache before entry will start getting evicted. + */ + @Override public int getMaxSize() { + return max; + } + + /** + * Sets maximum allowed size of cache before entry will start getting evicted. + * + * @param max Maximum allowed size of cache before entry will start getting evicted. + */ + @Override public void setMaxSize(int max) { + A.ensure(max > 0, "max > 0"); + + this.max = max; + } + + /** {@inheritDoc} */ + @Override public int getCurrentSize() { + return queue.size(); + } + + /** {@inheritDoc} */ + @Override public String getMetaAttributeName() { + return meta; + } + + /** + * Gets read-only view on internal {@code FIFO} queue in proper order. + * + * @return Read-only view ono internal {@code 'FIFO'} queue. + */ + public Collection<GridCacheEntry<K, V>> queue() { + return Collections.unmodifiableCollection(queue); + } + + /** {@inheritDoc} */ + @Override public void onEntryAccessed(boolean rmv, GridCacheEntry<K, V> entry) { + if (!rmv) { + if (!entry.isCached()) + return; + + if (touch(entry)) + shrink(); + } + else { + Node<GridCacheEntry<K, V>> node = entry.removeMeta(meta); + + if (node != null) + queue.unlinkx(node); + } + } + + /** + * @param entry Entry to touch. + * @return {@code True} if new node has been added to queue by this call. + */ + private boolean touch(GridCacheEntry<K, V> entry) { + Node<GridCacheEntry<K, V>> node = entry.meta(meta); + + // Entry has not been enqueued yet. + if (node == null) { + while (true) { + node = queue.offerLastx(entry); + + if (entry.putMetaIfAbsent(meta, node) != null) { + // Was concurrently added, need to clear it from queue. + queue.unlinkx(node); + + // Queue has not been changed. + return false; + } + else if (node.item() != null) { + if (!entry.isCached()) { + // Was concurrently evicted, need to clear it from queue. + queue.unlinkx(node); + + return false; + } + + return true; + } + // If node was unlinked by concurrent shrink() call, we must repeat the whole cycle. + else if (!entry.removeMeta(meta, node)) + return false; + } + } + else if (queue.unlinkx(node)) { + // Move node to tail. + Node<GridCacheEntry<K, V>> newNode = queue.offerLastx(entry); + + if (!entry.replaceMeta(meta, node, newNode)) + // Was concurrently added, need to clear it from queue. + queue.unlinkx(newNode); + } + + // Entry is already in queue. + return false; + } + + /** + * Shrinks queue to maximum allowed size. + */ + private void shrink() { + int max = this.max; + + int startSize = queue.sizex(); + + for (int i = 0; i < startSize && queue.sizex() > max; i++) { + GridCacheEntry<K, V> entry = queue.poll(); + + if (entry == null) + break; + + if (!entry.evict()) { + entry.removeMeta(meta); + + touch(entry); + } + } + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridCacheLruEvictionPolicy.class, this, "size", queue.sizex()); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicyMBean.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicyMBean.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicyMBean.java new file mode 100644 index 0000000..d23edc9 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/GridCacheLruEvictionPolicyMBean.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.eviction.lru; + +import org.apache.ignite.mbean.*; + +/** + * MBean for {@code LRU} eviction policy. + */ +@IgniteMBeanDescription("MBean for LRU cache eviction policy.") +public interface GridCacheLruEvictionPolicyMBean { + /** + * Gets name of metadata attribute used to store eviction policy data. + * + * @return Name of metadata attribute used to store eviction policy data. + */ + @IgniteMBeanDescription("Name of metadata attribute used to store eviction policy data.") + public String getMetaAttributeName(); + + /** + * Gets maximum allowed cache size. + * + * @return Maximum allowed cache size. + */ + @IgniteMBeanDescription("Maximum allowed cache size.") + public int getMaxSize(); + + /** + * Sets maximum allowed cache size. + * + * @param max Maximum allowed cache size. + */ + @IgniteMBeanDescription("Sets maximum allowed cache size.") + public void setMaxSize(int max); + + /** + * Gets current queue size. + * + * @return Current queue size. + */ + @IgniteMBeanDescription("Current queue size.") + public int getCurrentSize(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/package.html ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/package.html b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/package.html new file mode 100644 index 0000000..b3d5e88 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/package.html @@ -0,0 +1,23 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<body> + <!-- Package description. --> + Contains cache LRU eviction policy implementations. +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/eviction/package.html ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/package.html b/modules/core/src/main/java/org/apache/ignite/cache/eviction/package.html new file mode 100644 index 0000000..24ff600 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/package.html @@ -0,0 +1,23 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<body> + <!-- Package description. --> + Contains cache eviction policy implementations. +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicy.java new file mode 100644 index 0000000..3e80f47 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicy.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.eviction.random; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.eviction.*; +import org.gridgain.grid.cache.*; +import org.gridgain.grid.util.typedef.*; +import org.gridgain.grid.util.typedef.internal.*; + +/** + * Cache eviction policy which will select random cache entry for eviction if cache + * size exceeds the {@link #getMaxSize()} parameter. This implementation is + * extremely light weight, lock-free, and does not create any data structures to maintain + * any order for eviction. + * <p> + * Random eviction will provide the best performance over any key set in which every + * key has the same probability of being accessed. + */ +public class GridCacheRandomEvictionPolicy<K, V> implements GridCacheEvictionPolicy<K, V>, + GridCacheRandomEvictionPolicyMBean { + /** Maximum size. */ + private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE; + + /** + * Constructs random eviction policy with all defaults. + */ + public GridCacheRandomEvictionPolicy() { + // No-op. + } + + /** + * Constructs random eviction policy with maximum size. + * + * @param max Maximum allowed size of cache before entry will start getting evicted. + */ + public GridCacheRandomEvictionPolicy(int max) { + A.ensure(max > 0, "max > 0"); + + this.max = max; + } + + /** + * Gets maximum allowed size of cache before entry will start getting evicted. + * + * @return Maximum allowed size of cache before entry will start getting evicted. + */ + @Override public int getMaxSize() { + return max; + } + + /** + * Sets maximum allowed size of cache before entry will start getting evicted. + * + * @param max Maximum allowed size of cache before entry will start getting evicted. + */ + @Override public void setMaxSize(int max) { + A.ensure(max > 0, "max > 0"); + + this.max = max; + } + + /** {@inheritDoc} */ + @Override public void onEntryAccessed(boolean rmv, GridCacheEntry<K, V> entry) { + if (!entry.isCached()) + return; + + GridCache<K, V> cache = entry.projection().cache(); + + int size = cache.size(); + + for (int i = max; i < size; i++) { + GridCacheEntry<K, V> e = cache.randomEntry(); + + if (e != null) + e.evict(); + } + } + + /** + * Checks entry for empty value. + * + * @param entry Entry to check. + * @return {@code True} if entry is empty. + */ + private boolean empty(GridCacheEntry<K, V> entry) { + try { + return entry.peek(F.asList(GridCachePeekMode.GLOBAL)) == null; + } + catch (IgniteCheckedException e) { + U.error(null, e.getMessage(), e); + + assert false : "Should never happen: " + e; + + return false; + } + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridCacheRandomEvictionPolicy.class, this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicyMBean.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicyMBean.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicyMBean.java new file mode 100644 index 0000000..bcf9496 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/GridCacheRandomEvictionPolicyMBean.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.eviction.random; + +import org.apache.ignite.mbean.*; + +/** + * MBean for {@code random} eviction policy. + */ +@IgniteMBeanDescription("MBean for random cache eviction policy.") +public interface GridCacheRandomEvictionPolicyMBean { + /** + * Gets maximum allowed cache size. + * + * @return Maximum allowed cache size. + */ + @IgniteMBeanDescription("Maximum allowed cache size.") + public int getMaxSize(); + + /** + * Sets maximum allowed cache size. + * + * @param max Maximum allowed cache size. + */ + @IgniteMBeanDescription("Sets maximum allowed cache size.") + public void setMaxSize(int max); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/package.html ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/package.html b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/package.html new file mode 100644 index 0000000..0236bb0 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/package.html @@ -0,0 +1,23 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<body> + <!-- Package description. --> + Contains cache randomized eviction policy implementations. +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/package.html ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/package.html b/modules/core/src/main/java/org/apache/ignite/cache/package.html new file mode 100644 index 0000000..2d7869a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/package.html @@ -0,0 +1,24 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<body> + <!-- Package description. --> + Contains main <b>Data Grid APIs.</b> +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQuery.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQuery.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQuery.java new file mode 100644 index 0000000..9681734 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQuery.java @@ -0,0 +1,342 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import org.apache.ignite.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.lang.*; +import org.gridgain.grid.cache.*; +import org.jetbrains.annotations.*; + +import java.util.*; + +/** + * API for configuring and executing continuous cache queries. + * <p> + * Continuous queries are executed as follows: + * <ol> + * <li> + * Query is sent to requested grid nodes. Note that for {@link org.apache.ignite.cache.GridCacheMode#LOCAL LOCAL} + * and {@link org.apache.ignite.cache.GridCacheMode#REPLICATED REPLICATED} caches query will be always executed + * locally. + * </li> + * <li> + * Each node iterates through existing cache data and registers listeners that will + * notify about further updates. + * <li> + * Each key-value pair is passed through optional filter and if this filter returns + * true, key-value pair is sent to the master node (the one that executed query). + * If filter is not provided, all pairs are sent. + * </li> + * <li> + * When master node receives key-value pairs, it notifies the local callback. + * </li> + * </ol> + * <h2 class="header">NOTE</h2> + * Under some concurrent circumstances callback may get several notifications + * for one cache update. This should be taken into account when implementing callback. + * <h1 class="header">Query usage</h1> + * As an example, suppose we have cache with {@code 'Person'} objects and we need + * to query all persons with salary above 1000. + * <p> + * Here is the {@code Person} class: + * <pre name="code" class="java"> + * public class Person { + * // Name. + * private String name; + * + * // Salary. + * private double salary; + * + * ... + * } + * </pre> + * <p> + * You can create and execute continuous query like so: + * <pre name="code" class="java"> + * // Create new continuous query. + * qry = cache.createContinuousQuery(); + * + * // Callback that is called locally when update notifications are received. + * // It simply prints out information about all created persons. + * qry.callback(new GridPredicate2<UUID, Collection<Map.Entry<UUID, Person>>>() { + * @Override public boolean apply(UUID uuid, Collection<Map.Entry<UUID, Person>> entries) { + * for (Map.Entry<UUID, Person> e : entries) { + * Person p = e.getValue(); + * + * X.println(">>>"); + * X.println(">>> " + p.getFirstName() + " " + p.getLastName() + + * "'s salary is " + p.getSalary()); + * X.println(">>>"); + * } + * + * return true; + * } + * }); + * + * // This query will return persons with salary above 1000. + * qry.filter(new GridPredicate2<UUID, Person>() { + * @Override public boolean apply(UUID uuid, Person person) { + * return person.getSalary() > 1000; + * } + * }); + * + * // Execute query. + * qry.execute(); + * </pre> + * This will execute query on all nodes that have cache you are working with and notify callback + * with both data that already exists in cache and further updates. + * <p> + * To stop receiving updates call {@link #close()} method: + * <pre name="code" class="java"> + * qry.cancel(); + * </pre> + * Note that one query instance can be executed only once. After it's cancelled, it's non-operational. + * If you need to repeat execution, use {@link GridCacheQueries#createContinuousQuery()} method to create + * new query. + */ +public interface GridCacheContinuousQuery<K, V> extends AutoCloseable { + /** + * Default buffer size. Size of {@code 1} means that all entries + * will be sent to master node immediately (buffering is disabled). + */ + public static final int DFLT_BUF_SIZE = 1; + + /** Maximum default time interval after which buffer will be flushed (if buffering is enabled). */ + public static final long DFLT_TIME_INTERVAL = 0; + + /** + * Default value for automatic unsubscription flag. Remote filters + * will be unregistered by default if master node leaves topology. + */ + public static final boolean DFLT_AUTO_UNSUBSCRIBE = true; + + /** + * Sets local callback. This callback is called only + * in local node when new updates are received. + * <p> + * The callback predicate accepts ID of the node from where updates + * are received and collection of received entries. Note that + * for removed entries value will be {@code null}. + * <p> + * If the predicate returns {@code false}, query execution will + * be cancelled. + * <p> + * <b>WARNING:</b> all operations that involve any kind of JVM-local + * or distributed locking (e.g., synchronization or transactional + * cache operations), should be executed asynchronously without + * blocking the thread that called the callback. Otherwise, you + * can get deadlocks. + * + * @param cb Local callback. + * @deprecated Deprecated in favor of {@link #localCallback(IgniteBiPredicate)} method. + */ + @Deprecated + public void callback(@Nullable IgniteBiPredicate<UUID, Collection<Map.Entry<K, V>>> cb); + + /** + * Gets local callback. See {@link #callback(IgniteBiPredicate)} for more information. + * + * @return Local callback. + * @deprecated Deprecated in favor of {@link #localCallback()} method. + */ + @Deprecated + public IgniteBiPredicate<UUID, Collection<Map.Entry<K, V>>> callback(); + + /** + * Sets optional key-value filter. This filter is called before + * entry is sent to the master node. + * <p> + * <b>WARNING:</b> all operations that involve any kind of JVM-local + * or distributed locking (e.g., synchronization or transactional + * cache operations), should be executed asynchronously without + * blocking the thread that called the filter. Otherwise, you + * can get deadlocks. + * + * @param filter Key-value filter. + * @deprecated Deprecated in favor of {@link #remoteFilter(org.apache.ignite.lang.IgnitePredicate)} method. + */ + @Deprecated + public void filter(@Nullable IgniteBiPredicate<K, V> filter); + + /** + * Gets key-value filter. See {@link #filter(IgniteBiPredicate)} for more information. + * + * @return Key-value filter. + * @deprecated Deprecated in favor of {@link #remoteFilter()} method. + */ + @Deprecated + @Nullable public IgniteBiPredicate<K, V> filter(); + + /** + * Sets local callback. This callback is called only + * in local node when new updates are received. + * <p> + * The callback predicate accepts ID of the node from where updates + * are received and collection of received entries. Note that + * for removed entries value will be {@code null}. + * <p> + * If the predicate returns {@code false}, query execution will + * be cancelled. + * <p> + * <b>WARNING:</b> all operations that involve any kind of JVM-local + * or distributed locking (e.g., synchronization or transactional + * cache operations), should be executed asynchronously without + * blocking the thread that called the callback. Otherwise, you + * can get deadlocks. + * + * @param locCb Local callback. + */ + public void localCallback(IgniteBiPredicate<UUID, Collection<GridCacheContinuousQueryEntry<K, V>>> locCb); + + /** + * Gets local callback. See {@link #callback(IgniteBiPredicate)} for more information. + * + * @return Local callback. + */ + @Nullable public IgniteBiPredicate<UUID, Collection<GridCacheContinuousQueryEntry<K, V>>> localCallback(); + + /** + * Sets optional key-value filter. This filter is called before + * entry is sent to the master node. + * <p> + * <b>WARNING:</b> all operations that involve any kind of JVM-local + * or distributed locking (e.g., synchronization or transactional + * cache operations), should be executed asynchronously without + * blocking the thread that called the filter. Otherwise, you + * can get deadlocks. + * + * @param filter Key-value filter. + */ + public void remoteFilter(@Nullable IgnitePredicate<GridCacheContinuousQueryEntry<K, V>> filter); + + /** + * Gets key-value filter. See {@link #filter(IgniteBiPredicate)} for more information. + * + * @return Key-value filter. + */ + @Nullable public IgnitePredicate<GridCacheContinuousQueryEntry<K, V>> remoteFilter(); + + /** + * Sets buffer size. + * <p> + * When a cache update happens, entry is first put into a buffer. + * Entries from buffer will be sent to the master node only if + * the buffer is full or time provided via {@link #timeInterval(long)} + * method is exceeded. + * <p> + * Default buffer size is {@code 1} which means that entries will + * be sent immediately (buffering is disabled). + * + * @param bufSize Buffer size. + */ + public void bufferSize(int bufSize); + + /** + * Gets buffer size. See {@link #bufferSize(int)} for more information. + * + * @return Buffer size. + */ + public int bufferSize(); + + /** + * Sets time interval. + * <p> + * When a cache update happens, entry is first put into a buffer. + * Entries from buffer will be sent to the master node only if + * the buffer is full (its size can be provided via {@link #bufferSize(int)} + * method) or time provided via this method is exceeded. + * <p> + * Default time interval is {@code 0} which means that time check is + * disabled and entries will be sent only when buffer is full. + * + * @param timeInterval Time interval. + */ + public void timeInterval(long timeInterval); + + /** + * Gets time interval. See {@link #timeInterval(long)} for more information. + * + * @return Gets time interval. + */ + public long timeInterval(); + + /** + * Sets automatic unsubscribe flag. + * <p> + * This flag indicates that query filters on remote nodes should be automatically + * unregistered if master node (node that initiated the query) leaves topology. + * If this flag is {@code false}, filters will be unregistered only when + * the query is cancelled from master node, and won't ever be unregistered if + * master node leaves grid. + * <p> + * Default value for this flag is {@code true}. + * + * @param autoUnsubscribe Automatic unsubscription flag. + */ + public void autoUnsubscribe(boolean autoUnsubscribe); + + /** + * Gets automatic unsubscribe flag. See {@link #autoUnsubscribe(boolean)} + * for more information. + * + * @return Automatic unsubscribe flag. + */ + public boolean isAutoUnsubscribe(); + + /** + * Starts continuous query execution on the whole grid. + * <p> + * Note that if grid contains nodes without appropriate cache, + * these nodes will be filtered out. + * <p> + * Also note that for {@link org.apache.ignite.cache.GridCacheMode#LOCAL LOCAL} + * and {@link org.apache.ignite.cache.GridCacheMode#REPLICATED REPLICATED} caches + * query will be always executed locally. + * + * @throws IgniteCheckedException In case of error. + */ + public void execute() throws IgniteCheckedException; + + /** + * Starts continuous query execution on provided set of nodes. + * <p> + * Note that if provided projection contains nodes without + * appropriate cache, these nodes will be filtered out. + * <p> + * Also note that for {@link org.apache.ignite.cache.GridCacheMode#LOCAL LOCAL} + * and {@link org.apache.ignite.cache.GridCacheMode#REPLICATED REPLICATED} caches + * query will be always executed locally. + * + * @param prj Grid projection. + * @throws IgniteCheckedException In case of error. + */ + public void execute(@Nullable ClusterGroup prj) throws IgniteCheckedException; + + /** + * Stops continuous query execution. + * <p> + * Note that one query instance can be executed only once. + * After it's cancelled, it's non-operational. + * If you need to repeat execution, use {@link GridCacheQueries#createContinuousQuery()} + * method to create new query. + * + * @throws IgniteCheckedException In case of error. + */ + @Override public void close() throws IgniteCheckedException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQueryEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQueryEntry.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQueryEntry.java new file mode 100644 index 0000000..9601df8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheContinuousQueryEntry.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Entry used for continuous query notifications. + */ +public interface GridCacheContinuousQueryEntry<K, V> extends Map.Entry<K, V>, Serializable { + /** + * Gets entry key. + * + * @return Entry key. + */ + @Override public K getKey(); + + /** + * Gets entry new value. New value may be null, if entry is being removed. + * + * @return Entry new value. + */ + @Override @Nullable public V getValue(); + + /** + * Gets entry old value. Old value may be null if entry is being inserted (not updated). + * + * @return Gets entry old value. + */ + @Nullable public V getOldValue(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueries.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueries.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueries.java new file mode 100644 index 0000000..28727dc --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueries.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import org.apache.ignite.lang.*; +import org.jetbrains.annotations.*; + +import java.util.*; + +/** + * Facade for creating distributed queries. It contains various {@code 'createXxxQuery(..)'} + * methods for {@code SQL}, {@code TEXT}, and {@code SCAN} query creation (see {@link GridCacheQuery} + * for more information). + * <p> + * Instance of {@code GridCacheQueries} is obtained from cache projection as follows: + * <pre name="code" class="java"> + * GridCacheQueries q = GridGain.grid().cache("myCache").queries(); + * </pre> + */ +public interface GridCacheQueries<K, V> { + /** + * Creates user's SQL query, queried class, and query clause which is generally + * a where clause. For more information refer to {@link GridCacheQuery} documentation. + * + * @param cls Query class. + * @param clause Query clause. + * @return Created query. + */ + public GridCacheQuery<Map.Entry<K, V>> createSqlQuery(Class<?> cls, String clause); + + /** + * Creates user's SQL query, queried class, and query clause which is generally + * a where clause. For more information refer to {@link GridCacheQuery} documentation. + * + * @param clsName Query class name. + * @param clause Query clause. + * @return Created query. + */ + public GridCacheQuery<Map.Entry<K, V>> createSqlQuery(String clsName, String clause); + + /** + * Creates user's SQL fields query for given clause. For more information refer to + * {@link GridCacheQuery} documentation. + * + * @param qry Query. + * @return Created query. + */ + public GridCacheQuery<List<?>> createSqlFieldsQuery(String qry); + + /** + * Creates user's full text query, queried class, and query clause. + * For more information refer to {@link GridCacheQuery} documentation. + * + * @param clsName Query class name. + * @param search Search clause. + * @return Created query. + */ + public GridCacheQuery<Map.Entry<K, V>> createFullTextQuery(String clsName, String search); + + /** + * Creates user's full text query, queried class, and query clause. + * For more information refer to {@link GridCacheQuery} documentation. + * + * @param cls Query class. + * @param search Search clause. + * @return Created query. + */ + public GridCacheQuery<Map.Entry<K, V>> createFullTextQuery(Class<?> cls, String search); + + /** + * Creates user's predicate based scan query. + * + * @param filter Scan filter. + * @return Created query. + */ + public GridCacheQuery<Map.Entry<K, V>> createScanQuery(@Nullable IgniteBiPredicate<K, V> filter); + + /** + * Creates new continuous query. + * <p> + * For more information refer to {@link GridCacheContinuousQuery} documentation. + * + * @return Created continuous query. + * @see GridCacheContinuousQuery + */ + public GridCacheContinuousQuery<K, V> createContinuousQuery(); + + /** + * Forces this cache to rebuild all search indexes of given value type. Sometimes indexes + * may hold references to objects that have already been removed from cache. Although + * not affecting query results, these objects may consume extra memory. Rebuilding + * indexes will remove any redundant references that may have temporarily got stuck + * inside in-memory index. + * + * @param cls Value type to rebuild indexes for. + * + * @return Future that will be completed when rebuilding of all indexes is finished. + */ + public IgniteFuture<?> rebuildIndexes(Class<?> cls); + + /** + * Forces this cache to rebuild all search indexes of given value type. Sometimes indexes + * may hold references to objects that have already been removed from cache. Although + * not affecting query results, these objects may consume extra memory. Rebuilding + * indexes will remove any redundant references that may have temporarily got stuck + * inside in-memory index. + * + * @param typeName Value type name to rebuild indexes for. + * + * @return Future that will be completed when rebuilding of all indexes is finished. + */ + public IgniteFuture<?> rebuildIndexes(String typeName); + + /** + * Forces this cache to rebuild search indexes of all types. Sometimes indexes + * may hold references to objects that have already been removed from cache. Although + * not affecting query results, these objects may consume extra memory. Rebuilding + * indexes will remove any redundant references that may have temporarily got stuck + * inside in-memory index. + * + * @return Future that will be completed when rebuilding of all indexes is finished. + */ + public IgniteFuture<?> rebuildAllIndexes(); + + /** + * Accumulated metrics for all queries executed for this cache. + * + * @return Cache query metrics. + */ + public GridCacheQueryMetrics metrics(); + + /** + * Resets accumulated metrics. + */ + public void resetMetrics(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuery.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuery.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuery.java new file mode 100644 index 0000000..556e7e5 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuery.java @@ -0,0 +1,297 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import org.apache.ignite.cluster.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.lang.*; +import org.gridgain.grid.cache.*; +import org.gridgain.grid.cache.affinity.*; +import org.jetbrains.annotations.*; + +/** + * Main API for configuring and executing cache queries. + * <p> + * Cache queries are created from {@link GridCacheQueries} API via any of the available + * {@code createXXXQuery(...)} methods. + * <h1 class="header">SQL Queries</h1> + * {@code SQL} query allows to execute distributed cache + * queries using standard SQL syntax. All values participating in where clauses + * or joins must be annotated with {@link GridCacheQuerySqlField} annotation. Query can be created + * with {@link GridCacheQueries#createSqlQuery(Class, String)} method. + * <h2 class="header">Field Queries</h2> + * By default {@code select} clause is ignored as query result contains full objects. + * If it is needed to select individual fields, use {@link GridCacheQueries#createSqlFieldsQuery(String)} method. + * This type of query replaces full objects with individual fields. Note that selected fields + * must be annotated with {@link GridCacheQuerySqlField} annotation. + * <h2 class="header">Cross-Cache Queries</h2> + * You are allowed to query data from several caches. Cache that this query was created on is + * treated as default schema in this case. Other caches can be referenced by their names. + * <p> + * Note that cache name is case sensitive and has to always be specified in double quotes. + * Here is an example of cross cache query (note that 'replicated' and 'partitioned' are + * cache names for replicated and partitioned caches accordingly): + * <pre name="code" class="java"> + * GridCacheQuery<Map.Entry<Integer, FactPurchase>> storePurchases = cache.queries().createSqlQuery( + * Purchase.class, + * "from \"replicated\".Store, \"partitioned\".Purchase where Store.id=Purchase.storeId and Store.id=?"); + * </pre> + * <h2 class="header">Custom functions in SQL queries.</h2> + * It is possible to write custom Java methods and call then form SQL queries. These methods must be public static + * and annotated with {@link GridCacheQuerySqlFunction}. Classes containing these methods must be registered in + * {@link GridQueryConfiguration#setIndexCustomFunctionClasses(Class[])}. + * <h1 class="header">Full Text Queries</h1> + * GridGain supports full text queries based on Apache Lucene engine. This queries are created by + * {@link GridCacheQueries#createFullTextQuery(Class, String)} method. Note that all fields that + * are expected to show up in text query results must be annotated with {@link GridCacheQueryTextField} + * annotation. + * <h1 class="header">Scan Queries</h1> + * Sometimes when it is known in advance that SQL query will cause a full data scan, or whenever data set + * is relatively small, the full scan query may be used. This query will iterate over all cache + * entries, skipping over entries that don't pass the optionally provided key-value filter + * (see {@link GridCacheQueries#createScanQuery(org.apache.ignite.lang.IgniteBiPredicate)} method). + * <h2 class="header">Limitations</h2> + * Data in GridGain cache is usually distributed across several nodes, + * so some queries may not work as expected. Keep in mind following limitations + * (not applied if data is queried from one node only): + * <ul> + * <li> + * {@code Group by} and {@code sort by} statements are applied separately + * on each node, so result set will likely be incorrectly grouped or sorted + * after results from multiple remote nodes are grouped together. + * </li> + * <li> + * Aggregation functions like {@code sum}, {@code max}, {@code avg}, etc. + * are also applied on each node. Therefore you will get several results + * containing aggregated values, one for each node. + * </li> + * <li> + * Joins will work correctly only if joined objects are stored in + * collocated mode or at least one side of the join is stored in + * {@link org.apache.ignite.cache.GridCacheMode#REPLICATED} cache. Refer to + * {@link org.apache.ignite.cache.affinity.GridCacheAffinityKey} javadoc for more information about colocation. + * </li> + * </ul> + * <h1 class="header">Query usage</h1> + * As an example, suppose we have data model consisting of {@code 'Employee'} and {@code 'Organization'} + * classes defined as follows: + * <pre name="code" class="java"> + * public class Organization { + * // Indexed field. + * @GridCacheQuerySqlField(index = true) + * private long id; + * + * // Indexed field. + * @GridCacheQuerySqlField(index = true) + * private String name; + * ... + * } + * + * public class Person { + * // Indexed field. + * @GridCacheQuerySqlField(index = true) + * private long id; + * + * // Indexed field (Organization ID, used as a foreign key). + * @GridCacheQuerySqlField(index = true) + * private long orgId; + * + * // Without SQL field annotation, this field cannot be used in queries. + * private String name; + * + * // Not indexed field. + * @GridCacheQuerySqlField + * private double salary; + * + * // Index for text search. + * @GridCacheQueryTextField + * private String resume; + * ... + * } + * </pre> + * Then you can create and execute queries that check various salary ranges like so: + * <pre name="code" class="java"> + * GridCache<Long, Person> cache = G.grid().cache(); + * ... + * // Create query which selects salaries based on range for all employees + * // that work for a certain company. + * GridCacheQuery<Map.Entry<Long, Person>> qry = cache.queries().createSqlQuery(Person.class, + * "from Person, Organization where Person.orgId = Organization.id " + + * "and Organization.name = ? and Person.salary > ? and Person.salary <= ?"); + * + * // Query all nodes to find all cached GridGain employees + * // with salaries less than 1000. + * qry.execute("GridGain", 0, 1000); + * + * // Query only remote nodes to find all remotely cached GridGain employees + * // with salaries greater than 1000 and less than 2000. + * qry.projection(grid.remoteProjection()).execute("GridGain", 1000, 2000); + * </pre> + * Here is a possible query that will use Lucene text search to scan all resumes to + * check if employees have {@code Master} degree: + * <pre name="code" class="java"> + * GridCacheQuery<Map.Entry<Long, Person>> mastersQry = + * cache.queries().createFullTextQuery(Person.class, "Master"); + * + * // Query all cache nodes. + * mastersQry.execute(); + * </pre> + * <h1 class="header">Geo-Spatial Indexes and Queries</h1> + * GridGain also support <b>Geo-Spatial Indexes</b>. Here is an example of geo-spatial index: + * <pre name="code" class="java"> + * private class MapPoint implements Serializable { + * // Geospatial index. + * @GridCacheQuerySqlField(index = true) + * private com.vividsolutions.jts.geom.Point location; + * + * // Not indexed field. + * @GridCacheQuerySqlField + * private String name; + * + * public MapPoint(com.vividsolutions.jts.geom.Point location, String name) { + * this.location = location; + * this.name = name; + * } + * } + * </pre> + * Example of spatial query on the geo-indexed field from above: + * <pre name="code" class="java"> + * com.vividsolutions.jts.geom.GeometryFactory factory = new com.vividsolutions.jts.geom.GeometryFactory(); + * + * com.vividsolutions.jts.geom.Polygon square = factory.createPolygon(new Coordinate[] { + * new com.vividsolutions.jts.geom.Coordinate(0, 0), + * new com.vividsolutions.jts.geom.Coordinate(0, 100), + * new com.vividsolutions.jts.geom.Coordinate(100, 100), + * new com.vividsolutions.jts.geom.Coordinate(100, 0), + * new com.vividsolutions.jts.geom.Coordinate(0, 0) + * }); + * + * Map.Entry<String, UserData> records = cache.queries().createSqlQuery(MapPoint.class, "select * from MapPoint where location && ?") + * .queryArguments(square) + * .execute() + * .get(); + * </pre> + */ +public interface GridCacheQuery<T> { + /** Default query page size. */ + public static final int DFLT_PAGE_SIZE = 1024; + + /** + * Sets result page size. If not provided, {@link #DFLT_PAGE_SIZE} will be used. + * Results are returned from queried nodes one page at a tme. + * + * @param pageSize Page size. + * @return {@code this} query instance for chaining. + */ + public GridCacheQuery<T> pageSize(int pageSize); + + /** + * Sets query timeout. {@code 0} means there is no timeout (this + * is a default value). + * + * @param timeout Query timeout. + * @return {@code this} query instance for chaining. + */ + public GridCacheQuery<T> timeout(long timeout); + + /** + * Sets whether or not to keep all query results local. If not - only the current page + * is kept locally. Default value is {@code true}. + * + * @param keepAll Keep results or not. + * @return {@code this} query instance for chaining. + */ + public GridCacheQuery<T> keepAll(boolean keepAll); + + /** + * Sets whether or not to include backup entries into query result. This flag + * is {@code false} by default. + * + * @param incBackups Query {@code includeBackups} flag. + * @return {@code this} query instance for chaining. + */ + public GridCacheQuery<T> includeBackups(boolean incBackups); + + /** + * Sets whether or not to deduplicate query result set. If this flag is {@code true} + * then query result will not contain some key more than once even if several nodes + * returned entries with the same keys. Default value is {@code false}. + * + * @param dedup Query {@code enableDedup} flag. + * @return {@code this} query instance for chaining. + */ + public GridCacheQuery<T> enableDedup(boolean dedup); + + /** + * Sets optional grid projection to execute this query on. + * + * @param prj Projection. + * @return {@code this} query instance for chaining. + */ + public GridCacheQuery<T> projection(ClusterGroup prj); + + /** + * Executes the query and returns the query future. Caller may decide to iterate + * over the returned future directly in which case the iterator may block until + * the next value will become available, or wait for the whole query to finish + * by calling any of the {@code 'get(..)'} methods on the returned future. If + * {@link #keepAll(boolean)} flag is set to {@code false}, then {@code 'get(..)'} + * methods will only return the last page received, otherwise all pages will be + * accumulated and returned to user as a collection. + * <p> + * Note that if the passed in grid projection is a local node, then query + * will be executed locally without distribution to other nodes. + * <p> + * Also note that query state cannot be changed (clause, timeout etc.), except + * arguments, if this method was called at least once. + * + * @param args Optional arguments. + * @return Future for the query result. + */ + public GridCacheQueryFuture<T> execute(@Nullable Object... args); + + /** + * Executes the query the same way as {@link #execute(Object...)} method but reduces result remotely. + * + * @param rmtReducer Remote reducer. + * @param args Optional arguments. + * @return Future for the query result. + */ + public <R> GridCacheQueryFuture<R> execute(IgniteReducer<T, R> rmtReducer, @Nullable Object... args); + + /** + * Executes the query the same way as {@link #execute(Object...)} method but transforms result remotely. + * + * @param rmtTransform Remote transformer. + * @param args Optional arguments. + * @return Future for the query result. + */ + public <R> GridCacheQueryFuture<R> execute(IgniteClosure<T, R> rmtTransform, @Nullable Object... args); + + /** + * Gets metrics for this query. + * + * @return Query metrics. + */ + public GridCacheQueryMetrics metrics(); + + /** + * Resets metrics for this query. + */ + public void resetMetrics(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryConfiguration.java new file mode 100644 index 0000000..ad471c4 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryConfiguration.java @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import java.io.*; +import java.util.*; + +/** + * Query configuration object. + */ +public class GridCacheQueryConfiguration implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Collection of query type metadata. */ + private Collection<GridCacheQueryTypeMetadata> typeMeta; + + /** Query type resolver. */ + private GridCacheQueryTypeResolver typeRslvr; + + /** */ + private boolean idxPrimitiveKey; + + /** */ + private boolean idxPrimitiveVal; + + /** */ + private boolean idxFixedTyping; + + /** */ + private boolean escapeAll; + + /** + * Default constructor. + */ + public GridCacheQueryConfiguration() { + // No-op. + } + + /** + * @param cfg Configuration to copy. + */ + public GridCacheQueryConfiguration(GridCacheQueryConfiguration cfg) { + typeMeta = cfg.getTypeMetadata(); + typeRslvr = cfg.getTypeResolver(); + idxPrimitiveKey = cfg.isIndexPrimitiveKey(); + idxPrimitiveVal = cfg.isIndexPrimitiveValue(); + idxFixedTyping = cfg.isIndexFixedTyping(); + escapeAll = cfg.isEscapeAll(); + } + + /** + * Gets collection of query type metadata objects. + * + * @return Collection of query type metadata. + */ + public Collection<GridCacheQueryTypeMetadata> getTypeMetadata() { + return typeMeta; + } + + /** + * Sets collection of query type metadata objects. + * + * @param typeMeta Collection of query type metadata. + */ + public void setTypeMetadata(Collection<GridCacheQueryTypeMetadata> typeMeta) { + this.typeMeta = typeMeta; + } + + /** + * Gets query type resolver. + * + * @return Query type resolver. + */ + public GridCacheQueryTypeResolver getTypeResolver() { + return typeRslvr; + } + + /** + * Sets query type resolver. + * + * @param typeRslvr Query type resolver. + */ + public void setTypeResolver(GridCacheQueryTypeResolver typeRslvr) { + this.typeRslvr = typeRslvr; + } + + /** + * Gets flag indicating whether SQL engine should index by key in cases + * where key is primitive type + * + * @return {@code True} if primitive keys should be indexed. + */ + public boolean isIndexPrimitiveKey() { + return idxPrimitiveKey; + } + + /** + * Sets flag indicating whether SQL engine should index by key in cases + * where key is primitive type. + * + * @param idxPrimitiveKey {@code True} if primitive keys should be indexed. + */ + public void setIndexPrimitiveKey(boolean idxPrimitiveKey) { + this.idxPrimitiveKey = idxPrimitiveKey; + } + + /** + * Gets flag indicating whether SQL engine should index by value in cases + * where value is primitive type + * + * @return {@code True} if primitive values should be indexed. + */ + public boolean isIndexPrimitiveValue() { + return idxPrimitiveVal; + } + + /** + * Sets flag indexing whether SQL engine should index by value in cases + * where value is primitive type. + * + * @param idxPrimitiveVal {@code True} if primitive values should be indexed. + */ + public void setIndexPrimitiveValue(boolean idxPrimitiveVal) { + this.idxPrimitiveVal = idxPrimitiveVal; + } + + /** + * This flag essentially controls whether all values of the same type have + * identical key type. + * <p> + * If {@code false}, SQL engine will store all keys in BINARY form to make it possible to store + * the same value type with different key types. If {@code true}, key type will be converted + * to respective SQL type if it is possible, hence, improving performance of queries. + * <p> + * Setting this value to {@code false} also means that {@code '_key'} column cannot be indexed and + * cannot participate in query where clauses. The behavior of using '_key' column in where + * clauses with this flag set to {@code false} is undefined. + * + * @return {@code True} if SQL engine should try to convert values to their respective SQL + * types for better performance. + */ + public boolean isIndexFixedTyping() { + return idxFixedTyping; + } + + /** + * This flag essentially controls whether key type is going to be identical + * for all values of the same type. + * <p> + * If false, SQL engine will store all keys in BINARY form to make it possible to store + * the same value type with different key types. If true, key type will be converted + * to respective SQL type if it is possible, which may provide significant performance + * boost. + * + * @param idxFixedTyping {@code True} if SQL engine should try to convert values to their respective SQL + * types for better performance. + */ + public void setIndexFixedTyping(boolean idxFixedTyping) { + this.idxFixedTyping = idxFixedTyping; + } + + /** + * If {@code true}, then table name and all column names in 'create table' SQL + * generated for SQL engine are escaped with double quotes. This flag should be set if table name of + * column name is H2 reserved word or is not valid H2 identifier (e.g. contains space or hyphen). + * <p> + * Note if this flag is set then table and column name in SQL queries also must be escaped with double quotes. + + * @return Flag value. + */ + public boolean isEscapeAll() { + return escapeAll; + } + + /** + * If {@code true}, then table name and all column names in 'create table' SQL + * generated for SQL engine are escaped with double quotes. This flag should be set if table name of + * column name is H2 reserved word or is not valid H2 identifier (e.g. contains space or hyphen). + * <p> + * Note if this flag is set then table and column name in SQL queries also must be escaped with double quotes. + + * @param escapeAll Flag value. + */ + public void setEscapeAll(boolean escapeAll) { + this.escapeAll = escapeAll; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryFuture.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryFuture.java new file mode 100644 index 0000000..5824ffd --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryFuture.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import org.apache.ignite.*; +import org.apache.ignite.lang.*; +import org.jetbrains.annotations.*; + +import java.util.*; + +/** + * Cache query future returned by query execution. + * Refer to {@link GridCacheQuery} documentation for more information. + */ +public interface GridCacheQueryFuture<T> extends IgniteFuture<Collection<T>> { + /** + * Returns number of elements that are already fetched and can + * be returned from {@link #next()} method without blocking. + * + * @return Number of fetched elements which are available immediately. + * @throws IgniteCheckedException In case of error. + */ + public int available() throws IgniteCheckedException; + + /** + * Returns next element from result set. + * <p> + * This is a blocking call which will wait if there are no + * elements available immediately. + * + * @return Next fetched element or {@code null} if all the elements have been fetched. + * @throws IgniteCheckedException If failed. + */ + @Nullable public T next() throws IgniteCheckedException; + + /** + * Checks if all data is fetched by the query. + * + * @return {@code True} if all data is fetched, {@code false} otherwise. + */ + @Override public boolean isDone(); + + /** + * Cancels this query future and stop receiving any further results for the query + * associated with this future. + * + * @return {@inheritDoc} + * @throws IgniteCheckedException {@inheritDoc} + */ + @Override public boolean cancel() throws IgniteCheckedException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryGroupIndex.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryGroupIndex.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryGroupIndex.java new file mode 100644 index 0000000..8d6121c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryGroupIndex.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import java.lang.annotation.*; + +/** + * Describes group index. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface GridCacheQueryGroupIndex { + /** + * Group index name. + * + * @return Name. + */ + String name(); + + /** + * If this index is unique. + * + * @return True if this index is unique, false otherwise. + * @deprecated No longer supported, will be ignored. + */ + @Deprecated + boolean unique() default false; + + /** + * List of group indexes for type. + */ + @SuppressWarnings("PublicInnerClass") + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public static @interface List { + /** + * Gets array of group indexes. + * + * @return Array of group indexes. + */ + GridCacheQueryGroupIndex[] value(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryMetrics.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryMetrics.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryMetrics.java new file mode 100644 index 0000000..a8ada11 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryMetrics.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +/** + * Cache query metrics used to obtain statistics on query. You can get metrics for + * particular query via {@link GridCacheQuery#metrics()} method or accumulated metrics + * for all queries via {@link GridCacheQueries#metrics()}. + */ +public interface GridCacheQueryMetrics { + /** + * Gets minimum execution time of query. + * + * @return Minimum execution time of query. + */ + public long minimumTime(); + + /** + * Gets maximum execution time of query. + * + * @return Maximum execution time of query. + */ + public long maximumTime(); + + /** + * Gets average execution time of query. + * + * @return Average execution time of query. + */ + public double averageTime(); + + /** + * Gets total number execution of query. + * + * @return Number of executions. + */ + public int executions(); + + /** + * Gets total number of times a query execution failed. + * + * @return Total number of times a query execution failed. + */ + public int fails(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlField.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlField.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlField.java new file mode 100644 index 0000000..8d95753 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlField.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import java.lang.annotation.*; + +/** + * Annotates fields for SQL queries. All fields that will be involved in SQL clauses must have + * this annotation. For more information about cache queries see {@link GridCacheQuery} documentation. + * @see GridCacheQuery + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.FIELD}) +public @interface GridCacheQuerySqlField { + /** + * Specifies whether cache should maintain an index for this field or not. + * Just like with databases, field indexing may require additional overhead + * during updates, but makes select operations faster. + * <p> + * When indexing SPI and indexed field is + * of type {@code com.vividsolutions.jts.geom.Geometry} (or any subclass of this class) then GridGain will + * consider this index as spatial providing performance boost for spatial queries. + * + * @return {@code True} if index must be created for this field in database. + */ + boolean index() default false; + + /** + * Specifies whether index should be unique or not. This property only + * makes sense if {@link #index()} property is set to {@code true}. + * + * @return {@code True} if field index should be unique. + * @deprecated No longer supported, will be ignored. + */ + @Deprecated + boolean unique() default false; + + /** + * Specifies whether index should be in descending order or not. This property only + * makes sense if {@link #index()} property is set to {@code true}. + * + * @return {@code True} if field index should be in descending order. + */ + boolean descending() default false; + + /** + * Array of index groups this field belongs to. Groups are used for compound indexes, + * whenever index should be created on more than one field. All fields within the same + * group will belong to the same index. + * <p> + * Group indexes are needed because SQL engine can utilize only one index per table occurrence in a query. + * For example if we have two separate indexes on fields {@code a} and {@code b} of type {@code X} then + * query {@code select * from X where a = ? and b = ?} will use for filtering either index on field {@code a} + * or {@code b} but not both. For more effective query execution here it is preferable to have a single + * group index on both fields. + * <p> + * For more complex scenarios please refer to {@link GridCacheQuerySqlField.Group} documentation. + * + * @return Array of group names. + */ + String[] groups() default {}; + + /** + * Array of ordered index groups this field belongs to. For more information please refer to + * {@linkplain GridCacheQuerySqlField.Group} documentation. + * + * @return Array of ordered group indexes. + * @see #groups() + */ + Group[] orderedGroups() default {}; + + /** + * Property name. If not provided then field name will be used. + * + * @return Name of property. + */ + String name() default ""; + + /** + * Describes group of index and position of field in this group. + * <p> + * Opposite to {@link #groups()} this annotation gives control over order of fields in a group index. + * This can be needed in scenarios when we have a query like + * {@code select * from X where a = ? and b = ? order by b desc}. If we have index {@code (a asc, b asc)} + * sorting on {@code b} will be performed. Here it is preferable to have index {@code (b desc, a asc)} + * which will still allow query to search on index using both fields and avoid sorting because index + * is already sorted in needed way. + * + * @see #groups() + * @see #orderedGroups() + */ + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.METHOD, ElementType.FIELD}) + @SuppressWarnings("PublicInnerClass") + public static @interface Group { + /** + * Group index name where this field participate. + * + * @return Group index name + */ + String name(); + + /** + * Fields in this group index will be sorted on this attribute. + * + * @return Order number. + */ + int order(); + + /** + * Defines sorting order for this field in group. + * + * @return True if field will be in descending order. + */ + boolean descending() default false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlFunction.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlFunction.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlFunction.java new file mode 100644 index 0000000..9751235 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQuerySqlFunction.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import org.apache.ignite.configuration.*; + +import java.lang.annotation.*; + +/** + * Annotates public static methods in classes to be used in SQL queries as custom functions. + * Annotated class must be registered in H2 indexing SPI using following method + * {@link GridQueryConfiguration#setIndexCustomFunctionClasses(Class[])}. + * <p> + * Example usage: + * <pre name="code" class="java"> + * public class MyFunctions { + * @GridCacheQuerySqlFunction + * public static int sqr(int x) { + * return x * x; + * } + * } + * + * // Register. + * indexing.setIndexCustomFunctionClasses(MyFunctions.class); + * + * // And use in queries. + * cache.queries().createSqlFieldsQuery("select sqr(2) where sqr(1) = 1"); + * </pre> + * <p> + * For more information about H2 custom functions please refer to + * <a href="http://www.h2database.com/html/features.html#user_defined_functions">H2 documentation</a>. + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface GridCacheQuerySqlFunction { + /** + * Specifies alias for the function to be used form SQL queries. + * If no alias provided method name will be used. + * + * @return Alias for function. + */ + String alias() default ""; + + /** + * Specifies if the function is deterministic (result depends only on input parameters). + * <p> + * Deterministic function is a function which always returns the same result + * assuming that input parameters are the same. + * + * @return {@code true} If function is deterministic, {@code false} otherwise. + */ + boolean deterministic() default false; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryTextField.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryTextField.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryTextField.java new file mode 100644 index 0000000..a613e29 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryTextField.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +import java.lang.annotation.*; + +/** + * Annotation for fields or getters to be indexed for full text + * search using {@code H2 TEXT} indexing. For more information + * refer to {@link GridCacheQuery} documentation. + * @see GridCacheQuery + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) +public @interface GridCacheQueryTextField { + // No-op. +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7b1a738d/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryType.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryType.java b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryType.java new file mode 100644 index 0000000..4fe6487 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/GridCacheQueryType.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.query; + +/** + * Cache query type. + * <p> + * Used in {@link org.apache.ignite.events.IgniteCacheQueryExecutedEvent} and {@link org.apache.ignite.events.IgniteCacheQueryReadEvent} + * to identify the type of query for which an event was fired. + * + * @see org.apache.ignite.events.IgniteCacheQueryExecutedEvent#queryType() + * @see org.apache.ignite.events.IgniteCacheQueryReadEvent#queryType() + */ +public enum GridCacheQueryType { + /** SQL query. */ + SQL, + + /** SQL fields query. */ + SQL_FIELDS, + + /** Full text query. */ + FULL_TEXT, + + /** Scan query. */ + SCAN, + + /** Continuous query. */ + CONTINUOUS, + + /** SPI query. */ + SPI +}