Java 类org.springframework.jdbc.core.BeanPropertyRowMapper 实例源码

项目:batch-scheduler    文件:SysConfigDaoImpl.java   
@Override
public List<SysConfigEntity> findAll(String domainId) {
    RowMapper<SysConfigEntity> rowMapper = new BeanPropertyRowMapper<SysConfigEntity>(SysConfigEntity.class);
    List<SysConfigEntity> list = jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_181"), rowMapper);
    List<SysConfigEntity> list2 = jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_187"), rowMapper, domainId);
    Map<String, SysConfigEntity> map = new HashMap<>();

    for (int i = 0; i < list2.size(); i++) {
        map.put(list2.get(i).getConfigId(), list2.get(i));
    }

    for (int i = 0; i < list.size(); i++) {
        String cid = list.get(i).getConfigId();
        if (map.containsKey(cid)) {
            list.get(i).setConfigValue(map.get(cid).getConfigValue());
        }
    }
    return list;
}
项目:plugin-bt-jira    文件:JiraDao.java   
/**
 * Return all status changes of issues of given project and last known issue values : due date, resolution,
 * reporter,... in type {@link IssueDetails}.
 * 
 * @param dataSource
 *            The data source of JIRA database.
 * @param jira
 *            the JIRA project identifier.
 * @param pkey
 *            the project 'pkey'.
 * @param authoring
 *            When <code>true</code> authors are fetched for changes.
 * @param timing
 *            When <code>true</code> time spent data is fetched.
 * @return status changes of all issues of given project.
 */
public List<JiraChangeItem> getChanges(final DataSource dataSource, final int jira, final String pkey, final boolean authoring,
        final boolean timing) {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    final RowMapper<JiraChangeItem> rowMapper = new BeanPropertyRowMapper<>(JiraChangeItem.class);

    // First, get all created issues (first change)
    final List<JiraChangeItem> changes = getChanges(dataSource, jira, pkey, JiraChangeItem.class, timing, false);

    // Then add all status changes
    changes.addAll(jdbcTemplate.query(
            "SELECT i.ID AS id, cgi.OLDVALUE AS fromStatus, cgi.NEWVALUE AS toStatus, cg.CREATED AS created"
                    + (authoring ? ", cg.AUTHOR as author" : "")
                    + " FROM changeitem cgi INNER JOIN changegroup AS cg ON (cgi.groupid = cg.ID) INNER JOIN jiraissue AS i ON (cg.issueid = i.ID)"
                    + " WHERE cgi.FIELD = ? AND cgi.OLDVALUE IS NOT NULL AND cgi.NEWVALUE IS NOT NULL AND cg.CREATED IS NOT NULL AND i.PROJECT = ?",
            rowMapper, "status", jira));

    /*
     * Then sort the result by "created" date. The previous SQL query did not used since order had to be applied to
     * the whole collection. In addition, the result set of the previous query "should already been ordered since
     * the natural order in this table is chronological.
     */
    changes.sort(Comparator.comparing(IssueDetails::getCreated));
    return changes;
}
项目:plugin-bt-jira    文件:JiraDao.java   
/**
 * Return all status changes of issues of given project.
 * 
 * @param dataSource
 *            The data source of JIRA database.
 * @param jira
 *            the JIRA project identifier.
 * @param pkey
 *            the project 'pkey'.
 * @param resultType
 *            the bean type to build in result list.
 * @param timing
 *            When <code>true</code> time spent data is fetched.
 * @param summary
 *            When <code>true</code> Summary is fetched.
 * @return status changes of all issues of given project.
 */
public <T> List<T> getChanges(final DataSource dataSource, final int jira, final String pkey, final Class<T> resultType, final boolean timing,
        final boolean summary) {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    final RowMapper<T> rowMapper = new BeanPropertyRowMapper<>(resultType);

    // First, get all created issues (first change)
    final List<T> issues;
    final String sqlPart = ", RESOLUTION AS resolution, PRIORITY AS priority, issuestatus AS status, ASSIGNEE AS assignee,"
            + " REPORTER AS reporter, issuetype AS type, ? AS toStatus, DUEDATE AS dueDate, created"
            + (timing ? ", TIMESPENT AS timeSpent, TIMEESTIMATE AS timeEstimate, TIMEORIGINALESTIMATE AS timeEstimateInit" : "")
            + (summary ? ", SUMMARY AS summary" : "") + "  FROM jiraissue WHERE PROJECT = ?";
    if (getJiraVersion(dataSource).compareTo("6.0.0") < 0) {
        // JIRA 4-5 implementation, use "pkey"
        issues = jdbcTemplate.query("SELECT ID AS id, pkey AS pkey" + sqlPart, rowMapper, STATUS_OPEN, jira);
    } else {
        // JIRA 6+, "pkey" is no more available in the 'jiraissue' table
        issues = jdbcTemplate.query("SELECT ID AS id, CONCAT(?, issuenum) AS pkey" + sqlPart, rowMapper, pkey + "-", STATUS_OPEN, jira);
    }
    return issues;
}
项目:FastSQL    文件:BaseDAO.java   
/**
 * 通过where条件查找一条记录
 * 查找姓名为1年龄大于23的记录  selectOneWhere("name=? and age>?", "wang",23)
 *
 * @param sqlCondition name=:1 and age=:2
 * @param values       "wang",23
 */
