Search in sources :

Example 86 with HongsException

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);
    }
}
Also used : SQLException(java.sql.SQLException) HongsException(io.github.ihongs.HongsException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement)

Example 87 with HongsException

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());
}
Also used : HongsException(io.github.ihongs.HongsException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 88 with HongsException

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);
    }
}
Also used : SQLException(java.sql.SQLException) HongsException(io.github.ihongs.HongsException) NamingException(javax.naming.NamingException)

Example 89 with HongsException

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);
    }
}
Also used : SQLException(java.sql.SQLException) HongsException(io.github.ihongs.HongsException)

Example 90 with HongsException

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;
}
Also used : HongsException(io.github.ihongs.HongsException) Map(java.util.Map)

Aggregations

HongsException (io.github.ihongs.HongsException)138 Map (java.util.Map)77 HashMap (java.util.HashMap)61 LinkedHashMap (java.util.LinkedHashMap)31 IOException (java.io.IOException)29 Set (java.util.Set)26 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)24 List (java.util.List)20 HongsExemption (io.github.ihongs.HongsExemption)14 Action (io.github.ihongs.action.anno.Action)14 LinkedHashSet (java.util.LinkedHashSet)14 SQLException (java.sql.SQLException)13 FormSet (io.github.ihongs.action.FormSet)12 Table (io.github.ihongs.db.Table)12 FileNotFoundException (java.io.FileNotFoundException)11 CoreConfig (io.github.ihongs.CoreConfig)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 Iterator (java.util.Iterator)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9