Search in sources :

Example 1 with Column

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);
}
Also used : Table(com.github.drinkjava2.jdialects.model.Table) Column(com.github.drinkjava2.jdialects.model.Column) Test(org.junit.Test)

Example 2 with Column

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);
    }
}
Also used : ColumnModel(com.github.drinkjava2.jdialects.model.ColumnModel) TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 3 with Column

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);
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 4 with Column

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);
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 5 with Column

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;
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel)

Aggregations

TableModel (com.github.drinkjava2.jdialects.model.TableModel)11 Test (org.junit.Test)9 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)7 AutoIdGenerator (com.github.drinkjava2.jdialects.id.AutoIdGenerator)6 IdGenerator (com.github.drinkjava2.jdialects.id.IdGenerator)6 SequenceIdGenerator (com.github.drinkjava2.jdialects.id.SequenceIdGenerator)4 TableIdGenerator (com.github.drinkjava2.jdialects.id.TableIdGenerator)4 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)4 Table (com.github.drinkjava2.jdialects.model.Table)3 Column (com.github.drinkjava2.jdialects.model.Column)2 IndexModel (com.github.drinkjava2.jdialects.model.IndexModel)2 UniqueModel (com.github.drinkjava2.jdialects.model.UniqueModel)2 ArrayList (java.util.ArrayList)2 FKeyConstraint (com.github.drinkjava2.jdialects.model.FKeyConstraint)1 GlobalIdGenerator (com.github.drinkjava2.jdialects.model.GlobalIdGenerator)1 Sequence (com.github.drinkjava2.jdialects.model.Sequence)1 TableGenerator (com.github.drinkjava2.jdialects.model.TableGenerator)1 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 Annotation (java.lang.annotation.Annotation)1