Search in sources :

Example 36 with TableModel

use of com.github.drinkjava2.jdialects.model.TableModel in project jDialects by drinkjava2.

the class IdgeneratorTest method testSortedUUIDGenerator.

@Test
public void testSortedUUIDGenerator() {
    TableModel table = new TableModel("testSortedUUIDGenerator");
    table.sortedUUIDGenerator("sorteduuid", 8, 8);
    table.addGenerator(new SortedUUIDGenerator("sorteduuid2", 10, 10));
    table.column("id").STRING(30).pkey().idGenerator("sorteduuid");
    table.column("id2").STRING(30).pkey().idGenerator("sorteduuid2");
    reBuildDB(table);
    IdGenerator gen1 = table.getIdGenerator("sorteduuid");
    for (int i = 0; i < 10; i++) System.out.println(gen1.getNextID(dbPro, guessedDialect, null));
    IdGenerator gen2 = table.getIdGenerator("sorteduuid2");
    for (int i = 0; i < 10; i++) System.out.println(gen2.getNextID(dbPro, guessedDialect, null));
}
Also used : SortedUUIDGenerator(com.github.drinkjava2.jdialects.id.SortedUUIDGenerator) AutoIdGenerator(com.github.drinkjava2.jdialects.id.AutoIdGenerator) IdGenerator(com.github.drinkjava2.jdialects.id.IdGenerator) TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 37 with TableModel

use of com.github.drinkjava2.jdialects.model.TableModel in project jDialects by drinkjava2.

the class IdgeneratorTest method testUUIDs.

@Test
public void testUUIDs() {
    // nextID
    TableModel t = new TableModel("testNextIdTable");
    t.column("id1").STRING(25).pkey();
    t.column("id2").STRING(32);
    t.column("id3").STRING(36);
    String[] ddls = guessedDialect.toDropDDL(t);
    quietExecuteDDLs(ddls);
    ddls = guessedDialect.toCreateDDL(t);
    executeDDLs(ddls);
    for (int i = 0; i < 10; i++) {
        Object id1 = guessedDialect.getNexID(UUID25Generator.INSTANCE, dbPro, null);
        Object id2 = guessedDialect.getNexID(UUID32Generator.INSTANCE, dbPro, null);
        Object id3 = guessedDialect.getNexID(UUID36Generator.INSTANCE, dbPro, null);
        System.out.println(id1);
        System.out.println(id2);
        System.out.println(id3);
        Assert.assertTrue(("" + id1).length() == 25);
        Assert.assertTrue(("" + id2).length() == 32);
        Assert.assertTrue(("" + id3).length() == 36);
        dbPro.nExecute("insert into testNextIdTable (id1,id2,id3) values(?,?,?) ", id1, id2, id3);
    }
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 38 with TableModel

use of com.github.drinkjava2.jdialects.model.TableModel in project jDialects by drinkjava2.

the class IdgeneratorTest method testPKey.

@Test
public void testPKey() {
    // nextID
    TableModel t = new TableModel("testPKey");
    t.column("id1").STRING(25).pkey();
    Assert.assertTrue(t.column("id1").getPkey());
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 39 with TableModel

use of com.github.drinkjava2.jdialects.model.TableModel in project jDialects by drinkjava2.

the class IdgeneratorTest method testAutoIdGenerator.

@Test
public void testAutoIdGenerator() {
    TableModel table = new TableModel("testAutoIdGenerator");
    table.column("id").STRING(30).pkey().autoId();
    reBuildDB(table);
    IdGenerator gen = table.getColumn("id").getIdGenerator();
    for (int i = 0; i < 5; i++) System.out.println(gen.getNextID(dbPro, guessedDialect, null));
    gen = AutoIdGenerator.INSTANCE;
    for (int i = 0; i < 5; i++) System.out.println(gen.getNextID(dbPro, guessedDialect, null));
}
Also used : AutoIdGenerator(com.github.drinkjava2.jdialects.id.AutoIdGenerator) IdGenerator(com.github.drinkjava2.jdialects.id.IdGenerator) TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 40 with TableModel

use of com.github.drinkjava2.jdialects.model.TableModel in project jDialects by drinkjava2.

the class IdgeneratorTest method testPKey2.

@Test
public void testPKey2() {
    // nextID
    TableModel t = TableModelUtils.entity2Model(pkeyEntity.class);
    Assert.assertTrue(t.column("id1").getPkey());
    Assert.assertTrue(t.column("id2").getPkey());
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Aggregations

TableModel (com.github.drinkjava2.jdialects.model.TableModel)36 Test (org.junit.Test)19 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)11 AutoIdGenerator (com.github.drinkjava2.jdialects.id.AutoIdGenerator)9 IdGenerator (com.github.drinkjava2.jdialects.id.IdGenerator)9 SequenceIdGenerator (com.github.drinkjava2.jdialects.id.SequenceIdGenerator)5 TableIdGenerator (com.github.drinkjava2.jdialects.id.TableIdGenerator)5 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)5 IndexModel (com.github.drinkjava2.jdialects.model.IndexModel)3 UniqueModel (com.github.drinkjava2.jdialects.model.UniqueModel)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Dialect (com.github.drinkjava2.jdialects.Dialect)2 Connection (java.sql.Connection)2 Map (java.util.Map)2 SortedUUIDGenerator (com.github.drinkjava2.jdialects.id.SortedUUIDGenerator)1 Table (com.github.drinkjava2.jdialects.model.Table)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1