use of com.baidu.unbiz.common.genericdao.operator.Query in project disconf by knightliao.
the class QueryGenerator method getSelectQuery.
public Query getSelectQuery(Collection<Match> matches, Order... orders) {
Query query = getSelectQuery(matches);
if (orders == null || orders.length == 0) {
return query;
}
// 加入排序
StringBuilder sb = new StringBuilder(query.getSql());
sb.append(" order by ");
for (Order entry : orders) {
sb.append(entry.getColumn()).append(entry.isAsc() ? " asc" : " desc").append(',');
}
sb.deleteCharAt(sb.length() - 1);
query.setSql(sb.toString());
return query;
}
use of com.baidu.unbiz.common.genericdao.operator.Query in project disconf by knightliao.
the class GenericDao method findValue.
public <T> T findValue(String column, Class<T> tClass, Match... matches) {
Query query = queryGenerator.getMiniSelectQuery(Arrays.asList(column), matches);
List<T> ts = findOneColumn(query.getSql() + " limit 1", query.getParams(), 1, tClass);
if (CollectionUtils.isEmpty(ts)) {
return null;
} else {
return ts.get(0);
}
}
use of com.baidu.unbiz.common.genericdao.operator.Query in project disconf by knightliao.
the class GenericDao method count.
/**
* 查询符合条件组合的记录数
*
* @param matches
*
* @return 2013-8-26 下午3:04:02 created by wangchongjie
*/
public int count(List<Match> matches) {
Query query = queryGenerator.getCountQuery(matches);
// 执行操作
String sql = query.getSql();
return countBySQL(sql, query.getParams());
}
use of com.baidu.unbiz.common.genericdao.operator.Query in project disconf by knightliao.
the class GenericDao method update.
/**
* 批量更新
*
* @param entities
*
* @return
*/
public int update(List<ENTITY> entities) {
if (entities == null || entities.size() == 0) {
recordLog(" param entity is null!");
return 0;
}
final List<Query> queries = queryGenerator.getUpdateQuery(entities);
String sql = queries.get(0).getSql();
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement stmt, int index) throws SQLException {
int i = 1;
List<Object> params = queries.get(index).getParams();
for (Object o : params) {
stmt.setObject(i++, o);
}
}
public int getBatchSize() {
return queries.size();
}
});
return entities.size();
}
use of com.baidu.unbiz.common.genericdao.operator.Query in project disconf by knightliao.
the class QueryGenerator method getPageQuery.
public Query getPageQuery(int curPage, int pageSize, Collection<Match> matches, Order... orders) {
Query query = getSelectQuery(matches, orders);
if (curPage < 0 || pageSize <= 0) {
return query;
}
StringBuilder sb = new StringBuilder(query.getSql());
List<Object> params = query.getParams();
// 设置limit
int offset = (curPage) * pageSize;
int limit = pageSize;
sb.append(" limit ?, ?");
params.add(offset);
params.add(limit);
query.setSql(sb.toString());
return query;
}
Aggregations