Thanks for giving reply.
 
I need suggestions from you. I am adding how I am caching my table into
IgniteCache.  Let me know is it correct way or not. If not give me right
path.

User.java (Pojo class)
--------- 
public class User {
        @QuerySqlField(index = true)
        private Long userId;
        @QuerySqlField
    private String name;
        @QuerySqlField
    private String windowsLogin;
        @QuerySqlField
    private Long readAccess;
        @QuerySqlField
    private Long writeAccess;
        @QuerySqlField
    private Long taxonomy;
        @QuerySqlField
    private Long versionLock;
        @QuerySqlField
    private Long admin;
        @QuerySqlField
    private Long numbers;
        @QuerySqlField
    private Long superUser;
        @QuerySqlField
    private Long importAccess;
        @QuerySqlField
    private Long exportAccess;
        @QuerySqlField
    private Date lastModifiedOn;
        @QuerySqlField
    private Long lastModifiedBy;
//accesser methods

}

Cache Store Class
------------------

public class UserCacheStore extends CacheStoreAdapter<Long,User> {

        @CacheStoreSessionResource
    private CacheStoreSession ses;
        
        @Override
        public User load(Long key) throws CacheLoaderException {
                // TODO Auto-generated method stub
                return null;
        }

        @Override
        public void delete(Object arg0) throws CacheWriterException {
                // TODO Auto-generated method stub
                
        }

        @Override
        public void write(Entry<? extends Long, ? extends User> userEntry)
                        throws CacheWriterException {
                // TODO Auto-generated method stub
                
                Long key=userEntry.getKey();
                User user=userEntry.getValue();
                
                //Connection con=ses.attachment();
                
                /*try(PreparedStatement ps=con.prepareStatement("")){
                        
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }*/
                
                                
                
        }
        /** {@inheritDoc} */
    @Override public void loadCache(IgniteBiInClosure<Long, User> clo,
Object... args) {
        if (args == null || args.length == 0 || args[0] == null)
            throw new CacheLoaderException("Expected entry count parameter
is not provided.");

        final int entryCnt = (Integer)args[0];
                System.out.println("comming..........");
        Connection conn = ses.attachment();

        try (PreparedStatement stmt = conn.prepareStatement("select * from
USERS")) {
           // stmt.setInt(1, entryCnt);

            ResultSet rs = stmt.executeQuery();

            int cnt = 0;

            while (rs.next()) {
                User user = new User(rs.getLong("USERID"),
                                rs.getString("NAME"),
                                rs.getString("WINDOWS_LOGIN"),
                                rs.getLong("READACCESS"),
                                rs.getLong("WRITEACCESS"),
                                rs.getLong("TAXONOMY"),
                                rs.getLong("VERSIONLOCK"),
                                rs.getLong("ADMIN"),
                                rs.getLong("NUMBERS"),
                                rs.getLong("SUPERUSER"),
                                rs.getLong("IMPORTACCESS"),
                                rs.getLong("EXPORTACCESS"),
                                rs.getDate("LASTMODIFIEDON"),
                                rs.getLong("LASTMODIFIEDBY"));

                clo.apply(user.getUserId(), user);

                cnt++;
            }

            System.out.println(">>> Loaded " + cnt + " values into cache.");
        }
        catch (SQLException e) {
            throw new CacheLoaderException("Failed to load values from cache
store.", e);
        }
    }
}

Example Class
--------------

public class UserCacheJdbcExmaple {
        private static final String CACHE_NAME =
UserCacheJdbcExmaple.class.getSimpleName();
        /** Heap size required to run this example. */
    public static final int MIN_MEMORY = 1024 * 1024 * 1024;

    public static void main(String[] args) {
                // TODO Auto-generated method stub

                try (Ignite ignite =
Ignition.start("com/wallet/grigain/cache/store/example-ignite.xml")) {
            System.out.println();
            System.out.println(">>> User Cache store example started.");
                CacheConfiguration<Long, User> ccfg=new CacheConfiguration<Long,
User>("userCache");
                ccfg.setAtomicityMode(TRANSACTIONAL);

        // Configure JDBC store.
       
ccfg.setCacheStoreFactory(FactoryBuilder.factoryOf(UserCacheStore.class));

        // Configure JDBC session listener.
        ccfg.setCacheStoreSessionListenerFactories(new
Factory<CacheStoreSessionListener>() {
            @Override public CacheStoreSessionListener create() {
                CacheJdbcStoreSessionListener lsnr = new
CacheJdbcStoreSessionListener();

                lsnr.setDataSource(ConnectionUtil.DATA_SRC);

                return lsnr;
            }
        });
        
        ccfg.setIndexedTypes(Long.class,User.class);
        //ccfg.setTypeMetadata(typeMetadata());
        ccfg.setReadThrough(true);
        ccfg.setWriteThrough(true);
        
        IgniteCache<Long, User> cache=ignite.getOrCreateCache(ccfg);
        cache.loadCache(null, 99_99_99_999);
                
                }
        }
        
}





--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/Need-to-effect-cache-at-time-of-changes-made-in-database-tp2182p2191.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to