Load data to cache

classic Classic list List threaded Threaded
37 messages Options
12
kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Load data to cache

Hi,

I need to read data through ignite ODBC driver. How can I load data to it?
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi,

You need to load data in Ignite cluster just as ordinary, after that you
need to connect to one of the cluster nodes (OdbcConfiguration should
be set in spring config for this node) with an ODBC driver.

Once connection established you may read data just as with any other
ODBC driver.

You may want to look at ODBC example for reference - [1].


Best Regards,
Igor

On Thu, Mar 23, 2017 at 5:26 PM, kavitha <[hidden email]> wrote:
Hi,

I need to read data through ignite ODBC driver. How can I load data to it?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi,

I am using following code to load data in Ignite cluster. But I got below error.

my-file.xml code:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
  <property name="odbcConfiguration">
    <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
  </property> 
 <property name="cacheConfiguration">
        <list>
            <bean class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="name" value="personCache"></property>
                                <property name="queryEntities">
                    <list>
                        <bean class="org.apache.ignite.cache.QueryEntity">
                            <property name="keyType" value="java.lang.Long"></property>
                            <property name="valueType" value="ignite.myexamples.model.Person"></property>
                            <property name="fields">
                                <map>
                                    <entry key="id" value="java.lang.Long"></entry>
                                    <entry key="name" value="java.lang.String"></entry>
                                    <entry key="orgId" value="java.lang.Long"></entry>
                                    <entry key="salary" value="java.lang.Integer"></entry>
                                </map>
                            </property>
                        </bean>
                    </list>
                </property>
            </bean>
        </list>
    </property>
 
    <property name="peerClassLoadingEnabled" value="true"></property>
 
        </bean>
</beans>

class Person :IBinarizable
    {
        public long id { get; set; }
        public long orgId { get; set; }
        public string name { get; set; }
        public int salary { get; set; }

        public Person(long a, long b, string c, int d)
        {
            id = a;
            orgId = b;
            name = c;
            salary = d;
        }
        public void WriteBinary(IBinaryWriter writer)
        {
            var rawWriter = writer.GetRawWriter();

            rawWriter.WriteString(name);
            rawWriter.WriteInt(salary);
        }

        public void ReadBinary(IBinaryReader reader)
        {
            var rawReader = reader.GetRawReader();

            name = rawReader.ReadString();
            salary = rawReader.ReadInt();
        }
       
    }

 class Program
    {
        static void Main(string[] args)
        {
            Person obj = new Person(1,1000, "John",20000);
            Person obj1 = new Person(2,2000, "Smith", 38000);
           
            IIgnite ignite = Ignition.Start(@"F:Visual Studio 2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            var cache = ignite.GetOrCreateCache<int, Person>("Mycache");
            cache.Put(1,obj);
            cache.Put(2,obj1);
         }
   }
}


Error: An unhandled exception of type 'Apache.Ignite.Core.Binary.BinaryObjectException' occurred in Apache.Ignite.Core.dll

Additional information: Unsupported object type [type=CreateCluster.Person, object=CreateCluster.Person].

Specified type can not be serialized by Ignite: it is neither [Serializable], nor registered in IgniteConfiguration.BinaryConfiguration.
ptupitsyn ptupitsyn
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

You have to include Person class in binary configuration:

            IIgnite ignite = Ignition.Start(new IgniteConfiguration
            {
                SpringConfigUrl = @"F:\Visual Studio 2015\Projects\CreateCluster\CreateCluster\my-file.xml",
                BinaryConfiguration = new BinaryConfiguration(typeof(Person))
            });

Also you have different cache names in config (personCache) and code (Mycache).
Use GetCache instead of GetOrCreateCache to make sure that cache is started from XML config.



On Fri, Mar 24, 2017 at 11:32 AM, kavitha <[hidden email]> wrote:
Hi,

I am using following code to load data in Ignite cluster. But I got below
error.

my-file.xml code:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
  <property name="odbcConfiguration">
    <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
  </property>
 <property name="cacheConfiguration">
        <list>
            <bean
class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="name" value="personCache"></property>
                                <property name="queryEntities">
                    <list>
                        <bean class="org.apache.ignite.cache.QueryEntity">
                            <property name="keyType"
