use of com.healthmarketscience.jackcess.Database in project eol-globi-data by jhpoelen.
the class StudyImporterForADWTest method readMDB.
@Test
public void readMDB() throws URISyntaxException, IOException {
URI uri = getClass().getResource("spire/econetvis.mdb").toURI();
assertThat(uri, is(notNullValue()));
Database db = DatabaseBuilder.open(new File(uri));
assertThat(db.getFileFormat(), is(Database.FileFormat.V2000));
String[] tableNames = new String[] { "attribute_types", "common_names", "entities", "habitats", "links", "localities", "metastudies", "part_mapping_new", "part_qualifiers", "studies", "study_habitat", "study_local", "taxon", "taxon_attributes" };
Set<String> expectedSet = new HashSet<String>();
Collections.addAll(expectedSet, tableNames);
Set<String> actualTableNames = db.getTableNames();
assertThat(actualTableNames.size(), is(not(0)));
assertThat("expected tables names [" + Arrays.toString(tableNames) + "] to be present", CollectionUtils.subtract(expectedSet, actualTableNames).size(), is(0));
Table studies = db.getTable("studies");
for (Map<String, Object> study : studies) {
assertNotNull(study.get("reference"));
}
List<String> expectedColumnNames = Arrays.asList("study_id", "entity1", "entity2", "link_strength", "link_type", "table_ref", "link_number");
assertColumnNames(expectedColumnNames, db.getTable("links"));
expectedColumnNames = Arrays.asList("id", "latinname", "commonname", "parent", "webinfo", "moreinfo", "numchildren", "pos", "classification", "pictures", "sounds", "specimens", "idx", "extinct", "rank");
assertColumnNames(expectedColumnNames, db.getTable("taxon"));
Table taxonTable = db.getTable("taxon");
int numberOfTaxa = 0;
while (taxonTable.getNextRow() != null) {
numberOfTaxa++;
}
assertThat(numberOfTaxa, is(198301));
Table links = db.getTable("links");
int numberOfLinks = 0;
while (links.getNextRow() != null) {
numberOfLinks++;
}
assertThat(numberOfLinks, is(18189));
}
use of com.healthmarketscience.jackcess.Database in project pentaho-kettle by pentaho.
the class AccessOutputDialog method getTableName.
private void getTableName() {
AccessOutputMeta meta = new AccessOutputMeta();
getInfo(meta);
Database database = null;
// New class: SelectTableDialog
try {
String realFilename = transMeta.environmentSubstitute(meta.getFilename());
FileObject fileObject = KettleVFS.getFileObject(realFilename, transMeta);
File file = FileUtils.toFile(fileObject.getURL());
if (!file.exists() || !file.isFile()) {
throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.FileDoesNotExist", realFilename));
}
database = Database.open(file);
Set<String> set = database.getTableNames();
String[] tablenames = set.toArray(new String[set.size()]);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, tablenames, BaseMessages.getString(PKG, "AccessOutputDialog.Dialog.SelectATable.Title"), BaseMessages.getString(PKG, "AccessOutputDialog.Dialog.SelectATable.Message"));
String tablename = dialog.open();
if (tablename != null) {
wTablename.setText(tablename);
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "AccessOutputDialog.UnableToGetListOfTables.Title"), BaseMessages.getString(PKG, "AccessOutputDialog.UnableToGetListOfTables.Message"), e);
} finally {
// Don't forget to close the bugger.
try {
if (database != null) {
database.close();
}
} catch (Exception e) {
// Ignore close errors
}
}
}
use of com.healthmarketscience.jackcess.Database in project pentaho-kettle by pentaho.
the class AccessOutputMeta method getRequiredFields.
public RowMetaInterface getRequiredFields(VariableSpace space) throws KettleException {
String realFilename = space.environmentSubstitute(filename);
File file = new File(realFilename);
Database db = null;
try {
if (!file.exists() || !file.isFile()) {
throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.FileDoesNotExist", realFilename));
}
// open the database and get the table
db = Database.open(file);
String realTablename = space.environmentSubstitute(tablename);
Table table = db.getTable(realTablename);
if (table == null) {
throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.TableDoesNotExist", realTablename));
}
RowMetaInterface layout = getLayout(table);
return layout;
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.ErrorGettingFields"), e);
} finally {
try {
if (db != null) {
db.close();
}
} catch (IOException e) {
throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.ErrorClosingDatabase"), e);
}
}
}
use of com.healthmarketscience.jackcess.Database in project pentaho-kettle by pentaho.
the class AccessInputDialog method get.
private void get() {
RowMetaInterface fields = new RowMeta();
try {
AccessInputMeta meta = new AccessInputMeta();
getInfo(meta);
// Check if a table name is specified
if (!checkInputTableName(meta)) {
return;
}
FileInputList inputList = meta.getFiles(transMeta);
if (inputList.getFiles().size() > 0) {
// Open the file (only first file)...
Database d = Database.open(new File(AccessInputMeta.getFilename(inputList.getFile(0))), true);
String realTableName = transMeta.environmentSubstitute(meta.getTableName());
Table t = null;
if (realTableName.startsWith(AccessInputMeta.PREFIX_SYSTEM)) {
t = d.getSystemTable(realTableName);
} else {
t = d.getTable(realTableName);
}
// Get the list of columns
List<Column> col = t.getColumns();
int nr = col.size();
for (int i = 0; i < nr; i++) {
Column c = col.get(i);
ValueMetaInterface field = AccessInputMeta.getValueMeta(c);
if (field != null && fields.indexOfValue(field.getName()) < 0) {
fields.addValueMeta(field);
}
}
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "AccessInputDialog.ErrorReadingFile.DialogMessage", e.toString()), e);
}
if (fields.size() > 0) {
// Clear Fields Grid
wFields.removeAll();
for (int j = 0; j < fields.size(); j++) {
ValueMetaInterface field = fields.getValueMeta(j);
wFields.add(new String[] { field.getName(), field.getName(), field.getTypeDesc(), "", "-1", "", "", "", "", "none", "N" });
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
mb.setMessage(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogTitle"));
mb.setText(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogMessage"));
mb.open();
}
}
use of com.healthmarketscience.jackcess.Database in project pentaho-kettle by pentaho.
the class AccessInputDialog method getTableName.
private void getTableName() {
Database accessDatabase = null;
try {
AccessInputMeta meta = new AccessInputMeta();
getInfo(meta);
FileInputList fileInputList = meta.getFiles(transMeta);
if (fileInputList.nrOfFiles() > 0) {
// Check the first file
if (fileInputList.getFile(0).exists()) {
// Open the file (only first file) in readOnly ...
//
accessDatabase = Database.open(new File(AccessInputMeta.getFilename(fileInputList.getFile(0))), true);
// Get user tables
//
Set<String> settables = accessDatabase.getTableNames();
// Get System tables
settables.addAll(accessDatabase.getSystemTableNames());
// Get system tables
String[] tablenames = settables.toArray(new String[settables.size()]);
Const.sortStrings(tablenames);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, tablenames, BaseMessages.getString(PKG, "AccessInputDialog.Dialog.SelectATable.Title"), BaseMessages.getString(PKG, "AccessInputDialog.Dialog.SelectATable.Message"));
String tablename = dialog.open();
if (tablename != null) {
wTable.setText(tablename);
}
} else {
// The file not exists !
throw new KettleException(BaseMessages.getString(PKG, "AccessInputMeta.Exception.FileDoesNotExist", KettleVFS.getFilename(fileInputList.getFile(0))));
}
} else {
// No file specified
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "AccessInputDialog.FilesMissing.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
mb.open();
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "AccessInputDialog.UnableToGetListOfTables.Title"), BaseMessages.getString(PKG, "AccessInputDialog.UnableToGetListOfTables.Message"), e);
} finally {
// Don't forget to close the bugger.
try {
if (accessDatabase != null) {
accessDatabase.close();
}
} catch (Exception e) {
// Ignore close errors
}
}
}
Aggregations