use of com.github.drinkjava2.jdialects.model.Column in project jDialects by drinkjava2.
the class TableTest method testNoPkey.
@Test
public void testNoPkey() {
// Test no Prime Key
// append() is a linked method
Table table = new Table("tb").append(new Column("field1").INTEGER()).append(new Column("field2").LONG());
printAllDialectsDDLs(table);
}
use of com.github.drinkjava2.jdialects.model.Column in project jDialects by drinkjava2.
the class TableModelTest method cloneTest.
@Test
public void cloneTest() {
TableModel t1 = new TableModel("customers");
t1.column("name").STRING(20).pkey();
t1.column("email").STRING(20).pkey().entityField("email").updatable(true).insertable(false);
t1.column("address").VARCHAR(50).defaultValue("'Beijing'").comment("address comment");
t1.column("phoneNumber").VARCHAR(50).singleIndex("IDX2");
t1.column("age").INTEGER().notNull().check("'>0'");
t1.index("idx3").columns("address", "phoneNumber").unique();
Assert.assertNotNull(t1.getColumn("name").getTableModel());
TableModel t2 = t1.newCopy();
System.out.println(t1);
System.out.println(t2);
Assert.assertNotEquals(t1, t2);
Assert.assertNotNull(t2.getColumn("name").getTableModel());
System.out.println("================");
for (ColumnModel item : t1.getColumns()) {
System.out.println(item);
}
System.out.println("================");
for (ColumnModel item : t2.getColumns()) {
System.out.println(item);
}
}
use of com.github.drinkjava2.jdialects.model.Column in project jDialects by drinkjava2.
the class DDLTest method sampleTest.
@Test
public void sampleTest() {
// An example used to put on README.md
TableModel t1 = new TableModel("customers");
t1.column("name").STRING(20).pkey();
t1.column("email").STRING(20).pkey().entityField("email").updatable(true).insertable(false);
t1.column("address").VARCHAR(50).defaultValue("'Beijing'").comment("address comment");
t1.column("phoneNumber").VARCHAR(50).singleIndex("IDX2");
t1.column("age").INTEGER().notNull().check("'>0'");
t1.index("idx3").columns("address", "phoneNumber").unique();
TableModel t2 = new TableModel("orders").comment("order comment");
t2.column("id").LONG().autoId().pkey();
t2.column("name").STRING(20);
t2.column("email").STRING(20);
t2.column("name2").STRING(20).pkey().tail(" default 'Sam'");
t2.column("email2").STRING(20);
t2.fkey().columns("name2", "email2").refs("customers", "name", "email");
t2.fkey("fk1").columns("name", "email").refs("customers", "name", "email");
t2.unique("uk1").columns("name2", "email2");
TableModel t3 = new TableModel("sampletable");
t3.column("id").LONG().identityId().pkey();
t3.tableGenerator("table_gen1", "tb1", "pkcol2", "valcol", "pkval", 1, 10);
t3.column("id1").INTEGER().idGenerator("table_gen1");
t3.sequenceGenerator("seq1", "seq_1", 1, 1);
t3.column("id2").INTEGER().idGenerator("seq1");
t3.engineTail(" DEFAULT CHARSET=utf8");
String[] dropAndCreateDDL = Dialect.H2Dialect.toDropAndCreateDDL(t1, t2, t3);
for (String ddl : dropAndCreateDDL) System.out.println(ddl);
testOnCurrentRealDatabase(t1, t2, t3);
}
use of com.github.drinkjava2.jdialects.model.Column in project jDialects by drinkjava2.
the class DDLTest method testEngineTailAndColumnTail.
@Test
public void testEngineTailAndColumnTail() {
// engineTail and column Tail
TableModel t = new TableModel("tailsTestTable");
t.engineTail(" DEFAULT CHARSET=utf8");
t.column("id").STRING(20).pkey();
t.column("name").STRING(20).tail(" default 'hahaha'");
printOneDialectsDDLs(Dialect.Oracle10gDialect, t);
printOneDialectsDDLs(Dialect.H2Dialect, t);
printOneDialectsDDLs(Dialect.MySQL5InnoDBDialect, t);
printOneDialectsDDLs(Dialect.MariaDB53Dialect, t);
testOnCurrentRealDatabase(t);
}
use of com.github.drinkjava2.jdialects.model.Column in project jDialects by drinkjava2.
the class DDLTest method checkModel.
private static TableModel checkModel() {
// column check
TableModel t = new TableModel("testTable");
t.column("s1").STRING(20).notNull().check("s1>5");
t.column("s2").STRING(20).check("s2>5");
t.column("s3").STRING(20).notNull().check("s3>5");
t.column("s4").STRING(20).check("s4>5");
return t;
}
Aggregations