value="java.lang.Long"></property>
                            <property name="valueType"
value="ignite.myexamples.model.Person"></property>
                            <property name="fields">
                                <map>
                                    <entry key="id"
value="java.lang.Long"></entry>
                                    <entry key="name"
value="java.lang.String"></entry>
                                    <entry key="orgId"
value="java.lang.Long"></entry>
                                    <entry key="salary"
value="java.lang.Integer"></entry>
                                </map>
                            </property>
                        </bean>
                    </list>
                </property>
            </bean>
        </list>
    </property>

    <property name="peerClassLoadingEnabled" value="true"></property>

        </bean>
</beans>

class Person :IBinarizable
    {
        public long id { get; set; }
        public long orgId { get; set; }
        public string name { get; set; }
        public int salary { get; set; }

        public Person(long a, long b, string c, int d)
        {
            id = a;
            orgId = b;
            name = c;
            salary = d;
        }
        public void WriteBinary(IBinaryWriter writer)
        {
            var rawWriter = writer.GetRawWriter();

            rawWriter.WriteString(name);
            rawWriter.WriteInt(salary);
        }

        public void ReadBinary(IBinaryReader reader)
        {
            var rawReader = reader.GetRawReader();

            name = rawReader.ReadString();
            salary = rawReader.ReadInt();
        }

    }

 class Program
    {
        static void Main(string[] args)
        {
            Person obj = new Person(1,1000, "John",20000);
            Person obj1 = new Person(2,2000, "Smith", 38000);

            IIgnite ignite = Ignition.Start(@"F:Visual Studio
2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            var cache = ignite.GetOrCreateCache<int, Person>("Mycache");
            cache.Put(1,obj);
            cache.Put(2,obj1);
         }
   }
}


Error: An unhandled exception of type
'Apache.Ignite.Core.Binary.BinaryObjectException' occurred in
Apache.Ignite.Core.dll

Additional information: Unsupported object type [type=CreateCluster.Person,
object=CreateCluster.Person].

Specified type can not be serialized by Ignite: it is neither
[Serializable], nor registered in IgniteConfiguration.BinaryConfiguration.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11414.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

This post was updated on .
Hi,

I wrote code to display Tables from cache through ODBC driver. But I got empty TABLES. Because cache could not be load with data. How can I load data to it?

class Program
{
static void Main(string[] args)
        {
            IIgnite ignite = Ignition.Start(@"F:\Visual Studio 2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            OdbcConnection con = new OdbcConnection("DRIVER={Apache Ignite};server=localhost;port=10800;CACHE=Person");
            con.Open();
            DataTable Tables = con.GetSchema("Tables");
         }
}
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hello,

You should set "QueryEntity" for your cache:

    <property name="cacheConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="Person"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Integer"/>
                <property name="valueType" value="java.lang.String"/>
              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>


Best Regards,
Igor

On Fri, Mar 24, 2017 at 2:00 PM, kavitha <[hidden email]> wrote:
Hi,

I set cache name as 'Person' in Ignite ODBC driver.

<http://apache-ignite-users.70518.x6.nabble.com/file/n11420/Capture.png>
How Can I load data in it?
I tried following code to load data. But no tables exist, while connecting
database through odbc connection. Please explain me how to create database ?
class Program
    {
        static void Main(string[] args)
        {
            IIgnite ignite = Ignition.Start(@"F:Visual Studio
2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            var cache = ignite.GetOrCreateCache<int, string>("Person");
            cache.Put(1, "John");
            cache.Put(2, "Smith");
            cache.Get(1);
            cache.Get(2);
        }
    }

my-file.xml:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
  <property name="odbcConfiguration">
    <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
  </property>
 </bean>
 </beans>



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11420.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi Igor,

Yes. I set QueryEntry for cache. But I got empty table.
My Cache Configuration is:

<?xml version="1.0" encoding="UTF-8"?>

<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">

   
    <property name="odbcConfiguration">
      <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
    </property>

   
    <property name="cacheConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="Person"/>
          <property name="cacheMode" value="PARTITIONED"/>
          <property name="atomicityMode" value="TRANSACTIONAL"/>
          <property name="writeSynchronizationMode" value="FULL_SYNC"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Long"/>
                <property name="valueType" value="Person"/>

