You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by Apache Wiki <wi...@apache.org> on 2006/10/05 00:19:55 UTC

[Db-derby Wiki] Update of "DatabaseManager" by DonaldMcLean

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by DonaldMcLean:
http://wiki.apache.org/db-derby/DatabaseManager

The comment on the change is:
Added new initialization feature

------------------------------------------------------------------------------
  #format wiki
  #language en
  
- Derby and Hibernate are each very large packages full of power and fraught with complexities. When I first started working with them, I desperately wanted a very simple mechanism that would handle the basic drudgery so that I could concentrate on writing my application. The led me to the creation of a fairly small class (200 lines) that did everything that I needed.
+ Derby and Hibernate are each very large packages full of power and fraught with complexities. When I first started working with them, I desperately wanted a very simple mechanism that would handle the basic drudgery so that I could concentrate on writing my application. The led me to the creation of a fairly small class (~300 lines) that did everything that I needed.
  
  Please see the DatabaseManagerSource and the DatabaseUtilitiesSource.
  === Configuration Files ===
  The glue that makes everything work is the configuration files. A Hibernate file for each class (MyClass.hbm.xml) and a DatabaseManager.xml file (in the same package as the DatabaseManager class).
  
- The DatabaseManager XML file consists of a root element and two child elements, Classes and createSql. The Classes element is a list of "Class" elements containing the fully qualified class name of a class that you want to persist. The createSql element is a list of "statement" elements containing the SQL statements that will be used to create the database.
+ The DatabaseManager XML file consists of a root element and three child elements, Classes, createSql and Initialization.
+ 
+ The Classes element is a list of "Class" elements containing the fully qualified class name of a class that you want to persist. The createSql element is a list of "statement" elements containing the SQL statements that will be used to create the database. The Initialization element is a list of "Load" elements for which the Derby procedure SYSCS_IMPORT_DATA will be called.
+ 
+ The only catch with this initialization feature is that in order for it to work, you must write a static function "setContext()" that will initialize a path variable for the table files.
  
  {{{
  <DatabaseManager>
@@ -32, +36 @@

              sql to create table for Bark class goes here
          </statement>
      </createSql>
+ 
+     <Initialize>
+         <Load>
+             <Table>OINK_TABLE</Table>
+             <Columns>OINK_COLUMN1, OINK_COLUMN2, OINK_COLUMN3</Columns>
+             <File>PATH_TO_OINK_FILE</File>
+         </Load>
+     </Initialize>
  </DatabaseManager>
  }}}
  
@@ -39, +51 @@

  Using a DatabaseManager is fairly simple.
  
  {{{
+         DatabaseManager.setContext("my parameters go here");
  
          File dbFile = new File("PropertySetTest");
          DBUtilities.deleteAnyFile(dbFile);