4 Replies Latest reply on Aug 7, 2006 1:40 PM by Manik Surtani

    JDBCCacheLoader Problems

    Chciago Pool Newbie

      I am trying to use the JDBC Cache Loader to persist TreeCache to DB, Here is how i do it....
      public void configureCache(){
      try {
      System.out.println("Inside configureCache");
      Properties properties = new Properties();
      try {
      properties.load(new FileInputStream("jdbc-cache.properties"));
      } catch (IOException e) {
      e.printStackTrace();
      }
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(cache,getConfigFile());
      JDBCCacheLoader jdbcCacheLoader=new JDBCCacheLoader();
      jdbcCacheLoader.setConfig(properties);
      jdbcCacheLoader.setCache(cache);
      jdbcCacheLoader.create();
      jdbcCacheLoader.start();
      Fqn fqn=new Fqn("PaymentCache");
      System.out.println(cache.get(fqn));//I get NULL HERE

      } catch(Exception e) {
      e.printStackTrace();
      }

      I am following the life cycle of Loader as described in API fo CacheLoader interface. But i do a get on TreeCache cache i get a null pointer, looks like the cache is not getting any thing from loader the data is avaliable on the DB i can directly do a get on jdbccacheloader and get the info.

      Where am i going wrong is this the right way to attach a loader to TreeCache....

      Thanks in advance

        • 1. Re: JDBCCacheLoader Problems
          Manik Surtani Master

          1) You should not construct a Cache Loader explicitly. When you start the cache, a cache loader is created and configured for you based on your configuration file.

          2) Your configureCache() method is unnecessary.

          3) Your getConfigFile() method should return the name of an XML file (as a String) which needs to be in your classpath. This XML file would contain the cache configuration.

          • 2. Re: JDBCCacheLoader Problems
            Chciago Pool Newbie

            Thanks for your earlier replies Mr Manik Surtani I tried what you suggested but still i have problems with JDBC Cache Loader...I am assumging that there is some problem with XML file i am posting it maybe you can let me know the problem. When i use a properties file and pass it on to JDBC Cache Loader class explictly i have no problem but when i configure using xml i am not able to bind the TreeCache to JDBC. Here is the XML
            <?xml version="1.0" encoding="UTF-8"?>

            <!-- ===================================================================== -->
            <!-- -->
            <!-- Sample TreeCache Service Configuration -->
            <!-- -->
            <!-- ===================================================================== -->






            <!-- ==================================================================== -->
            <!-- Defines TreeCache configuration -->
            <!-- ==================================================================== -->



            jboss:service=Naming
            jboss:service=TransactionManager

            <!--
            Configure the TransactionManager
            -->
            org.jboss.cache.JBossTransactionManagerLookup


            <!--
            Node locking level : SERIALIZABLE
            REPEATABLE_READ (default)
            READ_COMMITTED
            READ_UNCOMMITTED
            NONE
            -->
            REPEATABLE_READ

            <!--
            Valid modes are LOCAL
            REPL_ASYNC
            REPL_SYNC
            -->
            LOCAL
            true

            <!-- Name of cluster. Needs to be the same for all clusters, in order
            to find each other
            TreeCache-Cluster
            -->

            <!-- Max number of milliseconds to wait for a lock acquisition -->
            15000
            <!-- Cache loader configuration -->



            <!-- Name of the eviction policy class. -->
            org.jboss.cache.eviction.LRUPolicy
            <!-- Specific eviction policy configurations. This is LRU -->


            5
            <!-- Cache wide default -->

            0
            0

            <!--
            0
            0
            -->





            false
            /
            false

            org.jboss.cache.loader.JDBCCacheLoader
            <!-- same as the old CacheLoaderConfig attribute -->

            cache.jdbc.table.name=jbosscache
            cache.jdbc.table.create=true
            cache.jdbc.table.drop=false
            cache.jdbc.table.primarykey=jbosscache_pk
            cache.jdbc.fqn.column=fqn
            cache.jdbc.fqn.type=varchar(255)
            cache.jdbc.node.column=node
            cache.jdbc.node.type=blob
            cache.jdbc.parent.column=parent
            cache.jdbc.driver=oracle.jdbc.OracleDriver
            cache.jdbc.url=jdbc:oracle:thin:@localhost:1521:XE
            cache.jdbc.user=system
            cache.jdbc.password=seshu

            <!-- whether the cache loader writes are asynchronous -->
            true
            <!-- only one cache loader in the chain may set fetchPersistentState to true.
            An exception is thrown if more than one cache loader sets this to true. -->
            true
            <!-- determines whether this cache loader ignores writes - defaults to false. -->
            true





            • 3. Re: JDBCCacheLoader Problems
              Chciago Pool Newbie



              false
              /
              false

              org.jboss.cache.loader.JDBCCacheLoader
              <!-- same as the old CacheLoaderConfig attribute -->

              cache.jdbc.table.name=jbosscache
              cache.jdbc.table.create=true
              cache.jdbc.table.drop=false
              cache.jdbc.table.primarykey=jbosscache_pk
              cache.jdbc.fqn.column=fqn
              cache.jdbc.fqn.type=varchar(255)
              cache.jdbc.node.column=node
              cache.jdbc.node.type=blob
              cache.jdbc.parent.column=parent
              cache.jdbc.driver=oracle.jdbc.OracleDriver
              cache.jdbc.url=jdbc:oracle:thin:@localhost:1521:XE
              cache.jdbc.user=system
              cache.jdbc.password=password

              <!-- whether the cache loader writes are asynchronous -->
              true
              <!-- only one cache loader in the chain may set fetchPersistentState to true.
              An exception is thrown if more than one cache loader sets this to true. -->
              true
              <!-- determines whether this cache loader ignores writes - defaults to false. -->
              true





              • 4. Re: JDBCCacheLoader Problems
                Manik Surtani Master

                sorry, coudl you post that snippet again, within [ code ] and [ / code ] tags?