com.jfinal.plugin.activerecord.Db.find()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(418)

本文整理了Java中com.jfinal.plugin.activerecord.Db.find()方法的一些代码示例,展示了Db.find()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Db.find()方法的具体详情如下:
包路径:com.jfinal.plugin.activerecord.Db
类名称:Db
方法名:find

Db.find介绍

暂无

代码示例

代码示例来源:origin: jfinal/jfinal

public static List<Record> find(Connection conn, String sql, Object... paras) throws SQLException {
  return Db.find(DbKit.config, conn, sql, paras);
}

代码示例来源:origin: jfinal/jfinal

public static List<Record> find(String configName, Connection conn, String sql, Object... paras) throws SQLException {
  return Db.find(DbKit.getConfig(configName), conn, sql, paras);
}

代码示例来源:origin: JpressProjects/jpress

@Override
public List<ArticleCategory> findListByArticleId(long articleId) {
  List<Record> mappings = Db.find("select * from article_category_mapping where article_id = ?", articleId);
  if (mappings == null || mappings.isEmpty()) {
    return null;
  }
  return mappings
      .stream()
      .map(record -> DAO.findById((long) record.get("category_id")))
      .filter(Objects::nonNull)
      .collect(Collectors.toList());
}

代码示例来源:origin: JpressProjects/jpress

@Override
public Long[] findCategoryIdsByArticleId(long articleId) {
  List<Record> records = Db.find("select * from article_category_mapping where article_id = ?", articleId);
  if (records == null || records.isEmpty())
    return null;
  return ArrayUtils.toObject(records.stream().mapToLong(record -> record.get("category_id")).toArray());
}

代码示例来源:origin: JpressProjects/jpress

@Cacheable(name = "user_permission", key = "role:#(roleId)", nullCacheEnable = true)
public List<Permission> findPermissionListByRoleId(long roleId) {
  String sql = "select * from role_permission_mapping where role_id = ? ";
  List<Record> rolePermissionRecords = Db.find(sql, roleId);
  if (rolePermissionRecords == null || rolePermissionRecords.isEmpty()) {
    return null;
  }
  List<Permission> permissionList = new ArrayList<>();
  for (Record rolePermissionRecord : rolePermissionRecords) {
    Permission permission = findById(rolePermissionRecord.getLong("permission_id"));
    if (permission != null) permissionList.add(permission);
  }
  return permissionList;
}

代码示例来源:origin: JpressProjects/jpress

@Cacheable(name = "user_role", key = "user_roles:#(userId)", nullCacheEnable = true)
public List<Role> findRoleListByUserId(long userId) {
  String sql = "select * from user_role_mapping where user_id = ?";
  List<Record> records = Db.find(sql, userId);
  if (records == null || records.isEmpty()) {
    return null;
  }
  List<Role> roles = new ArrayList<>();
  for (Record record : records) {
    Role role = findById(record.getLong("role_id"));
    if (role != null) roles.add(role);
  }
  return roles;
}

代码示例来源:origin: JpressProjects/jpress

@Cacheable(name = "user_permission", key = "user_permissions:#(userId)", nullCacheEnable = true)
  public List<Permission> findPermissionListByUserId(long userId) {

    Set<Permission> permissions = new HashSet<>();
    String sql = "select * from user_role_mapping where user_id = ? ";
    List<Record> userRoleRecords = Db.find(sql, userId);
    if (userRoleRecords != null) {
      for (Record userRoleRecord : userRoleRecords) {
        List<Permission> rolePermissions = findPermissionListByRoleId(userRoleRecord.getLong("role_id"));
        if (rolePermissions != null) {
          permissions.addAll(rolePermissions);
        }
      }
    }

//        sql = "select * from user_permission where user_id = ?";
//        List<Record> userPermissionList = Db.find(sql, userId);
//        if (userPermissionList != null) {
//            for (Record userPermission : userPermissionList) {
//                if (userPermission.getInt("own") > 0) {
//                    permissions.add(findById(userPermission.getLong("permission_id")));
//                } else {
//                    permissions.remove(findById(userPermission.getLong("permission_id")));
//                }
//            }
//        }

    return new ArrayList<>(permissions);
  }

代码示例来源:origin: JpressProjects/jpress

@Override
public boolean deleteById(Object id) {
  return Db.tx(() -> {
    boolean delOk = ArticleServiceProvider.super.deleteById(id);
    if (delOk == false) {
      return false;
    }
    List<Record> records = Db.find("select * from article_category_mapping where article_id = ? ", id);
    if (records == null || records.isEmpty()) {
      return true;
    }
    Db.update("delete from article_category_mapping where article_id = ?", id);
    records.stream().forEach(record -> {
      categoryService.updateCount(record.get("category_id"));
    });
    return true;
  });
}

代码示例来源:origin: com.github.sogyf/goja-jfinal

/**
 * Return the columns map of the record
 * @param record the Record object
 * @return the columns map of the record
public static final Map<String, Object> getColumns(Record record) {
  return record.getColumns();
} */

public static List<Record> find(Connection conn, String sql, Object... paras) throws SQLException {
  return Db.find(DbKit.config, conn, sql, paras);
}

代码示例来源:origin: com.jfinal/jfinal

public static List<Record> find(Connection conn, String sql, Object... paras) throws SQLException {
  return Db.find(DbKit.config, conn, sql, paras);
}

代码示例来源:origin: com.github.sogyf/goja-jfinal

