summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2008-01-14 16:07:17 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2008-01-14 16:07:17 +0000
commit683c1d5d4727a7a902d8058d79247798e75aebe6 (patch)
tree12ae9e1a83d1a223f3778c57b366965774d42110
parent1ac730c1df7fc870ae1e3d379bbe924495caa5a1 (diff)
downloadjackcess-683c1d5d4727a7a902d8058d79247798e75aebe6.tar.gz
jackcess-683c1d5d4727a7a902d8058d79247798e75aebe6.zip
check for max database size when adding pages
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@214 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/java/com/healthmarketscience/jackcess/JetFormat.java8
-rw-r--r--src/java/com/healthmarketscience/jackcess/PageChannel.java4
2 files changed, 12 insertions, 0 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java
index 53f69aa..4e7fd69 100644
--- a/src/java/com/healthmarketscience/jackcess/JetFormat.java
+++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java
@@ -62,6 +62,7 @@ public abstract class JetFormat {
/** Database page size in bytes */
public final int PAGE_SIZE;
+ public final long MAX_DATABASE_SIZE;
public final int MAX_ROW_SIZE;
@@ -145,6 +146,7 @@ public abstract class JetFormat {
_name = name;
PAGE_SIZE = definePageSize();
+ MAX_DATABASE_SIZE = defineMaxDatabaseSize();
MAX_ROW_SIZE = defineMaxRowSize();
@@ -206,6 +208,7 @@ public abstract class JetFormat {
}
protected abstract int definePageSize();
+ protected abstract long defineMaxDatabaseSize();
protected abstract int defineMaxRowSize();
@@ -280,6 +283,11 @@ public abstract class JetFormat {
protected int definePageSize() { return 4096; }
@Override
+ protected long defineMaxDatabaseSize() {
+ return (2L * 1024L * 1024L * 1024L);
+ }
+
+ @Override
protected int defineMaxRowSize() { return PAGE_SIZE - 16; }
@Override
diff --git a/src/java/com/healthmarketscience/jackcess/PageChannel.java b/src/java/com/healthmarketscience/jackcess/PageChannel.java
index e5c3fed..b5301aa 100644
--- a/src/java/com/healthmarketscience/jackcess/PageChannel.java
+++ b/src/java/com/healthmarketscience/jackcess/PageChannel.java
@@ -160,6 +160,10 @@ public class PageChannel implements Channel, Flushable {
public int writeNewPage(ByteBuffer page) throws IOException
{
long size = _channel.size();
+ if(size >= getFormat().MAX_DATABASE_SIZE) {
+ throw new IOException("Database is at maximum size " +
+ getFormat().MAX_DATABASE_SIZE);
+ }
page.rewind();
// push the buffer to the end of the page, so that a full page's worth of
// data is written regardless of the incoming buffer size (we use a tiny