public E selectOneWhere(String sqlCondition, Object... values) {
    //sql
    String sql = "SELECT * FROM " + tableName + " WHERE " + sqlCondition;

    List<E> dataList = getSqlFactory().createSQL().useSql(sql)
            .varParameter(values)
            .queryList(new BeanPropertyRowMapper<>(entityClass));

    if (dataList.isEmpty()) {
        return null;
    } else if (dataList.size() == 1) {
        return dataList.get(0);
    } else {
        log.error(tableName + "#findOneWhere()返回多条数据");
        throw new RuntimeException(tableName + "#findOneWhere()返回多条数据");
    }
}
项目:YiDu-Novel    文件:BookcaseServiceImpl.java   
@Override
public List<BookcaseDTO> findWithArticleInfo(BookcaseSearchBean searchBean) {
    // 初期SQL做成
    StringBuffer sql = new StringBuffer();
    sql.append("Select tb.*,ta.lastchapterno,ta.lastchapter,ta.chapters,ta.size,ta.fullflag,ta.lastupdate "
            + " ,ta.imgflag ,ta.pinyin  "
            + "      FROM t_bookcase tb                                                                     "
            + "      LEFT JOIN t_article ta ON tb.articleno = ta.articleno                                  "
            + "WHERE tb.userno= ");
    sql.append(searchBean.getUserno());
    // 添加排序信息
    if (searchBean.getPagination() != null) {
        sql.append(searchBean.getPagination().getSortInfo());
    } else {
        sql.append("ORDER BY ta.lastupdate DESC");
    }
    return yiduJdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<BookcaseDTO>(BookcaseDTO.class));
}
项目:YiDu-Novel    文件:SubscribeServiceImpl.java   
@Override
public List<SubscribeDTO> findAllData(SubscribeSearchBean searchBean) {
    StringBuffer sql = new StringBuffer();
    sql.append("SELECT ts.subscribeno, ta.* , tu.userno,tu.loginid,tu.email FROM t_subscribe ts ");
    sql.append(" join t_article ta on ts.articleno = ta.articleno ");
    sql.append(" join t_user tu on tu.userno = ts.userno ");
    sql.append(" where ta.deleteflag = false and  tu.deleteflag = false ");
    if (Utils.isDefined(searchBean.getUserno())) {
        sql.append(" AND ts.userno =  " + searchBean.getUserno());
    }

    if (Utils.isDefined(searchBean.getDateRange())) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.sss");
        sql.append(" AND ta.lastupdate >= '" + sdf.format(searchBean.getDateRange().getMinimum()) + "'");
        sql.append(" AND ta.lastupdate < '" + sdf.format(searchBean.getDateRange().getMaximum()) + "'");
    }
    sql.append(" order by ts.articleno ");

    List<Object> params = new ArrayList<Object>();
    List<SubscribeDTO> subscribeList = this.yiduJdbcTemplate.query(sql.toString(), params.toArray(),
            new BeanPropertyRowMapper<SubscribeDTO>(SubscribeDTO.class));
    return subscribeList;
}
项目:org.ops4j.pax.transx    文件:HsqlTest.java   
@Test
public void testSpringXaTx() throws Exception {
    DataSource ds = wrap(createHsqlDataSource());
    JdbcTemplate jdbc = new JdbcTemplate(ds);
    TransactionTemplate tx = new TransactionTemplate(ptm);

    jdbc.execute(DROP_USER);
    jdbc.execute(CREATE_TABLE_USER);

    tx.execute(ts -> jdbc.update(INSERT_INTO_USER, 1, "user1"));
    User user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
    assertEquals(new User(1, "user1"), user);
    tx.execute(ts -> jdbc.update(DELETE_FROM_USER_BY_ID, 1));

    tx.execute(ts -> {
        int nb = jdbc.update(INSERT_INTO_USER, 1, "user1");
        ts.setRollbackOnly();
        return nb;
    });
    try {
        user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
        fail("Expected a EmptyResultDataAccessException");
    } catch (EmptyResultDataAccessException e) {
        // expected
    }
}
项目:org.ops4j.pax.transx    文件:HsqlTest.java   
@Test
public void testSpringLocalTx() throws Exception {
    DataSource ds = wrap(createHsqlDataSource());
    JdbcTemplate jdbc = new JdbcTemplate(ds);
    TransactionTemplate tx = new TransactionTemplate(new DataSourceTransactionManager(ds));

    jdbc.execute(DROP_USER);
    jdbc.execute(CREATE_TABLE_USER);

    tx.execute(ts -> jdbc.update(INSERT_INTO_USER, 1, "user1"));
    User user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
    assertEquals(new User(1, "user1"), user);
    tx.execute(ts -> jdbc.update(DELETE_FROM_USER_BY_ID, 1));

    tx.execute(ts -> {
        int nb = jdbc.update(INSERT_INTO_USER, 1, "user1");
        ts.setRollbackOnly();
        return nb;
    });
    try {
        user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
        fail("Expected a EmptyResultDataAccessException");
    } catch (EmptyResultDataAccessException e) {
        // expected
    }
}
项目:org.ops4j.pax.transx    文件:H2Test.java   
@Test
public void testSpringXaTx() throws Exception {
    DataSource ds = wrap(createH2DataSource());
    JdbcTemplate jdbc = new JdbcTemplate(ds);
    TransactionTemplate tx = new TransactionTemplate(ptm);

    jdbc.execute(DROP_USER);
    jdbc.execute(CREATE_TABLE_USER);

    tx.execute(ts -> jdbc.update(INSERT_INTO_USER, 1, "user1"));
    User user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
    assertEquals(new User(1, "user1"), user);
    tx.execute(ts -> jdbc.update(DELETE_FROM_USER_BY_ID, 1));

    tx.execute(ts -> {
        int nb = jdbc.update(INSERT_INTO_USER, 1, "user1");
        ts.setRollbackOnly();
        return nb;
    });
    try {
        user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
        fail("Expected a EmptyResultDataAccessException");
    } catch (EmptyResultDataAccessException e) {
        // expected
    }
}
项目:org.ops4j.pax.transx    文件:H2Test.java   
@Test
public void testSpringLocalTx() throws Exception {
    DataSource ds = wrap(createH2DataSource());
    JdbcTemplate jdbc = new JdbcTemplate(ds);
    TransactionTemplate tx = new TransactionTemplate(new DataSourceTransactionManager(ds));

    jdbc.execute(DROP_USER);
    jdbc.execute(CREATE_TABLE_USER);

    tx.execute(ts -> jdbc.update(INSERT_INTO_USER, 1, "user1"));
    User user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
    assertEquals(new User(1, "user1"), user);
    tx.execute(ts -> jdbc.update(DELETE_FROM_USER_BY_ID, 1));

    tx.execute(ts -> {
        int nb = jdbc.update(INSERT_INTO_USER, 1, "user1");
        ts.setRollbackOnly();
        return nb;
    });
    try {
        user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
        fail("Expected a EmptyResultDataAccessException");
    } catch (EmptyResultDataAccessException e) {
        // expected
    }
}
项目:Yidu    文件:ArticleServiceImpl.java   
@Override
public List<TArticle> findRandomRecommendArticleList(final int count) {
    List<Object> params = new ArrayList<Object>();
    StringBuffer sql = new StringBuffer();
    // 为了提升性能,没有用hibernate,写了nactiveSQL
    sql.append(" SELECT * ");
    sql.append(" FROM  ( ");
    sql.append("    SELECT DISTINCT 1 + floor(random() * (select max(articleno) from t_article) )::integer AS articleno ");
    sql.append("    FROM   generate_series(1, 50) g ");
    sql.append("    ) r ");
    sql.append(" JOIN   t_article USING (articleno) ");
    sql.append(" where  deleteflag = false ");
    sql.append(" AND lastupdate is not null  ");
    sql.append(" AND lastchapterno is not null ");
    sql.append("LIMIT  ?");
    params.add(count);

    return this.yiduJdbcTemplate.query(sql.toString(), params.toArray(), new BeanPropertyRowMapper<TArticle>(
            TArticle.class));
}
项目:Yidu    文件:ArticleServiceImpl.java   
@Override
public List<TArticle> findRelativeArticleList(List<String> keys, String sortCol, boolean isAsc, int limitNum) {

    List<Object> params = new ArrayList<Object>();
    params.addAll(keys);
    params.add(sortCol);

    String cond = "";
    boolean isFirst = true;
    for (int i = 0; i < keys.size(); i++) {
        if (isFirst) {
            cond += " ?  % articlename ";
            isFirst = false;
        } else {
            cond += (" OR ?  % articlename ");
        }
    }
    String sql = "SELECT * FROM t_article where " + cond + "  order by ?  " + (isAsc ? "ASC" : "DESC") + " limit "
            + limitNum;
    return this.yiduJdbcTemplate.query(sql, params.toArray(), new BeanPropertyRowMapper<TArticle>(TArticle.class));
}
项目:Yidu    文件:SubscribeServiceImpl.java   
@Override
public List<SubscribeDTO> findAllData(SubscribeSearchBean searchBean) {
    StringBuffer sql = new StringBuffer();
    sql.append("SELECT ts.subscribeno, ta.* , tu.userno,tu.loginid,tu.email FROM t_subscribe ts ");
    sql.append(" join t_article ta on ts.articleno = ta.articleno ");
    sql.append(" join t_user tu on tu.userno = ts.userno ");
    sql.append(" where ta.deleteflag = false and  tu.deleteflag = false ");
    if (Utils.isDefined(searchBean.getUserno())) {
        sql.append(" AND ts.userno =  " + searchBean.getUserno());
    }

    if (Utils.isDefined(searchBean.getDateRange())) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.sss");
        sql.append(" AND ta.lastupdate >= '" + sdf.format(searchBean.getDateRange().getMinimum()) + "'");
        sql.append(" AND ta.lastupdate < '" + sdf.format(searchBean.getDateRange().getMaximum()) + "'");
    }
    sql.append(" order by ts.articleno ");

    List<Object> params = new ArrayList<Object>();
    List<SubscribeDTO> subscribeList = this.yiduJdbcTemplate.query(sql.toString(), params.toArray(),
            new BeanPropertyRowMapper<SubscribeDTO>(SubscribeDTO.class));
    return subscribeList;
}
项目:zuul-gateway    文件:CustomRouteLocator.java   
private Map<String, ZuulRoute> locateRoutesFromDB(){
    Map<String, ZuulRoute> routes = new LinkedHashMap<>();
    List<ZuulRouteVO> results = jdbcTemplate.query("select * from gateway_api_define where enabled = true ",new BeanPropertyRowMapper<>(ZuulRouteVO.class));
    for (ZuulRouteVO result : results) {
        if(org.apache.commons.lang3.StringUtils.isBlank(result.getPath()) /*|| org.apache.commons.lang3.StringUtils.isBlank(result.getUrl())*/ ){
            continue;
        }
        ZuulRoute zuulRoute = new ZuulRoute();
        try {
            org.springframework.beans.BeanUtils.copyProperties(result,zuulRoute);
        } catch (Exception e) {
            logger.error("=============load zuul route info from db with error==============",e);
        }
       // zuulRoute.setUrl(null);
       // zuulRoute.setRetryable(null);
        routes.put(zuulRoute.getPath(),zuulRoute);
    }
    return routes;
}
项目:batch-scheduler    文件:BatchGroupRunningDaoImpl.java   
@Override
public List<BatchGroupStatusEntity> findAll(String batchId, String asOfDate) {
    RowMapper<BatchGroupStatusEntity> rowMapper = new BeanPropertyRowMapper<>(BatchGroupStatusEntity.class);
    List<BatchGroupStatusEntity> list = jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_201"), rowMapper, batchId, asOfDate);
    for (BatchGroupStatusEntity bh : list) {

        Integer totalCnt = getTotalJobs(batchId, bh.getSuiteKey(), asOfDate);

        Integer completeCnt = getCompleteJobs(batchId, bh.getSuiteKey(), asOfDate);

        bh.setTotalJobsCnt(totalCnt);

        bh.setCompleteJobsCnt(completeCnt);
    }
    return list;
}
项目:plugin-bt-jira    文件:JiraDao.java   
/**
 * Return ordered custom fields by the given identifiers
 * 
 * @param dataSource
 *            The data source of JIRA database.
 * @param customFields
 *            the expected custom fields identifiers.
 * @param project
 *            Jira project identifier. Required to filter custom field agains contexts.
 * @return ordered custom fields by their identifier.
 */