                <property name="fields">
                  <map>
                    <entry key="firstName" value="java.lang.String"/>
                    <entry key="lastName" value="java.lang.String"/>
                    <entry key="salary" value="java.lang.Double"/>
                  </map>
                </property>
               
                <property name="indexes">
                    <list>
                        <bean class="org.apache.ignite.cache.QueryIndex">
                            <constructor-arg value="salary"/>
                        </bean>
                    </list>
                </property>
              </bean>
            </list>
          </property>
        </bean>
       
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="Organization"/>
          <property name="cacheMode" value="PARTITIONED"/>
          <property name="atomicityMode" value="TRANSACTIONAL"/>
          <property name="writeSynchronizationMode" value="FULL_SYNC"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Long"/>
                <property name="valueType" value="Organization"/>

                <property name="fields">
                  <map>
                    <entry key="name" value="java.lang.String"/>
                  </map>
                </property>
               
                <property name="indexes">
                    <list>
                        <bean class="org.apache.ignite.cache.QueryIndex">
                            <constructor-arg value="name"/>
                        </bean>
                    </list>
                </property>
              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>
  </bean>
</beans>
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Well, in your "Person" CacheConfiguration QueryEntity is wrong.

In your code you are creating cache with key of type "java.lang.Integer"
and value of type "java.lang.String", while in your QueryEntity you have
configured it only for types "java.lang.Integer" and "Person".

Best Regards,
Igor

On Fri, Mar 24, 2017 at 3:16 PM, kavitha <[hidden email]> wrote:
Hi Igor,

Yes. I set QueryEntry for cache. But I got empty table.
My Cache Configuration is:

<?xml version="1.0" encoding="UTF-8"?>

<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">


    <property name="odbcConfiguration">
      <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
    </property>


    <property name="cacheConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="Person"/>
          <property name="cacheMode" value="PARTITIONED"/>
          <property name="atomicityMode" value="TRANSACTIONAL"/>
          <property name="writeSynchronizationMode" value="FULL_SYNC"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Long"/>
                <property name="valueType" value="Person"/>

                <property name="fields">
                  <map>
                    <entry key="firstName" value="java.lang.String"/>
                    <entry key="lastName" value="java.lang.String"/>
                    <entry key="salary" value="java.lang.Double"/>
                  </map>
                </property>

                <property name="indexes">
                    <list>
                        <bean class="org.apache.ignite.cache.QueryIndex">
                            <constructor-arg value="salary"/>
                        </bean>
                    </list>
                </property>
              </bean>
            </list>
          </property>
        </bean>

        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="Organization"/>
          <property name="cacheMode" value="PARTITIONED"/>
          <property name="atomicityMode" value="TRANSACTIONAL"/>
          <property name="writeSynchronizationMode" value="FULL_SYNC"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Long"/>
                <property name="valueType" value="Organization"/>

                <property name="fields">
                  <map>
                    <entry key="name" value="java.lang.String"/>
                  </map>
                </property>

                <property name="indexes">
                    <list>
                        <bean class="org.apache.ignite.cache.QueryIndex">
                            <constructor-arg value="name"/>
                        </bean>
                    </list>
                </property>
              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>
  </bean>
</beans>



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11425.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi,

I changed my QueryEntity as you suggested. But still my database is empty.
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Please, share your final code. Also, can you share ODBC code?

Best Regards,
Igor

On Fri, Mar 24, 2017 at 3:42 PM, kavitha <[hidden email]> wrote:
Hi,

I changed my QueryEntity as you suggested. But still my database is empty.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11429.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

This post was updated on .
Hi Igor,

First I will explain you what I did. successfully build the solution from the location F:\Apache\apache-ignite-fabric-1.9.0-bin\apache-ignite-fabric-1.9.0-bin\platforms\cpp\project\vs\ignite.sln. Then executed the command Install_amd64 <absolute file path> to install ignite driver. After that created DSN like below screenshot.


My console application code is:
using System.Data;
using Apache.Ignite.Core;
using System.Data.Odbc;

namespace CreateCluster
{
public class Person : IBinarizable
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public Person(int id, string name)
        {
            Id = id;
            Name = name;
        }
        public void WriteBinary(IBinaryWriter writer)
        {
            var rawWriter = writer.GetRawWriter();
            rawWriter.WriteInt(Id);
            rawWriter.WriteString(Name);
        }

