Package org.sf.mustru.utils

Examples of org.sf.mustru.utils.DbTools


  { PropertyConfigurator.configure (Constants.LOG4J_FILE)}
 
  //*--  Create / Drop a  database
  public void testCreateDropDB()
  {
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t1 create",  dbt.createDB(DBNAME1, true) );
   assertTrue("t1 drop", dbt.dropDB(DBNAME1) );
   dbt.closeEnv();
   System.out.println("Completed create and drop tests...");
  }
View Full Code Here


  //*--  Open and close a database
  public void testOpenClose()
  { 
   //*-- first create the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t2 create",  dbt.createDB(DBNAME1, true) );
   dbt.closeEnv();
  
   //*-- open / close the database in read only mode
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t2 open read only", dbt.openDB(DBNAME1, true) );
   assertNotNull("t1 current DB null", dbt.getCurrentDB() );
   assertTrue("t2 close", dbt.closeDB());
   dbt.closeEnv();
 
   //*-- Open / close an existing database in r/w mode
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t2 open read write", dbt.openDB(DBNAME1, false) );
   assertTrue("t2 close", dbt.closeDB());
   dbt.closeEnv();
  
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t2 drop", dbt.dropDB(DBNAME1) )
   dbt.closeEnv();
   System.out.println("Completed open and close tests......");
  }
View Full Code Here

  //*-- try to open a non-existing database
  public void testOpenDB()
  {
   //*-- create a database 
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t3 create",  dbt.createDB(DBNAME1, true) );
   dbt.closeEnv();
  
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertFalse("t3 create",  dbt.openDB("Bad DB", true) );
   dbt.closeEnv();
  
   //*-- drop the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t3 drop", dbt.dropDB(DBNAME1) )
   dbt.closeEnv()
  }
View Full Code Here

   dbt.closeEnv()
  }
  //*-- Drop an existing database
  public void testDropDB()
  {
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t4 create",  dbt.createDB(DBNAME1, true) );
   assertTrue("t4 drop", dbt.dropDB(DBNAME1) );
  
   //*-- try to drop a non-existent databse
   assertFalse("t4 bad drop", dbt.dropDB("NotDB") );
View Full Code Here

  }
 
  public void testGetNextKey()
  {
   //*-- create an empty database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t5 create",  dbt.createDB(DBNAME2, true) );
   dbt.closeEnv();
   //*-- load the database with ten records
   int  numRecords = 10; loadDB("t4", numRecords, false, DBNAME2);
   String keyString = ++numRecords + "";
  
   //*-- get the next key
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t5 open read only", dbt.openDB(DBNAME2, true) );
   String dbKey = null; String nextKey = null;
   try { dbKey = dbt.getNextKey(); nextKey = StringTools.fillin( keyString, 10, false, '0', 10 - keyString.length()); }
   catch (DatabaseException dbe) { logger.error("Could not get next key " + dbe.getMessage() ); }
   assertEquals("t5 get n+1 key", nextKey, dbKey );
   assertTrue("t5 close", dbt.closeDB());
   dbt.closeEnv()
  
   //*-- drop the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t5 drop",  dbt.dropDB(DBNAME2) );
   dbt.closeEnv();
   System.out.println("Completed get next key test...");
  
  }
View Full Code Here

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

   //  *-- load a few rows
   loadDB("t6", 5, false, DBNAME2);

   //*-- open the database with primary key
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t6 open ", dbt.openDB(DBNAME2, false) );
   assertNotNull("t6 current null", dbt.getCurrentDB() );

   //*-- fetch the document and verify
   String dbKey = "0000000002";
   DatabaseEntry data = new DatabaseEntry(); TestDoc doc = new TestDoc();
   if (dbt.fetch(dbKey, data) )
   {  doc = (TestDoc) doc.getBdbBinding().entryToObject(data);    }
   String contents = "contents " + 2;
   assertEquals("t6", contents, doc.getContents() );
   dbt.closeDB(); dbt.closeEnv()

   //*-- drop the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t6 drop",  dbt.dropDB(DBNAME2) );
   dbt.closeEnv();
   System.out.println("Completed fetch document...");

  }
View Full Code Here

  }

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

   //*-- load a few rows
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   loadDB("t6a", 5, false, DBNAME2);
   assertEquals("t6a size 1", 5, dbt.sizeDB(DBNAME2));
   dbt.closeDB(); dbt.closeEnv();
  
   //*-- drop the database
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue("t6a drop",  dbt.dropDB(DBNAME2) );
   dbt.closeEnv();
  }
View Full Code Here

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

   //  *-- load a few rows
   loadDB("t7", 10, false, DBNAME2);

   //*-- fetch a document, delete the document and attempt to fetch it again
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue( "t7 open ", dbt.openDB(DBNAME2, false) );
   String dbKey = "0000000002"; DatabaseEntry data = new DatabaseEntry();
   assertTrue( "t7 fetch not successful", dbt.fetch(dbKey, data) );
   data = new DatabaseEntry();
   assertTrue("t7 delete failed", dbt.delete(dbKey) );
   assertFalse( "t7 fetch should have failed", dbt.fetch(dbKey, data) );
   dbt.closeDB(); dbt.closeEnv();

   //*-- try to delete a non-existent row
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue( "t7 open ", dbt.openDB(DBNAME2, false) );
   dbKey = "Bad key";
   assertFalse("t7 this delete should fail", dbt.delete(dbKey) );
   dbt.closeDB(); dbt.closeEnv();

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

   System.out.println("Completed delete document...");
  }
View Full Code Here

  }

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

   //  *-- load a few rows
   loadDB("t8", 10, false, DBNAME2);

   //*-- fetch a record, update its contents and verify the update
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue( "t8 open ", dbt.openDB(DBNAME2, false) );
   String dbKey = "0000000002"; DatabaseEntry data = new DatabaseEntry();
   assertTrue("t8 fetch", dbt.fetch(dbKey, data) );
   TestDoc doc = new TestDoc();
   doc =  (TestDoc) doc.getBdbBinding().entryToObject(data);

   String newContents = "new contents"; doc.setContents(newContents);
   assertTrue("t8 update", dbt.update(dbKey, (StoreAbleInterface) doc) );
   dbt.fetch(dbKey, data);
   doc = new TestDoc();
   doc =  (TestDoc) doc.getBdbBinding().entryToObject(data);
   assertEquals("t8 content was not updated", newContents, doc.getContents() );
   dbt.closeDB(); dbt.closeEnv();

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

   System.out.println("Completed update of document....");
  }
View Full Code Here

  }

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

   //  *-- load a few rows
   loadDB("t9", 10, false, DBNAME2);

   //*-- check if a row exists with the given key
   dbt = new DbTools(); dbt.openEnv(DBDIR, false);
   assertTrue( "t9 open ", dbt.openDB(DBNAME2, true) );
   try
   {
    assertTrue(" t9 exists should be OK", dbt.exists("0000000004") );
    assertFalse(" t9 exists should not be OK", dbt.exists("0000000099") );
   }
   catch (DatabaseException de)
   { System.out.println("Py.. key problem " + de.getMessage()); }
   finally { dbt.closeDB(); dbt.closeEnv(); }

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

   System.out.println("Completed exists with py key");
  }
View Full Code Here

TOP

Related Classes of org.sf.mustru.utils.DbTools

Copyright © 2018 www.massapicom. 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.