本文整理汇总了Java中com.healthmarketscience.jackcess.DatabaseBuilder.open方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseBuilder.open方法的具体用法?Java DatabaseBuilder.open怎么用?Java DatabaseBuilder.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.healthmarketscience.jackcess.DatabaseBuilder
的用法示例。
在下文中一共展示了DatabaseBuilder.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toFile
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
public static final JackcessDenseObjectMatrix2D toFile(File file, Object... parameters)
throws IOException {
Database db = DatabaseBuilder.open(file);
Set<String> tables = db.getTableNames();
String tablename = null;
if (parameters.length != 0) {
tablename = StringUtil.convert(parameters[0]);
}
if (tablename == null) {
if (tables.size() == 1) {
tablename = db.getTableNames().iterator().next();
}
}
db.close();
if (tablename == null) {
throw new IllegalArgumentException(
"please append the table name, i.e. one of these tables: " + tables);
}
return new JackcessDenseObjectMatrix2D(file, tablename);
}
示例2: export
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
/**
* Export the Access database to the given SQLite database. The referenced
* SQLite database should be empty.
*
* @param mdbFile The MS Access file.
* @param sqliteFile The SQLite file.
* @throws SQLException
* @throws SqlJetException
*/
public static void export(File mdbFile, File sqliteFile) throws Exception {
Database mdb = DatabaseBuilder.open(mdbFile);
SqlJetDb sqlite = SqlJetDb.open(sqliteFile, true);
sqlite.getOptions().setAutovacuum(true);
sqlite.beginTransaction(SqlJetTransactionMode.WRITE);
// Create the tables
MDB2SQLite.createTables(mdb, sqlite);
// Populate the tables
for (String tableName : mdb.getTableNames()) {
MDB2SQLite.populateTable(sqlite, mdb.getTable(tableName));
}
}
示例3: loadData
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
@Override
public void loadData(List<Tuple<String, File>> files, Importer importer) throws InvalidFileException, IOException {
Database database = DatabaseBuilder.open(files.get(0).getRight());
for (String tableName : database.getTableNames()) {
importer.startCollection(tableName);
Table table = database.getTable(tableName);
List<? extends Column> columns = table.getColumns();
for (int i = 0; i < columns.size(); i++) {
importer.registerPropertyName(i, columns.get(i).getName());
}
for (Row row : table) {
importer.startEntity();
for (int colNum = 0 ; colNum < columns.size(); colNum++) {
Object cellValue = row.get(columns.get(colNum).getName());
if (cellValue == null) {
cellValue = "";
}
importer.setValue(colNum, "" + cellValue);
}
importer.finishEntity();
}
importer.finishCollection();
}
}
示例4: mapAndGetOriginTable
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
private static String mapAndGetOriginTable(Path tempDBPath, List<ValueMapping> map,
final JDefaultDict<String, ConcurrentMap<ValueMapping, Tuple2<String, String>>> foreignKeyMapping,
final ConcurrentMap<ValueMapping, Joiner> joiners) throws IOException {
try (final Database db = DatabaseBuilder.open(tempDBPath.toFile());) {
// Populate the table mapping for each value mapping
return parseTableMappings(map, db, foreignKeyMapping, joiners);
}
}
示例5: JackcessDenseObjectMatrix2D
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
public JackcessDenseObjectMatrix2D(File file, String tablename) throws IOException {
super(0, 0);
database = DatabaseBuilder.open(file);
VerifyUtil.verifyNotNull(database, "database could not be opened");
table = database.getTable(tablename);
VerifyUtil.verifyNotNull(table, "table not found in database");
columns = table.getColumns();
cursor = CursorBuilder.createCursor(table);
for (int i = 0; i < columns.size(); i++) {
setColumnLabel(i, columns.get(i).getName());
}
setLabel(tablename);
}
示例6: getDB
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
private static Database getDB(String filename) throws IOException {
DatabaseBuilder dbb = new DatabaseBuilder();
dbb.setReadOnly(true);
dbb.setFile(new File(Controller.getPath(filename)));
dbb.setCharset(Charset.forName("ISO-8859-1"));
return dbb.open();
}
示例7: checkUsageMapRead
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
private static void checkUsageMapRead(
final File dbFile, final int expectedFirstPage, final int expectedLastPage)
throws IOException {
final Database db = DatabaseBuilder.open(dbFile);
final UsageMap usageMap = UsageMap.read((DatabaseImpl)db,
PageChannel.PAGE_GLOBAL_USAGE_MAP,
PageChannel.ROW_GLOBAL_USAGE_MAP,
true);
assertEquals("Unexpected FirstPageNumber.", expectedFirstPage,
usageMap.getFirstPageNumber());
assertEquals("Unexpected LastPageNumber.", expectedLastPage,
usageMap.getLastPageNumber());
}
示例8: MDBReader
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
public MDBReader(File mdbFile) throws IOException {
if (mdbFile == null)
throw new IllegalArgumentException();
this.jackcessDatabase = DatabaseBuilder.open(mdbFile);
database = new Database();
String schemaName = mdbFile.getName();
schemaName = schemaName.replace(".mdb", "").replace(".accdb", "");
database.setSchemaName(schemaName);
}
示例9: AccessDao
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
public AccessDao(File accessFile, Class<E> clazz) throws IOException {
this.accessFile = accessFile;
this.clazz = clazz;
this.mapper = new AccessMapper<E>(clazz);
db = DatabaseBuilder.open(this.accessFile);
table = db.getTable(mapper.getTableName());
if(table == null) {
throw new JackcessException("relation " + mapper.getTableName() + " does not exist");
}
}
示例10: open
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
public Database open(File fl,String pwd) throws IOException {
DatabaseBuilder dbd =new DatabaseBuilder(fl);
dbd.setAutoSync(false);
try {
dbd.setReadOnly(false);
return dbd.open();
} catch (IOException e) {
dbd.setReadOnly(true);
return dbd.open();
}
}
示例11: hasPassword
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
private static boolean hasPassword(File fl) throws IOException {
Database db;
try{
db = DatabaseBuilder.open(fl);
}catch(IOException e){
DatabaseBuilder dbb=new DatabaseBuilder();
dbb.setReadOnly(true);
db= dbb.open();
}
String pwd = db.getDatabasePassword();
db.close();
return pwd != null;
}
示例12: dumpToCSVs
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
private static void dumpToCSVs(InputStream input, Path outputDir, String csvPrefix, boolean debug,
boolean addTableNamePrefix) throws IOException {
Path tempFile = Files.createTempFile("Source-accessdb", ".accdb");
Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING);
try {
final CsvSchema schema = CSVStream
.buildSchema(Arrays.asList("OldField", "NewField", "Language", "Mapping"));
try (final Database db = DatabaseBuilder.open(tempFile.toFile());
final Writer columnCsv = Files
.newBufferedWriter(outputDir.resolve(csvPrefix + "AutoMapping-Columns.csv"));
final SequenceWriter columnCsvWriter = CSVStream.newCSVWriter(new BufferedWriter(columnCsv),
schema);) {
for (String tableName : db.getTableNames()) {
Table table = db.getTable(tableName);
if (debug) {
debugTable(table, columnCsvWriter);
}
System.out.println("");
String csvName = csvPrefix + tableName + ".csv";
Path csvPath = outputDir.resolve(csvName);
System.out.println("Converting " + tableName + " to CSV: " + csvPath.toAbsolutePath().toString());
String[] tempArray = new String[table.getColumnCount()];
int x = 0;
for (Column nextColumn : table.getColumns()) {
if (addTableNamePrefix) {
tempArray[x++] = tableName + "." + nextColumn.getName();
} else {
tempArray[x++] = nextColumn.getName();
}
}
final CsvSchema fullFileSchema = CSVStream.buildSchema(Arrays.asList(tempArray));
try (final Writer fullFileCsv = Files.newBufferedWriter(csvPath);
final SequenceWriter fullFileCsvWriter = CSVStream
.newCSVWriter(new BufferedWriter(fullFileCsv), fullFileSchema);) {
int rows = 0;
for (Row nextRow : table) {
int i = 0;
for (Object nextValue : nextRow.values()) {
if (nextValue == null) {
tempArray[i++] = null;
} else if (nextValue instanceof Date) {
tempArray[i++] = CSVUtil.oldDateToISO8601LocalDateTime((Date) nextValue);
} else {
tempArray[i++] = nextValue.toString();
}
}
fullFileCsvWriter.write(Arrays.asList(tempArray));
rows++;
}
System.out.println("Converted " + rows + " rows from table " + tableName);
}
System.out.println("");
System.out.println("----------------------------");
}
}
} finally {
Files.deleteIfExists(tempFile);
}
}
示例13: parseSchema
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
/**
* Interpret the schema and create postgres structures
*
* @param databaseFile
* @param commit
* @param serverName
* @param databaseName
* @return a map of TableImportResult instances with table creation results
* @throws IOException
*/
private Map<String, TableImportResult> parseSchema(File databaseFile,
boolean commit, String serverName, String databaseName)
throws IOException {
Database database = DatabaseBuilder.open(databaseFile);
Map<String, TableImportResult> results = new HashMap<String, TableImportResult>();
//
// Tables
//
Set<String> tablesName = database.getTableNames();
Iterator<String> tables = tablesName.iterator();
while (tables.hasNext()) {
Table table = database.getTable(tables.next());
TableImportResult result = new TableImportResult();
if (!excludeTable(table.getName())) {
if (!createTableStructure(table, commit, serverName,
databaseName)) {
log.error("Unable to create table structure");
result.setTableCreateResult(TableImportResult.FAILED);
} else {
result.setTableCreateResult(TableImportResult.SUCCESSFUL);
}
}
results.put(getNormalisedTableName(table.getName()), result);
}
//
// Constraints
//
Map<String, TableImportResult> constraintResults = createForeignKeys(
serverName, databaseName, database, commit);
//
// Merge results
//
for (String key : results.keySet()) {
results.get(key).merge(constraintResults.get(key));
}
return results;
}
示例14: resolveLinkedDatabase
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
public Database resolveLinkedDatabase(Database linkerDb,
String linkeeFileName)
throws IOException
{
return DatabaseBuilder.open(new File(linkeeFileName));
}
示例15: iteratorRaw
import com.healthmarketscience.jackcess.DatabaseBuilder; //导入方法依赖的package包/类
private TupleIterator iteratorRaw() throws IOException {
return new TupleIterator() {
Database db = DatabaseBuilder.open(new File(meta.getFileSpec()));
Table table = db.getTable(meta.getTable());
Cursor cursor = CursorBuilder.createCursor(table);
Row currentLine = null;
@Override
public boolean hasNext() {
if (currentLine != null)
return true;
try {
if (cursor.moveToNextRow()) {
currentLine = cursor.getCurrentRow();
if (currentLine == null)
return false;
return true;
}
} catch (IOException ioe) {
System.out.println("TableACCDB[1]: error " + ioe);
}
return false;
}
@Override
public ValueTuple next() {
if (hasNext())
try {
return toTuple(table, currentLine);
} finally {
currentLine = null;
}
else
return null;
}
@Override
public void close() {
try {
db.close();
} catch (IOException e) {
System.out.println("TableACCDB[2]: error " + e);
}
}
};
}