Search in sources :

Example 1 with DeleteAction

use of info.xiancloud.dao.core.action.delete.DeleteAction in project xian by happyyangyuan.

the class BaseDeleteDB method getActions.

@Override
public SqlAction[] getActions() {
    return new SqlAction[] { new DeleteAction() {

        @Override
        public String tableName() {
            Object tableName = getMap().get("$tableName");
            if (tableName instanceof String) {
                Table table = TableHeader.getTable(getMap().get("$tableName").toString());
                if (table.getType().equals(Table.Type.view)) {
                    throw new RuntimeException(String.format("视图:%s,不允许操作 BaseDeleteDB", table.getName()));
                }
                return table.getName();
            }
            return "";
        }

        @Override
        protected String[] searchConditions() {
            List<String> whereList = new ArrayList<>();
            Object tableName = getMap().get("$tableName");
            if (tableName instanceof String) {
                Map<String, Class<?>> columns = TableHeader.getTableColumnTypeMap(tableName.toString(), getSqlDriver());
                for (Entry<String, Class<?>> entry : columns.entrySet()) {
                    String key = entry.getKey();
                    Object value = getMap().get(StringUtil.underlineToCamel(key));
                    if (value != null) {
                        String[] array = fmtObjectToStrArray(value);
                        if (array != null) {
                            whereList.add(String.format("%s in {%s}", key, StringUtil.underlineToCamel(key)));
                        } else {
                            whereList.add(String.format("%s = {%s}", key, StringUtil.underlineToCamel(key)));
                        }
                    }
                }
            }
            // 这里不允许执行整表删除功能
            if (whereList.size() > 0) {
                return whereList.toArray(new String[] {});
            }
            return new String[] { "1 < 0" };
        }
    } };
}
Also used : Table(info.xiancloud.dao.core.model.ddl.Table) ArrayList(java.util.ArrayList) DeleteAction(info.xiancloud.dao.core.action.delete.DeleteAction) SqlAction(info.xiancloud.dao.core.action.SqlAction)

Aggregations

SqlAction (info.xiancloud.dao.core.action.SqlAction)1 DeleteAction (info.xiancloud.dao.core.action.delete.DeleteAction)1 Table (info.xiancloud.dao.core.model.ddl.Table)1 ArrayList (java.util.ArrayList)1