Skip to content

Commit

Permalink
ignite-sql-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
S.Vladykin committed Feb 24, 2015
1 parent 6942a85 commit 1b9a97a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
15 changes: 7 additions & 8 deletions examples/config/example-cache.xml
Expand Up @@ -151,14 +151,13 @@

<property name="indexedTypes">
<list>
<bean class="org.apache.ignite.lang.IgniteBiTuple">
<constructor-arg index="0" value="java.util.UUID"/>
<constructor-arg index="1" value="org.apache.ignite.examples.datagrid.CacheQueryExample.Organization"/>
</bean>
<bean class="org.apache.ignite.lang.IgniteBiTuple">
<constructor-arg index="0" value="java.util.UUID"/>
<constructor-arg index="1" value="org.apache.ignite.examples.datagrid.CacheQueryExample.Person"/>
</bean>
<!-- Key and value type for SQL table Organization. -->
<value>java.util.UUID</value>
<value>org.apache.ignite.examples.datagrid.CacheQueryExample.Organization</value>

<!-- Key and value type for SQL table Person. -->
<value>java.util.UUID</value>
<value>org.apache.ignite.examples.datagrid.CacheQueryExample.Person</value>
</list>
</property>
</bean>
Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.apache.ignite.cache.store.*;
import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
import org.jetbrains.annotations.*;

import javax.cache.configuration.*;
Expand Down Expand Up @@ -330,7 +329,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
private boolean sqlEscapeAll;

/** */
private IgniteBiTuple<Class<?>,Class<?>>[] indexedTypes;
private Class<?>[] indexedTypes;

/** */
private int sqlOnheapRowCacheSize = DFLT_SQL_ONHEAP_ROW_CACHE_SIZE;
Expand Down Expand Up @@ -1652,19 +1651,35 @@ public void setSqlEscapeAll(boolean sqlEscapeAll) {

/**
* Array of key and value type pairs to be indexed.
* It means each even (0,2,4...) class in the array will be considered as key type for cache entry,
* each odd (1,3,5...) class will be considered as value type for cache entry.
* <p>
* The same key class can occur multiple times for different value classes, but each value class must be unique
* because SQL table will be named as value class simple name.
* <p>
* To expose fields of these types onto SQL level and to index them you have to use annotations
* from package {@link org.apache.ignite.cache.query.annotations}.
*
* @return Key and value type pairs.
*/
public IgniteBiTuple<Class<?>,Class<?>>[] getIndexedTypes() {
public Class<?>[] getIndexedTypes() {
return indexedTypes;
}

/**
* Array of key and value type pairs to be indexed.
* It means each even (0,2,4...) class in the array will be considered as key type for cache entry,
* each odd (1,3,5...) class will be considered as value type for cache entry.
* <p>
* The same key class can occur multiple times for different value classes, but each value class must be unique
* because SQL table will be named as value class simple name.
* <p>
* To expose fields of these types onto SQL level and to index them you have to use annotations
* from package {@link org.apache.ignite.cache.query.annotations}.
*
* @param indexedTypes Key and value type pairs.
*/
public void setIndexedTypes(IgniteBiTuple<Class<?>,Class<?>>... indexedTypes) {
public void setIndexedTypes(Class<?>... indexedTypes) {
this.indexedTypes = indexedTypes;
}

Expand Down
Expand Up @@ -130,14 +130,19 @@ public void initializeCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedE
}
}

if (!F.isEmpty(ccfg.getIndexedTypes())) {
for (IgniteBiTuple<Class<?>,Class<?>> types : ccfg.getIndexedTypes()) {
TypeDescriptor desc = processKeyAndValue(ccfg, types.getKey(), types.getValue(),
declaredTypes);
Class<?>[] clss = ccfg.getIndexedTypes();

if (!F.isEmpty(clss)) {
for (int i = 0; i < clss.length; i += 2) {
Class<?> keyCls = clss[i];
Class<?> valCls = clss[i + 1];

TypeDescriptor desc = processKeyAndValueClasses(ccfg, keyCls, valCls, declaredTypes);

desc.registered(idx.registerType(ccfg.getName(), desc));

typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc);
types.put(new TypeId(ccfg.getName(), valCls), desc);
}
}
}
Expand All @@ -150,7 +155,7 @@ public void initializeCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedE
* @return Type descriptor.
* @throws IgniteCheckedException If failed.
*/
private TypeDescriptor processKeyAndValue(CacheConfiguration<?,?> ccfg, Class<?> keyCls, Class<?> valCls,
private TypeDescriptor processKeyAndValueClasses(CacheConfiguration<?,?> ccfg, Class<?> keyCls, Class<?> valCls,
Map<TypeName,CacheTypeMetadata> declaredTypes)
throws IgniteCheckedException {
TypeDescriptor d = new TypeDescriptor(ccfg);
Expand Down
Expand Up @@ -24,7 +24,6 @@
import org.apache.ignite.internal.*;
import org.apache.ignite.internal.processors.query.*;
import org.apache.ignite.internal.processors.query.h2.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.marshaller.optimized.*;
import org.apache.ignite.spi.discovery.tcp.*;
Expand Down Expand Up @@ -77,8 +76,9 @@ public class GridQueryParsingTest extends GridCommonAbstractTest {
cc.setSwapEnabled(false);
cc.setSqlFunctionClasses(GridQueryParsingTest.class);
cc.setIndexedTypes(
F.<Class<?>,Class<?>>t(String.class, Address.class),
F.<Class<?>,Class<?>>t(String.class, Person.class));
String.class, Address.class,
String.class, Person.class
);

c.setCacheConfiguration(cc);

Expand All @@ -90,11 +90,6 @@ public class GridQueryParsingTest extends GridCommonAbstractTest {
super.beforeTestsStarted();

ignite = startGrid();

GridCache cache = ((IgniteKernal)ignite).cache(null);

cache.putx("testAddr", new Address());
cache.putx("testPerson", new Person());
}

/**
Expand Down

0 comments on commit 1b9a97a

Please sign in to comment.