// Check initialization parameters
File dataDir = getDataDir();
if (dataDir == null) {
throw new SailException("Data dir has not been set");
}
else if (!dataDir.exists()) {
boolean success = dataDir.mkdirs();
if (!success) {
throw new SailException("Unable to create data directory: " + dataDir);
}
}
else if (!dataDir.isDirectory()) {
throw new SailException("The specified path does not denote a directory: " + dataDir);
}
else if (!dataDir.canRead()) {
throw new SailException("Not allowed to read from the specified directory: " + dataDir);
}
// try to lock the directory or fail
dirLock = new DirectoryLockManager(dataDir).lockOrFail();
logger.debug("Data dir is " + dataDir);
try {
namespaceStore = new NamespaceStore(dataDir);
valueStore = new ValueStore(dataDir, forceSync, valueCacheSize, valueIDCacheSize,
namespaceCacheSize, namespaceIDCacheSize);
tripleStore = new TripleStore(dataDir, tripleIndexes, forceSync);
}
catch (IOException e) {
// NativeStore initialization failed, release any allocated files
if (valueStore != null) {
try {
valueStore.close();
}
catch (IOException e1) {
logger.warn("Failed to close value store after native store initialization failure", e);
}
valueStore = null;
}
if (namespaceStore != null) {
namespaceStore.close();
namespaceStore = null;
}
dirLock.release();
throw new SailException(e);
}
logger.debug("NativeStore initialized");
}