        public void ReadBinary(IBinaryReader reader)
        {
            var rawReader = reader.GetRawReader();
            Id = rawReader.ReadInt();
            Name = rawReader.ReadString();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            IIgnite ignite =
                Ignition.Start(@"F:\Visual Studio2015\Projects\CreateCluster\CreateCluster\my-file.xml"));
           var cache = ignite.GetCache<int, Person>("Person");
            cache.Clear();
            Person p1 = new Person(1000,"John Smith");
            Person p2 = new Person(2000, "vinet");
            Person p3 = new Person(8000, "George");
            cache.Put(1,p1);
            cache.Put(2,p2);
            cache.Put(3,p3);
        }
    }
}

my-file.xml code:

<?xml version="1.0" encoding="UTF-8"?>

<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">

   
    <property name="odbcConfiguration">
      <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
    </property>
 <property name="cacheConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="Person"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Integer"/>
                <property name="valueType" value="Person"/>
              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>
            </bean>
        </beans>

If I run console application, node is started.
My problem is, no data exist in cache.
I got following error:

An unhandled exception of type 'Apache.Ignite.Core.Binary.BinaryObjectException' occurred in Apache.Ignite.Core.dll

Additional information: Unsupported object type [type=CreateCluster.Person, object=CreateCluster.Person].

Specified type can not be serialized by Ignite: it is neither [Serializable], nor registered in IgniteConfiguration.BinaryConfiguration.

Can you please help me, what will do to display data?
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

I've tried to reproduce the issue and I'm getting the data from the cluster using ODBC.
Can you share your ODBC code, which queries data? Or do you use some third-party
tool for that?

Best Regards,
Igor

On Sat, Mar 25, 2017 at 6:33 AM, kavitha <[hidden email]> wrote:
Hi Igor,

First I will explain you what I did. successfully build the solution from
the location
F:\Apache\apache-ignite-fabric-1.9.0-bin\apache-ignite-fabric-1.9.0-bin\platforms\cpp\project\vs\ignite.sln.
Then executed the command Install_amd64 <absolute file path> to install
ignite driver. After that created DSN like below screenshot.
<http://apache-ignite-users.70518.x6.nabble.com/file/n11442/DSN.png>

My console application code is:
using System.Data;
using Apache.Ignite.Core;
using System.Data.Odbc;

namespace CreateCluster
{
    class Program
    {
        static void Main(string[] args)
        {
            IIgnite ignite =
                Ignition.Start(@"F:\Visual
Studio2015\Projects\CreateCluster\CreateCluster\my-file.xml"));
            var cache = ignite.GetOrCreateCache<int, string>("Person");
            cache.Put(1, "John");
            cache.Put(2, "Smith");
            cache.Put(3, "Vinet");
            cache.Get(1);
            cache.Get(2);
            cache.Get(3);
        }
    }
}

my-file.xml code:

<?xml version="1.0" encoding="UTF-8"?>

<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">