public Map<Integer, CustomFieldEditor> getCustomFieldsById(final DataSource dataSource, final Set<Integer> customFields, final int project) {
    if (customFields.isEmpty()) {
        // No custom field, we save an useless query
        return new HashMap<>();
    }

    // Get map as list
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    final RowMapper<CustomFieldEditor> rowMapper = new BeanPropertyRowMapper<>(CustomFieldEditor.class);
    final List<CustomFieldEditor> resultList = jdbcTemplate
            .query("SELECT ID AS id, TRIM(cfname) AS name, DESCRIPTION AS description, CUSTOMFIELDTYPEKEY AS fieldType FROM customfield WHERE ID IN ("
                    + newIn(customFields) + ") ORDER BY id", rowMapper, customFields.toArray());

    // Make a Map of valid values for single/multi select values field
    final Map<Integer, CustomFieldEditor> result = new LinkedHashMap<>();
    addListToMapIdentifier(dataSource, resultList, result, project);
    return result;
}
项目:plugin-bt-jira    文件:JiraDao.java   
/**
 * Return all custom fields matching to the given names
 * 
 * @param dataSource
 *            The data source of JIRA database.
 * @param customFields
 *            the expected custom fields names.
 * @param project
 *            Jira project identifier. Required to filter custom field against contexts.
 * @return all custom field configurations referenced in the given project and matching the required names.
 */
