use of cn.hutool.db.sql.Condition in project hutool by looly.
the class AnsiSqlDialect method psForUpdate.
@Override
public PreparedStatement psForUpdate(Connection conn, Entity entity, Query query) throws SQLException {
Assert.notNull(query, "query must be not null !");
final Condition[] where = query.getWhere();
if (ArrayUtil.isEmpty(where)) {
// 对于无条件的删除语句直接抛出异常禁止,防止误删除
throw new SQLException("No 'WHERE' condition, we can't prepare statement for update everything.");
}
final SqlBuilder update = SqlBuilder.create(wrapper).update(entity).where(where);
return StatementUtil.prepareStatement(conn, update);
}
use of cn.hutool.db.sql.Condition in project hutool by looly.
the class DbUtil method buildConditions.
/**
* 通过实体对象构建条件对象
*
* @param entity 实体对象
* @return 条件对象
*/
public static Condition[] buildConditions(Entity entity) {
if (null == entity || entity.isEmpty()) {
return null;
}
final Condition[] conditions = new Condition[entity.size()];
int i = 0;
Object value;
for (Entry<String, Object> entry : entity.entrySet()) {
value = entry.getValue();
if (value instanceof Condition) {
conditions[i++] = (Condition) value;
} else {
conditions[i++] = new Condition(entry.getKey(), value);
}
}
return conditions;
}
use of cn.hutool.db.sql.Condition in project hutool by looly.
the class AnsiSqlDialect method psForDelete.
@Override
public PreparedStatement psForDelete(Connection conn, Query query) throws SQLException {
Assert.notNull(query, "query must be not null !");
final Condition[] where = query.getWhere();
if (ArrayUtil.isEmpty(where)) {
// 对于无条件的删除语句直接抛出异常禁止,防止误删除
throw new SQLException("No 'WHERE' condition, we can't prepared statement for delete everything.");
}
final SqlBuilder delete = SqlBuilder.create(wrapper).delete(query.getFirstTableName()).where(where);
return StatementUtil.prepareStatement(conn, delete);
}
Aggregations