use of com.github.drinkjava2.jsqlbox.SqlBoxException in project jSqlBox by drinkjava2.
the class EntityNetUtils method jointConfigModels.
public static TableModel[] jointConfigModels(TableModel[] bindeds, TableModel[] givens) {
// check setted to avoid user set empty value to TableModel
Map<String, TableModel> uses = new HashMap<String, TableModel>();
for (TableModel tb : givens) {
SqlBoxException.assureNotNull(tb.getEntityClass(), "EntityClass setting can not be null for '" + tb.getTableName() + "'");
SqlBoxException.assureNotEmpty(tb.getTableName(), "TableName setting can not be empty for '" + tb.getTableName() + "'");
uses.put(tb.getTableName().toLowerCase(), tb);
}
for (TableModel tb : bindeds) {
SqlBoxException.assureNotEmpty(tb.getTableName(), "TableName setting can not be empty for '" + tb.getTableName() + "'");
TableModel exist = uses.get(tb.getTableName().toLowerCase());
if (tb.getEntityClass() != null) {
// it's binded by has entityClass
if (exist == null)
uses.put(tb.getTableName().toLowerCase(), tb);
else
// exist and current tb both can use, duplicated
throw new SqlBoxException("Duplicated entityClass setting for '" + tb.getTableName() + "'");
}
}
for (TableModel tb : bindeds) {
// use alias to fill
TableModel exist = uses.get(tb.getTableName().toLowerCase());
if (exist != null && tb.getEntityClass() == null) {
// it's binded by
// has
// entityClass
String alias = tb.getAlias();
if (!StrUtils.isEmpty(alias) && StrUtils.isEmpty(exist.getAlias()))
exist.setAlias(alias);
}
}
TableModel[] result = new TableModel[uses.size()];
int i = 0;
for (Entry<String, TableModel> entry : uses.entrySet()) {
result[i++] = entry.getValue();
}
return result;
}
Aggregations