public Map<String, CustomFieldEditor> getCustomFields(final DataSource dataSource, final Set<String> customFields, final int project) {
    if (customFields.isEmpty()) {
        // No custom field, we save useless queries
        return new HashMap<>();
    }

    // Get map as list
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    final RowMapper<CustomFieldEditor> rowMapper = new BeanPropertyRowMapper<>(CustomFieldEditor.class);
    final List<CustomFieldEditor> resultList = jdbcTemplate
            .query("SELECT cf.ID AS id, TRIM(cf.cfname) AS name, cf.DESCRIPTION AS description, cf.CUSTOMFIELDTYPEKEY AS fieldType FROM customfield AS cf WHERE TRIM(cf.cfname) IN ("
                    + newIn(customFields) + ")", rowMapper, customFields.toArray());

    // Also add the translated items
    final List<CustomFieldEditor> resultListTranslated = jdbcTemplate.query(
            "SELECT cf.ID AS id, TRIM(cf.cfname) AS originalName, TRIM(ps.propertyvalue) AS name, cf.cfname AS originalName, cf.DESCRIPTION AS description, "
                    + "cf.CUSTOMFIELDTYPEKEY AS fieldType "
                    + "FROM customfield AS cf INNER JOIN propertyentry AS pe ON pe.ENTITY_ID = cf.ID INNER JOIN propertystring AS ps ON pe.ID = ps.ID "
                    + "WHERE pe.ENTITY_NAME=? AND PROPERTY_KEY LIKE ? AND TRIM(ps.propertyvalue) IN (" + newIn(customFields) + ")",
            rowMapper, ArrayUtils.addAll(new String[] { "CustomField", "%FR" }, customFields.toArray()));

    // Make a Map of valid values for single/multi select values field
    final Map<String, CustomFieldEditor> result = new HashMap<>();
    addListToMap(dataSource, resultList, result, project);
    addListToMap(dataSource, resultListTranslated, result, project);
    return result;
}
项目:hauth-java    文件:DomainShareDaoImpl.java   
@Override
public Set<String> findAll(String targetDomainId) {
    RowMapper<DomainShareEntity> rowMapper = new BeanPropertyRowMapper<>(DomainShareEntity.class);
    List<DomainShareEntity> list = jdbcTemplate.query(SqlDefine.sys_rdbms_116, rowMapper, targetDomainId);

    Set<String> set = new HashSet<>();
    set.add(targetDomainId);
    for (DomainShareEntity m : list) {
        set.add(m.getDomain_id());
    }
    return set;
}
项目:hauth-java    文件:MenuDaoImpl.java   
@Override
public MenuEntity getDetails(String resId) {
    RowMapper<MenuEntity> rowMapper = new BeanPropertyRowMapper<>(MenuEntity.class);
    List<MenuEntity> list = jdbcTemplate.query(SqlDefine.sys_rdbms_089, rowMapper, resId);
    if (list.size() == 1) {
        return list.get(0);
    }
    return null;
}
项目:batch-scheduler    文件:BatchGroupDaoImpl.java   
private Set<String> getChildren(String batchId, String id) {
    RowMapper<GroupDependencyEntity> rowMapper = new BeanPropertyRowMapper<>(GroupDependencyEntity.class);
    List<GroupDependencyEntity> list = jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_073"), rowMapper, batchId);

    Set<String> set = new HashSet<>();
    children(list, id, set);
    set.add(id);

    for (BatchGroupEntity m : getOwner(id)) {
        set.add(m.getUpSuiteKey());
    }
    return set;
}
项目:crypto-exchange    文件:DatabaseManager.java   
@SuppressWarnings("unchecked")
<T> RowMapper<T> getRowMapper(Class<T> clazz) {
    RowMapper<?> rowMapper = this.rowMappers.get(clazz);
    if (rowMapper == null) {
        rowMapper = new BeanPropertyRowMapper<>(clazz);
        rowMappers.put(clazz, rowMapper);
    }
    return (RowMapper<T>) rowMapper;
}
项目:common-dao    文件:SelectSupport.java   
public <T> PageInfo<T> selectByPage(int pageNum, int pageSize, T record) {

        Class<T> clazz = (Class<T>) record.getClass();
        Entity entity=getEntity(record.getClass());
        try {
            StringBuffer sql = new StringBuffer(SqlHelper.selectFromTable(entity.getTableName()));
            Set<Entity.Column> notNullColumn = getNotNullColumn(record, entity);
            Object primaryKeyValue = entity.getPrimaryKey().getField().get(record);
            if (primaryKeyValue!=null) {
                notNullColumn = Collections.singleton(entity.getPrimaryKey());
            }
            MapSqlParameterSource parameterMap = getParameterMap(record, notNullColumn, false);
            sql.append(SqlHelper.whereClause(notNullColumn));
            sql.append(SqlHelper.limitClause((pageNum-1) * pageSize, pageSize));
            String countSql=countSqlParser.getSimpleCountSql(sql.toString());
            //查询 count
            Integer count = jdbcTemplate.queryForObject(countSql, parameterMap, Integer.class);
            //分页查询
            List<T> result=jdbcTemplate.query(sql.toString(), getParameterMap(record, notNullColumn, false), new BeanPropertyRowMapper<>(clazz));

            System.out.println(sql.toString());
            System.out.println("count sql ===> "+countSql);

            PageInfo<T> pageInfo = new PageInfo<>(result, count == null ? 0 : count, pageNum,pageSize);

            return pageInfo;
//            return jdbcTemplate.query(sql.toString(), getParameterMap(record, notNullColumn, false), new BeanPropertyRowMapper<>(clazz));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
项目:common-dao    文件:SelectSupport.java   
public  List<?> selectByExample(Example example) {
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.selectFromTable(example.getTableName()));
    sql.append(SqlHelper.exampleWhereClause(example));
    System.out.println(sql.toString());
    return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(example.getEntityClass()));
}
项目:TITAN    文件:MonitorDao.java   
/**
 * @desc 根据IP查询数据集合
 *
 * @author liuliang
 *
 * @param serverType 服务类型 0:agent 1:目标机器
 * @param ips
 * @return
 */
