Search in sources :

Example 61 with HongsException

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

the class StatisHelper method acount.

private int acount(Map rd, IndexSearcher finder, Map<String, Map<Object, Long>> counts, Map<String, Set<Object>> countx) throws HongsException {
    Field[] fields = getGraderFields(counts.keySet(), rd);
    try {
        Query q = that.padQry(rd);
        if (4 == (4 & Core.DEBUG)) {
            CoreLogger.debug("StatisHelper.acount: " + q.toString());
        }
        if (counts.isEmpty()) {
            return finder.count(q);
        }
        StatisGrader.Acount c = new StatisGrader.Acount(fields, counts, countx);
        finder.search(q, c);
        return c.count();
    } catch (IOException e) {
        throw new HongsException(e);
    }
}
Also used : Field(io.github.ihongs.dh.search.StatisHandle.Field) Query(org.apache.lucene.search.Query) HongsException(io.github.ihongs.HongsException) IOException(java.io.IOException)

Example 62 with HongsException

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

the class SystemCmdlet method runSql.

private static void runSql(Element e, Date dt, Looker lg) {
    String d = Synt.declare(e.getAttribute("db"), "defalut");
    List<String> a = new ArrayList();
    List<String> b = new ArrayList();
    String c, s;
    NodeList x;
    Element m;
    // 获取参数
    x = e.getChildNodes();
    for (int j = 0; j < x.getLength(); j++) {
        Node u = x.item(j);
        if (u.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        m = (Element) u;
        c = m.getTagName();
        s = m.getTextContent();
        if (s != null && s.length() > 0) {
            if ("arg".equals(c)) {
                a.add(repTim(s, dt));
            } else {
                b.add(repTim(s, dt));
            }
        }
    }
    try {
        DB db = DB.getInstance(d);
        Object[] p = a.toArray();
        for (String q : b) {
            db.execute(q, p);
        }
    } catch (HongsException ex) {
        lg.error(ex);
    }
}
Also used : HongsException(io.github.ihongs.HongsException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) DB(io.github.ihongs.db.DB)

Example 63 with HongsException

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

the class SystemCmdlet method runCmd.

private static void runCmd(Date dt, File fo, Looker lg) throws HongsException {
    Document doc;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder dbn = dbf.newDocumentBuilder();
        doc = dbn.parse(fo);
    } catch (ParserConfigurationException ex) {
        throw new HongsException(ex);
    } catch (SAXException ex) {
        throw new HongsException(ex);
    } catch (IOException ex) {
        throw new HongsException(ex);
    }
    NodeList l = doc.getDocumentElement().getChildNodes();
    for (int i = 0; i < l.getLength(); i++) {
        Node n = l.item(i);
        if (n.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Element e = (Element) n;
        String t = e.getTagName();
        if ("runsql".equals(t)) {
            runSql(e, dt, lg);
        } else if ("cmdlet".equals(t)) {
            runCmd(e, dt, lg);
        } else if ("action".equals(t)) {
            runAct(e, dt, lg);
        } else {
            throw new HongsException("Wrong tagName: " + t);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HongsException(io.github.ihongs.HongsException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 64 with HongsException

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

the class SystemCmdlet method runSql.

private static void runSql(Date dt, File fo) throws HongsException {
    // 读取代码
    String sql;
    byte[] buf;
    try {
        FileInputStream in = new FileInputStream(fo);
        buf = new byte[in.available()];
        in.read(buf);
        sql = new String(buf, "UTF-8");
    } catch (FileNotFoundException ex) {
        throw new HongsException(ex);
    } catch (IOException ex) {
        throw new HongsException(ex);
    }
    // 解析配置
    Date dzt = null;
    String dbn = null;
    Matcher mat = SQL_SET_PAT.matcher(sql);
    while (mat.find()) {
        String key = mat.group(1);
        if ("DB".equals(key)) {
            dbn = /**
             */
            mat.group(2).trim();
        } else if ("DT".equals(key)) {
            dzt = getTim(mat.group(2).trim(), dt);
        }
    }
    if (dzt == null) {
        dzt = dt;
    }
    if (dbn == null) {
        dbn = fo.getName().replaceFirst("\\.[^\\.]+$", // 去掉扩展名
        "").replaceFirst("^[^\\.]+\\.", // 去掉前缀名
        "");
    }
    // 清理注释
    sql = SQL_CMN_PAT.matcher(sql).replaceAll("");
    // 设置时间
    sql = repTim(sql, dzt);
    CmdletHelper.println("Run '" + fo.getName() + "' for '" + dbn + "'");
    // 逐条执行
    String[] a = sql.split(";\\s*[\r\n]");
    DB db = DB.getInstance(dbn);
    long st = System.currentTimeMillis();
    int al = a.length;
    int ok = 0;
    int er = 0;
    for (String s : a) {
        s = s.trim();
        try {
            if (0 < s.length()) {
                db.execute(s);
            }
            CmdletHelper.progres(st, al, ++ok, er);
        } catch (HongsException ex) {
            CmdletHelper.progres(st, al, ok, ++er);
            if (0 < Core.DEBUG) {
                CmdletHelper.progres();
                throw ex;
            }
        }
    }
    CmdletHelper.progres();
}
Also used : HongsException(io.github.ihongs.HongsException) Matcher(java.util.regex.Matcher) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Date(java.util.Date) DB(io.github.ihongs.db.DB)

Example 65 with HongsException

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

the class LuceneRecord method getWriter.

public IndexWriter getWriter() throws HongsException {
    if (writer == null || writer.isOpen() == false) {
        String path = getDbPath();
        try {
            /**
             * 2021/04/18
             * 为在一个库里存多个表
             * 不再在开始预设分析器
             * 改为存字段时直接写入 TokenStream
             */
            CoreConfig cc = CoreConfig.getInstance();
            IndexWriterConfig iwc = new IndexWriterConfig();
            // IndexWriterConfig iwc = new IndexWriterConfig(getAnalyzer());
            iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
            iwc.setMaxBufferedDocs(cc.getProperty("core.lucene.max.buf.docs", -1));
            iwc.setRAMBufferSizeMB(cc.getProperty("core.lucene.ram.buf.size", 16D));
            Directory dir = FSDirectory.open(Paths.get(path));
            writer = new IndexWriter(dir, iwc);
        } catch (IOException x) {
            throw new HongsException(x);
        }
        if (4 == (4 & Core.DEBUG)) {
            CoreLogger.trace("Start the lucene writer for " + getDbName());
        }
    }
    return writer;
}
Also used : CoreConfig(io.github.ihongs.CoreConfig) IndexWriter(org.apache.lucene.index.IndexWriter) HongsException(io.github.ihongs.HongsException) IOException(java.io.IOException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

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