Search in sources :

Example 11 with IdGenerator

use of com.github.drinkjava2.jdialects.id.IdGenerator in project jDialects by drinkjava2.

the class IdgeneratorTest method testIdentityGenerator.

@Test
public void testIdentityGenerator() {
    TableModel table = new TableModel("testIdentity");
    table.column("id").INTEGER().identityId();
    table.column("name").STRING(30);
    reBuildDB(table);
    dbPro.nExecute("insert into testIdentity (name) values(?)", "Tom");
    dbPro.nExecute("insert into testIdentity (name) values(?)", "Sam");
    IdGenerator idGen = table.getIdGenerator(GenerationType.IDENTITY);
    System.out.println(idGen.getNextID(dbPro, guessedDialect, Type.INTEGER));
    idGen = table.getColumn("id").getIdGenerator();
    System.out.println(idGen.getNextID(dbPro, guessedDialect, Type.INTEGER));
}
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 12 with IdGenerator

use of com.github.drinkjava2.jdialects.id.IdGenerator in project jDialects by drinkjava2.

the class IdgeneratorTest method testSequenceIdGenerator.

@Test
public void testSequenceIdGenerator() {
    if (!guessedDialect.getDdlFeatures().supportBasicOrPooledSequence())
        return;
    TableModel table1 = new TableModel("testTableIdGenerator");
    table1.sequenceGenerator("seq1", "seq1", 1, 10);
    table1.column("id").STRING(30).pkey().idGenerator("seq1");
    table1.column("id2").STRING(30).pkey().sequenceGenerator("seq2", "seq2", 1, 20);
    TableModel table2 = new TableModel("testTableIdGenerator2");
    table2.sequenceGenerator("seq3", "seq3", 1, 10);
    table2.column("id").STRING(30).pkey().idGenerator("seq3");
    table2.column("id2").STRING(30).pkey().sequenceGenerator("seq2", "seq2", 1, 20);
    reBuildDB(table1, table2);
    IdGenerator gen1 = table1.getIdGenerator("seq1");
    IdGenerator gen2 = table1.getIdGenerator("seq2");
    for (int i = 0; i < 3; i++) {
        System.out.println(gen1.getNextID(dbPro, guessedDialect, null));
        System.out.println(gen2.getNextID(dbPro, guessedDialect, null));
    }
    IdGenerator gen3 = table2.getIdGenerator("seq3");
    IdGenerator gen4 = table2.getIdGenerator("seq2");
    for (int i = 0; i < 3; i++) {
        System.out.println(gen3.getNextID(dbPro, guessedDialect, null));
        System.out.println(gen4.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 13 with IdGenerator

use of com.github.drinkjava2.jdialects.id.IdGenerator in project jDialects by drinkjava2.

the class IdgeneratorTest method testTableIdGenerator.

@Test
public void testTableIdGenerator() {
    TableModel table1 = new TableModel("testTableIdGenerator");
    table1.tableGenerator("tab1", "tb1", "pkCol", "valueColname", "pkColVal", 1, 10);
    table1.column("id").STRING(30).pkey().idGenerator("tab1");
    table1.column("id2").STRING(30).pkey().tableGenerator("tab2", "tb1", "pkCol", "valueColname", "pkColVal", 1, 10);
    TableModel table2 = new TableModel("testTableIdGenerator2");
    table2.tableGenerator("tab3", "tb1", "pkCol", "valueColname", "pkColVal", 1, 10);
    table2.column("id").STRING(30).pkey().idGenerator("tab3");
    table2.column("id2").STRING(30).pkey().tableGenerator("tab2", "tb1", "pkCol", "valueColname", "pkColVal", 1, 10);
    reBuildDB(table1, table2);
    IdGenerator gen1 = table1.getIdGenerator("tab1");
    IdGenerator gen2 = table1.getIdGenerator("tab2");
    for (int i = 0; i < 3; i++) {
        System.out.println(gen1.getNextID(dbPro, guessedDialect, null));
        System.out.println(gen2.getNextID(dbPro, guessedDialect, null));
    }
    IdGenerator gen3 = table2.getIdGenerator("tab3");
    IdGenerator gen4 = table2.getIdGenerator("tab2");
    for (int i = 0; i < 3; i++) {
        System.out.println(gen3.getNextID(dbPro, guessedDialect, null));
        System.out.println(gen4.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)

Aggregations

TableModel (com.github.drinkjava2.jdialects.model.TableModel)11 AutoIdGenerator (com.github.drinkjava2.jdialects.id.AutoIdGenerator)9 IdGenerator (com.github.drinkjava2.jdialects.id.IdGenerator)9 Test (org.junit.Test)6 SequenceIdGenerator (com.github.drinkjava2.jdialects.id.SequenceIdGenerator)4 TableIdGenerator (com.github.drinkjava2.jdialects.id.TableIdGenerator)4 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)4 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)4 IndexModel (com.github.drinkjava2.jdialects.model.IndexModel)2 UniqueModel (com.github.drinkjava2.jdialects.model.UniqueModel)2 ArrayList (java.util.ArrayList)2 SortedUUIDGenerator (com.github.drinkjava2.jdialects.id.SortedUUIDGenerator)1