db4o_8.0对象数据库官方文档翻译_学习笔记三

紧接上篇:db4o_8.0对象数据库官方文档翻译_学习笔记

3. Object Manager Enterprise Overview(OME视图)即OME插件的使用

If you did not install the Object Manager Enterprise yet, please, return to FirstGlance chapter and follow the installation instructions there.

Once the Object Manager Enterprise (OME) is installed you can see it in Eclipse by selecting Window- >Open Perspective->Other and choosing "OME". Typically, OME window should look similar to this:

如果你没有安装OME,请返回第一章节并按照安装说明进行安装。

如果已经安装,则点击Window- >Open Perspective->Other 选择OME,你将会看到如下的界面:

 

In the OME perspective you can see:

在OME视图上,你可以看到如下菜单:

- OME menu:

 

- OME toolbar buttons to access the frequently used functionality fast

- Db4o Browser: window displaying the contents of the open db4o database

- Property Viewer: window displaying the properties of the open database or the properties of the selected database class

- Build Query: windows allowing to build a query using drag&drop functionality

- Query Results: window to browse the results of the query execution

 

--点工具栏按钮快速访问经常使用的功能
--Db4o浏览器:窗口显示打开的Db4o数据库内容
--属性查看器:窗口显示打开的Db4o数据库属性或选定的数据库类的属性
--构建查询:windows允许使用拖放功能建立一个查询

--查询结果:窗口浏览查询执行的结果

 

3.1. Browsing the database(浏览数据库)

In the previous chapter we've learned how to create a new database and store objects in it. Let's create a new database and store some objects in it now:

在前面的章节中,我们学习了如何创建一个数据库并存储对象,现在我们创建一个新的数据库并往里面存储一些对象:

// deleteDatabase

new File(DB4OFILENAME).delete();

OUTPUT:

 

 

// storePilots

ObjectContainer db=Db4oEmbedded.openFile(Db4oEmbedded

.newConfiguration(), DB4OFILENAME);

try {

Pilot pilot1=new Pilot("Michael Schumacher",100);

db.store(pilot1);

System.out.println("Stored "+pilot1);

Pilot pilot2=new Pilot("Rubens Barrichello",99);

db.store(pilot2);

System.out.println("Stored "+pilot2);

}

finally {

db.close();

}

OUTPUT:

Stored Michael Schumacher/100

Stored Rubens Barrichello/99

 

Now we can see the resultant database in the Object Manager. Please select OME-

>Connect/Disconnect DB (or use a shortcut button from the toolbar menu) and browse to ome.db4o file in your user folder. (normally it is c:/Documents and Settings/[user name] on Windows XP/2000, c:/Users/[user name] on Windows Vista and/home/[user_name] on *nix systems).

Once you've connected you will see a screen similar to this:

The db4o Browser window shows that there is 1 class in the database (Pilot), which contains 2 fields:name and points. In the Property Viewer you can see more information about the class fields. You can also change "Is indexed" field and add the index to the database by pressing "Save Index" button.

The filter panel on the top of the view allows easier navigation through the database with lots of different classes. You can use wildcard searches and benefit from the search history to make the selection faster.

现在我们用OME工具进行查看,依次选择Eclipse中菜单栏上的OME>Connect/Disconnect DB

 

点击打开文档的Browe,选择db4o的数据库所在目录(我本机保存名字为:firstDB.db,你可以根据实际情况选择你工作目录下生成的数据库文件)。

 

 

点击Connect to db4o database即可。

成功之后如下所示:

 

 

3.2. Querying

It is easy to retrieve all of the Pilot instances from the database: just right-click the Pilot class in db4o Browser and select "View All Objects". The list of the Pilot objects will be shown in the Query Result view:

很容易从数据库中检索到Pilot:右击Pilot,选择"View All Objects",结果将会显示在Query Result view中。



You can see object details in the detailed view below. Try to change any values and use Save button to persist the changes to the database. You can also use Delete button to delete objects from the database. For the objects containing field objects you will be prompted to use cascade on delete.

你可以从下面的详细视图看到对象细节。试图改变任何值,并使用Save按钮将更改保存到数据库。您还可以使用删除按钮将对象从数据库中删除。如果一个对象里面的字段包含对象类型,则需要使用及连删除。


More complex queries can be done using Build Query view:

对于复杂的查询,可以使用Build Query view完成:


Drag "points" field from the db4oBrowser view into the Build Query view, set condition "Greater Than", put a value "99" and run the query. You can return to the Built Query tab and modify the query later on again. For example: add "AND" operator, drag "name" field and set the value to "Michael Schumacher". Re-run the query.

When the new query is created, the previous query is stored and can be selected from the history drop-down:

将points字段从db4oBrowser view托到Build Query view,设置condition"Greater Than",设置value99,点击 下面的run the query,便可查看到查询后的结果。你可以修改查询条件,例如:修改operatinand ,然后将name也托到Build Query view中,输入value值“Michael Schumacher”,再次点击查询即可。


More sophisticated queries can be build by joining grouped constraints using "Add Group" button.

When you are done working with the database in OME, you can close the connection by using OME- >Connect/Disconnect DB menu command or by using the equivalent button on the toolbar.

In the next chapter we will explore more about db4o querying capabilities. You can continue using OME while going through the rest of this tutorial. If you are using the interactive version you will find the database in formula1.db4o file in your user folder. (normally it is c:/Documents and Settings/[user name] on Windows XP/2000, c:/Users/[user name] on Windows Vista and /home/[user_name] on *nix

systems). Please, remember to disconnect OME before running any of the tutorial examples, as only one active connection is allowed to the database file.

 

更复杂的查询可以通过加入分组构建约束,使用“添加组”按钮。
当你在OME下对数据库操作完成后,可以通过使用 OME- >Connect/Disconnect DB菜单命令或通过使用工具栏上的按钮关闭连接。

在下一章我们将探索更多关于db4o查询功能。你可以在本教程的其余部分继续使用OME。如果您正在使用数据库的交互式版本,你会发现formula1.db4o文件在您的用户文件夹中。

请记住在运行其它的教程例子之前断开OME连接,因为同一时间只能有一个连接牌活动状态。


下篇:db4o_8.0对象数据库官方文档翻译_学习笔记四 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值