use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class Link method execute.
/**
* 执行语句 *
*/
/**
* 执行方法
* @param sql
* @param params
* @return 成功或失败
* @throws HongsException
*/
public boolean execute(String sql, Object... params) throws HongsException {
this.ready();
if (4 == (4 & Core.DEBUG)) {
StringBuilder sb = new StringBuilder(sql);
List paramz = new ArrayList(Arrays.asList(params));
checkSQLParams(sb, paramz);
mergeSQLParams(sb, paramz);
CoreLogger.debug("DB.execute: " + sb.toString());
}
PreparedStatement ps = this.prepareStatement(sql, params);
try {
return ps.execute();
} catch (SQLException ex) {
throw new HongsException(1044, ex);
} finally {
this.closeStatement(ps);
}
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class Link method insert.
/**
* 添加记录
* <p>注: 调用update(sql, params...)实现</p>
* @param table
* @param values
* @return 插入条数
* @throws HongsException
*/
public int insert(String table, Map<String, Object> values) throws HongsException {
if (values == null || values.isEmpty()) {
throw new HongsException(1046, "Insert value can not be empty.");
}
table = quoteField(table);
/**
* 组织语句 *
*/
List paramz = new ArrayList(values.size());
String fs = "";
String vs = "";
Iterator it = values.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String field = (String) entry.getKey();
paramz.add((Object) entry.getValue());
fs += ", " + quoteField(field);
vs += ", ?";
}
String sql = "INSERT INTO " + table + " (" + fs.substring(2) + ")" + " VALUES" + " (" + vs.substring(2) + ")";
return this.updates(sql, paramz.toArray());
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class Origin method open.
@Override
public Connection open() throws HongsException {
try {
if (connection == null || connection.isClosed()) {
connection = open(jndi, path, info);
CoreLogger.trace("DB: Connect to '{}' by origin mode: {} {}", name, jndi, path);
}
return connection;
} catch (SQLException ex) {
throw new HongsException(1022, ex);
} catch (NamingException ex) {
throw new HongsException(1022, ex);
}
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class Source method open.
@Override
public Connection open() throws HongsException {
try {
if (connection == null || connection.isClosed()) {
connection = open(jdbc, path, info);
CoreLogger.trace("DB: Connect to '{}' by source mode: {} {}", name, jdbc, path);
}
return connection;
} catch (SQLException ex) {
throw new HongsException(1024, ex);
}
}
use of io.github.ihongs.HongsException in project HongsCORE by ihongs.
the class IsEnum method verify.
@Override
public Object verify(Value watch) throws Wrong {
// 跳过空值和空串
Object value = watch.get();
if (value == null) {
return STAND;
}
if (value.equals("")) {
return STAND;
}
String conf = Synt.asString(getParam("conf"));
String name = Synt.asString(getParam("enum"));
if (conf == null || "".equals(conf)) {
conf = Synt.asString(getParam("__conf__"));
}
if (name == null || "".equals(name)) {
name = Synt.asString(getParam("__name__"));
}
Map data;
try {
data = FormSet.getInstance(conf).getEnum(name);
} catch (HongsException ex) {
throw ex.toExemption();
}
if (!data.containsKey(value.toString())) {
throw new Wrong("fore.form.not.in.enum");
}
return value;
}
Aggregations