Java Code Examples for org.jooq.Result#getValues()

The following examples show how to use org.jooq.Result#getValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlSelector.java    From SqlFaker with Apache License 2.0 5 votes vote down vote up
/**
 * 选择表中的一列数据
 * @param sql sql 语句
 * @return 表中的一列数据
 */
public static List<String> selectColumn(String sql) {
    Connection connection = DatabaseHelper.getConnection();
    Asserts.isTrue(connection != null, "数据库连接获取失败,请先在 DBTools 中设置连接参数");

    // 执行 sql 并获取查询结果
    Result<Record> records = DSL.using(connection).fetch(sql);

    // 获取第 1 列的值
    return records.getValues(0, String.class);
}
 
Example 2
Source File: SqlSelector.java    From SqlFaker with Apache License 2.0 5 votes vote down vote up
/**
 * 选择表中的一列数据
 * @param sql sql 语句
 * @return 表中的一列数据
 */
public List<String> selectColumn(String sql) {
    // 执行 sql 并获取查询结果
    Result<Record> records = DSL.using(url, username, password).fetch(sql);

    // 获取第 1 列的值
    return records.getValues(0, String.class);
}
 
Example 3
Source File: CMSCrawler.java    From oneops with Apache License 2.0 4 votes vote down vote up
public Map<String, Organization> populateOrganizations(Connection conn) {

    log.info("Populating organizations cache");
    DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
    Map<String, Organization> organizationsMap = new HashMap<>();

    Result<Record4<Long, String, Integer, String>> OrganizationsWithAttributesRecords = create
        .select(CM_CI.CI_ID, CM_CI.CI_NAME, CM_CI_ATTRIBUTES.ATTRIBUTE_ID,
            CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE)
        .from(CM_CI).join(CM_CI_ATTRIBUTES).on(CM_CI.CI_ID.eq(CM_CI_ATTRIBUTES.CI_ID))
        .where(CM_CI.CLASS_ID.in(create.select(MD_CLASSES.CLASS_ID).from(MD_CLASSES)
            .where(MD_CLASSES.CLASS_NAME.eq("account.Organization"))))
        .fetch();

    List<Long> OrganizationIds = OrganizationsWithAttributesRecords.getValues(CM_CI.CI_ID);
    log.debug("OrganizationIds: " + OrganizationIds.toString());

    Set<Long> setOfOrganizationIds = new HashSet<Long>(OrganizationIds);
    log.debug("setOfOrganizationIds <" + setOfOrganizationIds.size() + "> " + setOfOrganizationIds);

    List<String> OrganizationNames = OrganizationsWithAttributesRecords.getValues(CM_CI.CI_NAME);
    log.debug("OrganizationNames: " + OrganizationNames.toString());

    Set<String> setOfOrganizationNames = new HashSet<String>(OrganizationNames);
    log.debug("setOfOrganizationNames: <" + setOfOrganizationNames.size() + "> "
        + setOfOrganizationNames);

    int description_AttribID =
        this.baseOrganizationMDClassAttributes_NameIdMapCache.get("description");
    int full_name_AttribID = this.baseOrganizationMDClassAttributes_NameIdMapCache.get("full_name");
    int owner_AttribID = this.baseOrganizationMDClassAttributes_NameIdMapCache.get("owner");
    int tags_AttribID = this.baseOrganizationMDClassAttributes_NameIdMapCache.get("tags");

    for (Record4<Long, String, Integer, String> OrganizationsWithAttributesRecord : OrganizationsWithAttributesRecords) {
      long organizationId = OrganizationsWithAttributesRecord.getValue(CM_CI.CI_ID);

      String organizationName = OrganizationsWithAttributesRecord.getValue(CM_CI.CI_NAME);
      Organization organization = organizationsMap.get(organizationName);
      log.debug("organizationId: " + organizationId);
      if (organization == null) {
        organization = new Organization();
        organizationsMap.put(organizationName, organization);

      }

      int attributeID = OrganizationsWithAttributesRecord.getValue(CM_CI_ATTRIBUTES.ATTRIBUTE_ID);

      if (attributeID == description_AttribID) {
        organization.setDescription(
            OrganizationsWithAttributesRecord.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE));

        continue;
      } else if (attributeID == full_name_AttribID) {
        organization.setFull_name(
            OrganizationsWithAttributesRecord.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE));

        continue;

      } else if (attributeID == owner_AttribID) {
        organization.setOwner(
            OrganizationsWithAttributesRecord.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE));

        continue;
      } else if (attributeID == tags_AttribID) {
        @SuppressWarnings("unchecked") 
        Map<String, String> tags = gson.fromJson(
            OrganizationsWithAttributesRecord.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE),
            Map.class);
        organization.setTags(tags);
        
        continue;
      }


    }

    log.info("Caching for Org Data Complete");
    return organizationsMap;
  }