use of app.hongs.db.DB in project HongsCORE by ihongs.
the class SignAction method signCreate.
/**
* 登录
* @param ah
* @throws HongsException
*/
@Action("create")
@Verify(conf = "master", form = "sign")
public void signCreate(ActionHelper ah) throws HongsException {
String appid = Synt.declare(ah.getParameter("appid"), "_WEB_");
String place = Synt.declare(ah.getParameter("place"), "public");
String username = Synt.declare(ah.getParameter("username"), "");
String password = Synt.declare(ah.getParameter("password"), "");
String passcode;
DB db = DB.getInstance("master");
Table tb = db.getTable("user");
FetchCase fc;
Map ud;
// 验证密码
fc = new FetchCase().from(tb.tableName).select("password, passcode, id, name, head, mtime, state").filter("username = ?", username);
ud = db.fetchLess(fc);
if (ud.isEmpty()) {
ah.reply(AuthKit.getWrong("username", "core.username.invalid"));
return;
}
passcode = Synt.declare(ud.get("passcode"), "");
password = AuthKit.getCrypt(password + passcode);
if (!password.equals(ud.get("password"))) {
ah.reply(AuthKit.getWrong("passowrd", "core.password.invalid"));
return;
}
String usrid = (String) ud.get("id");
String uname = (String) ud.get("name");
String uhead = (String) ud.get("head");
int state = Synt.declare(ud.get("state"), 0);
long utime = Synt.declare(ud.get("mtime"), 0L) * 1000;
// 验证状态
if (1 != state) {
ah.reply(AuthKit.getWrong("state", "core.sign.state.invalid"));
return;
}
// 验证区域
Set rs = RoleSet.getInstance(usrid);
if (0 != place.length() && !rs.contains(place)) {
ah.reply(AuthKit.getWrong("place", "core.sign.place.invalid"));
return;
}
ah.reply(AuthKit.userSign(ah, place, appid, usrid, uname, uhead, utime));
}
use of app.hongs.db.DB in project HongsCORE by ihongs.
the class SystemCmdlet method runSql.
private static void runSql(Date dt, File fo, String fn) 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.Common(ex);
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
// 解析配置
Date dzt = dt;
String dbn = fn;
Matcher mat = sqlDnmPatt.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);
}
}
// 清理注释
sql = sqlCmnPatt.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);
CmdletHelper.progred();
throw ex;
}
}
}
use of app.hongs.db.DB in project HongsCORE by ihongs.
the class DBDeff method syncSlaver.
/**
* 同步从数据库
* @param slaver
* @param tablePrefix 从库表前缀
* @param tableSuffix 从库表后缀
* @param delExtraTables 删除多余的表
* @param delExtraFields 删除多余的字段
* @throws app.hongs.HongsException
*/
public void syncSlaver(DB slaver, String tablePrefix, String tableSuffix, boolean delExtraTables, boolean delExtraFields) throws HongsException {
List<String> sqls = this.deffSlaver(slaver, tablePrefix, tableSuffix, delExtraTables, delExtraFields);
DB sdb = slaver;
sdb.begin();
try {
for (String sql : sqls) {
sdb.execute(sql);
}
sdb.commit();
} catch (HongsException ex) {
sdb.revert();
throw ex;
}
}
use of app.hongs.db.DB in project HongsCORE by ihongs.
the class Cmdrun method exec.
@Cmdlet("__main__")
public static void exec(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, "from=s", "to=s", "sync:b", "del-tables:b", "del-fields", "!U", "!A");
String fr = (String) opts.get("from");
String to = (String) opts.get("to");
boolean sc = (boolean) opts.get("sync");
boolean dt = (boolean) opts.get("del-tables");
boolean df = (boolean) opts.get("del-fields");
Pattern patt = Pattern.compile("\\.\\w+$");
Matcher frMt = patt.matcher(fr);
Matcher toMt = patt.matcher(to);
if (frMt.find() && toMt.find()) {
DB frDb = DB.getInstance(fr.substring(0, frMt.start()));
Table frTb = frDb.getTable(fr.substring(frMt.start() + 1));
DB toDb = DB.getInstance(to.substring(0, toMt.start()));
Table toTb = toDb.getTable(to.substring(toMt.start() + 1));
if (sc) {
new TableDeff(frTb).syncSlaver(toTb, df);
} else {
new TableDeff(frTb).deffSlaver(toTb, df);
}
} else {
DB frDb = DB.getInstance(fr);
DB toDb = DB.getInstance(fr);
if (sc) {
new DBDeff(frDb).syncSlaver(toDb, null, null, dt, df);
} else {
new DBDeff(frDb).deffSlaver(toDb, null, null, dt, df);
}
}
}
use of app.hongs.db.DB in project HongsCORE by ihongs.
the class TableDeff method syncSlaver.
/**
* 同步从表结构
* @param slaver
* @param delExtraFields 删除多余的字段
* @throws app.hongs.HongsException
*/
public void syncSlaver(Table slaver, boolean delExtraFields) throws HongsException {
List<String> sqls = this.deffSlaver(slaver, delExtraFields);
DB sdb = slaver.db;
sdb.begin();
try {
for (String sql : sqls) {
sdb.execute(sql);
}
sdb.commit();
} catch (HongsException ex) {
sdb.revert();
throw ex;
}
}
Aggregations