use of com.github.drinkjava2.jdialects.model.TableModel in project jDialects by drinkjava2.
the class TestBase method printAllDialectsDDLs.
protected static void printAllDialectsDDLs(TableModel... tables) {
Dialect[] diaList = Dialect.values();
for (Dialect dialect : diaList) {
System.out.println("======" + dialect + "=====");
try {
String[] ddls = dialect.toDropAndCreateDDL(tables);
printDDLs(ddls);
// printDDLs(DDLFormatter.format(ddls));
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception found: " + e.getMessage());
}
}
}
use of com.github.drinkjava2.jdialects.model.TableModel 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.TableModel in project jDialects by drinkjava2.
the class DDLTest method CommentModel.
private static TableModel CommentModel() {
// Comment
TableModel t = new TableModel("testTable").comment("table_comment");
t.column("s1").INTEGER().notNull().identityId().pkey();
t.column("s2").LONG().comment("column_comment1");
t.column("s3").BIGINT().comment("column_comment2");
return t;
}
use of com.github.drinkjava2.jdialects.model.TableModel 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.TableModel in project jDialects by drinkjava2.
the class DDLTest method SequenceModel.
private static TableModel SequenceModel() {
// SequenceGen
TableModel t = new TableModel("testTable");
t.sequenceGenerator("seq1", "seq_1", 1, 1);
t.sequenceGenerator("seq2", "seq_2", 1, 2);
t.column("i1").INTEGER().pkey().idGenerator("seq1");
t.column("i2").INTEGER().pkey().idGenerator("seq2");
return t;
}
Aggregations