阅读更多

14顶
1踩

编程语言

原创新闻 Ebean Orm 1.1.0发布——开始支持Groovy和Scala

2009-04-07 09:27 by 资深记者 kyo100900 评论(6) 有12963人浏览

Ebean的特性如下:


==============

l         使用标准的JPA annotation,即:@Entity, @OneToMany等。

l         提供Sessionless API,也就是说没有mergeflush等方法。(这也是EbeanHibernatetORM的重要区别之一

l         支持基于Object Graph进行自动查询调优

l         需要的话,可以使用数据库的元数据(如果有配了外键关联,不需要使用@JoinColumn,当然如果配置了多个关联,还是需要具体指明的,否则Ebean无法自动选择。)

l         基于LGPL开源协议

 

 

咱们来简单看看Ebean的使用吧:

 

Load方法几乎与Hibernate完全一样

 

Order order = Ebean.find(Order.class, 12);  

 

List方法也有Hibernate Criteria的影子,但似乎更简洁些:

 

List<Order> list = Ebean.find(Order.class).findList();  

// 其中 eq表示“等于”, gt表示“大于”
List<Order> list = Ebean.find(Order.class) .
where().
eq("status.code", "SHIPPED").
gt("shipDate", lastWeek).
findList();  

//也支持语句查询,注意关键字是“find”
String query = "find order where status.code=:status and shipDate > :shipped";   
  
List<Order> list = Ebean.find(Order.class)   
    .setQuery(query)   
    .setParameter("status", "SHIPPED")   
    .setParameter("shipped", lastWeek)   
    .findList();  

 

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

看个左连接的例子,OrderOrderDetail是一对多的关联, details是在Order类中定义的List<OrderDetail> details:

 

 

List<Order> orders =    
    Ebean.find(Order.class)   
        .join("details")   
        .findList();  

 

 

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

最后来看一个“局部”加载例子:

 

 

List<Order> orders =    
    Ebean.find(Order.class)   
        .select("orderDate, shipDate")   
        .findList();  

 

 

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

查询结果中会包括:id, orderDate, shipDate三项,注意主键id永远会包含其中。

 

 

至于save,update操作合并为save一个方法,删除还是delete:

 

 

Order order = new Order();   
order.setOrderDate(new Date());   
// 保存
Ebean.save(order);  
  
Order order = Ebean.find(Order.class, 12);   
order.setStatus("SHIPPED");   
// 更新
Ebean.save(order);  

Order order = Ebean.find(Order.class, 12);   
// 删除
Ebean.delete(order);  

 

 

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

至于咱们关心的事务处理一块,也有声明式和编程式的。声明式的就是使用@Transactional annotation

 

 

// any old pojo   
public class MyService {   
  
    @Transactional  
    public void runFirst() throws IOException {   
  
        // run in a Transaction (REQUIRED is the default)   
  
        // find a customer   
        Customer customer = Ebean.find(Customer.class, 1);   
  
        // call another "transactional" method   
        runInTrans();   
    }   
   …….

 

 

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

编程式也给个例子吧:

 

 

Ebean.beginTransaction();   
try {   
    // fetch some stuff...   
    User u = Ebean.find(User.class, 1);   
    // save or delete stuff...   
    Ebean.save(u);   
    Ebean.commitTransaction();   
} finally {   
    Ebean.endTransaction();   
}  

 

 

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

总的来说,Ebean还是比较容易简单上手的。文档也不过100页,很有Hibernate精简子集的感觉。

 

 

 

Groovy的支持:
==============

与配置Java一样,你可以通过Ebean使用JPAannoations(比如说@Entity)来配置你的Groovy beans

 

 

Scala的支持:
==============

类似的,你也可以通过Ebean使用JPA来配置你的Scala beans。注意,你不再需要使用@BeanProperty annotation了,因为Ebean会识别出scalaproperty

 

更多的信息参考:http://www.avaje.org

 

 

 

 

 

 

来自: theserverside
14
1
评论 共 6 条 请登录后发表评论
6 楼 littleJava 2009-06-11 13:16
ebean支持存储过程的
5 楼 InnocentBoy 2009-04-08 11:33
JPA现在支持存储过程吗?虽然不常用,但是总感觉少点什么。
4 楼 天机老人 2009-04-08 05:50
没啥实质性的改变
3 楼 SSailYang 2009-04-07 18:36
hibernate lite?但我可以在spring里使用gorm
2 楼 nihongye 2009-04-07 15:55
个人觉得精简子集的方式挺好
1 楼 whaosoft 2009-04-07 14:37
我还是用习惯了 hibernate

发表评论

您还没有登录,请您登录后再发表评论

相关推荐

  • 使用VB捕捉键盘事件

    VB源码,键盘捕捉程序,比较不错,可以看看。

  • 自定义控件里的keydown方法无法捕获所有的按键消息的处理方法1

    自定义控件里的keydown方法无法捕获所有的按键消息的处理方法1(自定义控件里的keydown方法无法获取的键值如 空格键 Space,上下左右键等) 处理办法具体如下: 1、首先在自定义控件UserControl1中重写ProcessDialogKey方法  自定义控件UserControl1中重写ProcessDialogKey方法代码如下:          protect

  • 屏蔽Enter或是Esc键

    一般来说,对于一个默认情况下的对话框程序,用户在运行的时候,如果不小心按下了Enter或是Esc键,程序就会立刻退出。 因为:当用户按下Enter时, Windows就会自动寻找输入焦点(focus)落在哪一个按钮上(当前获得焦点的按钮即为当前选中的按钮,用Tab键可以来回切换,按钮四周将被点线包围)。 此时,即使对话框中没有OK按钮,OnOK()函数也会被调用,对于普通的对话框程序来说,On

  • 捕捉回车键

    JS代码捕捉回车键 &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;JS代码捕捉回车键&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; window.onload = function () {

  • vb底层开发之Hook(钩子)

    原帖地址:http://hi.baidu.com/starwork/blog/item/6d989ed3b2cb2c35960a1638.htmlhook是WINDOWS提供的一种消息处理机制,它使得程序员可以使用子过程来监视系统消息,并在消息到达目标过程前得到处理。 下面将介绍WINNDOWS HOOKS并且说明如何在WINDOWS 程序中使用它。 关于HOOKS 使用HOOK 将会降低

  • Mac端实现.gitignore忽略node_modules文件夹

    使用.gitignore忽略node_modules文件夹

  • vb Hook比较详细的讲解 ---> vb获取按键消息(钩子方式)

    Windows系统中钩子具有相当强大的功能,通过这种技术可以对几乎所有的Windows 系统中的消息进行拦截、监视、处理。这种技术可以广泛应用于各种软件,尤其是需要有监控、自动记录等对系统进行监测功能的软件。本文针对这个专题进行了探讨,希望可以为读者朋友们起到抛砖引玉的作用。   一、钩子的机制及类型   Windows的应用程序都是基于消息驱动的,应用程序的操作都依赖于它所得到的消息

  • Jq_keyup(),keypress(),keydown()

    keyup() 当键盘按下松开后触发,即输入完成后 KeyPress主要用来接收字母、数字等ANSI字符,而 KeyDown 和 KeyUP 事件过程可以处理任何不被 KeyPress 识别的击键,诸如:功能键(F1-F12)、编辑键、定位键以及任何这些键和键盘换档键的组合等。与 KeyDown 和KeyUp 事件不同的是,KeyPress 不显示键盘的物理状态(SHIFT键),而只是传递

  • 用VB编写键盘拦截程序[转]

    我们知道,在一些程序中,有一些快捷方式(如:Shift键最小化、ESC键退出、Ctrl+S存盘、Alt+x退出等等)。以前有一些介绍使用Win32 API可以做到,但过于繁琐,其实VB本身已经给我们提供了这个功能。   我们来新建一个窗体Form1,对于键盘操作可以看到有三个事件KeyPress(),KeyDown和KeyUp,下面我对它们分别介绍:   KeyPress()事件是当用户按下和松开

  • VBA 禁止在某个sheet中使用键盘Delete键

    1.按Alt+F11打开VBA编辑窗口 2.双击要禁止delete的sheet,例如sheet1 3.在右边的编辑区的最上面加入下面的函数声明 [code=&quot;java&quot;]Private Declare Function GetKeyboardState Lib &quot;user32&quot; (pbKeyState As Byte) As Long[/code] 对该sheet追加change事...

  • 极客DIY:只用两步教你制作一款可编程键盘 [译]

    原文出处: Freebuf黑客与极客 对于那些工作时需要与许多组合键打交道的人(比如经常使用Photoshop的人)来说,一款可编程键盘无疑是十分实用的。本期的DIY将为大家带来一款可编程键盘,其制作过程非常简单,有兴趣的小伙伴可以一试。 DIY材料及工具:

  • VB屏蔽所有键盘按键

    这是一个使用SetWindowsHookEx的程序,屏蔽了键盘按键(包括系统按键)。 如果只想屏蔽某个按键,请更改下面的代码。 Form1.Text1 = wParam Form1.Label1 = kk.vkCode & ":" & kk.scanCode & ":" & kk.Time 'If wParam = 256 Then Myfunc = 1: Exit Function 'endif wParam 的按键值可以在程序运行中测试中找到。

Global site tag (gtag.js) - Google Analytics