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));
}
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));
}
}
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));
}
}
Aggregations