    <property name="odbcConfiguration">
      <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
    </property>
 <property name="cacheConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="Person"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Integer"/>
                <property name="valueType" value="java.lang.String"/>
              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>
            </bean>
        </beans>

If I run console application, node is started.
My problem is, no data exist in database while connecting through ignite
ODBC driver.

Can you please help me, what will do to display data?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11442.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi Igor,

I shared all my code previously. I don't understand what you ask. ODBC code means?
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

You say you connect to the Ignite using ODBC driver, right?
So the question is how you do that. Do you use some external tool
or do you write some code to do so on your own?

I can't see any ODBC-related code here or any mentions on how you
are trying to get the data. You only say you've failed to do so.

Best Regards,
Igor

On Mon, Mar 27, 2017 at 12:49 PM, kavitha <[hidden email]> wrote:
Hi Igor,

I shared all my code previously. I don't understand what you ask. ODBC code
means?




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11460.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi,

This is my ODBC code. Is it possible to create database as mentioned below.

OdbcConnection con = new OdbcConnection("DRIVER={Apache Ignite};ADDRESS=localhost:10800;CACHE=Person");
            con.Open();
            var command = con.CreateCommand();
            command.CommandText = "create database Northwind";
            var reader = command.ExecuteReader();
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Currently, Ignite does not support DDL, though it is planned for the Ignite 2.0,
so you can't create databases using SQL now. Instead you should assume
that you already have database, where the schemas are caches and tables are
types. So to get data from your caches you'd need to run some query like that:

SELECT _key, _value from "Person".String

Best Regards,
Igor

On Mon, Mar 27, 2017 at 1:33 PM, kavitha <[hidden email]> wrote:
Hi,

This is my ODBC code. Is it possible to create database as mentioned below.

OdbcConnection con = new OdbcConnection("DRIVER={Apache
Ignite};ADDRESS=localhost:10800;CACHE=Person");
            con.Open();
            var command = con.CreateCommand();
            command.CommandText = "create database Northwind";
            var reader = command.ExecuteReader();



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11462.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Okay fine.
I have NORTHWND sql database. Table name is 'Categories' and their columns are CategoryID, CategoryName, Description. My code is below. But I can't get data. Empty Table only displayed. Can you please say me what I am missing here?

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity.Migrations.Model;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Apache.Ignite.Core;
using Apache.Ignite.Core.Events;
using Apache.Ignite.Core.Binary;
using System.Data.Odbc;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using Apache.Ignite.Core.Cache;
using Apache.Ignite.Core.Cache.Configuration;
using Apache.Ignite.Core.Cache.Query;
using Apache.Ignite.Core.Discovery.Tcp;
using Apache.Ignite.Core.Discovery.Tcp.Static;
using Apache.Ignite.Core.Services;
using Apache.Ignite.ExamplesDll.Binary;
using Apache.Ignite.Core.Cache.Store;
using Apache.Ignite.Core.Cluster;
using Apache.Ignite.Core.Common;
using Apache.Ignite.Core.Compute;
using Apache.Ignite.Core.Datastream;

namespace CreateCluster
{
    [Serializable]
    public class Categories
    {
        public int CategoryID { get; set; }
        public string CategoryName { get; set; }
        public string Description { get; set; }

