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);
}
}
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);
}
}
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);
}
}
}
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();
}
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;
}
Aggregations