Examples of DBTools


Examples of org.sf.mustru.utils.DbTools

  public void testcreateSecDB()
  {

   //*-- create an empty database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   boolean dupFlag = false;
   assertTrue("t10 create",  dbt.createDB(DBNAME2, true, dupFlag) );
   dbt.closeEnv()

   //  *-- load a few rows
   loadDB("t10", 10, dupFlag, DBNAME2)

   //*-- create the secondary database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dbt.openDB(DBNAME2, false, dupFlag);
   DBKeyCreator skc =  new DBKeyCreator(new TestDocBinding() );
   assertTrue("t10 create SEC ",  dbt.createSecDB(SECDB, false, skc) );

   //*-- drop the secondary database
   assertTrue("t10 drop SEC",  dbt.dropSecDB(SECDB ) );
   dbt.closeDB(); dbt.closeEnv()

   //*-- drop the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t10 drop",  dbt.dropDB(DBNAME2) );
   dbt.closeEnv()

   System.out.println("Completed create/drop sec DB");
  }
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

  public void testOpenSecDB()
  {

   //*-- create an empty database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   boolean dupFlag = false;
   assertTrue("t11 create",  dbt.createDB(DBNAME2, true, dupFlag) );
   dbt.closeEnv()

   //  *-- load a few rows
   loadDB("t11", 10, dupFlag, DBNAME2)

   //*-- create the secondary database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dbt.openDB(DBNAME2, false, dupFlag);
   DBKeyCreator skc1 =  new DBKeyCreator(new TestDocBinding() );
   assertTrue("t11 create SEC ",  dbt.createSecDB(SECDB, false, skc1) );
   dbt.closeDB(); dbt.closeEnv()

   //*-- open the secondary database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dbt.openDB(DBNAME2, false, dupFlag);
   DBKeyCreator skc2 =  new DBKeyCreator(new TestDocBinding() );
   assertTrue("t11 open SEC", dbt.openSecDB(SECDB, false, skc2) );
   assertTrue("t11 close SEC", dbt.closeSecDB() );
   dbt.closeDB(); dbt.closeEnv()

   //*-- drop the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dbt.openDB(DBNAME2, false, dupFlag);
   assertTrue("t11 open SEC", dbt.openSecDB(SECDB, false, skc2) );
   assertTrue("t11 close SEC", dbt.closeSecDB() );
   assertTrue("t11 drop",  dbt.dropDB(DBNAME2) );
   dbt.closeEnv()
View Full Code Here

Examples of org.sf.mustru.utils.DbTools


  public void testFetchSecDB()
  {   
   //*-- create an empty database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   boolean dupFlag = false;
   assertTrue("t12 create",  dbt.createDB(DBNAME2, true, dupFlag) );
   dbt.closeEnv()

   //  *-- load a few rows
   loadDB("t12", 10, dupFlag, DBNAME2)

   //*-- create the secondary database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dbt.openDB(DBNAME2, false, dupFlag);
   DBKeyCreator skc1 =  new DBKeyCreator(new TestDocBinding() );
   assertTrue("t12 create SEC ",  dbt.createSecDB(SECDB, false, skc1) );
   dbt.closeDB(); dbt.closeEnv()

   //*-- open the secondary database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dbt.openDB(DBNAME2, false, dupFlag);
   DBKeyCreator skc2 =  new DBKeyCreator(new TestDocBinding() );
   assertTrue("t12 create SEC ",  dbt.createSecDB(SECDB, false, skc2) );
   assertTrue("t12 open SEC", dbt.openSecDB(SECDB, false, skc2) );

   //*-- fetch a single entry
   DatabaseEntry dbe = dbt.fetchSec("1");
   assertNotNull("t12 fetch SEC", dbe );
   TestDoc doc = new TestDoc(); doc = (TestDoc) doc.getBdbBinding().entryToObject(dbe);
   assertEquals("t12 contents SEC", "contents 2", doc.getContents() );

   //*--  fetch an array of entries
   DatabaseEntry[] dbeArray = dbt.fetchSecArray("3");
   assertNotNull("t12 fetch SEC Array", dbeArray );
   for (int i = 0; i < dbeArray.length; i++)
   { TestDoc doc1 = new TestDoc(); doc1 = (TestDoc) doc1.getBdbBinding().entryToObject(dbeArray[i]);
   System.out.println("Sec. Key: " + doc1.getSeckey() + " Contents: " + doc1.getContents() );
   }
   assertTrue("t12 close SEC", dbt.closeSecDB() );
   dbt.closeDB(); dbt.closeEnv()

   //*-- drop the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dbt.openDB(DBNAME2, false, dupFlag);
   assertTrue("t12 drop",  dbt.dropDB(DBNAME2) );
   dbt.closeEnv()

   System.out.println("Completed fetch sec DB");
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

  }

  public void testMultipleDB()
  {
   //*-- create two dbs
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   boolean dupFlag = false;
   assertTrue("t13 create db1",  dbt.createDB(DBNAME1, true, dupFlag) );
   assertTrue("t13 create db2",  dbt.createDB(DBNAME2, true, dupFlag) );
   dbt.closeEnv();   

   loadDB("t13", 10, dupFlag, DBNAME1);
   loadDB("t13a", 20, dupFlag, DBNAME2);

   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   dupFlag = false;
   assertTrue("t13 open db1",  dbt.openDB(DBNAME1, true, dupFlag) );
   assertTrue("t13 open db2",  dbt.openDB(DBNAME2, true, dupFlag) );

   //*-- fetch a single entry from DBNAME1
   dbt.setCurrentDB(DBNAME1);
   String dbKey = "0000000002"; DatabaseEntry data = new DatabaseEntry();
   assertTrue("t13 fetch", dbt.fetch(dbKey, data) );
   TestDoc doc = new TestDoc();
   doc =  (TestDoc) doc.getBdbBinding().entryToObject(data);
   assertEquals("t13 contents from 1", "contents 2", doc.getContents());

   //*-- fetch a single entry from DBNAME2
   dbt.setCurrentDB(DBNAME2);
   dbKey = "0000000012"; data = new DatabaseEntry();
   assertTrue("t13 fetch", dbt.fetch(dbKey, data) );
   doc = new TestDoc();
   doc =  (TestDoc) doc.getBdbBinding().entryToObject(data);
   assertEquals("t13 contents from 2", "contents 12", doc.getContents());

   assertTrue("t13 close db1",  dbt.closeDB(DBNAME1) );
   assertTrue("t13 close db2",  dbt.closeDB(DBNAME2) );

   dbt.closeEnv();   

   //*-- drop the two dbs
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t13 drop db2",  dbt.dropDB(DBNAME1) );
   assertTrue("t13 drop db1",  dbt.dropDB(DBNAME2) );
   dbt.closeEnv()

   System.out.println("Completed multiple databases test");
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

  }

  public boolean loadDB(String testNo, int nrows, boolean dupFlag, String dbname)
  {
   //*-- open the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue( testNo + " open ", dbt.openDB(dbname, false, dupFlag) );
   assertNotNull(testNo + " py. null", dbt.getCurrentDB() );

   //*-- insert n rows in the database
   for (int i = 1; i <= nrows; i++)
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

   return true;
  }

  public void ttestDumpDB()
  {
   dbt = new DbTools(); dbt.openEnv(Constants.getDBDIR(), false);
   String dbName = "QUERY_DB"; TupleBinding tpb = new IndexableDoc().getBdbBinding();
   String filename = "/home/manuk/out.txt";
   assertTrue("t5 create",  dbt.dumpDB(dbName, tpb, filename) );
   dbt.closeEnv();
   System.out.println("Completed database dump test");
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

   System.out.println("Completed database dump test");
  }

  protected void tearDown()
  {
   DbTools dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   /*   List dbnames = dbt.fetchDBnames();
   for (int i = 0; i < dbnames.size(); i++)
     { dbt.dropDB((String) dbnames.get(i) );
       System.out.println("tearDown: dropped " + (String) dbnames.get(i));
     }*/
   dbt.closeEnv();
  }
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

  { PropertyConfigurator.configure (Constants.LOG4J_FILE);
    Constants.setDBDIR("/big/trec/db");
    Constants.setINDEXDIR("/big/trec/index");
   // Constants.setDBDIR("/home/manuk/mustru/data/db");
   // Constants.setINDEXDIR("/home/manuk/mustru/data/index");
    dbt = new DbTools(); dbt.openEnv(Constants.getDBDIR(), true);
    Constants.setDbt(dbt);
   
  }
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

   //*-- submit the question to the search engine and fetch the hits
   Hits hits = getHits(question);
   if (hits == null) throw new IOException("Could not find any hits for question " + question);
  
   //*-- build the list of answers
   DbTools dbt = Constants.getDbt();
   dbt.openDB(Constants.EXT_FILES_DB, true, false); //*-- read only access
  
   Explanation explanation;
   LOOP: for (int i = 0; i < hits.length(); i++)
   {
     //*-- limit explanations for the top 100 hits
     if (i > 100) break LOOP; boolean foundHit = false;
   
     //*-- check if the hit rank matches the passed rank
     for (int j = 0; j < ranks.length; j++) if (ranks[j] == i) foundHit = true;
     if (!foundHit) continue LOOP;
    
     retv.append("Document: " + i + Constants.NEWLINE);
     explanation = is.explain(query, hits.id(i))
     Document doc = hits.doc(i);
     String key = doc.get("key");
     DatabaseEntry data = new DatabaseEntry();
     if (!dbt.fetch(key, data)) continue LOOP;

     //*-- extract the text
     IndexableDoc idoc = new IndexableDoc();
     idoc = (IndexableDoc) idoc.getBdbBinding().entryToObject(data);
     String line= idoc.getContents().toString();
View Full Code Here

Examples of org.sf.mustru.utils.DbTools

   Properties dprops = null;
   try { dprops = new Properties(); dprops.load(new FileInputStream(Constants.DOCTYPES_FILE)); }
   catch (IOException e)  { System.out.println("Could not read " + Constants.DOCTYPES_FILE + " " + e.getMessage()); }

   //*-- Create the Berkeley DB environment and fetch the matching documents
   DbTools dbt = Constants.getDbt();
   if (hits.length() == 0results[j++] = " Try " + getAlt();
   LOOP: for (int i = 0; i < hits.length(); i++)
   {
    //*-- use the key to fetch the matching database entry
    Document doc = hits.doc(i);
    String key = doc.get("key");
    String ftype = doc.get("type");
    DatabaseEntry data = new DatabaseEntry();

    String dbname = (ftype.equalsIgnoreCase("email")) ? Constants.EXT_MESSAGES_DB: Constants.EXT_FILES_DB;
    dbt.openDB(dbname, true, false); //*-- no create and no dups            
    dbt.fetch(key, data);
    dbt.closeDB();

    //*-- use the type of the document to create a doc instance of the specified type
    String docClass = dprops.getProperty(ftype);
    if ( (docClass == null) || (docClass.equals("")) ) docClass = "org.sf.mustru.docs.TextDoc";
    Class docType = Class.forName(docClass);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.