This discussion is archived
2 Replies Latest reply: Mar 22, 2013 6:07 AM by 998288 RSS

Bug with setAllowCreate of Environment

998288 Newbie
Currently Being Moderated
Hi,

Maybe I missunderstand something, but setAllowCreate(true) of Environment class doesn't work properly. I don't want to pre create the folder for my db, so i set allowCreate to true and let sleepycat create it for me if the folder doesn't exist. But that doesn't work and i have not seen any mkdirs() to create the folder in the source code:

class EnvironmentImpl line 453:

fileManager = new FileManager(this, envHome, isReadOnly); // the exception is thrown here because "envHome" doesn't exist.

if (!envConfig.getAllowCreate() && !fileManager.filesExist()) {
throw new EnvironmentNotFoundException
(this, "Home directory: " + envHome);
}

Moreover, the line "fileManager = new FileManager(this, envHome, isReadOnly);" should be after the "if", so if the "envHome" doesn't exists, it would be checked in the the "if" just after, and if getAllowCreate return true, it should create the folder, so the "fileManager" could be instatiated correctly. I see it smth like this :

if (envConfig.getAllowCreate() && !envHome.exists()) {
if(!envHome.mkdirs()) {
throw new IllegalStateException("Unable to create folder "+envHome.getAbsolutePath());
}
}

fileManager = new FileManager(this, envHome, isReadOnly);



My config:

je-5.0.73 version
Spring 3.1.3


To resolve this problem our team has extended the Environment class like this :


public class FixEnvironment extends Environment {
     public FixEnvironment(File envHome, EnvironmentConfig envConfig,
               boolean openIfNeeded, RepConfigProxy repConfigProxy,
               EnvironmentImpl envImplParam) {
          super(envHome, envConfig, openIfNeeded, repConfigProxy, envImplParam);
     }

     public FixEnvironment(File envHome, EnvironmentConfig configuration,
               RepConfigProxy repConfigProxy, EnvironmentImpl envImplParam) {
          super(envHome, configuration, repConfigProxy, envImplParam);
     }

     public FixEnvironment(File envHome, EnvironmentConfig configuration)
               throws EnvironmentNotFoundException, EnvironmentLockedException,
               VersionMismatchException, DatabaseException,
               IllegalArgumentException {
          super(envHome, configuration);
     }

     protected EnvironmentImpl makeEnvironmentImpl(File envHome,
               EnvironmentConfig envConfig, boolean openIfNeeded,
               RepConfigProxy repConfigProxy) {

          if (envConfig.getAllowCreate() && !envHome.exists()) {
               if(!envHome.mkdirs()) {
                    throw new IllegalStateException("Unable to create folder "+envHome.getAbsolutePath());
               }
          }

          return super.makeEnvironmentImpl(envHome, envConfig, openIfNeeded,
                    repConfigProxy);
     }

}


So instead of using the native sleepycat Environment class, we now use the FixEnvironment and that does the trick.

Edited by: 995285 on 21 mars 2013 03:06

Edited by: 995285 on 21 mars 2013 03:07
  • 1. Re: Bug with setAllowCreate of Environment
    Linda Lee Journeyer
    Currently Being Moderated
    The setAllowCreate method is meant to apply to the files that make up the BDB JE environment. In all cases, we expect the directory location to exist. See http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/applicationoverview.html#dbIntro:
    "To use a database environment, it must first be created and then opened. In order to create a database environment, the directory location in which it resides must already exist."

    If you want to check if the directory exists, it would probably work to just use java.io.File.exists or createNewFile, depending on the semantics you want.
  • 2. Re: Bug with setAllowCreate of Environment
    998288 Newbie
    Currently Being Moderated
    Ok, thanks for reply.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points