use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class DataWriter method open.
public void open() throws StorageException {
if (this.luceneIndexWriter == null || !this.luceneIndexWriter.isOpen()) {
try {
Directory directory = FSDirectory.open(Paths.get(this.indexDirectory));
IndexWriterConfig conf = new IndexWriterConfig(analyzer);
this.luceneIndexWriter = new IndexWriter(directory, conf);
this.isOpen = true;
} catch (IOException e) {
throw new StorageException(e.getMessage(), e);
}
}
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class RelationManager method initializeCatalog.
/*
* Initializes the system catalog tables.
*/
private void initializeCatalog() throws StorageException {
try {
// create table catalog
writeTableInfoToCatalog(CatalogConstants.TABLE_CATALOG.toLowerCase(), new File(CatalogConstants.TABLE_CATALOG_DIRECTORY).getCanonicalPath(), CatalogConstants.TABLE_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
// create schema catalog
writeTableInfoToCatalog(CatalogConstants.SCHEMA_CATALOG.toLowerCase(), new File(CatalogConstants.SCHEMA_CATALOG_DIRECTORY).getCanonicalPath(), CatalogConstants.SCHEMA_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
} catch (IOException e) {
throw new StorageException(e);
}
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class RelationManager method getTableDirectory.
/**
* Gets the directory of a table.
*
* @param tableName, the name of the table, case insensitive
* @return
* @throws StorageException
*/
public String getTableDirectory(String tableName) throws StorageException {
// get the tuples with tableName from the table catalog
Tuple tableCatalogTuple = getTableCatalogTuple(tableName);
// if the tuple is not found, then the table name is not found
if (tableCatalogTuple == null) {
throw new StorageException(String.format("The directory for table %s is not found.", tableName));
}
// get the directory field
IField directoryField = tableCatalogTuple.getField(CatalogConstants.TABLE_DIRECTORY);
return directoryField.getValue().toString();
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class RelationManager method getTableAnalyzer.
/**
* Gets the Lucene analyzer of a table.
*
* @param tableName, the name of the table, case insensitive
* @return
* @throws StorageException
*/
public Analyzer getTableAnalyzer(String tableName) throws StorageException {
String analyzerString = getTableAnalyzerString(tableName);
// convert a lucene analyzer string to an analyzer object
Analyzer luceneAnalyzer = null;
try {
luceneAnalyzer = LuceneAnalyzerConstants.getLuceneAnalyzer(analyzerString);
} catch (DataFlowException e) {
throw new StorageException(e);
}
return luceneAnalyzer;
}
use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.
the class Utils method getTextdbHomePath.
/**
* Gets the path of the textdb home directory by:
* 1): try to use TEXTDB_HOME environment variable,
* if it fails then:
* 2): compare if the current directory is textdb (where TEXTDB_HOME should be),
* if it's not then:
* 3): compare if the current directory is a textdb subproject,
* if it's not then:
*
* Finding textdb home directory will fail
*
* @return the real absolute path to textdb home directory
* @throws StorageException if can not find textdb home
*/
public static String getTextdbHomePath() throws StorageException {
try {
// try to use TEXTDB_HOME environment variable first
if (System.getenv(DataConstants.HOME_ENV_VAR) != null) {
String textdbHome = System.getenv(DataConstants.HOME_ENV_VAR);
return Paths.get(textdbHome).toRealPath().toString();
} else {
// if the environment variable is not found, try if the current directory is textdb
String currentWorkingDirectory = Paths.get("").toRealPath().toString();
// if the current directory ends with textdb (TEXTDB_HOME location)
boolean isTextdbHome = currentWorkingDirectory.endsWith(DataConstants.HOME_FOLDER_NAME);
// if the current directory is one of the sub-projects
boolean isSubProject = Arrays.asList(TextdbProject.values()).stream().map(project -> project.getProjectName()).filter(project -> currentWorkingDirectory.endsWith(project)).findAny().isPresent();
if (isTextdbHome) {
return Paths.get(currentWorkingDirectory).toRealPath().toString();
}
if (isSubProject) {
return Paths.get(currentWorkingDirectory, "../").toRealPath().toString();
}
throw new StorageException("Finding textdb home path failed. Current working directory is " + currentWorkingDirectory);
}
} catch (IOException e) {
throw new StorageException(e);
}
}
Aggregations