package com.healthmarketscience.jackcess;
import java.io.BufferedReader;
+import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
+import java.io.Flushable;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
-import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
* @author Tim McCune
*/
public class Database
- implements Iterable<Table>
+ implements Iterable<Table>, Closeable, Flushable
{
private static final Log LOG = LogFactory.getLog(Database.class);
throw (IOException)new IOException(e.getMessage()).initCause(e);
}
}
+
+ /**
+ * Flushes any current changes to the database file to disk.
+ */
+ public void flush() throws IOException {
+ _pageChannel.flush();
+ }
/**
* Close the database file
package com.healthmarketscience.jackcess;
+import java.io.Flushable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.Channel;
import java.nio.channels.FileChannel;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
* Reads and writes individual pages in a database file
* @author Tim McCune
*/
-public class PageChannel implements Channel {
+public class PageChannel implements Channel, Flushable {
private static final Log LOG = LogFactory.getLog(PageChannel.class);
_channel.write(page, (((long) pageNumber * (long) _format.PAGE_SIZE) +
(long) pageOffset));
if(_autoSync) {
- _channel.force(true);
+ flush();
}
}
rtn.order(ByteOrder.LITTLE_ENDIAN);
return rtn;
}
+
+ public void flush() throws IOException {
+ _channel.force(true);
+ }
public void close() throws IOException {
- _channel.force(true);
+ flush();
_channel.close();
}
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.BitSet;
-import java.util.List;
import java.util.logging.Handler;
import org.apache.commons.logging.Log;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import junit.framework.TestCase;
assertEquals(tval, readRow.get("c"));
}
+
+
+ public void testUsageMapPromotion() throws Exception {
+ File srcFile = new File("test/data/testPromotion.mdb");
+ File dbFile = File.createTempFile("databaseTest", ".mdb");
+ dbFile.deleteOnExit();
+ copyFile(srcFile, dbFile);
+
+ Database db = Database.open(dbFile);
+ Table t = db.getTable("jobDB1");
+
+ String lval = createString(255); // "--255 chars long text--";
+
+ for(int i = 0; i < 1000; ++i) {
+ t.addRow(i, 13, 57, 47.0d, lval, lval, lval, lval, lval, lval);
+ }
+
+ Set<Integer> ids = new HashSet<Integer>();
+ for(Map<String,Object> row : t) {
+ ids.add((Integer)row.get("ID"));
+ }
+ assertEquals(1000, ids.size());
+
+ db.close();
+ }
static Object[] createTestRow(String col1Val) {
return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d,