public static List<Record> find(String configName, Connection conn, String sql, Object... paras) throws SQLException {
  return Db.find(DbKit.getConfig(configName), conn, sql, paras);
}

代码示例来源:origin: com.jfinal/jfinal

public static List<Record> find(String configName, Connection conn, String sql, Object... paras) throws SQLException {
  return Db.find(DbKit.getConfig(configName), conn, sql, paras);
}

代码示例来源:origin: yjjdick/sdb-mall

@Override
public List<ProductDTO> listDetailByProductIds(String productIds) {
  String[] productIdArr = productIds.split(",");
  SqlPara sqlPara = Db.getSqlPara("product.listDetailByProductIds", Kv.by("productIds", productIdArr));
  List<Record> recordList = Db.find(sqlPara);
  List<ProductDTO> productDTOList = RecordUtils.converModel(recordList, ProductDTO.class);
  return productDTOList;
}

代码示例来源:origin: yjjdick/sdb-mall

public List<String> queryAllPerms(Long userId) {
  SqlPara sqlPara = Db.getSqlPara("sysUser.queryAllPerms", Kv.by("userId", userId));
  List<Record> sysUserList = Db.find(sqlPara);
  List<String> perms = new ArrayList<>();
  for (Record r:sysUserList
     ) {
    if(r == null || r.get("perms") == null) {
      continue;
    }
    perms.add(r.get("perms"));
  }
  return perms;
}

代码示例来源:origin: yjjdick/sdb-mall

public List<Long> queryAllMenuId(Long userId) {
  SqlPara sqlPara = Db.getSqlPara("sysUser.queryAllMenuId", Kv.by("userId", userId));
  List<Record> sysMenuList = Db.find(sqlPara);
  List<Long> menuIds = new ArrayList<>();
  for (Record r:sysMenuList
     ) {
    if(r == null || r.get("menu_id") == null) {
      continue;
    }
    menuIds.add(r.get("menu_id"));
  }
  return menuIds;
}

代码示例来源:origin: yjjdick/sdb-mall

@Override
  public List<CartDTO> listDetail(String userId) {
    SqlPara sqlPara =  Db.getSqlPara("cart.listDetail", Kv.by("userId", userId));
    List<Record> recordList = Db.find(sqlPara);
    List<CartDTO> cartDTOList = RecordUtils.converModel(recordList, CartDTO.class);
    return cartDTOList;
  }
}

代码示例来源:origin: yjjdick/sdb-mall

@Override
  public List<FavoriteGoodsDTO> list(String userId) {
    SqlPara sqlPara =  Db.getSqlPara("favoriteGoods.list", Kv.by("userId", userId));
    List<Record> recordList = Db.find(sqlPara);
    List<FavoriteGoodsDTO> favoriteGoodsDTOList = RecordUtils.converModel(recordList, FavoriteGoodsDTO.class);
    return favoriteGoodsDTOList;
  }
}

代码示例来源:origin: ticktack/kungfu

protected static String dynamicUpdate(String database, String tableName, Model<?> model) {
  DynamicSQL dsql = new DynamicSQL();
  dsql.append("  update  " + tableName);
  dsql.append("  set " );
  List<Record> columns = Db.find(columnSql, database, tableName);
  for (Record rd : columns) 
    if (StrKit.notNull(rd.getStr("columnName"))) 
      dsql.isNotEmpty(String.format(" %s = %s , ", rd.getStr("columnName"), placeholder(rd.getStr("dataType"))),  model.get(rd.getStr("columnName")));
  
  String sql = dsql.toString();
  sql = sql.substring(0, sql.lastIndexOf(','));
  dsql.clear();
  
  return sql;
}

代码示例来源:origin: ticktack/kungfu

protected static String selectSql(String database, String tableName, Model<?> model) {
  DynamicSQL dsql = new DynamicSQL();
  dsql.append("  select * from " + tableName);
  dsql.append("  where 1= 1 " );
  List<Record> columns = Db.find(columnSql, database, tableName);
  
  for (Record rd : columns) 
    if (StrKit.isNull(rd.getStr("columnName"))) 
      dsql.isNotEmpty(String.format(" and %s = %s ", rd.getStr("columnName"), placeholder(rd.getStr("dataType"))),  model.get(rd.getStr("columnName")));
  
  String sql = dsql.toString();
  dsql.clear();
  
  return sql;
}

代码示例来源:origin: ticktack/kungfu

protected static String insertSql(String database, String tableName, Model<?> model) {
  DynamicSQL dsql = new DynamicSQL();
  dsql.append("  insert into  " + tableName);
  dsql.append("  ( " );
  List<Record> columns = Db.find(columnSql, database, tableName);
  
  // INSERT INTO table_name (列1, 列2,...) 
  for (Record rd : columns) 
    if (ModelKit.recordNotBlank(model.get(rd.getStr("columnName")))) 
      dsql.isNotEmpty(" $, ",  rd.getStr("columnName"));
  
  dsql.append("  ) values( " );
  // VALUES (值1, 值2,....)
  for (Record rd : columns) 
    if (StrKit.notNull(rd.getStr("columnName"))) 
      dsql.isNotEmpty(String.format(" %s, ", placeholder(rd.getStr("dataType"))),  model.get(rd.getStr("columnName")));
  
  dsql.append("  ) " );
  String sql = dsql.toString();
  sql = sql.replaceAll(", \\)", ")");
  dsql.clear();
  
  return sql;
}

相关文章