diff options
Diffstat (limited to 'src')
14 files changed, 336 insertions, 248 deletions
diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5f8f374..a2e8af6 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -4,6 +4,12 @@ <author email="javajedi@users.sf.net">Tim McCune</author> </properties> <body> + <release version="3.5.1" date="TBD"> + <action dev="jahlborn" type="update"> + Add more static utility methods to DatabaseBuilder to enable more + succinct object construction code using static imports. + </action> + </release> <release version="3.5.0" date="2020-07-31"> <action dev="jahlborn" type="update"> Add support for Access 97 general collation order, enabling indexes to diff --git a/src/main/java/com/healthmarketscience/jackcess/DatabaseBuilder.java b/src/main/java/com/healthmarketscience/jackcess/DatabaseBuilder.java index 6c46729..18ba994 100644 --- a/src/main/java/com/healthmarketscience/jackcess/DatabaseBuilder.java +++ b/src/main/java/com/healthmarketscience/jackcess/DatabaseBuilder.java @@ -360,6 +360,87 @@ public class DatabaseBuilder return cal; } + /** + * Convenience method for constructing a DatabaseBuilder. + */ + public static DatabaseBuilder newDatabase() { + return new DatabaseBuilder(); + } + + /** + * Convenience method for constructing a DatabaseBuilder. + */ + public static DatabaseBuilder newDatabase(Path path) { + return new DatabaseBuilder(path); + } + + /** + * Convenience method for constructing a DatabaseBuilder. + */ + public static DatabaseBuilder newDatabase(File file) { + return new DatabaseBuilder(file); + } + + /** + * Convenience method for constructing a TableBuilder. + */ + public static TableBuilder newTable(String name) { + return new TableBuilder(name); + } + + /** + * Convenience method for constructing a TableBuilder. + */ + public static TableBuilder newTable(String name, boolean escapeIdentifiers) { + return new TableBuilder(name, escapeIdentifiers); + } + + /** + * Convenience method for constructing a ColumnBuilder. + */ + public static ColumnBuilder newColumn(String name) { + return new ColumnBuilder(name); + } + + /** + * Convenience method for constructing a TableBuilder. + */ + public static ColumnBuilder newColumn(String name, DataType type) { + return new ColumnBuilder(name, type); + } + + /** + * Convenience method for constructing an IndexBuilder. + */ + public static IndexBuilder newIndex(String name) { + return new IndexBuilder(name); + } + + /** + * Convenience method for constructing a primary key IndexBuilder. + */ + public static IndexBuilder newPrimaryKey(String... colNames) { + return new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME) + .addColumns(colNames) + .setPrimaryKey(); + } + + /** + * Convenience method for constructing a RelationshipBuilder. + */ + public static RelationshipBuilder newRelationship( + String fromTable, String toTable) { + return new RelationshipBuilder(fromTable, toTable); + } + + /** + * Convenience method for constructing a RelationshipBuilder. + */ + public static RelationshipBuilder newRelationship( + Table fromTable, Table toTable) { + return new RelationshipBuilder(fromTable, toTable); + } + private static Path toPath(File file) { return ((file != null) ? file.toPath() : null); } diff --git a/src/main/java/com/healthmarketscience/jackcess/Table.java b/src/main/java/com/healthmarketscience/jackcess/Table.java index 8c6e43b..9eb2b15 100644 --- a/src/main/java/com/healthmarketscience/jackcess/Table.java +++ b/src/main/java/com/healthmarketscience/jackcess/Table.java @@ -24,6 +24,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; import com.healthmarketscience.jackcess.util.ErrorHandler; +import com.healthmarketscience.jackcess.util.OleBlob; /** * A single database table. A Table instance is retrieved from a {@link @@ -324,4 +325,12 @@ public interface Table extends Iterable<Row> * Convenience method for constructing a new CursorBuilder for this Table. */ public CursorBuilder newCursor(); + + + /** + * Convenience method for constructing a new OleBlob.Builder. + */ + default public OleBlob.Builder newBlob() { + return new OleBlob.Builder(); + } } diff --git a/src/test/java/com/healthmarketscience/jackcess/CursorBuilderTest.java b/src/test/java/com/healthmarketscience/jackcess/CursorBuilderTest.java index 64c26e5..51567b0 100644 --- a/src/test/java/com/healthmarketscience/jackcess/CursorBuilderTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/CursorBuilderTest.java @@ -35,14 +35,14 @@ public class CursorBuilderTest extends TestCase { { assertSame(expected.getTable(), found.getTable()); if(expected instanceof IndexCursor) { - assertSame(((IndexCursor)expected).getIndex(), + assertSame(((IndexCursor)expected).getIndex(), ((IndexCursor)found).getIndex()); } assertEquals(expected.getSavepoint().getCurrentPosition(), found.getSavepoint().getCurrentPosition()); } - + public void test() throws Exception { for (final TestDB indexCursorDB : CursorTest.INDEX_CURSOR_DBS) { @@ -53,23 +53,21 @@ public class CursorBuilderTest extends TestCase { Cursor expected = CursorBuilder.createCursor(table); - Cursor found = new CursorBuilder(table).toCursor(); + Cursor found = table.newCursor().toCursor(); assertCursor(expected, found); expected = CursorBuilder.createCursor(idx); - found = new CursorBuilder(table) - .setIndex(idx) - .toCursor(); + found = idx.newCursor().toCursor(); assertCursor(expected, found); expected = CursorBuilder.createCursor(idx); - found = new CursorBuilder(table) + found = table.newCursor() .setIndexByName("id") .toCursor(); assertCursor(expected, found); try { - new CursorBuilder(table) + table.newCursor() .setIndexByName("foo"); fail("IllegalArgumentException should have been thrown"); } catch(IllegalArgumentException ignored) { @@ -77,13 +75,13 @@ public class CursorBuilderTest extends TestCase { } expected = CursorBuilder.createCursor(idx); - found = new CursorBuilder(table) + found = table.newCursor() .setIndexByColumns(table.getColumn("id")) .toCursor(); assertCursor(expected, found); try { - new CursorBuilder(table) + table.newCursor() .setIndexByColumns(table.getColumn("value")); fail("IllegalArgumentException should have been thrown"); } catch(IllegalArgumentException ignored) { @@ -91,7 +89,7 @@ public class CursorBuilderTest extends TestCase { } try { - new CursorBuilder(table) + table.newCursor() .setIndexByColumns(table.getColumn("id"), table.getColumn("value")); fail("IllegalArgumentException should have been thrown"); } catch(IllegalArgumentException ignored) { @@ -100,14 +98,14 @@ public class CursorBuilderTest extends TestCase { expected = CursorBuilder.createCursor(table); expected.beforeFirst(); - found = new CursorBuilder(table) + found = table.newCursor() .beforeFirst() .toCursor(); assertCursor(expected, found); expected = CursorBuilder.createCursor(table); expected.afterLast(); - found = new CursorBuilder(table) + found = table.newCursor() .afterLast() .toCursor(); assertCursor(expected, found); @@ -115,7 +113,7 @@ public class CursorBuilderTest extends TestCase { expected = CursorBuilder.createCursor(table); expected.moveNextRows(2); Cursor.Savepoint sp = expected.getSavepoint(); - found = new CursorBuilder(table) + found = table.newCursor() .afterLast() .restoreSavepoint(sp) .toCursor(); @@ -124,8 +122,7 @@ public class CursorBuilderTest extends TestCase { expected = CursorBuilder.createCursor(idx); expected.moveNextRows(2); sp = expected.getSavepoint(); - found = new CursorBuilder(table) - .setIndex(idx) + found = idx.newCursor() .beforeFirst() .restoreSavepoint(sp) .toCursor(); @@ -134,8 +131,7 @@ public class CursorBuilderTest extends TestCase { expected = CursorBuilder.createCursor(idx, idx.constructIndexRowFromEntry(3), null); - found = new CursorBuilder(table) - .setIndex(idx) + found = idx.newCursor() .setStartEntry(3) .toCursor(); assertCursor(expected, found); @@ -145,8 +141,7 @@ public class CursorBuilderTest extends TestCase { false, idx.constructIndexRowFromEntry(7), false); - found = new CursorBuilder(table) - .setIndex(idx) + found = idx.newCursor() .setStartEntry(3) .setStartRowInclusive(false) .setEndEntry(7) @@ -159,5 +154,5 @@ public class CursorBuilderTest extends TestCase { db.close(); } } - + } diff --git a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java index c208605..fa2ee53 100644 --- a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java @@ -38,6 +38,7 @@ import com.healthmarketscience.jackcess.util.RowFilterTest; import com.healthmarketscience.jackcess.util.SimpleColumnMatcher; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** * @author James Ahlborn @@ -89,9 +90,9 @@ public class CursorTest extends TestCase { { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG)) - .addColumn(new ColumnBuilder("value", DataType.TEXT)) + Table table = newTable("test") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("value", DataType.TEXT)) .toTable(db); for(Map<String,Object> row : createTestTableData()) { @@ -147,9 +148,9 @@ public class CursorTest extends TestCase { { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG)) - .addColumn(new ColumnBuilder("value", DataType.TEXT)) + Table table = newTable("test") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("value", DataType.TEXT)) .toTable(db); for(Map<String,Object> row : createDupeTestTableData()) { @@ -1279,11 +1280,11 @@ public class CursorTest extends TestCase { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG)) - .addColumn(new ColumnBuilder("value", DataType.TEXT)) - .addColumn(new ColumnBuilder("memo", DataType.MEMO)) - .addIndex(new IndexBuilder("value_idx") + Table table = newTable("test") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("value", DataType.TEXT)) + .addColumn(newColumn("memo", DataType.MEMO)) + .addIndex(newIndex("value_idx") .addColumns("value")) .toTable(db); @@ -1337,13 +1338,13 @@ public class CursorTest extends TestCase { Database db = createMem(fileFormat); - TableImpl t = (TableImpl)new TableBuilder("Test") - .addColumn(new ColumnBuilder("id", DataType.LONG)) - .addColumn(new ColumnBuilder("data1", DataType.TEXT)) - .addColumn(new ColumnBuilder("num2", DataType.LONG)) - .addColumn(new ColumnBuilder("key3", DataType.TEXT)) - .addColumn(new ColumnBuilder("value", DataType.TEXT)) - .addIndex(new IndexBuilder("idx3").addColumns("data1", "num2", "key3")) + TableImpl t = (TableImpl)newTable("Test") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("data1", DataType.TEXT)) + .addColumn(newColumn("num2", DataType.LONG)) + .addColumn(newColumn("key3", DataType.TEXT)) + .addColumn(newColumn("value", DataType.TEXT)) + .addIndex(newIndex("idx3").addColumns("data1", "num2", "key3")) .toTable(db); Index idx = t.findIndexForColumns(Arrays.asList("data1"), @@ -1366,7 +1367,7 @@ public class CursorTest extends TestCase { TableImpl.IndexFeature.EXACT_MATCH)); - new IndexBuilder("idx2") + newIndex("idx2") .addColumns("data1", "num2") .addToTable(t); @@ -1390,7 +1391,7 @@ public class CursorTest extends TestCase { TableImpl.IndexFeature.EXACT_MATCH)); - new IndexBuilder("idx1") + newIndex("idx1") .addColumns("data1") .addToTable(t); @@ -1421,13 +1422,13 @@ public class CursorTest extends TestCase { Database db = createMem(fileFormat); - TableImpl t = (TableImpl)new TableBuilder("Test") - .addColumn(new ColumnBuilder("id", DataType.LONG)) - .addColumn(new ColumnBuilder("data1", DataType.TEXT)) - .addColumn(new ColumnBuilder("num2", DataType.LONG)) - .addColumn(new ColumnBuilder("key3", DataType.TEXT)) - .addColumn(new ColumnBuilder("value", DataType.TEXT)) - .addIndex(new IndexBuilder("idx3") + TableImpl t = (TableImpl)newTable("Test") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("data1", DataType.TEXT)) + .addColumn(newColumn("num2", DataType.LONG)) + .addColumn(newColumn("key3", DataType.TEXT)) + .addColumn(newColumn("value", DataType.TEXT)) + .addIndex(newIndex("idx3") .addColumns(true, "data1") .addColumns(false, "num2") .addColumns(true, "key3") @@ -1448,13 +1449,13 @@ public class CursorTest extends TestCase { Index idx = t.getIndex("idx3"); doPartialIndexLookup(idx); - idx = new IndexBuilder("idx2") + idx = newIndex("idx2") .addColumns(true, "data1") .addColumns(false, "num2") .addToTable(t); doPartialIndexLookup(idx); - idx = new IndexBuilder("idx1") + idx = newIndex("idx1") .addColumns(true, "data1") .addToTable(t); doPartialIndexLookup(idx); @@ -1466,7 +1467,7 @@ public class CursorTest extends TestCase { private static void doPartialIndexLookup(Index idx) throws Exception { int colCount = idx.getColumnCount(); - IndexCursor c = new CursorBuilder(idx.getTable()).setIndex(idx).toIndexCursor(); + IndexCursor c = idx.newCursor().toIndexCursor(); doFindFirstByEntry(c, 21, "C"); doFindFirstByEntry(c, null, "Z"); diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index 2d118a7..d127f9f 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -48,6 +48,7 @@ import com.healthmarketscience.jackcess.util.LinkResolver; import com.healthmarketscience.jackcess.util.RowFilterTest; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** @@ -65,16 +66,16 @@ public class DatabaseTest extends TestCase Database db = create(fileFormat); try { - new TableBuilder("test").toTable(db); + newTable("test").toTable(db); fail("created table with no columns?"); } catch(IllegalArgumentException e) { // success } try { - new TableBuilder("test") - .addColumn(new ColumnBuilder("A", DataType.TEXT)) - .addColumn(new ColumnBuilder("a", DataType.MEMO)) + newTable("test") + .addColumn(newColumn("A", DataType.TEXT)) + .addColumn(newColumn("a", DataType.MEMO)) .toTable(db); fail("created table with duplicate column names?"); } catch(IllegalArgumentException e) { @@ -82,8 +83,8 @@ public class DatabaseTest extends TestCase } try { - new TableBuilder("test") - .addColumn(new ColumnBuilder("A", DataType.TEXT) + newTable("test") + .addColumn(newColumn("A", DataType.TEXT) .setLengthInUnits(352)) .toTable(db); fail("created table with invalid column length?"); @@ -92,22 +93,22 @@ public class DatabaseTest extends TestCase } try { - new TableBuilder("test") - .addColumn(new ColumnBuilder("A_" + createString(70), DataType.TEXT)) + newTable("test") + .addColumn(newColumn("A_" + createString(70), DataType.TEXT)) .toTable(db); fail("created table with too long column name?"); } catch(IllegalArgumentException e) { // success } - new TableBuilder("test") - .addColumn(new ColumnBuilder("A", DataType.TEXT)) + newTable("test") + .addColumn(newColumn("A", DataType.TEXT)) .toTable(db); try { - new TableBuilder("Test") - .addColumn(new ColumnBuilder("A", DataType.TEXT)) + newTable("Test") + .addColumn(newColumn("A", DataType.TEXT)) .toTable(db); fail("create duplicate tables?"); } catch(IllegalArgumentException e) { @@ -295,7 +296,7 @@ public class DatabaseTest extends TestCase File bogusFile = new File("fooby-dooby.mdb"); assertTrue(!bogusFile.exists()); try { - new DatabaseBuilder(bogusFile).setReadOnly(true). + newDatabase(bogusFile).setReadOnly(true). setAutoSync(getTestAutoSync()).open(); fail("FileNotFoundException should have been thrown"); } catch(FileNotFoundException e) { @@ -340,8 +341,8 @@ public class DatabaseTest extends TestCase for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("A", DataType.MONEY)) + Table table = newTable("test") + .addColumn(newColumn("A", DataType.MONEY)) .toTable(db); table.addRow(new BigDecimal("-2341234.03450")); @@ -378,8 +379,8 @@ public class DatabaseTest extends TestCase for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("A", DataType.GUID)) + Table table = newTable("test") + .addColumn(newColumn("A", DataType.GUID)) .toTable(db); table.addRow("{32A59F01-AA34-3E29-453F-4523453CD2E6}"); @@ -420,13 +421,13 @@ public class DatabaseTest extends TestCase for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - ColumnBuilder col = new ColumnBuilder("A", DataType.NUMERIC) + ColumnBuilder col = newColumn("A", DataType.NUMERIC) .setScale(4).setPrecision(8).toColumn(); assertTrue(col.getType().isVariableLength()); - Table table = new TableBuilder("test") + Table table = newTable("test") .addColumn(col) - .addColumn(new ColumnBuilder("B", DataType.NUMERIC) + .addColumn(newColumn("B", DataType.NUMERIC) .setScale(8).setPrecision(28)) .toTable(db); @@ -598,10 +599,10 @@ public class DatabaseTest extends TestCase for(int i = 0; i < numColumns; ++i) { String colName = "MyColumnName" + i; colNames.add(colName); - columns.add(new ColumnBuilder(colName, DataType.TEXT).toColumn()); + columns.add(newColumn(colName, DataType.TEXT).toColumn()); } - Table t = new TableBuilder("test") + Table t = newTable("test") .addColumns(columns) .toTable(db); @@ -627,9 +628,9 @@ public class DatabaseTest extends TestCase Database db = createMem(fileFormat); db.setDateTimeType(DateTimeType.DATE); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("name", DataType.TEXT)) - .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + Table table = newTable("test") + .addColumn(newColumn("name", DataType.TEXT)) + .addColumn(newColumn("date", DataType.SHORT_DATE_TIME)) .toTable(db); // since jackcess does not really store millis, shave them off before @@ -699,9 +700,9 @@ public class DatabaseTest extends TestCase db.setDateTimeType(DateTimeType.DATE); db.setTimeZone(tz); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("name", DataType.TEXT)) - .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + Table table = newTable("test") + .addColumn(newColumn("name", DataType.TEXT)) + .addColumn(newColumn("date", DataType.SHORT_DATE_TIME)) .toTable(db); for(String dateStr : dates) { diff --git a/src/test/java/com/healthmarketscience/jackcess/IndexTest.java b/src/test/java/com/healthmarketscience/jackcess/IndexTest.java index 4836231..a312ae8 100644 --- a/src/test/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/IndexTest.java @@ -35,6 +35,7 @@ import com.healthmarketscience.jackcess.impl.RowIdImpl; import com.healthmarketscience.jackcess.impl.TableImpl; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** * @author James Ahlborn @@ -430,11 +431,10 @@ public class IndexTest extends TestCase { 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()) + Table t = newTable("TestTable") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("data", DataType.TEXT)) + .setPrimaryKey("id") .toTable(db); assertEquals(1, t.getIndexes().size()); @@ -470,14 +470,13 @@ public class IndexTest extends TestCase { 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()) - .addIndex(new IndexBuilder("Index1").addColumns("id")) - .addIndex(new IndexBuilder("Index2").addColumns("id")) - .addIndex(new IndexBuilder("Index3").addColumns(false, "id")) + Table t = newTable("TestTable") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("data", DataType.TEXT)) + .setPrimaryKey("id") + .addIndex(newIndex("Index1").addColumns("id")) + .addIndex(newIndex("Index2").addColumns("id")) + .addIndex(newIndex("Index3").addColumns(false, "id")) .toTable(db); assertEquals(4, t.getIndexes().size()); @@ -554,12 +553,11 @@ public class IndexTest extends TestCase { 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()) - .addIndex(new IndexBuilder("data_ind") + Table t = newTable("TestTable") + .addColumn(newColumn("id", DataType.LONG)) + .addColumn(newColumn("data", DataType.TEXT)) + .setPrimaryKey("id") + .addIndex(newIndex("data_ind") .addColumns("data").setUnique()) .toTable(db); @@ -651,12 +649,11 @@ public class IndexTest extends TestCase { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - Table t = new TableBuilder("TestTable") - .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true)) - .addColumn(new ColumnBuilder("data", DataType.TEXT)) - .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME) - .addColumns("id").setPrimaryKey()) - .addIndex(new IndexBuilder("data_ind") + Table t = newTable("TestTable") + .addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) + .addColumn(newColumn("data", DataType.TEXT)) + .setPrimaryKey("id") + .addIndex(newIndex("data_ind") .addColumns("data").setUnique()) .toTable(db); diff --git a/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java b/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java index 1eb11db..0e8be65 100644 --- a/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java @@ -37,6 +37,7 @@ import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; import static com.healthmarketscience.jackcess.Database.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** * @@ -54,9 +55,9 @@ public class LocalDateTimeTest extends TestCase db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("name", DataType.TEXT)) - .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + Table table = newTable("test") + .addColumn(newColumn("name", DataType.TEXT)) + .addColumn(newColumn("date", DataType.SHORT_DATE_TIME)) .toTable(db); // since jackcess does not really store millis, shave them off before @@ -125,9 +126,9 @@ public class LocalDateTimeTest extends TestCase db.setZoneId(zoneId); db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("name", DataType.TEXT)) - .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + Table table = newTable("test") + .addColumn(newColumn("name", DataType.TEXT)) + .addColumn(newColumn("date", DataType.SHORT_DATE_TIME)) .toTable(db); for(String dateStr : dates) { @@ -218,9 +219,9 @@ public class LocalDateTimeTest extends TestCase db.setZoneId(zoneId); db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("name", DataType.TEXT)) - .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + Table table = newTable("test") + .addColumn(newColumn("name", DataType.TEXT)) + .addColumn(newColumn("date", DataType.SHORT_DATE_TIME)) .toTable(db); // since jackcess does not really store millis, shave them off before diff --git a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java index 056ca68..f5cb304 100644 --- a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java @@ -33,6 +33,7 @@ import com.healthmarketscience.jackcess.impl.PropertyMaps; import com.healthmarketscience.jackcess.impl.TableImpl; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** * @author James Ahlborn @@ -279,7 +280,7 @@ public class PropertiesTest extends TestCase // modify but do not save - db = new DatabaseBuilder(dbFile).open(); + db = open(dbFile); t = db.getTable("Table1"); @@ -299,7 +300,7 @@ public class PropertiesTest extends TestCase // modify and save - db = new DatabaseBuilder(dbFile).open(); + db = open(dbFile); t = db.getTable("Table1"); @@ -326,7 +327,7 @@ public class PropertiesTest extends TestCase // reload saved props - db = new DatabaseBuilder(dbFile).open(); + db = open(dbFile); t = db.getTable("Table1"); @@ -360,20 +361,20 @@ public class PropertiesTest extends TestCase } File file = TestUtil.createTempFile(false); - Database db = new DatabaseBuilder(file) + Database db = newDatabase(file) .setFileFormat(ff) .putUserDefinedProperty("testing", "123") .create(); UUID u1 = UUID.randomUUID(); UUID u2 = UUID.randomUUID(); - Table t = new TableBuilder("Test") + Table t = newTable("Test") .putProperty("awesome_table", true) - .addColumn(new ColumnBuilder("id", DataType.LONG) + .addColumn(newColumn("id", DataType.LONG) .setAutoNumber(true) .putProperty(PropertyMap.REQUIRED_PROP, true) .putProperty(PropertyMap.GUID_PROP, u1)) - .addColumn(new ColumnBuilder("data", DataType.TEXT) + .addColumn(newColumn("data", DataType.TEXT) .putProperty(PropertyMap.ALLOW_ZERO_LEN_PROP, false) .putProperty(PropertyMap.GUID_PROP, u2)) .toTable(db); @@ -382,7 +383,7 @@ public class PropertiesTest extends TestCase db.close(); - db = new DatabaseBuilder(file).open(); + db = open(file); assertEquals("123", db.getUserDefinedProperties().getValue("testing")); @@ -411,11 +412,11 @@ public class PropertiesTest extends TestCase for(final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - Table t = new TableBuilder("testReq") - .addColumn(new ColumnBuilder("id", DataType.LONG) + Table t = newTable("testReq") + .addColumn(newColumn("id", DataType.LONG) .setAutoNumber(true) .putProperty(PropertyMap.REQUIRED_PROP, true)) - .addColumn(new ColumnBuilder("value", DataType.TEXT) + .addColumn(newColumn("value", DataType.TEXT) .putProperty(PropertyMap.REQUIRED_PROP, true)) .toTable(db); @@ -441,11 +442,11 @@ public class PropertiesTest extends TestCase assertTable(expectedRows, t); - t = new TableBuilder("testNz") - .addColumn(new ColumnBuilder("id", DataType.LONG) + t = newTable("testNz") + .addColumn(newColumn("id", DataType.LONG) .setAutoNumber(true) .putProperty(PropertyMap.REQUIRED_PROP, true)) - .addColumn(new ColumnBuilder("value", DataType.TEXT) + .addColumn(newColumn("value", DataType.TEXT) .putProperty(PropertyMap.ALLOW_ZERO_LEN_PROP, false)) .toTable(db); @@ -471,11 +472,11 @@ public class PropertiesTest extends TestCase assertTable(expectedRows, t); - t = new TableBuilder("testReqNz") - .addColumn(new ColumnBuilder("id", DataType.LONG) + t = newTable("testReqNz") + .addColumn(newColumn("id", DataType.LONG) .setAutoNumber(true) .putProperty(PropertyMap.REQUIRED_PROP, true)) - .addColumn(new ColumnBuilder("value", DataType.TEXT)) + .addColumn(newColumn("value", DataType.TEXT)) .toTable(db); Column col = t.getColumn("value"); diff --git a/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java b/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java index bb26719..f03bc76 100644 --- a/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java @@ -36,6 +36,7 @@ import junit.framework.TestCase; import static com.healthmarketscience.jackcess.Database.*; import static com.healthmarketscience.jackcess.TestUtil.*; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** * @@ -54,12 +55,12 @@ public class PropertyExpressionTest extends TestCase Database db = create(fileFormat); db.setEvaluateExpressions(true); - Table t = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true)) - .addColumn(new ColumnBuilder("data1", DataType.TEXT) + Table t = newTable("test") + .addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) + .addColumn(newColumn("data1", DataType.TEXT) .putProperty(PropertyMap.DEFAULT_VALUE_PROP, "=\"FOO \" & \"BAR\"")) - .addColumn(new ColumnBuilder("data2", DataType.LONG) + .addColumn(newColumn("data2", DataType.LONG) .putProperty(PropertyMap.DEFAULT_VALUE_PROP, "37")) .toTable(db); @@ -118,15 +119,15 @@ public class PropertyExpressionTest extends TestCase Database db = create(FileFormat.V2016); db.setEvaluateExpressions(true); - Table t = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true)) - .addColumn(new ColumnBuilder("c1", DataType.LONG) + Table t = newTable("test") + .addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) + .addColumn(newColumn("c1", DataType.LONG) .setCalculatedInfo("[c2]+[c3]")) - .addColumn(new ColumnBuilder("c2", DataType.LONG) + .addColumn(newColumn("c2", DataType.LONG) .setCalculatedInfo("[c3]*5")) - .addColumn(new ColumnBuilder("c3", DataType.LONG) + .addColumn(newColumn("c3", DataType.LONG) .setCalculatedInfo("[c4]-6")) - .addColumn(new ColumnBuilder("c4", DataType.LONG)) + .addColumn(newColumn("c4", DataType.LONG)) .toTable(db); t.addRow(Column.AUTO_NUMBER, null, null, null, 16); @@ -163,12 +164,12 @@ public class PropertyExpressionTest extends TestCase Database db = create(fileFormat); db.setEvaluateExpressions(true); - Table t = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true)) - .addColumn(new ColumnBuilder("data1", DataType.LONG) + Table t = newTable("test") + .addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) + .addColumn(newColumn("data1", DataType.LONG) .putProperty(PropertyMap.VALIDATION_RULE_PROP, ">37")) - .addColumn(new ColumnBuilder("data2", DataType.LONG) + .addColumn(newColumn("data2", DataType.LONG) .putProperty(PropertyMap.VALIDATION_RULE_PROP, "between 7 and 10") .putProperty(PropertyMap.VALIDATION_TEXT_PROP, @@ -236,10 +237,10 @@ public class PropertyExpressionTest extends TestCase Database db = create(fileFormat); db.setEvaluateExpressions(true); - Table t = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true)) - .addColumn(new ColumnBuilder("data1", DataType.LONG)) - .addColumn(new ColumnBuilder("data2", DataType.LONG)) + Table t = newTable("test") + .addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) + .addColumn(newColumn("data1", DataType.LONG)) + .addColumn(newColumn("data2", DataType.LONG)) .putProperty(PropertyMap.VALIDATION_RULE_PROP, "([data1] > 10) and ([data2] < 100)") .putProperty(PropertyMap.VALIDATION_TEXT_PROP, @@ -322,15 +323,15 @@ public class PropertyExpressionTest extends TestCase db.setEvaluateExpressions(true); - Table t = new TableBuilder("test") - .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true)) - .addColumn(new ColumnBuilder("data1", DataType.TEXT) + Table t = newTable("test") + .addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) + .addColumn(newColumn("data1", DataType.TEXT) .putProperty(PropertyMap.DEFAULT_VALUE_PROP, "=FooFunc()")) - .addColumn(new ColumnBuilder("data2", DataType.TEXT) + .addColumn(newColumn("data2", DataType.TEXT) .putProperty(PropertyMap.DEFAULT_VALUE_PROP, "=Date()")) - .addColumn(new ColumnBuilder("data3", DataType.TEXT) + .addColumn(newColumn("data3", DataType.TEXT) .putProperty(PropertyMap.DEFAULT_VALUE_PROP, "=Time()")) .toTable(db); diff --git a/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java b/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java index 2d97d37..fe6a447 100644 --- a/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java @@ -28,6 +28,7 @@ import com.healthmarketscience.jackcess.impl.DatabaseImpl; import com.healthmarketscience.jackcess.impl.TableImpl; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** * @@ -45,9 +46,9 @@ public class TableUpdaterTest extends TestCase Database db = create(fileFormat); doTestUpdating(db, false, true, null); - + db.close(); - } + } } public void testTableUpdatingOneToOne() throws Exception { @@ -55,9 +56,9 @@ public class TableUpdaterTest extends TestCase Database db = create(fileFormat); doTestUpdating(db, true, true, null); - + db.close(); - } + } } public void testTableUpdatingNoEnforce() throws Exception { @@ -65,9 +66,9 @@ public class TableUpdaterTest extends TestCase Database db = create(fileFormat); doTestUpdating(db, false, false, null); - + db.close(); - } + } } public void testTableUpdatingNamedRelationship() throws Exception { @@ -75,53 +76,51 @@ public class TableUpdaterTest extends TestCase Database db = create(fileFormat); doTestUpdating(db, false, true, "FKnun3jvv47l9kyl74h85y8a0if"); - + db.close(); - } + } } - private void doTestUpdating(Database db, boolean oneToOne, boolean enforce, String relationshipName) + private void doTestUpdating(Database db, boolean oneToOne, boolean enforce, String relationshipName) throws Exception { - Table t1 = new TableBuilder("TestTable") - .addColumn(new ColumnBuilder("id", DataType.LONG)) + Table t1 = newTable("TestTable") + .addColumn(newColumn("id", DataType.LONG)) .toTable(db); - - Table t2 = new TableBuilder("TestTable2") - .addColumn(new ColumnBuilder("id2", DataType.LONG)) + + Table t2 = newTable("TestTable2") + .addColumn(newColumn("id2", DataType.LONG)) .toTable(db); int t1idxs = 1; - new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME) - .addColumns("id").setPrimaryKey() + newPrimaryKey("id") .addToTable(t1); - new ColumnBuilder("data", DataType.TEXT) + newColumn("data", DataType.TEXT) .addToTable(t1); - new ColumnBuilder("bigdata", DataType.MEMO) + newColumn("bigdata", DataType.MEMO) .addToTable(t1); - new ColumnBuilder("data2", DataType.TEXT) + newColumn("data2", DataType.TEXT) .addToTable(t2); - new ColumnBuilder("bigdata2", DataType.MEMO) + newColumn("bigdata2", DataType.MEMO) .addToTable(t2); int t2idxs = 0; if(oneToOne) { ++t2idxs; - new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME) - .addColumns("id2").setPrimaryKey() + newPrimaryKey("id2") .addToTable(t2); } - RelationshipBuilder rb = new RelationshipBuilder("TestTable", "TestTable2") + RelationshipBuilder rb = newRelationship("TestTable", "TestTable2") .addColumns("id", "id2"); if(enforce) { ++t1idxs; - ++t2idxs; + ++t2idxs; rb.setReferentialIntegrity() .setCascadeDeletes(); } - + if (relationshipName != null) { rb.setName(relationshipName); } @@ -168,7 +167,7 @@ public class TableUpdaterTest extends TestCase t2.addRow(10, "row10", "row-data10"); if(enforce) { fail("ConstraintViolationException should have been thrown"); - } + } } catch(ConstraintViolationException cv) { // success if(!enforce) { throw cv; } @@ -176,7 +175,7 @@ public class TableUpdaterTest extends TestCase Row r1 = CursorBuilder.findRowByPrimaryKey(t1, 5); t1.deleteRow(r1); - + int id = 0; for(Row r : t1) { assertEquals(id, r.get("id")); @@ -185,7 +184,7 @@ public class TableUpdaterTest extends TestCase ++id; } } - + id = 0; for(Row r : t2) { assertEquals(id, r.get("id2")); @@ -201,24 +200,24 @@ public class TableUpdaterTest extends TestCase for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - Table t1 = new TableBuilder("TestTable") - .addColumn(new ColumnBuilder("id", DataType.LONG)) + Table t1 = newTable("TestTable") + .addColumn(newColumn("id", DataType.LONG)) .toTable(db); try { - new ColumnBuilder("ID", DataType.TEXT) + newColumn("ID", DataType.TEXT) .addToTable(t1); fail("created table with no columns?"); } catch(IllegalArgumentException e) { // success } - Table t2 = new TableBuilder("TestTable2") - .addColumn(new ColumnBuilder("id2", DataType.LONG)) + Table t2 = newTable("TestTable2") + .addColumn(newColumn("id2", DataType.LONG)) .toTable(db); try { - new RelationshipBuilder(t1, t2) + newRelationship(t1, t2) .toRelationship(db); fail("created rel with no columns?"); } catch(IllegalArgumentException e) { @@ -226,16 +225,16 @@ public class TableUpdaterTest extends TestCase } try { - new RelationshipBuilder("TestTable", "TestTable2") + newRelationship("TestTable", "TestTable2") .addColumns("id", "id") .toRelationship(db); fail("created rel with wrong columns?"); } catch(IllegalArgumentException e) { // success } - + db.close(); - } + } } public void testUpdateLargeTableDef() throws Exception @@ -245,8 +244,8 @@ public class TableUpdaterTest extends TestCase final int numColumns = 89; - Table t = new TableBuilder("test") - .addColumn(new ColumnBuilder("first", DataType.TEXT)) + Table t = newTable("test") + .addColumn(newColumn("first", DataType.TEXT)) .toTable(db); List<String> colNames = new ArrayList<String>(); @@ -255,7 +254,7 @@ public class TableUpdaterTest extends TestCase String colName = "MyColumnName" + i; colNames.add(colName); DataType type = (((i % 3) == 0) ? DataType.MEMO : DataType.TEXT); - new ColumnBuilder(colName, type) + newColumn(colName, type) .addToTable(t); } @@ -274,5 +273,5 @@ public class TableUpdaterTest extends TestCase db.close(); } - } + } } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java index eae2c25..6dc013a 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java @@ -23,14 +23,13 @@ import java.util.Map; import java.util.UUID; import com.healthmarketscience.jackcess.Column; -import com.healthmarketscience.jackcess.ColumnBuilder; import com.healthmarketscience.jackcess.CursorBuilder; import com.healthmarketscience.jackcess.DataType; import com.healthmarketscience.jackcess.Database; import static com.healthmarketscience.jackcess.Database.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; import com.healthmarketscience.jackcess.Row; import com.healthmarketscience.jackcess.Table; -import com.healthmarketscience.jackcess.TableBuilder; import static com.healthmarketscience.jackcess.TestUtil.*; import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; @@ -48,24 +47,24 @@ public class AutoNumberTest extends TestCase } - public void testAutoNumber() throws Exception + public void testAutoNumber() throws Exception { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("a", DataType.LONG) + Table table = newTable("test") + .addColumn(newColumn("a", DataType.LONG) .setAutoNumber(true)) - .addColumn(new ColumnBuilder("b", DataType.TEXT)) + .addColumn(newColumn("b", DataType.TEXT)) .toTable(db); doTestAutoNumber(table); db.close(); } - } + } - public void testAutoNumberPK() throws Exception + public void testAutoNumberPK() throws Exception { for (final TestDB testDB : SUPPORTED_DBS_TEST) { Database db = openMem(testDB); @@ -76,7 +75,7 @@ public class AutoNumberTest extends TestCase db.close(); } - } + } private static void doTestAutoNumber(Table table) throws Exception { @@ -98,7 +97,7 @@ public class AutoNumberTest extends TestCase Object[] smallRow = {Column.AUTO_NUMBER}; row = table.addRow(smallRow); assertNotSame(row, smallRow); - assertEquals(6, ((Integer)row[0]).intValue()); + assertEquals(6, ((Integer)row[0]).intValue()); table.reset(); @@ -123,18 +122,18 @@ public class AutoNumberTest extends TestCase "a", 6, "b", null)); - assertTable(expectedRows, table); + assertTable(expectedRows, table); } - public void testAutoNumberGuid() throws Exception + public void testAutoNumberGuid() throws Exception { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("a", DataType.GUID) + Table table = newTable("test") + .addColumn(newColumn("a", DataType.GUID) .setAutoNumber(true)) - .addColumn(new ColumnBuilder("b", DataType.TEXT)) + .addColumn(newColumn("b", DataType.TEXT)) .toTable(db); Object[] row = {null, "row1"}; @@ -152,23 +151,23 @@ public class AutoNumberTest extends TestCase db.close(); } - } + } public void testInsertLongAutoNumber() throws Exception { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("a", DataType.LONG) + Table table = newTable("test") + .addColumn(newColumn("a", DataType.LONG) .setAutoNumber(true)) - .addColumn(new ColumnBuilder("b", DataType.TEXT)) + .addColumn(newColumn("b", DataType.TEXT)) .toTable(db); doTestInsertLongAutoNumber(table); db.close(); - } + } } public void testInsertLongAutoNumberPK() throws Exception @@ -176,17 +175,17 @@ public class AutoNumberTest extends TestCase for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("a", DataType.LONG) + Table table = newTable("test") + .addColumn(newColumn("a", DataType.LONG) .setAutoNumber(true)) - .addColumn(new ColumnBuilder("b", DataType.TEXT)) + .addColumn(newColumn("b", DataType.TEXT)) .setPrimaryKey("a") .toTable(db); doTestInsertLongAutoNumber(table); db.close(); - } + } } private static void doTestInsertLongAutoNumber(Table table) throws Exception @@ -232,7 +231,7 @@ public class AutoNumberTest extends TestCase assertEquals(13, ((Integer)row[0]).intValue()); assertEquals(13, ((TableImpl)table).getLastLongAutoNumber()); - + try { table.addRow("not a number", "nope"); fail("NumberFormatException should have been thrown"); @@ -265,19 +264,19 @@ public class AutoNumberTest extends TestCase row13.put("a", 55); // reset to db-level policy (which in this case is "false") - table.setAllowAutoNumberInsert(null); + table.setAllowAutoNumberInsert(null); row13 = table.updateRow(row13); // no change, as confirmed by... assertEquals(-1, row13.get("a")); assertEquals(45, ((TableImpl)table).getLastLongAutoNumber()); - + } public void testInsertComplexAutoNumber() throws Exception { for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { - + Database db = openMem(testDB); Table t1 = db.getTable("Table1"); @@ -301,7 +300,7 @@ public class AutoNumberTest extends TestCase checkAllComplexAutoNums(lastAutoNum, row); assertEquals(lastAutoNum, ((TableImpl)t1).getLastComplexTypeAutoNumber()); - + row = t1.addRow("row5", 5, null, null, 5, 5); checkAllComplexAutoNums(5, row); @@ -341,7 +340,7 @@ public class AutoNumberTest extends TestCase checkAllComplexAutoNums(14, row); assertEquals(14, ((TableImpl)t1).getLastComplexTypeAutoNumber()); - + Row row13 = CursorBuilder.findRow( t1, Collections.singletonMap("id", "row13")); @@ -352,7 +351,7 @@ public class AutoNumberTest extends TestCase checkAllComplexAutoNums(45, row13); assertEquals(45, ((TableImpl)t1).getLastComplexTypeAutoNumber()); - + row13.put("attach-data", -1); try { @@ -403,15 +402,15 @@ public class AutoNumberTest extends TestCase assertEquals(expected, ((Number)row.get("attach-data")).intValue()); } - public void testInsertGuidAutoNumber() throws Exception + public void testInsertGuidAutoNumber() throws Exception { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); - Table table = new TableBuilder("test") - .addColumn(new ColumnBuilder("a", DataType.GUID) + Table table = newTable("test") + .addColumn(newColumn("a", DataType.GUID) .setAutoNumber(true)) - .addColumn(new ColumnBuilder("b", DataType.TEXT)) + .addColumn(newColumn("b", DataType.TEXT)) .toTable(db); db.setAllowAutoNumberInsert(true); @@ -433,11 +432,11 @@ public class AutoNumberTest extends TestCase table.setAllowAutoNumberInsert(null); assertTrue(table.isAllowAutoNumberInsert()); - + Row row2 = CursorBuilder.findRow( table, Collections.singletonMap("b", "row2")); assertEquals("row2", row2.getString("b")); - + String row2Guid = row2.getString("a"); table.deleteRow(row2); @@ -484,6 +483,6 @@ public class AutoNumberTest extends TestCase db.close(); } - } + } } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java index 143ac9b..e3ab82d 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java @@ -23,17 +23,14 @@ import java.util.List; import java.util.Map; import com.healthmarketscience.jackcess.Column; -import com.healthmarketscience.jackcess.ColumnBuilder; import com.healthmarketscience.jackcess.Cursor; -import com.healthmarketscience.jackcess.CursorBuilder; import com.healthmarketscience.jackcess.DataType; import com.healthmarketscience.jackcess.Database; -import com.healthmarketscience.jackcess.IndexBuilder; import com.healthmarketscience.jackcess.Table; -import com.healthmarketscience.jackcess.TableBuilder; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; +import static com.healthmarketscience.jackcess.DatabaseBuilder.*; /** * @@ -58,18 +55,18 @@ public class BigIntTest extends TestCase Database db = create(fileFormat); - Table t = new TableBuilder("Test") - .addColumn(new ColumnBuilder("id", DataType.LONG) + Table t = newTable("Test") + .addColumn(newColumn("id", DataType.LONG) .setAutoNumber(true)) - .addColumn(new ColumnBuilder("data1", DataType.TEXT)) - .addColumn(new ColumnBuilder("num1", DataType.BIG_INT)) - .addIndex(new IndexBuilder("idx").addColumns("num1")) + .addColumn(newColumn("data1", DataType.TEXT)) + .addColumn(newColumn("num1", DataType.BIG_INT)) + .addIndex(newIndex("idx").addColumns("num1")) .toTable(db); long[] vals = new long[] { 0L, -10L, 3844L, -45309590834L, 50392084913L, 65000L, -6489273L}; - List<Map<String, Object>> expectedTable = + List<Map<String, Object>> expectedTable = new ArrayList<Map<String, Object>>(); int idx = 1; @@ -83,7 +80,7 @@ public class BigIntTest extends TestCase } Collections.sort(expectedTable, new Comparator<Map<String, Object>>() { - public int compare( + @Override public int compare( Map<String, Object> r1, Map<String, Object> r2) { Long l1 = (Long)r1.get("num1"); @@ -91,8 +88,8 @@ public class BigIntTest extends TestCase return l1.compareTo(l2); } }); - - Cursor c = new CursorBuilder(t).setIndexByName("idx").toIndexCursor(); + + Cursor c = t.newCursor().setIndexByName("idx").toIndexCursor(); assertCursor(expectedTable, c); diff --git a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java index 725daa0..3096be3 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java @@ -66,7 +66,7 @@ public class OleBlobTest extends TestCase OleBlob blob = null; try { - blob = new OleBlob.Builder() + blob = t.newBlob() .setSimplePackage(sampleFile) .toBlob(); t.addRow(1, blob); @@ -75,7 +75,7 @@ public class OleBlobTest extends TestCase } try { - blob = new OleBlob.Builder() + blob = t.newBlob() .setLink(sampleFile) .toBlob(); t.addRow(2, blob); @@ -84,7 +84,7 @@ public class OleBlobTest extends TestCase } try { - blob = new OleBlob.Builder() + blob = t.newBlob() .setPackagePrettyName("Text File") .setPackageClassName("Text.File") .setPackageTypeName("TextFile") |