public List<Monitor> queryListByIP(int serverType,String ips) throws Exception{
    String[] arr = ips.split("\\,");
    StringBuilder sb = new StringBuilder();
    for(int i=0,length = arr.length;i<length;i++) {
        sb.append("'").append(arr[i]).append("'");
        if((i+1) != length) {
            sb.append(",");
        }
    }
    String sql = "SELECT * FROM t_monitor WHERE server_type = " + serverType + " AND ip IN (" + sb.toString() + ")";
       return jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(Monitor.class));
}
项目:TITAN    文件:MonitorDao.java   
/**
 * @desc
 *
 * @author liuliang
 *
 * @param i
 * @param ips
 * @param startTime
 * @param endTime
 * @return
 */
public List<Monitor> queryListByIP(int serverType, String ips, long startTime, long endTime) throws Exception{
    String[] arr = ips.split("\\,");
    StringBuilder sb = new StringBuilder();
    for(int i=0,length = arr.length;i<length;i++) {
        sb.append("'").append(arr[i]).append("'");
        if((i+1) != length) {
            sb.append(",");
        }
    }
    String sql = "SELECT * FROM t_monitor WHERE server_type = " + serverType + " AND ip IN (" + sb.toString() + ") AND create_time >= " + startTime+ " AND create_time <= " + endTime + " ORDER BY create_time DESC";
       return jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(Monitor.class));
}
项目:TITAN    文件:MonitorSetDao.java   
/**
 * @desc 根据场景ID查询监控集
 *
 * @author liuliang
 *
 * @param sceneId 场景ID
 * @return
 */
