Your SlideShare is downloading. ×
First Steps. (db4o - Object Oriented Database)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

First Steps. (db4o - Object Oriented Database)

656
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
656
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. #2 First Steps Wildan Maulana wildan.m@openthinklabs.com
  • 2. First Stepspackage com.db4odoc.f1.chapter1; ....public class Pilot { public String getName() { private String name; return name; private int points; } public Pilot(String name,int points) { public String toString() { this.name=name; return name+"/"+points; this.points=points; } } } public int getPoints() { return points; } public void addPoints(int points) { this.points+=points; } .....
  • 3. Opening the database// accessDb4oObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded .newConfiguration(), DB4OFILENAME);try { // do something with db4o} finally { db.close();}
  • 4. Storing objects// storeFirstPilotPilot pilot1 = new Pilot("Michael Schumacher", 100);db.store(pilot1);System.out.println("Stored " + pilot1);// storeSecondPilotPilot pilot2 = new Pilot("Rubens Barrichello", 99);db.store(pilot2);System.out.println("Stored " + pilot2);
  • 5. Retrieving objects public static void listResult(List<?> result){ System.out.println(result.size()); for (Object o : result) { System.out.println(o); Shorcut for JDK 5 } } List <Pilot> pilots = db.query(Pilot.class);// retrieveAllPilotQBEPilot proto = new Pilot(null, 0);ObjectSet result = db.queryByExample(proto);listResult(result); // retrieveAllPilots ObjectSet result = db.queryByExample(Pilot.class); listResult(result);
  • 6. Retrieving objectsQuery Pillot By Name// retrievePilotByNamePilot proto = new Pilot("Michael Schumacher", 0);ObjectSet result = db.queryByExample(proto);listResult(result); Query for Pilots with a specific number of points // retrievePilotByExactPoints Pilot proto = new Pilot(null, 100); ObjectSet result = db.queryByExample(proto); listResult(result);
  • 7. Updating objects// updatePilotObjectSet result = db .queryByExample(new Pilot("Michael Schumacher", 0));Pilot found = (Pilot) result.next();found.addPoints(11);db.store(found);System.out.println("Added 11 points for " + found);retrieveAllPilots(db);
  • 8. Deleting objects// deleteFirstPilotByNameObjectSet result = db .queryByExample(new Pilot("Michael Schumacher", 0));Pilot found = (Pilot) result.next();db.delete(found);System.out.println("Deleted " + found);retrieveAllPilots(db); // deleteSecondPilotByName ObjectSet result = db .queryByExample(new Pilot("Rubens Barrichello", 0)); Pilot found = (Pilot) result.next(); db.delete(found); System.out.println("Deleted " + found); retrieveAllPilots(db);
  • 9. Q&Adb4o forums db4o community