diff options
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess/util')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/util/CustomLinkResolver.java | 39 | ||||
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java | 9 |
2 files changed, 29 insertions, 19 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/CustomLinkResolver.java b/src/main/java/com/healthmarketscience/jackcess/util/CustomLinkResolver.java index 7992d71..fce5289 100644 --- a/src/main/java/com/healthmarketscience/jackcess/util/CustomLinkResolver.java +++ b/src/main/java/com/healthmarketscience/jackcess/util/CustomLinkResolver.java @@ -117,28 +117,31 @@ public abstract class CustomLinkResolver implements LinkResolver * <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(), - getDefaultTempDirectory()); + // if linker is read-only, open linkee read-only + boolean readOnly = ((linkerDb instanceof DatabaseImpl) ? + ((DatabaseImpl)linkerDb).isReadOnly() : false); + return createTempDb(customFile, getDefaultFormat(), isDefaultInMemory(), + getDefaultTempDirectory(), readOnly); } return LinkResolver.DEFAULT.resolveLinkedDatabase(linkerDb, linkeeFileName); } @@ -157,8 +160,9 @@ public abstract class CustomLinkResolver implements LinkResolver * * @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, File tempDir, + boolean readOnly) throws IOException { File dbFile = null; @@ -178,8 +182,8 @@ public abstract class CustomLinkResolver implements LinkResolver } TempDatabaseImpl.initDbChannel(channel, format); - TempDatabaseImpl db = new TempDatabaseImpl(this, customFile, dbFile, - channel, format); + TempDatabaseImpl db = new TempDatabaseImpl(this, customFile, dbFile, + channel, format, readOnly); success = true; return db; @@ -203,7 +207,7 @@ public abstract class CustomLinkResolver implements LinkResolver ByteUtil.closeQuietly((Closeable)customFile); } } - + /** * Called by {@link #resolveLinkedDatabase} to determine whether the * linkeeFileName should be treated as a custom file (thus utiliziing a temp @@ -252,21 +256,22 @@ public abstract class CustomLinkResolver implements LinkResolver private final Object _customFile; protected TempDatabaseImpl(CustomLinkResolver resolver, Object customFile, - File file, FileChannel channel, - FileFormat fileFormat) + File file, FileChannel channel, + FileFormat fileFormat, boolean readOnly) throws IOException { - super(file, channel, true, false, fileFormat, null, null, null); + super(file, channel, true, false, fileFormat, null, null, null, + readOnly); _resolver = resolver; _customFile = customFile; } @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); } diff --git a/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java b/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java index ebb1bbd..5310449 100644 --- a/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java +++ b/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java @@ -21,6 +21,7 @@ import java.io.IOException; import com.healthmarketscience.jackcess.Database; import com.healthmarketscience.jackcess.DatabaseBuilder; +import com.healthmarketscience.jackcess.impl.DatabaseImpl; /** * Resolver for linked databases. @@ -28,7 +29,7 @@ import com.healthmarketscience.jackcess.DatabaseBuilder; * @author James Ahlborn * @usage _intermediate_class_ */ -public interface LinkResolver +public interface LinkResolver { /** * default link resolver used if none provided @@ -39,7 +40,11 @@ public interface LinkResolver String linkeeFileName) throws IOException { - return DatabaseBuilder.open(new File(linkeeFileName)); + // if linker is read-only, open linkee read-only + boolean readOnly = ((linkerDb instanceof DatabaseImpl) ? + ((DatabaseImpl)linkerDb).isReadOnly() : false); + return new DatabaseBuilder(new File(linkeeFileName)) + .setReadOnly(readOnly).open(); } }; |