public MonitorSet query(long sceneId) throws Exception{
    String sql = "SELECT * FROM t_monitor_set WHERE scene_id = ?";
    List<MonitorSet> dataList = jdbcTemplate.query(sql,new Object[]{sceneId},BeanPropertyRowMapper.newInstance(MonitorSet.class));
    if((null != dataList) && (0 < dataList.size())){
        return dataList.get(0);
    }else{
        return null;
    }
}
项目:spring-boot-frameset    文件:LearnDaoImpl.java   
@Override
public LearnResouce queryLearnResouceById(Long id) {
    List<LearnResouce> list = jdbcTemplate.query("select * from learn_resource where id = ?", new Object[]{id}, new BeanPropertyRowMapper(LearnResouce.class));
    if(null != list && list.size()>0){
        LearnResouce learnResouce = list.get(0);
        return learnResouce;
    }else{
        return null;
    }
}
项目:org.ops4j.pax.transx    文件:HsqlTest.java   
@Test
public void testSpring() throws Exception {
    DataSource ds = wrap(createHsqlDataSource());
    JdbcTemplate jdbc = new JdbcTemplate(ds);

    jdbc.execute(DROP_USER);
    jdbc.execute(CREATE_TABLE_USER);

    jdbc.update(INSERT_INTO_USER, 1, "user1");
    User user = jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1);
    assertEquals(new User(1, "user1"), user);

    jdbc.update(DELETE_FROM_USER_BY_ID, 1);
}
项目:Yidu    文件:UserServiceImpl.java   
@Override
public TUser findByLoginInfoByJDBC(final String loginid, final String password) {
    String sql = "select * from t_user where loginid = ? AND password = ? AND deleteflag=false";
    List<Object> params = new ArrayList<Object>();
    params.add(loginid);
    params.add(password);
    List<TUser> userinfoList = this.yiduJdbcTemplate.query(sql, params.toArray(), new BeanPropertyRowMapper<TUser>(
            TUser.class));
    if (userinfoList.size() > 0) {
        return userinfoList.get(0);
    }
    return null;
}
项目:batch-scheduler    文件:GroupTaskDaoImpl.java   
@Transactional
@Override
public List<GroupTaskEntity> getTaskDependency(String id) {
    RowMapper<GroupTaskEntity> rowMapper = new BeanPropertyRowMapper<>(GroupTaskEntity.class);
    List<GroupTaskEntity> list = jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_134"), rowMapper, id);
    return list;
}
项目:Yidu    文件:ArticleServiceImpl.java   
@Override
public TArticle findByPinyinRegularRxpressions(String pinyin) {
    String sql = "SELECT * FROM t_article where pinyin ~ '^" + pinyin + "[\\d]*$' order by pinyin desc;";
    List<TArticle> articleList = this.yiduJdbcTemplate.query(sql, new BeanPropertyRowMapper<TArticle>(
            TArticle.class));
    if (articleList != null && articleList.size() > 0) {
        return articleList.get(0);
    }
    return null;
}
项目:nakadi-producer-spring-boot-starter    文件:EventLogRepositoryImpl.java   
@Override
public EventLog findOne(Integer id) {
    Map<String, Object> namedParameterMap = new HashMap<>();
    namedParameterMap.put("id", id);
    try {
        return jdbcTemplate.queryForObject(
            "SELECT * FROM nakadi_events.event_log where id = :id",
            namedParameterMap,
            new BeanPropertyRowMapper<>(EventLog.class)
        );
    } catch (EmptyResultDataAccessException ignored) {
        return null;
    }
}
项目:batch-scheduler    文件:BatchArgumentDaoImpl.java   
@Override
public List findAll(String domainId, String batchId) {
    RowMapper<BatchArgumentEntiry> rowMapper = new BeanPropertyRowMapper<BatchArgumentEntiry>(BatchArgumentEntiry.class);

    // 获取固定参数,任务参数,任务组参数
    List<BatchArgumentEntiry> list = jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_163"), rowMapper, domainId, batchId);

    //获取批次类型参数
    List<BatchArgumentEntiry> list2 = jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_164"), rowMapper, domainId, batchId);

    return bindAsofdate(list, list2);
}
项目:nakadi-producer-spring-boot-starter    文件:EventLogRepositoryImpl.java   
@Override
public Collection<EventLog> findByLockedByAndLockedUntilGreaterThan(String lockedBy, Instant lockedUntil) {
    Map<String, Object> namedParameterMap = new HashMap<>();
    namedParameterMap.put("lockedBy", lockedBy);
    namedParameterMap.put("lockedUntil", toSqlTimestamp(lockedUntil));
    return jdbcTemplate.query(
        "SELECT * FROM nakadi_events.event_log where locked_by = :lockedBy and locked_until > :lockedUntil",
        namedParameterMap,
        new BeanPropertyRowMapper<>(EventLog.class)
    );
}
项目:batch-scheduler    文件:MenuDaoImpl.java   
@Override
public MenuEntity getDetails(String resId) {
    RowMapper<MenuEntity> rowMapper = new BeanPropertyRowMapper<>(MenuEntity.class);
    List<MenuEntity> list = jdbcTemplate.query(sqlText.getSql("sys089"), rowMapper, resId);
    if (list.size() == 1) {
        return list.get(0);
    }
    return null;
}
项目:batch-scheduler    文件:MenuDaoImpl.java   
@Override
public ThemeValueEntity getThemeDetails(String themeId, String resId) {
    RowMapper<ThemeValueEntity> rowMapper = new BeanPropertyRowMapper<>(ThemeValueEntity.class);
    List<ThemeValueEntity> list = jdbcTemplate.query(sqlText.getSql("sys070"), rowMapper, themeId, resId);
    if (list.size() == 1) {
        return list.get(0);
    }
    return null;
}
项目:batch-scheduler    文件:BatchGroupRunningDaoImpl.java   
@Override
public BatchGroupStatusEntity getDetails(String batchId, String suiteKey, String asOfDate) {

    RowMapper<BatchGroupStatusEntity> rowMapper = new BeanPropertyRowMapper<>(BatchGroupStatusEntity.class);
    BatchGroupStatusEntity batchGroupStatusEntity = jdbcTemplate.queryForObject(batchSqlText.getSql("sys_rdbms_205"), rowMapper, batchId, suiteKey, asOfDate);

    Integer totalCnt = getTotalJobs(batchId, suiteKey, asOfDate);

    Integer completeCnt = getCompleteJobs(batchId, suiteKey, asOfDate);

    Integer ratio = 100;

    if (totalCnt != 0) {
        ratio = 100 * completeCnt / totalCnt;
    } else {
        String statusCd = batchGroupStatusEntity.getStatus();
        if (statusCd.equals("0") || statusCd.equals("1")) {
            ratio = 0;
        }
    }

    batchGroupStatusEntity.setTotalJobsCnt(totalCnt);

    batchGroupStatusEntity.setCompleteJobsCnt(completeCnt);

    batchGroupStatusEntity.setRatio(ratio);

    return batchGroupStatusEntity;
}
项目:batch-scheduler    文件:BatchDefineDaoImpl.java   
@Override
public BatchDefineEntity findDetailsByBatchId(String batchId) {
    RowMapper<BatchDefineEntity> rowMapper = BeanPropertyRowMapper.newInstance(BatchDefineEntity.class);
    BatchDefineEntity row = jdbcTemplate.queryForObject(batchSqlText.getSql("sys_rdbms_210"), rowMapper, batchId);
    row.setAsOfDate(TimeFormat.formatTime(row.getAsOfDate()));
    row.setCompleteDate(TimeFormat.formatTime(row.getCompleteDate()));
    return row;
}
项目:EasyTransaction    文件:DataBaseTransactionLogReaderImpl.java   
@Override
public List<LogCollection> getUnfinishedLogs(LogCollection locationId,
        int pageSize, Date createTimeFloor) {

    JdbcTemplate localJdbcTemplate = getJdbcTemplate();

    List<DataBaseTransactionLogDetail> query;

    List<String> transIdList = null;
    if(locationId != null){
        String transIdLocation = EasyTransStaticHelper.getTransId(locationId.getAppId(), locationId.getBusCode(), locationId.getTrxId());
        transIdList = localJdbcTemplate.queryForList("select trans_log_id from trans_log_unfinished where create_time <= ? and trans_log_id > ? ORDER BY trans_log_id LIMIT ?", new Object[]{createTimeFloor,transIdLocation,pageSize},String.class);
    }else{
        transIdList = localJdbcTemplate.queryForList("select trans_log_id from trans_log_unfinished where create_time <= ? ORDER BY trans_log_id LIMIT ?", new Object[]{createTimeFloor,pageSize},String.class);
    }

    if(transIdList == null || transIdList.size() ==0){
        return new ArrayList<LogCollection>();
    }

    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(localJdbcTemplate);
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("ids", transIdList);
    query = namedTemplate.query("select * from trans_log_detail where trans_log_id in (:ids)  order by trans_log_id,log_detail_id;", paramSource,new BeanPropertyRowMapper<DataBaseTransactionLogDetail>(DataBaseTransactionLogDetail.class));


    List<LogCollection> result = new ArrayList<LogCollection>();
    List<DataBaseTransactionLogDetail> currentDoList = new ArrayList<DataBaseTransactionLogDetail>();
    List<Content> currentContentList = new ArrayList<Content>();
    String currentId = null;
    for(DataBaseTransactionLogDetail detailDo:query){
        if(!detailDo.getTransLogId().equals(currentId)){
            addToResult(result, currentDoList, currentContentList);
            currentContentList.clear();
            currentDoList.clear();
            currentId = detailDo.getTransLogId();
        }

        currentDoList.add(detailDo);
        currentContentList.addAll(deserializer(detailDo));
    }
    addToResult(result, currentDoList, currentContentList);

    return result;
}