use of com.github.drinkjava2.jdialects.model.Table in project jDialects by drinkjava2.
the class DDLDropUtils method transferTableToObjectList.
/**
* Transfer table to a mixed DDL String or TableGen Object list
*/
private static void transferTableToObjectList(Dialect dialect, TableModel t, List<Object> objectResultList) {
StringBuilder buf = new StringBuilder();
String tableName = t.getTableName();
List<ColumnModel> columns = t.getColumns();
// Reserved words check
dialect.checkNotEmptyReservedWords(tableName, "Table name can not be empty");
// check index names
List<IndexModel> l = t.getIndexConsts();
if (l != null && !l.isEmpty())
for (IndexModel index : l) dialect.checkReservedWords(index.getName());
// check unique names
List<UniqueModel> l2 = t.getUniqueConsts();
if (l2 != null && !l2.isEmpty())
for (UniqueModel unique : l2) dialect.checkReservedWords(unique.getName());
// check Fkey names
List<FKeyModel> fkeyChks = t.getFkeyConstraints();
if (fkeyChks != null && !fkeyChks.isEmpty())
for (FKeyModel fkey : fkeyChks) dialect.checkReservedWords(fkey.getFkeyName());
for (ColumnModel col : columns) dialect.checkNotEmptyReservedWords(col.getColumnName(), "Column name can not be empty");
// idGenerator
for (IdGenerator idGen : t.getIdGenerators()) objectResultList.add(idGen);
// Foreign key
for (FKeyModel fkey : t.getFkeyConstraints()) objectResultList.add(fkey);
// drop table
buf.append(dialect.dropTableDDL(tableName));
objectResultList.add(buf.toString());
}
use of com.github.drinkjava2.jdialects.model.Table 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));
}
use of com.github.drinkjava2.jdialects.model.Table 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));
}
use of com.github.drinkjava2.jdialects.model.Table 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.model.Table in project jDialects by drinkjava2.
the class DDLCreateUtils method checkAndInsertToNotRepeatTable.
/**
* if name not found, add <br/>
* If name same, but other fields different, throw exception </br>
* If name same, and other field same, ignore </br>
*/
protected static void checkAndInsertToNotRepeatTable(Set<TableIdGenerator> notRepeatedSeq, TableIdGenerator tab) {
DialectException.assureNotEmpty(tab.getName(), "TableGen name can not be empty");
DialectException.assureNotEmpty(tab.getTable(), "TableGen tableName can not be empty of \"" + tab.getName() + "\"");
DialectException.assureNotEmpty(tab.getPkColumnName(), "TableGen pkColumnName can not be empty of \"" + tab.getName() + "\"");
DialectException.assureNotEmpty(tab.getPkColumnValue(), "TableGen pkColumnValue can not be empty of \"" + tab.getName() + "\"");
DialectException.assureNotEmpty(tab.getValueColumnName(), "TableGen valueColumnName can not be empty of \"" + tab.getName() + "\"");
boolean canAdd = true;
for (TableIdGenerator not : notRepeatedSeq) {
if (tab.getName().equals(not.getName())) {
canAdd = false;
if (!(tab.getTable().equals(not.getTable()) && tab.getPkColumnName().equals(not.getPkColumnName()) && tab.getPkColumnValue().equals(not.getPkColumnValue()) && tab.getValueColumnName().equals(not.getValueColumnName()) && tab.getInitialValue().equals(not.getInitialValue()) && tab.getAllocationSize().equals(not.getAllocationSize())))
throw new DialectException("In one or more tableModel, duplicated TableIdGenerator name '" + tab.getName() + "' but different value of table/pKColumnName/pkColumnValue/valueColumnName/initialValue/allocationSize setting");
}
}
if (canAdd)
notRepeatedSeq.add(tab);
}
Aggregations