use of com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler in project jSqlBox by drinkjava2.
the class EntityNetFactory method createEntityNet.
/**
* Create a EntityNet instance, load data from database buy given loadKeyOnly
* and configObjects parameters
*
* @param ctx
* A SqlBoxContext instance
* @param loadKeyOnly
* If true will only load PKey and FKeys field, otherwise load all
* columns
* @param configObjects
* netConfigs array, can be entity class, entity, SqlBox or
* TableModel instance
* @return The EntityNet
*/
public static EntityNet createEntityNet(SqlBoxContext ctx, boolean loadKeyOnly, Object... configObjects) {
if (configObjects == null || configObjects.length == 0)
throw new EntityNetException("LoadNet() does not support empty netConfigs parameter");
TableModel[] models = EntityNetUtils.objectConfigsToModels(ctx, configObjects);
EntityNet net = new EntityNet();
String starOrSharp = loadKeyOnly ? ".##" : ".**";
for (TableModel t : models) {
List<Map<String, Object>> mapList = null;
String alias = t.getAlias();
if (StrUtils.isEmpty(alias))
alias = t.getTableName();
try {
mapList = ctx.nQuery(new EntitySqlMapListHandler(t), "select " + alias + starOrSharp + " from " + t.getTableName() + " as " + alias);
} finally {
EntityNetUtils.removeBindedTableModel(mapList);
}
net.addMapList(mapList, t);
}
return net;
}
Aggregations