Ejemplo n.º 1
0
  private void createSecDB(SecondaryConfig secConfig) {
    TupleBinding<DataRow> tBinder = new GenericTupleBinder(tMap);
    SecondaryKeyCreator secKeyCreator = new GenericSecKeyCreator(tBinder, secIndexPos, tMap);

    // Get a secondary object and set the key creator on it.
    secConfig.setKeyCreator(secKeyCreator);
    String secDbName = tableName + "-secDB";
    secDB = myDbEnvironment.openSecondaryDatabase(null, secDbName, myDB, secConfig);
  }
Ejemplo n.º 2
0
  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
    }
  }