<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
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);
}
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
* 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();
+ }
}
{
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) {
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) {
}
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) {
}
try {
- new CursorBuilder(table)
+ table.newCursor()
.setIndexByColumns(table.getColumn("id"), table.getColumn("value"));
fail("IllegalArgumentException should have been thrown");
} catch(IllegalArgumentException ignored) {
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);
expected = CursorBuilder.createCursor(table);
expected.moveNextRows(2);
Cursor.Savepoint sp = expected.getSavepoint();
- found = new CursorBuilder(table)
+ found = table.newCursor()
.afterLast()
.restoreSavepoint(sp)
.toCursor();
expected = CursorBuilder.createCursor(idx);
expected.moveNextRows(2);
sp = expected.getSavepoint();
- found = new CursorBuilder(table)
- .setIndex(idx)
+ found = idx.newCursor()
.beforeFirst()
.restoreSavepoint(sp)
.toCursor();
expected = CursorBuilder.createCursor(idx,
idx.constructIndexRowFromEntry(3),
null);
- found = new CursorBuilder(table)
- .setIndex(idx)
+ found = idx.newCursor()
.setStartEntry(3)
.toCursor();
assertCursor(expected, found);
false,
idx.constructIndexRowFromEntry(7),
false);
- found = new CursorBuilder(table)
- .setIndex(idx)
+ found = idx.newCursor()
.setStartEntry(3)
.setStartRowInclusive(false)
.setEndEntry(7)
db.close();
}
}
-
+
}
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
{
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()) {
{
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()) {
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);
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"),
TableImpl.IndexFeature.EXACT_MATCH));
- new IndexBuilder("idx2")
+ newIndex("idx2")
.addColumns("data1", "num2")
.addToTable(t);
TableImpl.IndexFeature.EXACT_MATCH));
- new IndexBuilder("idx1")
+ newIndex("idx1")
.addColumns("data1")
.addToTable(t);
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")
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);
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");
import com.healthmarketscience.jackcess.util.RowFilterTest;
import junit.framework.TestCase;
import static com.healthmarketscience.jackcess.TestUtil.*;
+import static com.healthmarketscience.jackcess.DatabaseBuilder.*;
/**
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) {
}
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?");
}
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) {
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) {
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"));
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}");
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);
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);
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
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) {
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
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());
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());
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);
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);
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.*;
/**
*
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
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) {
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
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
// modify but do not save
- db = new DatabaseBuilder(dbFile).open();
+ db = open(dbFile);
t = db.getTable("Table1");
// modify and save
- db = new DatabaseBuilder(dbFile).open();
+ db = open(dbFile);
t = db.getTable("Table1");
// reload saved props
- db = new DatabaseBuilder(dbFile).open();
+ db = open(dbFile);
t = db.getTable("Table1");
}
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);
db.close();
- db = new DatabaseBuilder(file).open();
+ db = open(file);
assertEquals("123", db.getUserDefinedProperties().getValue("testing"));
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);
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);
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");
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.*;
/**
*
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);
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);
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,
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,
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);
import com.healthmarketscience.jackcess.impl.TableImpl;
import junit.framework.TestCase;
import static com.healthmarketscience.jackcess.TestUtil.*;
+import static com.healthmarketscience.jackcess.DatabaseBuilder.*;
/**
*
Database db = create(fileFormat);
doTestUpdating(db, false, true, null);
-
+
db.close();
- }
+ }
}
public void testTableUpdatingOneToOne() throws Exception {
Database db = create(fileFormat);
doTestUpdating(db, true, true, null);
-
+
db.close();
- }
+ }
}
public void testTableUpdatingNoEnforce() throws Exception {
Database db = create(fileFormat);
doTestUpdating(db, false, false, null);
-
+
db.close();
- }
+ }
}
public void testTableUpdatingNamedRelationship() throws Exception {
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);
}
t2.addRow(10, "row10", "row-data10");
if(enforce) {
fail("ConstraintViolationException should have been thrown");
- }
+ }
} catch(ConstraintViolationException cv) {
// success
if(!enforce) { throw cv; }
Row r1 = CursorBuilder.findRowByPrimaryKey(t1, 5);
t1.deleteRow(r1);
-
+
int id = 0;
for(Row r : t1) {
assertEquals(id, r.get("id"));
++id;
}
}
-
+
id = 0;
for(Row r : t2) {
assertEquals(id, r.get("id2"));
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) {
}
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
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>();
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);
}
db.close();
}
- }
+ }
}
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.*;
}
- 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);
db.close();
}
- }
+ }
private static void doTestAutoNumber(Table table) throws Exception
{
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();
"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"};
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
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
assertEquals(13, ((Integer)row[0]).intValue());
assertEquals(13, ((TableImpl)table).getLastLongAutoNumber());
-
+
try {
table.addRow("not a number", "nope");
fail("NumberFormatException should have been thrown");
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");
checkAllComplexAutoNums(lastAutoNum, row);
assertEquals(lastAutoNum, ((TableImpl)t1).getLastComplexTypeAutoNumber());
-
+
row = t1.addRow("row5", 5, null, null, 5, 5);
checkAllComplexAutoNums(5, row);
checkAllComplexAutoNums(14, row);
assertEquals(14, ((TableImpl)t1).getLastComplexTypeAutoNumber());
-
+
Row row13 = CursorBuilder.findRow(
t1, Collections.singletonMap("id", "row13"));
checkAllComplexAutoNums(45, row13);
assertEquals(45, ((TableImpl)t1).getLastComplexTypeAutoNumber());
-
+
row13.put("attach-data", -1);
try {
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);
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);
db.close();
}
- }
+ }
}
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.*;
/**
*
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;
}
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");
return l1.compareTo(l2);
}
});
-
- Cursor c = new CursorBuilder(t).setIndexByName("idx").toIndexCursor();
+
+ Cursor c = t.newCursor().setIndexByName("idx").toIndexCursor();
assertCursor(expectedTable, c);
OleBlob blob = null;
try {
- blob = new OleBlob.Builder()
+ blob = t.newBlob()
.setSimplePackage(sampleFile)
.toBlob();
t.addRow(1, blob);
}
try {
- blob = new OleBlob.Builder()
+ blob = t.newBlob()
.setLink(sampleFile)
.toBlob();
t.addRow(2, blob);
}
try {
- blob = new OleBlob.Builder()
+ blob = t.newBlob()
.setPackagePrettyName("Text File")
.setPackageClassName("Text.File")
.setPackageTypeName("TextFile")