Search in sources :

Example 76 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class Proclet method doAction.

@Override
public void doAction(Core core, ActionHelper ah) throws ServletException, IOException {
    HttpServletRequest req = ah.getRequest();
    HttpServletResponse rsp = ah.getResponse();
    try {
        this._jspService(new Request(req), rsp);
    } catch (ServletException ex) {
        Throwable ax = ex.getCause();
        if (ax == null) {
            ax = ex;
        }
        if (ax instanceof HongsCause) {
            ah.fault((HongsCause) ax);
        } else {
            ah.fault(new HongsException(ax));
        }
    } catch (RuntimeException ax) {
        if (ax instanceof HongsCause) {
            ah.fault((HongsCause) ax);
        } else {
            ah.fault(new HongsException(ax));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HongsCause(io.github.ihongs.HongsCause) HongsException(io.github.ihongs.HongsException) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 77 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class Batch method close.

@Override
public void close() {
    if (!servs.isShutdown()) {
        servs.shutdownNow();
    }
    if (back == null) {
        if (!tasks.isEmpty()) {
            CoreLogger.error("There has {} task(s) not run.", tasks.size());
        }
        return;
    }
    /**
     * 将缓冲区滞留的任务写回 tasks
     * 即使重启后 servs 数量改变也没有关系
     */
    Collection<T> c = new ArrayList();
    for (Collection<T> taskz : cache) {
        c.addAll(taskz);
        taskz.clear();
    }
    c.addAll(tasks);
    tasks.clear();
    tasks.addAll(c);
    File file;
    file = back;
    back = null;
    if (!tasks.isEmpty()) {
        try {
            save(file);
            CoreLogger.trace("There has {} task(s) not run, save to '{}'.", tasks.size(), back.getPath());
        } catch (HongsException ex) {
            CoreLogger.error(ex);
        }
    } else if (file.exists()) {
        file.delete();
    }
}
Also used : HongsException(io.github.ihongs.HongsException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 78 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class Table method valiException.

private HongsException valiException(int code, String error, String fieldName, String... otherParams) {
    List<String> trans = new ArrayList(otherParams.length + 2);
    trans.add(db.name + "." + name);
    trans.add(/*the*/
    fieldName);
    trans.addAll(Arrays.asList(otherParams));
    return new HongsException(code, error + " (Table:" + name + ")").setLocalizedOptions(trans.toArray(new String[] {}));
}
Also used : HongsException(io.github.ihongs.HongsException) ArrayList(java.util.ArrayList)

Example 79 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class Loop method next.

@Override
public Map next() {
    // 判断是否到达末尾
    if (!hasNext()) {
        this.close();
        return null;
    }
    il = null;
    // 获取当前字段类型
    try {
        // getMetaData();
        getTypeDict();
    } catch (HongsException ex) {
        this.close();
        throw ex.toExemption();
    }
    // 获取行内每列数据
    try {
        int i = 0;
        Map<String, Object> row = new LinkedHashMap();
        if (ib) {
            for (Map.Entry<String, Class> et : td.entrySet()) {
                // row.put(et.getKey() , rs.getString(++ i /* No Type */ ));
                Dict.put(row, rs.getString(++i), (Object[]) et.getKey().split("\\."));
            }
        } else {
            for (Map.Entry<String, Class> et : td.entrySet()) {
                // row.put(et.getKey() , rs.getObject(++ i, et.getValue()));
                Dict.put(row, rs.getObject(++i), (Object[]) et.getKey().split("\\."));
            }
        }
        return row;
    } catch (SQLException ex) {
        this.close();
        throw new HongsExemption(1153, ex);
    }
}
Also used : HongsException(io.github.ihongs.HongsException) SQLException(java.sql.SQLException) HongsExemption(io.github.ihongs.HongsExemption) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 80 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class Simple method open.

@Override
public Connection open() throws HongsException {
    try {
        if (connection == null || connection.isClosed()) {
            connection = open(jdbc, path, info);
            CoreLogger.trace("DB: Connect to '{}' by simple mode: {} {}", name, jdbc, path);
        }
        return connection;
    } catch (SQLException ex) {
        throw new HongsException(1024, ex);
    } catch (ClassNotFoundException ex) {
        throw new HongsException(1024, ex);
    }
}
Also used : SQLException(java.sql.SQLException) HongsException(io.github.ihongs.HongsException)

Aggregations

HongsException (io.github.ihongs.HongsException)138 Map (java.util.Map)77 HashMap (java.util.HashMap)61 LinkedHashMap (java.util.LinkedHashMap)31 IOException (java.io.IOException)29 Set (java.util.Set)26 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)24 List (java.util.List)20 HongsExemption (io.github.ihongs.HongsExemption)14 Action (io.github.ihongs.action.anno.Action)14 LinkedHashSet (java.util.LinkedHashSet)14 SQLException (java.sql.SQLException)13 FormSet (io.github.ihongs.action.FormSet)12 Table (io.github.ihongs.db.Table)12 FileNotFoundException (java.io.FileNotFoundException)11 CoreConfig (io.github.ihongs.CoreConfig)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 Iterator (java.util.Iterator)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9