/*
 * Section4.java
 *
 * Code template for Berkeley DB practice.
 *
 * Harvard Extension School
 * CSCI E-66
 */

import com.sleepycat.je.*;                // for Database, Environment, etc.
import java.io.*;

public class Section4 {

    private static final int FIELD1_LENGTH = 7;     // length of instructorID
    private static final int KEY_LENGTH = 7;        // length of record keys

    public static void main(String[] args) {
        
        Environment env = null; 
        Database db = null;
        
        // 1. creating and opening a BDB environment
        env = problemOne();
        
        // 2. creating and opening and new b-tree database
        db = problemTwo(env);
        
        // 3. storing a new record
        problemThree(db);
        
        // 4. looking up the new record
        problemFour(db);

        // 5. iterating over all records in the database
        problemFive(db);

        /*
         * Always close your database and environment before exiting!
         */
        
        try { 
            if (db != null)
                db.close(); 

            if (env != null)
                env.close(); 

        } catch (DatabaseException de) { 
            /*
             * Any necessary exception handling would
             * go here.
             */
        }
    }

    
    private static Environment problemOne() {
        /*
         * Creates a new directory in the current working directory
         * that will contain the environment and later, the database
         * file.
         */
        File envHome = new File("db_dir");
        envHome.mkdir();

        // create a new EnvironmentConfig object

        // create and return a new Environment object
        
        return null;
    }


    private static Database problemTwo(Environment env) {
        String dbFileName = new String("courses.db"); 

        // create a new DatabaseConfig object
        
        // create and return a new Database object

        return null;
    }


    private static void problemThree(Database db) {
        String keyStr = "CSCIE66"; 
        String instructorID = "1234567";
        int enrollment = 35;

        // create RowOutput objects for the key and value

        // write bytes to the RowOutput buffers

        // create new DatabaseEntry objects for key and value
        
        // use database's put() method to store the record
    }


    private static void problemFour(Database db) {
        String keyStr = "CSCIE66";

        // create RowOutput object for the key

        // write bytes to the RowOutput object

        // create new DatabaseEntry objects for the key and value
        
        // use the database's get() method
    
        // if the operation was a success, print the record
    }


    private static void problemFive(Database db) {
        // create Cursor object
        
        // create DatabaseEntry objects for keys and values
        
        // use Cursor's getNext method
        
        // unmarshall each record and print it
    }

}