        public Categories()
        {
           
        }
        public Categories(int id, string name, string des)
        {
            CategoryID = id;
            CategoryName = name;
            Description = des;
        }
       
       
    }
    class Program
    {
        static void Main(string[] args)
        {
          IIgnite ignite = Ignition.Start(@"F:\Visual Studio2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            var cache = ignite.GetCache<int, Categories>("NORTHWND");
            OdbcConnection con = new OdbcConnection("DRIVER={Apache Ignite};ADDRESS=localhost:10800;CACHE=NORTHWND");
            con.Open();
            OdbcCommand cmd = new OdbcCommand("Select * from Categories", con);
            OdbcDataReader dr1 = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
            DataTable table1 = new DataTable();
            table1.Load(dr1);
        }
    }
}


My-file.xml code:

<?xml version="1.0" encoding="UTF-8"?>

<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="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"/>
  <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">

   
    <property name="odbcConfiguration">
      <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
    </property>
<property name="cacheConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="NORTHWND"/>
           <property name="cacheMode" value="PARTITIONED"/>
            <property name="atomicityMode" value="ATOMIC"/>
            <property name="cacheStoreFactory">
                <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
                    <property name="dataSourceBean" value="dataSource"/>
                    <property name="dialect">
                        <bean class="org.apache.ignite.cache.store.jdbc.dialect.SQLServerDialect">
                        </bean>
                    </property>
                    <property name="types">
                        <list>
                            <bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
                                <property name="cacheName" value="NORTHWND"/>
                                <property name="keyType" value="java.lang.Integer"/>
                                <property name="valueType" value="Categories"/>
                                <property name="databaseSchema" value="Categories"/>
                                <property name="databaseTable" value="Categories"/>
<property name="keyFields">
                                    <list>
                                        <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant static-field="java.sql.Types.INTEGER"/>
                                            </constructor-arg>
                                            <constructor-arg value="CategoryID"/>
                                            <constructor-arg value="int"/>
                                            <constructor-arg value="Categoryid"/>
                                        </bean>
                                    </list>
                                </property>
                                <property name="valueFields">
                                    <list>
                                        <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant static-field="java.sql.Types.INTEGER"/>
                                            </constructor-arg>
                                            <constructor-arg value="CategoryID"/>
                                            <constructor-arg value="int"/>
                                            <constructor-arg value="Categoryid"/>
                                        </bean>
                                        <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant static-field="java.sql.Types.VARCHAR"/>
                                            </constructor-arg>
                                            <constructor-arg value="CategoryName"/>
                                            <constructor-arg value="java.lang.String"/>
                                            <constructor-arg value="Categoryname"/></bean>
                                        <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant static-field="java.sql.Types.VARCHAR"/>
                                            </constructor-arg>
                                            <constructor-arg value="Description"/>
                                            <constructor-arg value="java.lang.String"/>
                                            <constructor-arg value="Description"/>
                                        </bean>
                                    </list>
                                </property>
                            </bean>
                        </list>
                    </property>
                </bean>
            </property>
            <property name="readThrough" value="true"/>
            <property name="writeThrough" value="true"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Integer"/>
                <property name="valueType" value="Categories"/>
<property name="fields">
                            <map>
                                <entry key="CategoryID" value="java.lang.Integer"/>
                                <entry key="CategoryName" value="java.lang.String"/>
                                <entry key="Description" value="java.lang.String"/>
                            </map>
                        </property>

              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>
            </bean>
        </beans>







Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

I can't see you putting any value into your cache. If you want to load it from a
storage you need to call cache.loadCache();

Best Regards,
Igor

On Mon, Mar 27, 2017 at 2:27 PM, kavitha <[hidden email]> wrote:
Okay fine.
I have NORTHWND sql database. Table name is 'Categories' and their columns
are CategoryID, CategoryName, Description. My code is below. But I can't get
data. Empty Table only displayed. Can you please say me what I am missing
here?

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity.Migrations.Model;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Apache.Ignite.Core;
using Apache.Ignite.Core.Events;
using Apache.Ignite.Core.Binary;
using System.Data.Odbc;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using Apache.Ignite.Core.Cache;
using Apache.Ignite.Core.Cache.Configuration;
using Apache.Ignite.Core.Cache.Query;
using Apache.Ignite.Core.Discovery.Tcp;
using Apache.Ignite.Core.Discovery.Tcp.Static;
using Apache.Ignite.Core.Services;
using Apache.Ignite.ExamplesDll.Binary;
using Apache.Ignite.Core.Cache.Store;
using Apache.Ignite.Core.Cluster;
using Apache.Ignite.Core.Common;
using Apache.Ignite.Core.Compute;
using Apache.Ignite.Core.Datastream;

namespace CreateCluster
{
    [Serializable]
    public class Categories
    {
        public int CategoryID { get; set; }
        public string CategoryName { get; set; }
        public string Description { get; set; }

        public Categories()
        {

        }
        public Categories(int id, string name, string des)
        {
            CategoryID = id;
            CategoryName = name;
            Description = des;
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
          IIgnite ignite = Ignition.Start(@"F:\Visual
Studio2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            var cache = ignite.GetCache<int, Categories>("NORTHWND");
            OdbcConnection con = new OdbcConnection("DRIVER={Apache
Ignite};ADDRESS=localhost:10800;CACHE=NORTHWND");
            con.Open();
            OdbcCommand cmd = new OdbcCommand("Select * from Categories",
con);
            OdbcDataReader dr1 =
cmd.ExecuteReader(CommandBehavior.SchemaOnly);
            DataTable table1 = new DataTable();
            table1.Load(dr1);
        }
    }
}


My-file.xml code:

<?xml version="1.0" encoding="UTF-8"?>

<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="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"/>
  <bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">


