<author email="javajedi@users.sf.net">Tim McCune</author>
</properties>
<body>
+ <release version="2.1.6" date="TBD">
+ <action dev="jahlborn" type="update" system="SourceForge2Features"
+ issue="34">
+ When opening a database for a format which is read-only, automatically
+ open the channel as read-only (instead of throwing an exception if
+ readOnly is false).
+ </action>
+ </release>
<release version="2.1.5" date="2016-10-03">
<action dev="jahlborn" type="update">
Change multi-value complex columns so that they return all relevant
JetFormat jetFormat = JetFormat.getFormat(channel);
if(jetFormat.READ_ONLY) {
- throw new IOException("file format " +
- jetFormat.getPossibleFileFormats().values() +
- " does not support writing for " + mdbFile);
+
+ if(closeChannel) {
+ // we own the channel, close and re-open read only
+ ByteUtil.closeQuietly(channel);
+ channel = null;
+ readOnly = true;
+ channel = openChannel(mdbFile, readOnly);
+ } else {
+ throw new IOException("file format " +
+ jetFormat.getPossibleFileFormats().values() +
+ " does not support writing for " + mdbFile);
+ }
}
}
package com.healthmarketscience.jackcess.impl;
import java.io.File;
-import java.io.IOException;
import java.nio.channels.FileChannel;
+import java.nio.channels.NonWritableChannelException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.Database.*;
import com.healthmarketscience.jackcess.DatabaseBuilder;
+import com.healthmarketscience.jackcess.PropertyMap;
import junit.framework.TestCase;
import static com.healthmarketscience.jackcess.TestUtil.*;
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
Database db = null;
- IOException failure = null;
+ Exception failure = null;
try {
db = openCopy(testDB);
- } catch(IOException e) {
+
+ if(testDB.getExpectedFormat().READ_ONLY) {
+ PropertyMap props = db.getUserDefinedProperties();
+ props.put("foo", "bar");
+ props.save();
+ }
+
+ } catch(Exception e) {
failure = e;
} finally {
if(db != null) {
if(!testDB.getExpectedFormat().READ_ONLY) {
assertNull(failure);
} else {
- assertTrue(failure.getMessage().contains("does not support writing"));
+ assertTrue(failure instanceof NonWritableChannelException);
}
}