ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From siva <siva.ka...@bizruntime.com>
Subject Re: Persistence store(MSSQL) using cross-platform c#(Ignite Client windows) and java(Ignite Server linux version)
Date Fri, 06 Oct 2017 12:55:25 GMT
Alexey, Yes we have a multi tenant app,actually not rename the cache ,need to
create a cache for each tenant(employee,manager etc nearly 1000+ entities)
.suppose cache name based on the tenant is  *TenantId + "Entities"*.Under
this cache need to store all the entities. Here tenantId is dynamic.  Assume
the following is a piece of code 

                    //client c# this one is call frequently to insert the
new entity
                    IIgnite ignite = Ignition.Start(@"C:\Ignite\ApacheIgnite
2.1 version\apache-ignite-fabric-2.1.0-bin\config\default-config.xml");
                   //tenant id dynamic
                    string TenantId = message.TenantId
                    string cacheName = TenantId + "Entities";
                    string entityId= message.EntityId;
                     string EntityData = message.EntityData;
                    //get or create a cache based on the incoming tenantId
                    var tenantCache = ignite.GetOrCreateCache<String,
                    //storing entity into cache as well as db (cache key is
entity Id)
                    tenantCache[entityId] = new
EntityInfo(TenantId,EntityId, EntityData);

Config file :
 <property name="cacheConfiguration">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
          <property name="name" value="tenantId_Entities"/>
          <property name="readThrough" value="true"/>
          <property name="writeThrough" value="true"/>
          <property name="cacheStoreFactory">
            <bean class="javax.cache.configuration.FactoryBuilder"

as you told ,created a jar file for java cache store 

public class EntityCacheStore extends  CacheStoreAdapter<String,Entity>{



	public void write(Entry<? extends String, ? extends String> entry) throws
CacheWriterException {
		System.out.println("Hello from ......................");
		String key = entry.getKey().toString();
		String message = entry.getValue();
		try {
		String url = 
			Connection con =  DriverManager.getConnection(url);
			int updated;
			PreparedStatement st = con.prepareStatement("insert into EmployeeEntity
(tenantId,employeeId,EntityData) values (?, ?, ?)");
			updated = st.executeUpdate();
			System.out.println("For insert command...............");
			// If update failed, try to insert.

		} catch (SQLException e) {
			throw new CacheWriterException(e.getMessage()+"Failed to write object
[key=" + key + "+, val=" + message + ']', e);

 and added in the standalone ignite class path, what iam asking is 
  *//get or create a cache based on the incoming tenantId
   var tenantCache = ignite.GetOrCreateCache<String,
String>(cacheName);*,but we have hard coded the cache name in the property  
* <property name="name" value="tenantId_Entities"/>*.

Sent from: http://apache-ignite-users.70518.x6.nabble.com/

View raw message