    <property name="odbcConfiguration">
      <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
    </property>
<property name="cacheConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="NORTHWND"/>
           <property name="cacheMode" value="PARTITIONED"/>
            <property name="atomicityMode" value="ATOMIC"/>
            <property name="cacheStoreFactory">
                <bean
class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
                    <property name="dataSourceBean" value="dataSource"/>
                    <property name="dialect">
                        <bean
class="org.apache.ignite.cache.store.jdbc.dialect.SQLServerDialect">
                        </bean>
                    </property>
                    <property name="types">
                        <list>
                            <bean
class="org.apache.ignite.cache.store.jdbc.JdbcType">
                                <property name="cacheName"
value="NORTHWND"/>
                                <property name="keyType"
value="java.lang.Integer"/>
                                <property name="valueType"
value="Categories"/>
                                <property name="databaseSchema"
value="Categories"/>
                                <property name="databaseTable"
value="Categories"/>
<property name="keyFields">
                                    <list>
                                        <bean
class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant
static-field="java.sql.Types.INTEGER"/>
                                            </constructor-arg>
                                            <constructor-arg
value="CategoryID"/>
                                            <constructor-arg value="int"/>
                                            <constructor-arg
value="Categoryid"/>
                                        </bean>
                                    </list>
                                </property>
                                <property name="valueFields">
                                    <list>
                                        <bean
class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant
static-field="java.sql.Types.INTEGER"/>
                                            </constructor-arg>
                                            <constructor-arg
value="CategoryID"/>
                                            <constructor-arg value="int"/>
                                            <constructor-arg
value="Categoryid"/>
                                        </bean>
                                        <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant
static-field="java.sql.Types.VARCHAR"/>
                                            </constructor-arg>
                                            <constructor-arg
value="CategoryName"/>
                                            <constructor-arg
value="java.lang.String"/>
                                            <constructor-arg
value="Categoryname"/></bean>
                                        <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                            <constructor-arg>
                                                <util:constant
static-field="java.sql.Types.VARCHAR"/>
                                            </constructor-arg>
                                            <constructor-arg
value="Description"/>
                                            <constructor-arg
value="java.lang.String"/>
                                            <constructor-arg
value="Description"/>
                                        </bean>
                                    </list>
                                </property>
                            </bean>
                        </list>
                    </property>
                </bean>
            </property>
            <property name="readThrough" value="true"/>
            <property name="writeThrough" value="true"/>

          <property name="queryEntities">
            <list>
              <bean class="org.apache.ignite.cache.QueryEntity">
                <property name="keyType" value="java.lang.Integer"/>
                <property name="valueType" value="Categories"/>
<property name="fields">
                            <map>
                                <entry key="CategoryID"
value="java.lang.Integer"/>
                                <entry key="CategoryName"
value="java.lang.String"/>
                                <entry key="Description" value="java.lang.String"/>
                            </map>
                        </property>

              </bean>
            </list>
          </property>
        </bean>
      </list>
    </property>
            </bean>
        </beans>











--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11468.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

kavitha kavitha
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi,

I tried following code to load cache. Could you please correct the code, If It is wrong?

 IIgnite ignite = Ignition.Start(@"F:\Visual Studio2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            var cache = ignite.GetCache<int, Categories>("NORTHWND");
            object[] arg = new object[] { typeof(int),typeof(string) };
             cache.LoadCache(null,arg);

Error Message:
n unhandled exception of type 'Apache.Ignite.Core.Cache.Store.CacheStoreException' occurred in Apache.Ignite.Core.dll

Additional information: Provided key type is not found in store or cache configuration [cache=NORTHWND, key=BinaryObject [idHash=1473137063, hash=51348210, typeId=87]]
Igor Sapego Igor Sapego
Reply | Threaded
Open this post in threaded view
|

Re: Load data to cache

Hi,

Which database do you use?

Best Regards,
Igor

On Tue, Mar 28, 2017 at 7:57 AM, kavitha <[hidden email]> wrote:
Hi,

I tried following code to load cache. Could you please correct the code, If
It is wrong?

 IIgnite ignite = Ignition.Start(@"F:\Visual
Studio2015\Projects\CreateCluster\CreateCluster\my-file.xml");
            var cache = ignite.GetCache<int, Categories>("NORTHWND");
            object[] arg = new object[] { typeof(int),typeof(string) };
             cache.LoadCache(null,arg);

Error Message:
n unhandled exception of type
'Apache.Ignite.Core.Cache.Store.CacheStoreException' occurred in
Apache.Ignite.Core.dll

Additional information: Provided key type is not found in store or cache
configuration [cache=NORTHWND, key=BinaryObject [idHash=1473137063,
hash=51348210, typeId=87]]



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Load-data-to-cache-tp11394p11483.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

12