git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1407 f203690c-595d-4dc9-a70b-905162fa7fd2master
* @param creator description of the indexes to write | * @param creator description of the indexes to write | ||||
* @param buffer Buffer to write to | * @param buffer Buffer to write to | ||||
*/ | */ | ||||
@SuppressWarnings("resource") | |||||
protected static void writeDefinition( | protected static void writeDefinition( | ||||
TableMutator creator, ByteBuffer buffer, | TableMutator creator, ByteBuffer buffer, | ||||
TableMutator.IndexDataState idxDataState, ByteBuffer rootPageBuffer) | TableMutator.IndexDataState idxDataState, ByteBuffer rootPageBuffer) | ||||
_between = between; | _between = between; | ||||
} | } | ||||
public DataPage getDataPage() { | |||||
DataPage getDataPage() { | |||||
return _dataPage; | return _dataPage; | ||||
} | } | ||||
public int getIndex() { | |||||
int getIndex() { | |||||
return _idx; | return _idx; | ||||
} | } | ||||
public int getNextIndex() { | |||||
int getNextIndex() { | |||||
// note, _idx does not need to be advanced if it was pointing at a | // note, _idx does not need to be advanced if it was pointing at a | ||||
// between position | // between position | ||||
return(_between ? _idx : (_idx + 1)); | return(_between ? _idx : (_idx + 1)); | ||||
} | } | ||||
public int getPrevIndex() { | |||||
int getPrevIndex() { | |||||
// note, we ignore the between flag here because the index will be | // note, we ignore the between flag here because the index will be | ||||
// pointing at the correct next index in either the between or | // pointing at the correct next index in either the between or | ||||
// non-between case | // non-between case | ||||
return(_idx - 1); | return(_idx - 1); | ||||
} | } | ||||
public Entry getEntry() { | |||||
Entry getEntry() { | |||||
return _entry; | return _entry; | ||||
} | } | ||||
public boolean isBetween() { | |||||
return _between; | |||||
} | |||||
public boolean equalsEntry(Entry entry) { | |||||
boolean equalsEntry(Entry entry) { | |||||
return _entry.equals(entry); | return _entry.equals(entry); | ||||
} | } | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.HashSet; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.LinkedHashMap; | import java.util.LinkedHashMap; | ||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Queue; | import java.util.Queue; | ||||
import java.util.RandomAccess; | import java.util.RandomAccess; | ||||
import java.util.Set; | |||||
import static com.healthmarketscience.jackcess.impl.IndexData.*; | import static com.healthmarketscience.jackcess.impl.IndexData.*; | ||||
import com.healthmarketscience.jackcess.impl.IndexData.DataPage; | import com.healthmarketscience.jackcess.impl.IndexData.DataPage; |
import com.healthmarketscience.jackcess.expr.Identifier; | import com.healthmarketscience.jackcess.expr.Identifier; | ||||
import com.healthmarketscience.jackcess.util.ErrorHandler; | import com.healthmarketscience.jackcess.util.ErrorHandler; | ||||
import com.healthmarketscience.jackcess.util.ExportUtil; | import com.healthmarketscience.jackcess.util.ExportUtil; | ||||
import org.apache.commons.lang3.builder.ToStringBuilder; | |||||
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
} | } | ||||
private static final String FUNC_START_DELIM = "("; | private static final String FUNC_START_DELIM = "("; | ||||
private static final String FUNC_END_DELIM = ")"; | |||||
private static final String OPEN_PAREN = "("; | private static final String OPEN_PAREN = "("; | ||||
private static final String CLOSE_PAREN = ")"; | private static final String CLOSE_PAREN = ")"; | ||||
private static final String FUNC_PARAM_SEP = ","; | private static final String FUNC_PARAM_SEP = ","; |
public static MemFileChannel newChannel(File file, String mode) | public static MemFileChannel newChannel(File file, String mode) | ||||
throws IOException | throws IOException | ||||
{ | { | ||||
RandomAccessFile raf = null; | |||||
FileChannel in = null; | FileChannel in = null; | ||||
try { | try { | ||||
return newChannel(in = new RandomAccessFile( | |||||
file, RO_CHANNEL_MODE).getChannel(), | |||||
mode); | |||||
raf = new RandomAccessFile(file, RO_CHANNEL_MODE); | |||||
return newChannel(in = raf.getChannel(), mode); | |||||
} finally { | } finally { | ||||
ByteUtil.closeQuietly(in); | ByteUtil.closeQuietly(in); | ||||
ByteUtil.closeQuietly(raf); | |||||
} | } | ||||
} | } | ||||
Map<String,Object> row2 = createTestRowMap("Tim2"); | Map<String,Object> row2 = createTestRowMap("Tim2"); | ||||
Map<String,Object> row3 = createTestRowMap("Tim3"); | Map<String,Object> row3 = createTestRowMap("Tim3"); | ||||
Table table = db.getTable("Test"); | Table table = db.getTable("Test"); | ||||
@SuppressWarnings("unchecked") | |||||
List<Map<String,Object>> rows = Arrays.asList(row1, row2, row3); | List<Map<String,Object>> rows = Arrays.asList(row1, row2, row3); | ||||
table.addRowsFromMaps(rows); | table.addRowsFromMaps(rows); | ||||
assertRowCount(3, table); | assertRowCount(3, table); |
import java.util.UUID; | import java.util.UUID; | ||||
import static com.healthmarketscience.jackcess.Database.*; | import static com.healthmarketscience.jackcess.Database.*; | ||||
import com.healthmarketscience.jackcess.InvalidValueException; | |||||
import com.healthmarketscience.jackcess.impl.DatabaseImpl; | import com.healthmarketscience.jackcess.impl.DatabaseImpl; | ||||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | ||||
import com.healthmarketscience.jackcess.impl.PropertyMapImpl; | import com.healthmarketscience.jackcess.impl.PropertyMapImpl; |
package com.healthmarketscience.jackcess; | package com.healthmarketscience.jackcess; | ||||
import java.io.DataInputStream; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.FileOutputStream; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import java.io.OutputStream; | |||||
import java.io.PrintWriter; | |||||
import java.io.*; | |||||
import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||
import java.nio.ByteBuffer; | import java.nio.ByteBuffer; | ||||
import java.nio.channels.FileChannel; | import java.nio.channels.FileChannel; | ||||
import java.time.Instant; | import java.time.Instant; | ||||
import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||||
import java.time.ZoneId; | import java.time.ZoneId; | ||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.Calendar; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import java.util.TimeZone; | |||||
import static com.healthmarketscience.jackcess.Database.*; | |||||
import java.util.*; | |||||
import java.util.stream.StreamSupport; | |||||
import com.healthmarketscience.jackcess.Database.FileFormat; | |||||
import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; | import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; | ||||
import com.healthmarketscience.jackcess.impl.ByteUtil; | |||||
import com.healthmarketscience.jackcess.impl.DatabaseImpl; | |||||
import com.healthmarketscience.jackcess.impl.IndexData; | |||||
import com.healthmarketscience.jackcess.impl.IndexImpl; | |||||
import com.healthmarketscience.jackcess.impl.JetFormatTest; | |||||
import com.healthmarketscience.jackcess.impl.*; | |||||
import com.healthmarketscience.jackcess.impl.JetFormatTest.TestDB; | import com.healthmarketscience.jackcess.impl.JetFormatTest.TestDB; | ||||
import com.healthmarketscience.jackcess.impl.RowIdImpl; | |||||
import com.healthmarketscience.jackcess.impl.RowImpl; | |||||
import com.healthmarketscience.jackcess.util.MemFileChannel; | import com.healthmarketscience.jackcess.util.MemFileChannel; | ||||
import org.junit.Assert; | import org.junit.Assert; | ||||
} | } | ||||
public static int countRows(Table table) throws Exception { | public static int countRows(Table table) throws Exception { | ||||
int rtn = 0; | |||||
for(Map<String, Object> row : CursorBuilder.createCursor(table)) { | |||||
rtn++; | |||||
} | |||||
return rtn; | |||||
Cursor cursor = CursorBuilder.createCursor(table); | |||||
return (int) StreamSupport.stream(cursor.spliterator(), false).count(); | |||||
} | } | ||||
public static void assertTable( | public static void assertTable( |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.Comparator; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
throws Exception | throws Exception | ||||
{ | { | ||||
long dbLen = dbFile.length(); | long dbLen = dbFile.length(); | ||||
FileChannel fileChannel = new RandomAccessFile(dbFile, "rw").getChannel(); | |||||
ByteBuffer bb = ByteBuffer.allocate(pageSize) | |||||
.order(PageChannel.DEFAULT_BYTE_ORDER); | |||||
for(long offset = pageSize; offset < dbLen; offset += pageSize) { | |||||
bb.clear(); | |||||
fileChannel.read(bb, offset); | |||||
try (RandomAccessFile randomAccessFile = new RandomAccessFile(dbFile, "rw"); | |||||
FileChannel fileChannel = randomAccessFile.getChannel()) { | |||||
ByteBuffer bb = ByteBuffer.allocate(pageSize) | |||||
.order(PageChannel.DEFAULT_BYTE_ORDER); | |||||
for(long offset = pageSize; offset < dbLen; offset += pageSize) { | |||||
bb.clear(); | |||||
fileChannel.read(bb, offset); | |||||
int pageNumber = (int)(offset / pageSize); | |||||
if(simple) { | |||||
simpleEncode(bb.array(), bb.array(), pageNumber, 0, pageSize); | |||||
} else { | |||||
fullEncode(bb.array(), bb.array(), pageNumber); | |||||
} | |||||
int pageNumber = (int)(offset / pageSize); | |||||
if(simple) { | |||||
simpleEncode(bb.array(), bb.array(), pageNumber, 0, pageSize); | |||||
} else { | |||||
fullEncode(bb.array(), bb.array(), pageNumber); | |||||
bb.rewind(); | |||||
fileChannel.write(bb, offset); | |||||
} | } | ||||
bb.rewind(); | |||||
fileChannel.write(bb, offset); | |||||
} | } | ||||
fileChannel.close(); | |||||
} | } | ||||
private static void simpleEncode(byte[] inBuffer, byte[] outBuffer, | private static void simpleEncode(byte[] inBuffer, byte[] outBuffer, |
public void testUnicodeCompression() throws Exception | public void testUnicodeCompression() throws Exception | ||||
{ | { | ||||
File dbFile = new File("src/test/data/V2003/testUnicodeCompV2003.mdb"); | File dbFile = new File("src/test/data/V2003/testUnicodeCompV2003.mdb"); | ||||
Database db = open(Database.FileFormat.V2003, new File("src/test/data/V2003/testUnicodeCompV2003.mdb"), true); | |||||
Database db = open(Database.FileFormat.V2003, dbFile, true); | |||||
StringBuilder sb = new StringBuilder(127); | StringBuilder sb = new StringBuilder(127); | ||||
for(int i = 1; i <= 0xFF; ++i) { | for(int i = 1; i <= 0xFF; ++i) { |
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | |||||
import com.healthmarketscience.jackcess.Column; | import com.healthmarketscience.jackcess.Column; | ||||
import com.healthmarketscience.jackcess.ColumnBuilder; | import com.healthmarketscience.jackcess.ColumnBuilder; | ||||
import com.healthmarketscience.jackcess.CursorBuilder; | |||||
import com.healthmarketscience.jackcess.DataType; | import com.healthmarketscience.jackcess.DataType; | ||||
import com.healthmarketscience.jackcess.Database; | import com.healthmarketscience.jackcess.Database; | ||||
import com.healthmarketscience.jackcess.Database.FileFormat; | import com.healthmarketscience.jackcess.Database.FileFormat; | ||||
import com.healthmarketscience.jackcess.IndexCursor; | |||||
import com.healthmarketscience.jackcess.PropertyMap; | import com.healthmarketscience.jackcess.PropertyMap; | ||||
import com.healthmarketscience.jackcess.Row; | import com.healthmarketscience.jackcess.Row; | ||||
import com.healthmarketscience.jackcess.Table; | import com.healthmarketscience.jackcess.Table; |
super(name); | super(name); | ||||
} | } | ||||
@SuppressWarnings("unchecked") | |||||
public void testFilter() throws Exception | public void testFilter() throws Exception | ||||
{ | { | ||||
Row row0 = createExpectedRow(ID_COL, 0, COL1, "foo", COL2, 13, COL3, "bar"); | Row row0 = createExpectedRow(ID_COL, 0, COL1, "foo", COL2, 13, COL3, "bar"); |