Beispiel #1
0
  /** See if this new handle's configuration is compatible with the pre-existing database. */
  private void validateConfigAgainstExistingDb(DatabaseConfig config, DatabaseImpl databaseImpl)
      throws DatabaseException {

    /*
     * The allowDuplicates property is persistent and immutable.  It does
     * not need to be specified if the useExistingConfig property is set.
     */
    if (!config.getUseExistingConfig()) {
      if (databaseImpl.getSortedDuplicates() != config.getSortedDuplicates()) {
        throw new DatabaseException(
            "You can't open a Database with a duplicatesAllowed "
                + "configuration of "
                + config.getSortedDuplicates()
                + " if the underlying database was created with a "
                + "duplicatesAllowedSetting of "
                + databaseImpl.getSortedDuplicates()
                + ".");
      }
    }

    /*
     * The transactional property is kept constant while any handles are
     * open, and set when the first handle is opened.  It does not need to
     * be specified if the useExistingConfig property is set.
     */
    if (databaseImpl.hasOpenHandles()) {
      if (!config.getUseExistingConfig()) {
        if (config.getTransactional() != databaseImpl.isTransactional()) {
          throw new DatabaseException(
              "You can't open a Database with a transactional "
                  + "configuration of "
                  + config.getTransactional()
                  + " if the underlying database was created with a "
                  + "transactional configuration of "
                  + databaseImpl.isTransactional()
                  + ".");
        }
      }
    } else {
      databaseImpl.setTransactional(config.getTransactional());
    }

    /*
     * Only re-set the comparators if the override is allowed.
     */
    if (config.getOverrideBtreeComparator()) {
      databaseImpl.setBtreeComparator(config.getBtreeComparator());
    }

    if (config.getOverrideDuplicateComparator()) {
      databaseImpl.setDuplicateComparator(config.getDuplicateComparator());
    }
  }
Beispiel #2
0
 private void validateConfigAgainstExistingDb__wrappee__base(
     DatabaseConfig config, DatabaseImpl databaseImpl) throws DatabaseException {
   if (!config.getUseExistingConfig()) {
     if (databaseImpl.getSortedDuplicates() != config.getSortedDuplicates()) {
       throw new DatabaseException(
           "You can't open a Database with a duplicatesAllowed "
               + "configuration of "
               + config.getSortedDuplicates()
               + " if the underlying database was created with a "
               + "duplicatesAllowedSetting of "
               + databaseImpl.getSortedDuplicates()
               + ".");
     }
   }
   if (databaseImpl.hasOpenHandles()) {
     if (!config.getUseExistingConfig()) {
       if (config.getTransactional() != databaseImpl.isTransactional()) {
         throw new DatabaseException(
             "You can't open a Database with a transactional "
                 + "configuration of "
                 + config.getTransactional()
                 + " if the underlying database was created with a "
                 + "transactional configuration of "
                 + databaseImpl.isTransactional()
                 + ".");
       }
     }
   } else {
     databaseImpl.setTransactional(config.getTransactional());
   }
   if (config.getOverrideBtreeComparator()) {
     databaseImpl.setBtreeComparator(config.getBtreeComparator());
   }
   if (config.getOverrideDuplicateComparator()) {
     databaseImpl.setDuplicateComparator(config.getDuplicateComparator());
   }
 }