use of com.baidu.unbiz.common.genericdao.operator.Match in project disconf by knightliao.
the class QueryGenerator method appendMatches.
public void appendMatches(Collection<Match> matches, StringBuilder sb, List<Object> params) {
for (Match match : matches) {
Object value = match.getValue();
String column = match.getColumn();
if (value == null) {
sb.append(column).append(" is null");
} else if (value instanceof LikeParam) {
sb.append(column).append(" like ?");
params.add('%' + ((LikeParam) value).getWord() + '%');
} else if (value instanceof BetweenParam) {
BetweenParam bp = (BetweenParam) value;
Object start = bp.getStart();
Object end = bp.getEnd();
if (start == null && end == null) {
sb.append("1!=1");
} else if (start == null) {
sb.append(column).append(" <= ?");
params.add(end);
} else if (end == null) {
sb.append(column).append(" >= ?");
params.add(start);
} else {
sb.append(column).append(" between ? and ?");
params.add(start);
params.add(end);
}
} else if (value instanceof GteParam) {
sb.append(column).append(" >= ?");
params.add(((GteParam) value).getValue());
} else if (value instanceof GreaterThanParam) {
sb.append(column).append(" > ?");
params.add(((GreaterThanParam) value).getValue());
} else if (value instanceof LteParam) {
sb.append(column).append(" <= ?");
params.add(((LteParam) value).getValue());
} else if (value instanceof LessThanParam) {
sb.append(column).append(" < ?");
params.add(((LessThanParam) value).getValue());
} else if (value instanceof ExpressionParam) {
sb.append('(').append(column).append(')');
} else {
// 如果是取反的参数
boolean reverse = value instanceof NotParam;
if (reverse) {
value = ((NotParam) value).getValue();
}
if (value == null && reverse) {
sb.append(column).append(" is not null");
} else if (value instanceof Collection<?>) {
Collection<?> coll = (Collection<?>) value;
if (coll.size() == 0) {
sb.append(reverse ? "1=1" : "1!=1");
} else if (coll.size() == 1) {
sb.append(column).append(reverse ? "!=?" : "=?");
params.add(coll.iterator().next());
} else {
sb.append(column).append(reverse ? " not in " : " in");
sb.append(connectObjects(coll));
params.addAll(coll);
}
} else if (value.getClass().isArray()) {
Object[] array = (Object[]) value;
if (array.length == 0) {
sb.append(reverse ? "1=1" : "1!=1");
} else if (array.length == 1) {
sb.append(column).append(reverse ? "!=?" : "=?");
params.add(array[0]);
} else {
sb.append(column).append(reverse ? " not in " : " in");
sb.append(connectObjects(Arrays.asList(array)));
for (Object o : array) {
params.add(o);
}
}
} else {
sb.append(column).append(reverse ? "!=?" : "=?");
params.add(value);
}
}
sb.append(" and ");
}
sb.delete(sb.length() - 5, sb.length());
}
use of com.baidu.unbiz.common.genericdao.operator.Match in project disconf by knightliao.
the class ConfigDaoImpl method getConfigList.
/**
*
*/
@Override
public List<Config> getConfigList(Long appId, Long envId, String version, Boolean hasValue) {
List<Match> matchs = new ArrayList<Match>();
matchs.add(new Match(Columns.APP_ID, appId));
matchs.add(new Match(Columns.ENV_ID, envId));
matchs.add(new Match(Columns.VERSION, version));
matchs.add(new Match(Columns.STATUS, Constants.STATUS_NORMAL));
if (hasValue) {
return find(matchs, new ArrayList<Order>());
} else {
return findColumns(matchs, new String[] { Columns.CONFIG_ID, Columns.TYPE, Columns.NAME, Columns.CREATE_TIME, Columns.UPDATE_TIME, Columns.STATUS, Columns.APP_ID, Columns.ENV_ID, Columns.VERSION });
}
}
use of com.baidu.unbiz.common.genericdao.operator.Match in project disconf by knightliao.
the class ConfigDaoImpl method getConfigList.
/**
*
*/
@Override
public DaoPageResult<Config> getConfigList(Long appId, Long envId, String version, Page page) {
DaoPage daoPage = DaoUtils.daoPageAdapter(page);
List<Match> matchs = new ArrayList<Match>();
matchs.add(new Match(Columns.APP_ID, appId));
matchs.add(new Match(Columns.ENV_ID, envId));
matchs.add(new Match(Columns.VERSION, version));
matchs.add(new Match(Columns.STATUS, Constants.STATUS_NORMAL));
return page2(matchs, daoPage);
}
use of com.baidu.unbiz.common.genericdao.operator.Match in project disconf by knightliao.
the class QueryGenerator method getKeyMatches.
/**
* 获取主键匹配的条件
*
* @param id
*
* @return 上午9:45:33 created by Darwin(Tianxin)
*/
public List<Match> getKeyMatches(KEY id) {
Set<String> keyColumn = orMapping.getKeyColumn();
List<Match> matches = new ArrayList<Match>(keyColumn.size());
for (String column : keyColumn) {
Object value = getKeyColumnValue(column, id);
matches.add(new Match(column, value));
}
return matches;
}
use of com.baidu.unbiz.common.genericdao.operator.Match in project disconf by knightliao.
the class QueryGenerator method getUpdateQuery.
public List<Query> getUpdateQuery(List<ENTITY> entities) {
List<Query> queries = new ArrayList<Query>(entities.size());
Set<String> modifiableColumns = orMapping.getModifiableColumns();
for (ENTITY entity : entities) {
List<Match> matches = getKeyMatches(entity.getId());
List<Modify> modifies = new ArrayList<Modify>(modifiableColumns.size());
for (String column : modifiableColumns) {
Object value = getColumnValue(column, entity);
modifies.add(new Modify(column, value));
}
queries.add(getUpdateQuery(modifies, matches));
}
return queries;
}
Aggregations