import java.io.Flushable;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.file.Path;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
import com.healthmarketscience.jackcess.expr.EvalConfig;
-import com.healthmarketscience.jackcess.query.Query;
import com.healthmarketscience.jackcess.impl.DatabaseImpl;
+import com.healthmarketscience.jackcess.query.Query;
import com.healthmarketscience.jackcess.util.ColumnValidatorFactory;
import com.healthmarketscience.jackcess.util.ErrorHandler;
import com.healthmarketscience.jackcess.util.LinkResolver;
*/
public File getFile();
+ /**
+ * Returns the File underlying this Database
+ */
+ public Path getPath();
+
/**
* @return The names of all of the user tables
* @usage _general_method_
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
+import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
* @author James Ahlborn
* @usage _general_class_
*/
-public class DatabaseBuilder
+public class DatabaseBuilder
{
/** the file name of the mdb to open/create */
- private File _mdbFile;
+ private Path _mdbFile;
/** whether or not to open existing mdb read-only */
private boolean _readOnly;
/** whether or not to auto-sync writes to the filesystem */
/** database user-defined (if any) */
private Map<String,PropertyMap.Property> _userProps;
-
+
public DatabaseBuilder() {
- this(null);
+ this((Path)null);
}
public DatabaseBuilder(File mdbFile) {
+ this(toPath(mdbFile));
+ }
+
+ public DatabaseBuilder(Path mdbFile) {
_mdbFile = mdbFile;
}
* @usage _general_method_
*/
public DatabaseBuilder setFile(File mdbFile) {
+ return setPath(toPath(mdbFile));
+ }
+
+ /**
+ * File containing an existing database for {@link #open} or target file for
+ * new database for {@link #create} (in which case, <b>tf this file already
+ * exists, it will be overwritten.</b>)
+ * @usage _general_method_
+ */
+ public DatabaseBuilder setPath(Path mdbFile) {
_mdbFile = mdbFile;
return this;
}
public DatabaseBuilder putDatabaseProperty(String name, Object value) {
return putDatabaseProperty(name, null, value);
}
-
+
/**
* Sets the database property with the given name and type to the given
* value.
_dbProps = putProperty(_dbProps, name, type, value);
return this;
}
-
+
/**
* Sets the summary database property with the given name to the given
* value. Attempts to determine the type of the property (see
public DatabaseBuilder putSummaryProperty(String name, Object value) {
return putSummaryProperty(name, null, value);
}
-
+
/**
* Sets the summary database property with the given name and type to
* the given value.
public DatabaseBuilder putUserDefinedProperty(String name, Object value) {
return putUserDefinedProperty(name, null, value);
}
-
+
/**
* Sets the user-defined database property with the given name and type to
* the given value.
* Creates a new Database using the configured information.
*/
public Database create() throws IOException {
- Database db = DatabaseImpl.create(_fileFormat, _mdbFile, _channel, _autoSync,
+ Database db = DatabaseImpl.create(_fileFormat, _mdbFile, _channel, _autoSync,
_charset, _timeZone);
if(_dbProps != null) {
PropertyMap props = db.getDatabaseProperties();
* Open an existing Database. If the existing file is not writeable, the
* file will be opened read-only. Auto-syncing is enabled for the returned
* Database.
- *
+ *
* @param mdbFile File containing the database
- *
+ *
* @see DatabaseBuilder for more flexible Database opening
* @usage _general_method_
*/
public static Database open(File mdbFile) throws IOException {
return new DatabaseBuilder(mdbFile).open();
}
-
+
/**
* Create a new Database for the given fileFormat
- *
+ *
* @param fileFormat version of new database.
* @param mdbFile Location to write the new database to. <b>If this file
* already exists, it will be overwritten.</b>
* @see DatabaseBuilder for more flexible Database creation
* @usage _general_method_
*/
- public static Database create(Database.FileFormat fileFormat, File mdbFile)
- throws IOException
+ public static Database create(Database.FileFormat fileFormat, File mdbFile)
+ throws IOException
{
return new DatabaseBuilder(mdbFile).setFileFormat(fileFormat).create();
}
}
return cal;
}
+
+ private static Path toPath(File file) {
+ return ((file != null) ? file.toPath() : null);
+ }
}
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.RandomAccessFile;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.OpenOption;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
SYSTEM_OBJECT_FLAG | ALT_SYSTEM_OBJECT_FLAG;
/** read-only channel access mode */
- public static final String RO_CHANNEL_MODE = "r";
+ public static final OpenOption[] RO_CHANNEL_OPTS =
+ {StandardOpenOption.READ};
/** read/write channel access mode */
- public static final String RW_CHANNEL_MODE = "rw";
+ public static final OpenOption[] RW_CHANNEL_OPTS =
+ {StandardOpenOption.READ, StandardOpenOption.WRITE};
/** Name of the system object that is the parent of all tables */
private static final String SYSTEM_OBJECT_NAME_TABLES = "Tables";
Pattern.compile("[\\p{Cntrl}.!`\\]\\[]");
/** the File of the database */
- private final File _file;
+ private final Path _file;
/** the simple name of the database */
private final String _name;
/** Buffer to hold database pages */
* @usage _advanced_method_
*/
public static DatabaseImpl open(
- File mdbFile, boolean readOnly, FileChannel channel,
+ Path mdbFile, boolean readOnly, FileChannel channel,
boolean autoSync, Charset charset, TimeZone timeZone,
CodecProvider provider)
throws IOException
{
boolean closeChannel = false;
if(channel == null) {
- if(!mdbFile.exists() || !mdbFile.canRead()) {
+ if(!Files.isReadable(mdbFile)) {
throw new FileNotFoundException("given file does not exist: " +
mdbFile);
}
// force read-only for non-writable files
- readOnly |= !mdbFile.canWrite();
+ readOnly |= !Files.isWritable(mdbFile);
// open file channel
channel = openChannel(mdbFile, readOnly);
* @param timeZone TimeZone to use, if {@code null}, uses default
* @usage _advanced_method_
*/
- public static DatabaseImpl create(FileFormat fileFormat, File mdbFile,
+ public static DatabaseImpl create(FileFormat fileFormat, Path mdbFile,
FileChannel channel, boolean autoSync,
Charset charset, TimeZone timeZone)
throws IOException
* that name cannot be created, or if some other error occurs
* while opening or creating the file
*/
- static FileChannel openChannel(final File mdbFile, final boolean readOnly)
- throws FileNotFoundException
+ static FileChannel openChannel(Path mdbFile, boolean readOnly)
+ throws IOException
{
- final String mode = (readOnly ? RO_CHANNEL_MODE : RW_CHANNEL_MODE);
- return new RandomAccessFile(mdbFile, mode).getChannel();
+ OpenOption[] opts = (readOnly ? RO_CHANNEL_OPTS : RW_CHANNEL_OPTS);
+ return FileChannel.open(mdbFile, opts);
}
/**
* @param charset Charset to use, if {@code null}, uses default
* @param timeZone TimeZone to use, if {@code null}, uses default
*/
- protected DatabaseImpl(File file, FileChannel channel, boolean closeChannel,
+ protected DatabaseImpl(Path file, FileChannel channel, boolean closeChannel,
boolean autoSync, FileFormat fileFormat, Charset charset,
TimeZone timeZone, CodecProvider provider)
throws IOException
}
public File getFile() {
+ return ((_file != null) ? _file.toFile() : null);
+ }
+
+ public Path getPath() {
return _file;
}
FILE_FORMAT_DETAILS.put(fileFormat, new FileFormatDetails(emptyFile, format));
}
- private static String getName(File file) {
+ private static String getName(Path file) {
if(file == null) {
return "<UNKNOWN.DB>";
}
- return file.getName();
+ return file.getFileName().toString();
}
private String withErrorContext(String msg) {
package com.healthmarketscience.jackcess.util;
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
-import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Random;
import com.healthmarketscience.jackcess.Database;
/** temp dbs default to the filesystem, not in memory */
public static final boolean DEFAULT_IN_MEMORY = false;
/** temp dbs end up in the system temp dir by default */
- public static final File DEFAULT_TEMP_DIR = null;
+ public static final Path DEFAULT_TEMP_DIR = null;
private final FileFormat _defaultFormat;
private final boolean _defaultInMemory;
- private final File _defaultTempDir;
+ private final Path _defaultTempDir;
/**
* Creates a CustomLinkResolver using the default behavior for creating temp
* directory)
*/
protected CustomLinkResolver(FileFormat defaultFormat, boolean defaultInMemory,
- File defaultTempDir)
+ Path defaultTempDir)
{
_defaultFormat = defaultFormat;
_defaultInMemory = defaultInMemory;
return _defaultInMemory;
}
- protected File getDefaultTempDirectory() {
+ protected Path getDefaultTempDirectory() {
return _defaultTempDir;
}
* <pre>
* // attempt to load the linkeeFileName as a custom file
* Object customFile = loadCustomFile(linkerDb, linkeeFileName);
- *
+ *
* if(customFile != null) {
* // this is a custom file, create and return relevant temp db
* return createTempDb(customFile, getDefaultFormat(), isDefaultInMemory(),
* getDefaultTempDirectory());
* }
- *
+ *
* // not a custmom file, load using the default behavior
* return LinkResolver.DEFAULT.resolveLinkedDatabase(linkerDb, linkeeFileName);
* </pre>
- *
+ *
* @see #loadCustomFile
* @see #createTempDb
* @see LinkResolver#DEFAULT
*/
public Database resolveLinkedDatabase(Database linkerDb, String linkeeFileName)
- throws IOException
+ throws IOException
{
Object customFile = loadCustomFile(linkerDb, linkeeFileName);
if(customFile != null) {
- return createTempDb(customFile, getDefaultFormat(), isDefaultInMemory(),
+ return createTempDb(customFile, getDefaultFormat(), isDefaultInMemory(),
getDefaultTempDirectory());
}
return LinkResolver.DEFAULT.resolveLinkedDatabase(linkerDb, linkeeFileName);
*
* @return the temp db for holding the linked table info
*/
- protected Database createTempDb(Object customFile, FileFormat format,
- boolean inMemory, File tempDir)
+ protected Database createTempDb(Object customFile, FileFormat format,
+ boolean inMemory, Path tempDir)
throws IOException
{
- File dbFile = null;
+ Path dbFile = null;
FileChannel channel = null;
boolean success = false;
try {
if(inMemory) {
- dbFile = new File(MEM_DB_PREFIX + DB_ID.nextLong() +
- format.getFileExtension());
+ dbFile = Paths.get(MEM_DB_PREFIX + DB_ID.nextLong() +
+ format.getFileExtension());
channel = MemFileChannel.newChannel();
} else {
- dbFile = File.createTempFile(FILE_DB_PREFIX, format.getFileExtension(),
- tempDir);
- channel = new RandomAccessFile(dbFile, DatabaseImpl.RW_CHANNEL_MODE)
- .getChannel();
+ dbFile = ((tempDir != null) ?
+ Files.createTempFile(tempDir, FILE_DB_PREFIX,
+ format.getFileExtension()) :
+ Files.createTempFile(FILE_DB_PREFIX,
+ format.getFileExtension()));
+ channel = FileChannel.open(dbFile, DatabaseImpl.RW_CHANNEL_OPTS);
}
TempDatabaseImpl.initDbChannel(channel, format);
- TempDatabaseImpl db = new TempDatabaseImpl(this, customFile, dbFile,
+ TempDatabaseImpl db = new TempDatabaseImpl(this, customFile, dbFile,
channel, format);
success = true;
return db;
}
}
- private static void deleteDbFile(File dbFile) {
- if((dbFile != null) && (dbFile.getName().startsWith(FILE_DB_PREFIX))) {
- dbFile.delete();
+ private static void deleteDbFile(Path dbFile) {
+ if((dbFile != null) &&
+ dbFile.getFileName().toString().startsWith(FILE_DB_PREFIX)) {
+ try {
+ Files.deleteIfExists(dbFile);
+ } catch(IOException ignores) {}
}
}
ByteUtil.closeQuietly((Closeable)customFile);
}
}
-
+
/**
* Called by {@link #resolveLinkedDatabase} to determine whether the
* linkeeFileName should be treated as a custom file (thus utiliziing a temp
private final Object _customFile;
protected TempDatabaseImpl(CustomLinkResolver resolver, Object customFile,
- File file, FileChannel channel,
+ Path file, FileChannel channel,
FileFormat fileFormat)
throws IOException
{
}
@Override
- protected TableImpl getTable(String name, boolean includeSystemTables)
- throws IOException
+ protected TableImpl getTable(String name, boolean includeSystemTables)
+ throws IOException
{
TableImpl table = super.getTable(name, includeSystemTables);
- if((table == null) &&
+ if((table == null) &&
_resolver.loadCustomTable(this, _customFile, name)) {
table = super.getTable(name, includeSystemTables);
}
try {
super.close();
} finally {
- deleteDbFile(getFile());
+ deleteDbFile(getPath());
closeCustomFile(_customFile);
}
}
import java.nio.channels.NonWritableChannelException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
+import java.nio.file.OpenOption;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
* @author James Ahlborn
* @usage _advanced_class_
*/
-public class MemFileChannel extends FileChannel
+public class MemFileChannel extends FileChannel
{
+ /** read-only channel access mode */
+ public static final String RO_CHANNEL_MODE = "r";
+ /** read/write channel access mode */
+ public static final String RW_CHANNEL_MODE = "rw";
+
private static final byte[][] EMPTY_DATA = new byte[0][];
// use largest possible Jet "page size" to ensure that reads/writes will
/** current amount of actual data in the file */
private long _size;
/** chunks containing the file data. the length of the chunk array is
- always a power of 2 and the chunks are always CHUNK_SIZE. */
+ always a power of 2 and the chunks are always CHUNK_SIZE. */
private byte[][] _data;
- private MemFileChannel()
+ private MemFileChannel()
{
this(0L, 0L, EMPTY_DATA);
}
* affect the original File source.
*/
public static MemFileChannel newChannel(File file) throws IOException {
- return newChannel(file, DatabaseImpl.RW_CHANNEL_MODE);
+ return newChannel(file, RW_CHANNEL_MODE);
}
/**
* modifications to the returned channel will <i>not</i> affect the original
* File source.
*/
- public static MemFileChannel newChannel(File file, String mode)
- throws IOException
+ public static MemFileChannel newChannel(File file, String mode)
+ throws IOException
{
FileChannel in = null;
try {
return newChannel(in = new RandomAccessFile(
- file, DatabaseImpl.RO_CHANNEL_MODE).getChannel(),
+ file, RO_CHANNEL_MODE).getChannel(),
+ mode);
+ } finally {
+ ByteUtil.closeQuietly(in);
+ }
+ }
+
+ /**
+ * Creates a new MemFileChannel containing the contents of the
+ * given Path with the given mode (for mode details see
+ * {@link RandomAccessFile#RandomAccessFile(File,String)}). Note,
+ * modifications to the returned channel will <i>not</i> affect the original
+ * File source.
+ */
+ public static MemFileChannel newChannel(Path file, OpenOption... opts)
+ throws IOException
+ {
+ FileChannel in = null;
+ try {
+ String mode = RO_CHANNEL_MODE;
+ if(opts != null) {
+ for(OpenOption opt : opts) {
+ if(opt == StandardOpenOption.WRITE) {
+ mode = RW_CHANNEL_MODE;
+ break;
+ }
+ }
+ }
+ return newChannel(in = FileChannel.open(file, StandardOpenOption.READ),
mode);
} finally {
ByteUtil.closeQuietly(in);
}
}
+ /**
+ * Creates a new read/write MemFileChannel containing the contents of the
+ * given Path. Note, modifications to the returned channel will <i>not</i>
+ * affect the original File source.
+ */
+ public static MemFileChannel newChannel(Path file) throws IOException {
+ return newChannel(file, DatabaseImpl.RW_CHANNEL_OPTS);
+ }
+
/**
* Creates a new read/write MemFileChannel containing the contents of the
* given InputStream.
*/
public static MemFileChannel newChannel(InputStream in) throws IOException {
- return newChannel(in, DatabaseImpl.RW_CHANNEL_MODE);
+ return newChannel(in, RW_CHANNEL_MODE);
}
/**
* given InputStream with the given mode (for mode details see
* {@link RandomAccessFile#RandomAccessFile(File,String)}).
*/
- public static MemFileChannel newChannel(InputStream in, String mode)
- throws IOException
+ public static MemFileChannel newChannel(InputStream in, String mode)
+ throws IOException
{
return newChannel(Channels.newChannel(in), mode);
}
* Creates a new read/write MemFileChannel containing the contents of the
* given ReadableByteChannel.
*/
- public static MemFileChannel newChannel(ReadableByteChannel in)
+ public static MemFileChannel newChannel(ReadableByteChannel in)
throws IOException
{
- return newChannel(in, DatabaseImpl.RW_CHANNEL_MODE);
+ return newChannel(in, RW_CHANNEL_MODE);
}
/**
* given ReadableByteChannel with the given mode (for mode details see
* {@link RandomAccessFile#RandomAccessFile(File,String)}).
*/
- public static MemFileChannel newChannel(ReadableByteChannel in, String mode)
+ public static MemFileChannel newChannel(ReadableByteChannel in, String mode)
throws IOException
{
MemFileChannel channel = new MemFileChannel();
if(position >= _size) {
return 0L;
}
-
+
count = Math.min(count, _size - position);
int chunkIndex = getChunkIndex(position);
numBytes += bytesWritten;
count -= bytesWritten;
} while(src.hasRemaining());
-
+
++chunkIndex;
chunkOffset = 0;
}
count -= bytesRead;
_size = Math.max(_size, position + numBytes);
} while(dst.hasRemaining());
-
+
++chunkIndex;
- chunkOffset = 0;
+ chunkOffset = 0;
}
-
+
return numBytes;
}
private static int getChunkIndex(long pos) {
return (int)(pos / CHUNK_SIZE);
}
-
+
private static int getChunkOffset(long pos) {
return (int)(pos % CHUNK_SIZE);
}
private static int getNumChunks(long size) {
return getChunkIndex(size + CHUNK_SIZE - 1);
}
-
+
@Override
public long write(ByteBuffer[] srcs, int offset, int length)
throws IOException
@Override
public long read(ByteBuffer[] dsts, int offset, int length)
throws IOException
- {
+ {
long numBytes = 0L;
for(int i = offset; i < offset + length; ++i) {
if(_position >= _size) {
{
super(channel._position, channel._size, channel._data);
}
-
+
@Override
public int write(ByteBuffer src, long position) throws IOException {
throw new NonWritableChannelException();
throws IOException
{
throw new NonWritableChannelException();
- }
+ }
}
}
/**
* @author Tim McCune
*/
-public class DatabaseTest extends TestCase
+public class DatabaseTest extends TestCase
{
public DatabaseTest(String name) throws Exception {
super(name);
db.close();
}
}
-
+
public void testReadDeletedRows() throws Exception {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL, true)) {
Table table = open(testDB).getTable("Table");
while (table.getNextRow() != null) {
rows++;
}
- assertEquals(2, rows);
+ assertEquals(2, rows);
table.getDatabase().close();
}
}
-
+
public void testGetColumns() throws Exception {
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
checkColumn(columns, 8, "I", DataType.BOOLEAN);
}
}
-
+
private static void checkColumn(
- List<? extends Column> columns, int columnNumber, String name,
+ List<? extends Column> columns, int columnNumber, String name,
DataType dataType)
throws Exception
{
assertEquals(name, column.getName());
assertEquals(dataType, column.getType());
}
-
+
public void testGetNextRow() throws Exception {
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
final Database db = open(testDB);
db.close();
}
}
-
+
public void testDeleteCurrentRow() throws Exception {
// make sure correct row is deleted
table.reset();
List<Row> rows = RowFilterTest.toList(table);
-
+
Row r1 = rows.remove(7);
Row r2 = rows.remove(3);
assertEquals(8, rows.size());
table.deleteRow(r2);
table.deleteRow(r1);
- assertTable(rows, table);
+ assertTable(rows, table);
}
}
-
+
public void testMissingFile() throws Exception {
File bogusFile = new File("fooby-dooby.mdb");
assertTrue(!bogusFile.exists());
}
rowNum++;
}
-
+
table.getDatabase().close();
}
}
db.close();
}
- }
+ }
public void testMultiPageTableDef() throws Exception
{
db.close();
}
- }
+ }
public void testLargeTableDef() throws Exception {
TimeZone tz = TimeZone.getTimeZone("America/New_York");
SimpleDateFormat sdf = DatabaseBuilder.createDateFormat("yyyy-MM-dd");
sdf.getCalendar().setTimeZone(tz);
-
- List<String> dates = Arrays.asList("1582-10-15", "1582-10-14",
+
+ List<String> dates = Arrays.asList("1582-10-15", "1582-10-14",
"1492-01-10", "1392-01-10");
Date d = sdf.parse(dateStr);
table.addRow("row " + dateStr, d);
}
-
+
List<String> foundDates = new ArrayList<String>();
for(Row row : table) {
foundDates.add(sdf.format(row.getDate("date")));
sysTables.addAll(
Arrays.asList("MSysObjects", "MSysQueries", "MSysACES",
"MSysRelationships"));
-
+
if (fileFormat == FileFormat.GENERIC_JET4) {
assertNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects"));
} else if (fileFormat.ordinal() < FileFormat.V2003.ordinal()) {
if(fileFormat.ordinal() >= FileFormat.V2010.ordinal()) {
sysTables.add("f_12D7448B56564D8AAE333BCC9B3718E5_Data");
sysTables.add("MSysResources");
- }
+ }
}
assertEquals(sysTables, db.getSystemTableNames());
-
+
assertNotNull(db.getSystemTable("MSysObjects"));
assertNotNull(db.getSystemTable("MSysQueries"));
assertNotNull(db.getSystemTable("MSysACES"));
assertEquals("MSysObjects", tmd.getName());
assertFalse(tmd.isLinked());
assertTrue(tmd.isSystem());
-
+
db.close();
}
}
"RawData[(12) FF FE 6F 74 68 65 72 20 64 61 74 61]",
null);
List<String> fixVals = Arrays.asList("RawData[(4) 37 00 00 00]",
- "RawData[(4) F3 FF FF FF]",
+ "RawData[(4) F3 FF FF FF]",
"RawData[(4) 02 00 00 00]");
int idx = 0;
Database linkeeDb = db.getLinkedDatabases().get(linkeeDbName);
assertNotNull(linkeeDb);
assertEquals(linkeeFile, linkeeDb.getFile());
-
+ assertEquals("linkeeTest.accdb", ((DatabaseImpl)linkeeDb).getName());
+
List<? extends Map<String, Object>> expectedRows =
createExpectedTable(
createExpectedRow(
assertTable(expectedRows, t2);
- db.createLinkedTable("FooTable", linkeeDbName, "Table2");
+ db.createLinkedTable("FooTable", linkeeDbName, "Table2");
tmd = db.getTableMetaData("FooTable");
assertEquals("FooTable", tmd.getName());
assertNull(tmd.getLinkedDbName());
Table t1 = tmd.open(db);
-
+
assertFalse(db.isLinkedTable(null));
assertTrue(db.isLinkedTable(t2));
assertTrue(db.isLinkedTable(t3));
assertTrue(tables.contains(t2));
assertTrue(tables.contains(t3));
assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog()));
-
+
tables = getTables(db.newIterable().setIncludeNormalTables(false));
assertEquals(2, tables.size());
assertFalse(tables.contains(t1));
assertTrue(tables.contains(t2));
assertTrue(tables.contains(t3));
assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog()));
-
+
tables = getTables(db.newIterable().withLocalUserTablesOnly());
assertEquals(1, tables.size());
assertTrue(tables.contains(t1));
assertFalse(tables.contains(t2));
assertFalse(tables.contains(t3));
assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog()));
-
+
tables = getTables(db.newIterable().withSystemTablesOnly());
assertTrue(tables.size() > 5);
assertFalse(tables.contains(t1));
}
return tableList;
}
-
+
public void testTimeZone() throws Exception
{
TimeZone tz = TimeZone.getTimeZone("America/New_York");
throws Exception
{
FileChannel channel = (inMem ? MemFileChannel.newChannel(
- file, DatabaseImpl.RW_CHANNEL_MODE)
+ file, MemFileChannel.RW_CHANNEL_MODE)
: null);
final Database db = new DatabaseBuilder(file).setReadOnly(true)
.setAutoSync(getTestAutoSync()).setChannel(channel).open();
}
SUPPORTED_FILEFORMATS = supported.toArray(new FileFormat[0]);
- SUPPORTED_FILEFORMATS_FOR_READ =
+ SUPPORTED_FILEFORMATS_FOR_READ =
supportedForRead.toArray(new FileFormat[0]);
}
private final File dbFile;
private final FileFormat expectedFileFormat;
- private TestDB(File databaseFile,
+ private TestDB(File databaseFile,
FileFormat expectedDBFileFormat) {
dbFile = databaseFile;
public final File getFile() { return dbFile; }
- public final FileFormat getExpectedFileFormat() {
- return expectedFileFormat;
+ public final FileFormat getExpectedFileFormat() {
+ return expectedFileFormat;
}
- public final JetFormat getExpectedFormat() {
- return DatabaseImpl.getFileFormatDetails(expectedFileFormat).getFormat();
+ public final JetFormat getExpectedFormat() {
+ return DatabaseImpl.getFileFormatDetails(expectedFileFormat).getFormat();
}
@Override
boolean readOnly) {
List<TestDB> supportedTestDBs = new ArrayList<TestDB>();
- for (FileFormat fileFormat :
+ for (FileFormat fileFormat :
(readOnly ? SUPPORTED_FILEFORMATS_FOR_READ :
SUPPORTED_FILEFORMATS)) {
File testFile = getFileForBasename(basename, fileFormat);
if(!testFile.exists()) {
continue;
}
-
+
// verify that the db is the file format expected
try {
Database db = new DatabaseBuilder(testFile).setReadOnly(true).open();
private static File getFileForBasename(
Basename basename, FileFormat fileFormat) {
- return new File(DIR_TEST_DATA,
+ return new File(DIR_TEST_DATA,
fileFormat.name() + File.separator +
- basename + fileFormat.name() +
+ basename + fileFormat.name() +
fileFormat.getFileExtension());
}
}
- public static final List<TestDB> SUPPORTED_DBS_TEST =
+ public static final List<TestDB> SUPPORTED_DBS_TEST =
TestDB.getSupportedForBasename(Basename.TEST);
- public static final List<TestDB> SUPPORTED_DBS_TEST_FOR_READ =
+ public static final List<TestDB> SUPPORTED_DBS_TEST_FOR_READ =
TestDB.getSupportedForBasename(Basename.TEST, true);
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
- final FileChannel channel = DatabaseImpl.openChannel(testDB.dbFile, false);
+ final FileChannel channel = DatabaseImpl.openChannel(
+ testDB.dbFile.toPath(), false);
try {
JetFormat fmtActual = JetFormat.getFormat(channel);
- assertEquals("Unexpected JetFormat for dbFile: " +
+ assertEquals("Unexpected JetFormat for dbFile: " +
testDB.dbFile.getAbsolutePath(),
testDB.getExpectedFormat(), fmtActual);
PropertyMap props = db.getUserDefinedProperties();
props.put("foo", "bar");
props.save();
- }
+ }
} catch(Exception e) {
failure = e;
}
public void testSqlTypes() throws Exception {
-
+
JetFormat v2000 = JetFormat.VERSION_4;
for(DataType dt : DataType.values()) {
if(v2000.isSupportedDataType(dt)) {
package com.healthmarketscience.jackcess.util;
-import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.file.Path;
import com.healthmarketscience.jackcess.ColumnBuilder;
import com.healthmarketscience.jackcess.DataType;
Table t1 = db.getTable("Table1");
assertNotNull(t1);
assertNotSame(db, t1.getDatabase());
-
+
assertTable(createExpectedTable(createExpectedRow("id", 0,
"data1", "row0"),
createExpectedRow("id", 1,
Database linkerDb, String linkeeFileName) throws IOException
{
return (("testFile1.txt".equals(linkeeFileName) ||
- "testFile2.txt".equals(linkeeFileName)) ?
+ "testFile2.txt".equals(linkeeFileName)) ?
linkeeFileName : null);
}
for(int i = 0; i < 3; ++i) {
t.addRow(i, "row" + i);
}
-
+
return true;
} else if("OtherTable2".equals(tableName)) {
for(int i = 3; i < 6; ++i) {
t.addRow(i, "row" + i);
}
-
+
return true;
} else if("Table4".equals(tableName)) {
@Override
protected Database createTempDb(Object customFile, FileFormat format,
- boolean inMemory, File tempDir)
+ boolean inMemory, Path tempDir)
throws IOException
{
inMemory = "testFile1.txt".equals(customFile);