JavaBean框架 UJO

fmms 12年前發布 | 18K 次閱讀 Java Java開發

UJO Framework為對象提供了一種有別于JavaBeans的架構。最初的想法來源于Java5.0的范型。但是,隨著時間的流逝,這種架構表現一些激動人心的特性:

  • 很輕松實現對象的自省(introspection)而不再需要笨重的PropertyDescriptor實現
  • 一個transfer UJO對象屬性可以是集合(并非values)
  • 核心部分才兩個接口(UjoUjoProperty),實現起來非常簡單。
  • multi row insert, update and delete is supported by a single SQL statement
  • resources for ORM mapping can be a database table, view or native SQL SELECT
  • LIMIT and OFFSET are supported
  • subset of table columns on SELECT can be specified for the SQL statement
  • JDBC query parameters are passed by a 'question mark' notation to the PreparedStatement for a high security
  • stored database procedures and functions are supported
  • all persistent objects are based on the interface OrmUjo, namely on the implementation OrmTable
  • internal object cache is based on the WeakHashMap class so that large transactions does not cause any OutOfMemoryException
  • database indexes are created by the meta-model, added support for unique, non-unique indexes including the composed one

JavaBean框架 UJO

代碼示例:

import java.util.HashMap;
import org.ujoframework.*;
import org.ujoframework.core.UjoManager;
import org.ujoframework.implementation.map.*;

@SuppressWarnings("unchecked")
public class Person implements Ujo {

  public static final MapProperty NAME = new MapProperty("Name", String.class);
  public static final MapProperty MALE = new MapProperty("Male", Boolean.class);
  public static final MapProperty CASH = new MapProperty("Cash", 0d);

  // --- The start of the MapUjo implementation ---
  private HashMap map = new HashMap();  
  public Object readValue(UjoProperty property) {
    Object result = map.get(property);
    return result!=null ? result : property.getDefault();
  }
  public void writeValue(UjoProperty property, Object value) {
    map.put(property, value);
  }
  public UjoProperty[] readProperties() {
    return UjoManager.getInstance().readProperties(getClass());
  }
  public boolean readAuthorization(UjoAction action, UjoProperty property, Object value) {
    return true;
  } // --- The end of MapUjo implementation ---

  /** Add cash in the Ujo implementation */
  public void addCash(double cash) {
    double newPrice = CASH.of(this) + cash;
    CASH.setValue(this, newPrice);
  }
}

項目主頁:http://www.baiduhome.net/lib/view/home/1326937077843

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!