Perfil de Zhong简单做人FotosBlogListasMás Herramientas Ayuda

Blog


    14 julio

    ibatis 使用心得体会

    • abator

      使用abator产生代码和sqlmap配置文件,可能需要稍稍修改产生的代码, 我特不喜欢"abatorgenerated_..."这种naming,数字类型的转化也不是很理想,例如小数一概转换成BigDecimal - If the scale is greater then zero, or the length is greater than 18, then the java.math.BigDecimal type will be used。

      比较难配置的是<table>,跟具体的数据库有关,下面是oracle的例子:
      <table schema="newslink" tableName="ADMIN_ACCOUNT" domainObjectName="Admin" enableSelectByExample ="false" enableUpdateByPrimaryKey="false" enableDeleteByExample="false">
      <generatedKey column="OID" sqlStatement="SELECT ADMIN_ACCOUNT_SEQ.NEXTVAL FROM DUAL" identity="false" />
      <columnOverride column="OID" property="id" />
      <columnOverride column="LAST_LOGIN" property="lastLogin" javaType="java.sql.Timestamp" jdbcType="TIMESTAMP" />
      <columnOverride column="LAST_LOGOFF" property="lastLogoff" javaType="java.sql.Timestamp" jdbcType="TIMESTAMP" />
      <columnOverride column="CREATEON" javaType="java.sql.Timestamp" jdbcType="TIMESTAMP" />
      <columnOverride column="UPDATEON" property="lastLogoff" javaType="java.sql.Timestamp" jdbcType="TIMESTAMP" />
      </table>
      Oracle 10g支持Date&Timestamp column,对应的jdbc也返回相应的jdbc type,不需要编写特定的TypeHandler或TypeHandlerCallback,所以这一经常碰到的问题已经得到很好地解决(oracle 10g + oracle 10g jdbc + jdk1.6 )(不过用hashmap/hashtable直接对raw的resultset就不行了,返回的是oracle.sql.timestamp)。
    • 在sqlmap中想要用$,#必须escape: ##,$$ (document中好像没有说明,这个会还是害死人,因为sql完全没有错) -
    • sqlmap: 使用namespace(default: false)
    • caching: 不直接使用OSCache,而是在ibatis之外采用Spring的AOP来实现
    • pagination, 可采取一般的SqlMapClient.queryForList,不需要queryForPagenatedList,通过特定的数据库sql实现
    • Spring中可采取ibatis batch的方法,具体见Spring的SqlMapClientTemplate的文档
    • n+1: 有两种方法 (lazy loading or join sql),不过better "avoid" it instead of solving it. 这就是为什么设计上不一定要用“pure” ORM,hibernate, ejb, jdo, 涉及到太多问题了,在绝大多数情况下(非成熟商业模型,非产品开发),我个人倾向join sql。
    • dynamic sql: oh, it is ownsome , 唯一有抱怨的是拿不到最终的sql,解释是ibatis用的都是preparestatement,但这样就不可以重用(不一定是for ibatis),除非改source code,不过看到它是可以的,把log4j调成log4j.logger.java.sql=DEBUG, stdout
    • removeFirstPrepend="true" & prepend 有时要显式使用,可结合preparestatement来调试。
    • jasperreport 产生动态报表,使用JRMapCollectionDataSource来取得ibatis地返回数据(可直接用hashmap作为resultClass),如果数据量太大,可参考类似hibernate的方法:http://www.javalobby.org/articles/hibernatequery103

    Comentarios (2)

    Espera...
    El comentario que has escrito es demasiado largo. Acórtalo.
    No has escrito nada. Vuelve a intentarlo.
    No se puede agregar tu comentario en este momento. Vuelve a intentarlo más tarde.
    Para agregar un comentario, necesitas permiso de tus padres. Pedir permiso
    Tus padres han desactivado los comentarios.
    No se puede eliminar tu comentario en este momento. Vuelve a intentarlo más tarde.
    Has superado el número máximo de comentarios que se puede dejar en un día. Vuelve a intentarlo en 24 horas.
    Se ha deshabilitado la capacidad de tu cuenta de dejar comentarios porque nuestros sistemas indican que podrías estar enviando correo no solicitado a otros usuarios. Si crees que tu cuenta se ha deshabilitado por error, ponte en contacto con el servicio de soporte técnico de Windows Live.
    Para terminar de dejar tu comentario, realiza la siguiente comprobación de seguridad.
    Los caracteres que escribas en la comprobación de seguridad deben coincidir con los de la imagen o el audio.

    Para agregar un comentario, inicia sesión con tu cuenta de Windows Live ID (si utilizas Hotmail, Messenger o Xbox LIVE, ya tienes una cuenta de Windows Live ID). Iniciar sesión


    ¿No tienes una cuenta de Windows Live ID? Regístrate

    Zhongescribió:
    Recently test drive on iBatis v3 (still beta version). It seems the designer is fascinated by the new technologies and iBatis is "trying" to be a full/powerful ORM, in another word, more complicated, again in another word, not a good sign. Configuration by convention, annotation, caching, transaction support, ... No, we DO NOT need that because Spring + v2 already support all of them so well, why growing bigger but does not add MUCH value? Will I choose iBatis as ORM framework? Absolutely NOT, I will use hibernate, jpa, and many others. The bottom line is the biggest value of iBatis is it is a light-weight JDBC wrapper, the power of iBatis is on "R" side (SQL) not O side. As framework designer or architect, please re-consider when change or add new features, this has to be very careful as Joshua Bloch shared his expertise in How to Design a Good API & Why it Matters(http://www.infoq.com/presentations/effective-api-design)
    7 Oct
    Zhongescribió:
    pagination - 大家不要抱怨,没有通用的方法,也不要再去发明,如果有,那都是软件模拟的,还是通过特定的数据库sql实现,这就是ibatis好的原因,也印证了Thomas Kyte的话,数据库是你的基础,为啥抛弃它的特性?!
    http://zlit.spaces.live.com/blog/cns!8861E8E763F023DA!155.entry
    27 Sep

    Vínculos de referencia

    La dirección URL del vínculo de referencia de esta entrada es:
    http://zlit.spaces.live.com/blog/cns!8861E8E763F023DA!235.trak
    Weblogs que hacen referencia a esta entrada
    • Ninguno