Package org.nutz.dao

Examples of org.nutz.dao.DaoException


  @SuppressWarnings("unchecked")
  public void _addMappingClass(Element klassElement) throws Exception {
    String className = klassElement.getAttribute("name");
    String tableName = klassElement.getAttribute("table");
    if (Strings.isBlank(className)) {
      throw new DaoException("Blank class Name!");
    }
    if (Strings.isBlank(tableName)) {
      throw new DaoException("Blank table Name!");
    }
    NutEntity en = new NutEntity(Class.forName(className));
    en.setTableName(tableName);
    en.setViewName(tableName);
    Mirror mirror = Mirror.me(en.getType());
View Full Code Here


 
  public NutMappingField ele2FieldMapping(NutEntity en, Element ele) {
    NutMappingField mappingField = new NutMappingField(en);
    String name = ele.getAttribute("name");
    if (Strings.isBlank(name)) {
      throw new DaoException("blank name property " + en.getType());
    }
    mappingField.setName(name);
    if (ele.hasAttribute("column")) {
      mappingField.setColumnName(ele.getAttribute("column"));
    } else {
View Full Code Here

                    list.add(re);
                    return true;
                }
                catch (Exception e) {
                    if (name != null) {
                        throw new DaoException(String.format("Column Name=%s, index=%d",
                                                             name,
                                                             i),
                                               e);
                    }
                    throw new DaoException(e);
                }
            }
        };
        ing.doLoop(rs, sql.getContext());
        return ing.getList();
View Full Code Here

 
  private Condition having;
 
  public GroupBySet(String...names) {
    if (Lang.length(names) == 0)
      throw new DaoException("NULL for GroupBy");
    this.names = names;
  }
View Full Code Here

        // 检查对象的创建方法
        BornContext<T> bc = Borns.evalByArgTypes(type, ResultSet.class);
        if (null != bc)
            this.bornByRS = bc.getBorning();
        else if (null == bornByDefault)
            throw new DaoException("Need non-arg constructor : " + type);

        // 映射
        this.ones = new LinkFieldSet();
        this.manys = new LinkFieldSet();
        this.manymanys = new LinkFieldSet();
View Full Code Here

    }

    public static PItem cndId(Entity<?> en, Number id) {
        MappingField mappingField = en.getIdField();
        if (mappingField == null)
            throw new DaoException("expect @Id but NOT found. " + en.getType().getName());
      return cndColumn(mappingField, id);
    }
View Full Code Here

    }

    public static PItem cndName(Entity<?> en, String name) {
        MappingField mappingField = en.getNameField();
            if (mappingField == null)
                throw new DaoException("expect @Name but NOT found. " + en.getType().getName());
      return cndColumn(mappingField, name);
    }
View Full Code Here

              log.debug("SQLException", e);
              SQLException nextException = e.getNextException();
                if (e != null)
                  log.debug("SQL NextException", nextException);
            }
            throw new DaoException(format(    "!Nutz SQL Error: '%s'\nPreparedStatement: \n'%s'",
                                            st.toString(),
                                            st.toPreparedStatement()), e);
        }

    }
View Full Code Here

                        catch (SQLException e1) {
                            if (log.isErrorEnabled())
                                log.error(e1);
                        }
                    }
                throw new DaoException(Lang.unwrapThrow(e));
            }
        }
        // 无事务
        else {
            Connection conn = null;
            boolean old = false;
            // 开始一个连接
            try {
                conn = dataSource.getConnection();
                // 多条语句运行,将自动提交设为 false
                old = conn.getAutoCommit();
                conn.setAutoCommit(false);
                // 开始循环运行
                callback.invoke(conn);
                // 完成提交
                if (!conn.getAutoCommit())
                    conn.commit();
            }
            // 异常回滚
            catch (Exception e) {
                try {
                    if (conn != null) // 高并发时,从数据库连接池获取连接就已经抛错误,所以conn可能为null的
                        conn.rollback();
                }
                catch (SQLException e1) {}// TODO 简单记录一下?
                throw new DaoException(e);
            }
            // 保证释放资源
            finally {
                if (null != conn) {
                    // 恢复链接自动提交设定
View Full Code Here

            }
            return re;
        }
        catch (SQLException e) {
          if (name != null) {
            throw new DaoException(String.format("Column Name=%s, index=%d", name, i), e);
          }
            throw new DaoException(e);
        }
    }
View Full Code Here

TOP

Related Classes of org.nutz.dao.DaoException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.