Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
org.apache.ignite.IgniteCheckedException: Indexing is disabled
package lk.uscs.msc.project;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import javax.cache.Cache;
/**
* User: chamindah
* Date: 3/11/15
* Time: 10:26 PM
*/
public class BasicCache {
public static void main(String[] args) {
Ignite ignite = Ignition.start("../resource/example-cache.xml");
IgniteCache<Long, Customer> cache = ignite.jcache("test");
cache.put(1L, new Customer(1, "hetti", "asfdfdf", 10));
cache.put(2L, new Customer(2, "hetti2", "asfdfdf", 20));
cache.put(3L, new Customer(3, "hetti3", "asfdfdf", 30));
cache.put(4L, new Customer(4, "hetti4", "asfdfdf", 40));
SqlQuery sql = new SqlQuery("from Customer");
try {
QueryCursor<Cache.Entry<Long, Customer>> cursor = cache.query(sql);
for (Cache.Entry<Long, Customer> e : cursor) {
System.out.println(e);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
class Customer {
@QuerySqlField
private int customerId;
@QuerySqlField
private String cusName;
@QuerySqlField
private String cusAddress;
@QuerySqlField
private int age;
public Customer(int customerId, String cusName, String cusAddress, int age) {
this.customerId = customerId;
this.cusName = cusName;
this.cusAddress = cusAddress;
this.age = age;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCusName() {
return cusName;
}
public void setCusName(String cusName) {
this.cusName = cusName;
}
public String getCusAddress() {
return cusAddress;
}
public void setCusAddress(String cusAddress) {
this.cusAddress = cusAddress;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Customer{" +
"customerId=" + customerId +
", cusName='" + cusName + '\'' +
", cusAddress='" + cusAddress + '\'' +
", age=" + age +
'}';
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<!--
Ignite Spring configuration file to startup ignite cache.
When starting a standalone node, you need to execute the following command:
{IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/example-cache.xml
When starting Ignite from Java IDE, pass path to this file to Ignition:
Ignition.start("examples/config/example-cache.xml");
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Set to true to enable distributed class loading for examples, default is false. -->
<property name="peerClassLoadingEnabled" value="false"/>
<property name="marshaller">
<bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
<!-- Set to false to allow non-serializable objects in examples, default is true. -->
<property name="requireSerializable" value="false"/>
</bean>
</property>
<!-- Enable cache events for examples. -->
<!--<property name="includeEventTypes">-->
<!--<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_EXPIRED"/>-->
<!--</property>-->
<!-- Cache configurations (all properties are optional). -->
<property name="cacheConfiguration">
<list>
<!-- Replicated cache example configuration (Transactional mode). -->
<bean parent="cache-template">
<property name="name" value="test"/>
<property name="cacheMode" value="LOCAL"/>
<property name="atomicityMode" value="ATOMIC"/>
<property name="backups" value="0"/>
<property name="writeSynchronizationMode" value="PRIMARY_SYNC"/>
<property name="queryIndexEnabled" value="true"/>
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
<constructor-arg>
<bean class="lk.uscs.msc.project.CacheJdbcPersonStore">
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</list>
</property>
<!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<!--
Ignite provides several options for automatic discovery that can be used
instead os static IP based discovery. For information on all options refer
to our documentation: http://doc.gridgain.org/latest/Automatic+Node+Discovery
-->
<!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
<!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
<property name="addresses">
<list>
<!-- In distributed environment, replace with actual host IP address. -->
<value>127.0.0.1</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
<!-- Template for all example cache configurations. -->
<bean id="cache-template" abstract="true" class="org.apache.ignite.configuration.CacheConfiguration">
<!-- Initial cache size. -->
<property name="startSize" value="3000000"/>
<!-- Set synchronous preloading (default is asynchronous). -->
<property name="preloadMode" value="SYNC"/>
<!-- Set to FULL_SYNC for examples, default is PRIMARY_SYNC. -->
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<!-- Set to true to enable indexing for query examples, default value is false. -->
<property name="queryIndexEnabled" value="true"/>
<!-- Allow to index primitive values. -->
<property name="queryConfiguration">
<bean class="org.apache.ignite.configuration.CacheQueryConfiguration">
<!-- Index primitives. -->
<property name="indexPrimitiveKey" value="true"/>
</bean>
</property>
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
<constructor-arg>
<bean class="lk.uscs.msc.project.CacheJdbcPersonStore">
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.