100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > db4o_8.0对象数据库官方文档翻译_学习笔记三

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

时间:2023-08-28 01:00:59

相关推荐

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

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

3.ObjectManagerEnterpriseOverview(OME视图)即OME插件的使用

IfyoudidnotinstalltheObjectManagerEnterpriseyet,please,returntoFirstGlancechapterandfollowtheinstallationinstructionsthere.

OncetheObjectManagerEnterprise(OME)isinstalledyoucanseeitinEclipsebyselectingWindow->OpenPerspective->Otherandchoosing"OME".Typically,OMEwindowshouldlooksimilartothis:

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

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

IntheOMEperspectiveyoucansee:

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

-OMEmenu:

-OMEtoolbarbuttonstoaccessthefrequentlyusedfunctionalityfast

-Db4oBrowser:windowdisplayingthecontentsoftheopendb4odatabase

-PropertyViewer:windowdisplayingthepropertiesoftheopendatabaseorthepropertiesoftheselecteddatabaseclass

-BuildQuery:windowsallowingtobuildaqueryusingdrag&dropfunctionality

-QueryResults:windowtobrowsetheresultsofthequeryexecution

--点工具栏按钮快速访问经常使用的功能

--Db4o浏览器:窗口显示打开的Db4o数据库内容

--属性查看器:窗口显示打开的Db4o数据库属性或选定的数据库类的属性

--构建查询:windows允许使用拖放功能建立一个查询

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

3.1.Browsingthedatabase(浏览数据库)

Inthepreviouschapterwe'velearnedhowtocreateanewdatabaseandstoreobjectsinit.Let'screateanewdatabaseandstoresomeobjectsinitnow:

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

//deleteDatabase

newFile(DB4OFILENAME).delete();

OUTPUT:

//storePilots

ObjectContainerdb=Db4oEmbedded.openFile(Db4oEmbedded

.newConfiguration(),DB4OFILENAME);

try{

Pilotpilot1=newPilot("MichaelSchumacher",100);

db.store(pilot1);

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

Pilotpilot2=newPilot("RubensBarrichello",99);

db.store(pilot2);

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

}

finally{

db.close();

}

OUTPUT:

StoredMichaelSchumacher/100

StoredRubensBarrichello/99

NowwecanseetheresultantdatabaseintheObjectManager.PleaseselectOME-

>Connect/DisconnectDB(oruseashortcutbuttonfromthetoolbarmenu)andbrowsetoome.db4ofileinyouruserfolder.(normallyitisc:/DocumentsandSettings/[username]onWindowsXP/2000,c:/Users/[username]onWindowsVistaand/home/[user_name]on*nixsystems).

Onceyou'veconnectedyouwillseeascreensimilartothis:

Thedb4oBrowserwindowshowsthatthereis1classinthedatabase(Pilot),whichcontains2fields:nameandpoints.InthePropertyVieweryoucanseemoreinformationabouttheclassfields.Youcanalsochange"Isindexed"fieldandaddtheindextothedatabasebypressing"SaveIndex"button.

Thefilterpanelonthetopoftheviewallowseasiernavigationthroughthedatabasewithlotsofdifferentclasses.Youcanusewildcardsearchesandbenefitfromthesearchhistorytomaketheselectionfaster.

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

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

点击Connecttodb4odatabase即可。

成功之后如下所示:

3.2.Querying

ItiseasytoretrieveallofthePilotinstancesfromthedatabase:justright-clickthePilotclassindb4oBrowserandselect"ViewAllObjects".ThelistofthePilotobjectswillbeshownintheQueryResultview:

很容易从数据库中检索到Pilot:右击Pilot,选择"ViewAllObjects",结果将会显示在QueryResultview中。

Youcanseeobjectdetailsinthedetailedviewbelow.TrytochangeanyvaluesanduseSavebuttontopersistthechangestothedatabase.YoucanalsouseDeletebuttontodeleteobjectsfromthedatabase.Fortheobjectscontainingfieldobjectsyouwillbepromptedtousecascadeondelete.

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

MorecomplexqueriescanbedoneusingBuildQueryview:

对于复杂的查询,可以使用BuildQueryview完成:

Drag"points"fieldfromthedb4oBrowserviewintotheBuildQueryview,setcondition"GreaterThan",putavalue"99"andrunthequery.YoucanreturntotheBuiltQuerytabandmodifythequerylateronagain.Forexample:add"AND"operator,drag"name"fieldandsetthevalueto"MichaelSchumacher".Re-runthequery.

Whenthenewqueryiscreated,thepreviousqueryisstoredandcanbeselectedfromthehistorydrop-down:

将points字段从db4oBrowserview托到BuildQueryview,设置condition为"GreaterThan",设置value为99,点击下面的runthequery,便可查看到查询后的结果。你可以修改查询条件,例如:修改operatin为and,然后将name也托到BuildQueryview中,输入value值“MichaelSchumacher”,再次点击查询即可。

Moresophisticatedqueriescanbebuildbyjoininggroupedconstraintsusing"AddGroup"button.

WhenyouaredoneworkingwiththedatabaseinOME,youcanclosetheconnectionbyusingOME->Connect/DisconnectDBmenucommandorbyusingtheequivalentbuttononthetoolbar.

Inthenextchapterwewillexploremoreaboutdb4oqueryingcapabilities.YoucancontinueusingOMEwhilegoingthroughtherestofthistutorial.Ifyouareusingtheinteractiveversionyouwillfindthedatabaseinformula1.db4ofileinyouruserfolder.(normallyitisc:/DocumentsandSettings/[username]onWindowsXP/2000,c:/Users/[username]onWindowsVistaand/home/[user_name]on*nix

systems).Please,remembertodisconnectOMEbeforerunninganyofthetutorialexamples,asonlyoneactiveconnectionisallowedtothedatabasefile.

更复杂的查询可以通过加入分组构建约束,使用“添加组”按钮。

当你在OME下对数据库操作完成后,可以通过使用OME->Connect/DisconnectDB菜单命令或通过使用工具栏上的按钮关闭连接。

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

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。