use of app.hongs.HongsException in project HongsCORE by ihongs.
the class JRecord method del.
/**
* 删除数据
* @param key
*/
@Override
public void del(String key) throws HongsException {
// table.db.open( );
table.db.ready();
try (PreparedStatement ps = table.db.prepareStatement("DELETE FROM `" + table.tableName + "` WHERE id = ?")) {
ps.setString(1, key);
ps.executeUpdate();
} catch (SQLException ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class JRecord method set.
/**
* 设置过期
* @param key
* @param exp
* @throws HongsException
*/
@Override
public void set(String key, long exp) throws HongsException {
long now = System.currentTimeMillis() / 1000;
// table.db.open( );
table.db.ready();
try (PreparedStatement ps = table.db.prepareStatement("UPDATE `" + table.tableName + "` SET xtime = ?, mtime = ? WHERE id = ?")) {
ps.setString(3, key);
ps.setLong(1, exp);
ps.setLong(2, now);
ps.executeUpdate();
} catch (SQLException ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.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;
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(val);
out.flush();
arr = bos.toByteArray();
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
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 = ?")) {
ps.setString(4, key);
ps.setBytes(1, arr);
ps.setLong(2, exp);
ps.setLong(3, now);
if (ps.executeUpdate() > 0) {
return;
}
} catch (SQLException ex) {
throw new HongsException.Common(ex);
}
try (PreparedStatement ps = table.db.prepareStatement("INSERT INTO `" + table.tableName + "` (id, data, xtime, mtime) VALUES (?, ?, ?, ?)")) {
ps.setString(1, key);
ps.setBytes(2, arr);
ps.setLong(3, exp);
ps.setLong(4, now);
if (ps.executeUpdate() > 0) {
return;
}
} catch (SQLException ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.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 ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class FileAction method create.
@Override
@Action("create")
public void create(ActionHelper helper) throws HongsException {
CoreLocale lang = CoreLocale.getInstance("manage");
String path = helper.getParameter("path");
String type = helper.getParameter("type");
String text = helper.getParameter("text");
File file;
if (path == null) {
helper.fault(lang.translate("core.manage.file.path.required"));
return;
}
path = realPath(path);
if (path == null) {
helper.fault(lang.translate("core.manage.file.path.is.error"));
return;
}
file = new File(path);
if (file.exists()) {
helper.fault(lang.translate("core.manage.file.path.is.exist"));
return;
}
if (isDenyFile(file)) {
helper.fault(lang.translate("core.manage.file.interdicted"));
return;
}
// 创建目录
if ("dir".equals(type)) {
new File(path).mkdirs();
helper.reply("");
return;
}
// 写入文件
try {
saveFile(file, text);
} catch (Exception ex) {
CoreLogger.error(ex);
helper.fault(lang.translate("core.manage.file.create.failed"));
return;
}
helper.reply("");
}
Aggregations