summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2011-03-04 12:58:55 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2011-03-04 12:58:55 +0000
commit334c5ff3e738e3b715198493ca79c3c6421a3b08 (patch)
treec6743941c8dee80f6894d5d32182bb6b8a042568 /test
parentf32d67c43250ec993267f9dfbc833fefc26eb5c0 (diff)
downloadjackcess-334c5ff3e738e3b715198493ca79c3c6421a3b08.tar.gz
jackcess-334c5ff3e738e3b715198493ca79c3c6421a3b08.zip
add support for creating indexes (except foreign key indexes) on a table when a table is created
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@515 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/IndexTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
index a2f00ca..5ce7174 100644
--- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
@@ -38,6 +38,7 @@ import java.util.TreeSet;
import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.Database.*;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
import static com.healthmarketscience.jackcess.JetFormatTest.*;
@@ -422,6 +423,46 @@ public class IndexTest extends TestCase {
db.close();
}
}
+
+ public void testIndexCreation() throws Exception
+ {
+ for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
+ Database db = create(fileFormat);
+
+ Table t = new TableBuilder("TestTable")
+ .addColumn(new ColumnBuilder("id", DataType.LONG))
+ .addColumn(new ColumnBuilder("data", DataType.TEXT))
+ .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME)
+ .addColumns("id").setPrimaryKey())
+ .toTable(db);
+
+ assertEquals(1, t.getIndexes().size());
+ Index idx = t.getIndexes().get(0);
+
+ assertEquals(IndexBuilder.PRIMARY_KEY_NAME, idx.getName());
+ assertEquals(1, idx.getColumns().size());
+ assertEquals("id", idx.getColumns().get(0).getName());
+ assertTrue(idx.getColumns().get(0).isAscending());
+ assertTrue(idx.isPrimaryKey());
+ assertTrue(idx.isUnique());
+ assertFalse(idx.shouldIgnoreNulls());
+ assertNull(idx.getReference());
+
+ t.addRow(2, "row2");
+ t.addRow(1, "row1");
+ t.addRow(3, "row3");
+
+ Cursor c = new CursorBuilder(t)
+ .setIndexByName(IndexBuilder.PRIMARY_KEY_NAME).toCursor();
+
+ for(int i = 1; i <= 3; ++i) {
+ Map<String,Object> row = c.getNextRow();
+ assertEquals(i, row.get("id"));
+ assertEquals("row" + i, row.get("data"));
+ }
+ assertFalse(c.moveToNextRow());
+ }
+ }
private void checkIndexColumns(Table table, String... idxInfo)
throws Exception