5 Replies Latest reply: Jun 14, 2011 9:45 PM by Linda Lee-Oracle RSS

    Truncate data in replication

    868408
      Hi,

      I have a problem with functions removeDatabase and truncateClass, now I want to clear all data in a database with a small cost and I found these two APIs can meet my needs, but it awalys give me com.sleepycat.je.rep.DatabasePreemptedException when a request comes to replicated node, the master node works fine. Below is my code:

      trans = env.beginTransaction(null, null);
                     closeDatabase(); //Close database and entity store

                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.BdbMember#mobile");
                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.BdbMember");
                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.Card#businessNo");
                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.Card");

                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.PointFreeze");

                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.RedMemberBlockPeriod");

      reOpenDatabase("persist#EntityStore#xxx.BdbMember");
                     reOpenDatabase("persist#EntityStore#xxx.Card");
                     reOpenDatabase("persist#EntityStore#xxx.PointFreeze");
                     reOpenDatabase("persist#EntityStore#xxx.RedMemberBlockPeriod");               
                     trans.commit();




      private Database reOpenDatabase(String dbName) throws Exception {
                Transaction trans = null;
                Database db = null;
                try {
                     trans = env.beginTransaction(null, null);
                     DatabaseConfig dc = new DatabaseConfig();
                     dc.setTransactional(true);
                     dc.setAllowCreate(true);
                     db = env.openDatabase(trans, dbName, dc);
                     trans.commit();
                } catch (Exception e) {
                     if (trans != null) {
                          trans.abort();
                     }
                     throw e;
                }
                return db;
           }

      Please do help me!
      Thanks