Search in sources :

Example 6 with EntitySqlMapListHandler

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;
}
Also used : Map(java.util.Map) TableModel(com.github.drinkjava2.jdialects.model.TableModel) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)

Aggregations

EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)6 Map (java.util.Map)6 Test (org.junit.Test)5 User (com.github.drinkjava2.functionstest.entitynet.entities.User)3 EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)3 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)2 Address (com.github.drinkjava2.functionstest.entitynet.entities.Address)1 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)1 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)1 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)1 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)1 Wrap (com.github.drinkjava2.jdbpro.handler.Wrap)1 TableModel (com.github.drinkjava2.jdialects.model.TableModel)1 Node (com.github.drinkjava2.jsqlbox.entitynet.Node)1 EntityListHandler (com.github.drinkjava2.jsqlbox.handler.EntityListHandler)1 PaginHandler (com.github.drinkjava2.jsqlbox.handler.PaginHandler)1