use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class JRecord method set.
/**
* 设置数据
* @param key
* @param val
* @param exp
*/
@Override
public void set(String key, T val, long exp) throws HongsException {
// 序列化值
byte[] arr = null;
String str = null;
if (!bytes) {
str = Dawn.toString(val);
} else
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(val);
out.flush();
arr = bos.toByteArray();
} catch (IOException e) {
throw new HongsException(e);
}
long now = System.currentTimeMillis() / 1000;
// table.db.open( );
table.db.ready();
try (PreparedStatement ps = table.db.prepareStatement("UPDATE `" + table.tableName + "` SET data= ?, xtime= ?, mtime= ? WHERE id = ?")) {
if (arr != null) {
ps.setBytes(1, arr);
} else {
ps.setString(1, str);
}
ps.setLong(2, exp);
ps.setLong(3, now);
ps.setString(4, key);
if (ps.executeUpdate() > 0) {
return;
}
} catch (SQLException e) {
throw new HongsException(1045, e);
}
try (PreparedStatement ps = table.db.prepareStatement("INSERT INTO `" + table.tableName + "` (data, xtime, mtime, id) VALUES (?, ?, ?, ?)")) {
if (arr != null) {
ps.setBytes(1, arr);
} else {
ps.setString(1, str);
}
ps.setLong(2, exp);
ps.setLong(3, now);
ps.setString(4, key);
if (ps.executeUpdate() > 0) {
return;
}
} catch (SQLException e) {
throw new HongsException(1045, e);
}
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class JRecord method del.
/**
* 清除数据
* @param exp
*/
@Override
public void del(long exp) throws HongsException {
// table.db.open( );
table.db.ready();
try (PreparedStatement ps = table.db.prepareStatement("DELETE FROM `" + table.tableName + "` WHERE xtime <= ? AND xtime != 0")) {
ps.setLong(1, exp);
ps.executeUpdate();
} catch (SQLException e) {
throw new HongsException(1045, e);
}
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class Sesion method close.
@Override
public void close() throws HongsException {
store();
IRecord rec = getRecord();
// 如果数据记录对象可关闭, 关闭之
if (rec instanceof AutoCloseable) {
try {
((AutoCloseable) rec).close();
} catch (Exception err) {
throw new HongsException(err);
}
}
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class SessFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain flt) throws ServletException, IOException {
HttpServletRequest raq = (HttpServletRequest) req;
HttpServletResponse rzp = (HttpServletResponse) rsp;
/**
* 对于嵌套相同过滤, 不在内部重复执行;
* 如外部设置了忽略, 则跳过忽略的路径.
*/
if ((inside != null && Synt.declare(req.getAttribute(inside), false)) || (patter != null && !patter.matches(ActionDriver.getRecentPath(raq)))) {
flt.doFilter(req, rsp);
return;
}
try {
raq = new SessAccess(raq, rzp, this);
raq.setAttribute(inside, true);
flt.doFilter(raq, rzp);
} finally {
raq.removeAttribute(inside);
// 最终任务完成后对会话进行保存
HttpSession ses = raq.getSession(false);
if (null != ses && ses instanceof Sesion) {
try {
((Sesion) ses).close();
} catch (HongsException ex) {
throw new ServletException(ex);
}
}
}
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class Unit method makeDocument.
private Document makeDocument() throws HongsException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.newDocument();
} catch (ParserConfigurationException e) {
throw new HongsException(e);
}
}
Aggregations