public BDBCreator(String tableName, ArrayList<Integer> keyPositions, int secondaryIndex) { /* Creates and loads a BDB table with a secondary index on the column defined by*/ this.tableName = tableName.toLowerCase(); this.keyPositions = keyPositions; this.secIndexPos = secondaryIndex; this.tMap = Main.indexTypeMaps.get(this.tableName); setEnvironment(); dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); myDB = myDbEnvironment.openDatabase(null, this.tableName, dbConfig); SecondaryConfig secConfig = new SecondaryConfig(); secConfig.setAllowCreate(true); secConfig.setSortedDuplicates(true); createSecDB(secConfig); setConfig(dbConfig, secConfig); loadData(); if (secDB != null) { secDB.close(); } if (myDB != null) { myDB.close(); } closeEnvironment(); }
public static void main(String[] args) { Environment myEnv; Database myDatabase; try { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); myEnv = new Environment(new File("/Users/broso/testDB"), envConfig); // Environment open omitted for clarity DatabaseConfig myDbConfig = new DatabaseConfig(); SecondaryConfig mySecConfig = new SecondaryConfig(); myDbConfig.setAllowCreate(true); mySecConfig.setAllowCreate(true); // Duplicates are frequently required for secondary databases. mySecConfig.setSortedDuplicates(true); // Open the primary String dbName = "myPrimaryDatabase"; Database myDb = myEnv.openDatabase(null, dbName, myDbConfig); // Open the secondary. // Key creators are described in the next section. // AKeyCreator akc = new AKeyCreator(); // Get a secondary object and set the key creator on it. // mySecConfig.setKeyCreator(keyCreator); // Perform the actual open String secDbName = "mySecondaryDatabase"; SecondaryDatabase mySecDb = myEnv.openSecondaryDatabase(null, secDbName, myDb, mySecConfig); } catch (DatabaseException de) { // Exception handling goes here } }