db4o (database for objects) is an embeddable open source object database for Java and .NET developers.
db4o represents an object-oriented database model.
db4o does not require a separate data model creation, the application’s class model defines the structure of the data in db4o database.
Features:
Advantages:
Drawbacks:
Eliminate Mapping Complexity
Java Sample Code:
Model Class:
public class Pilot {
private String name;
private int points;
private List<String> address ;
private Map<String,String> addressMap ;
//Getter and Setter Methods
}
Access DB4O database:
public static void accessDb4o() {
// do something with db4o
} finally {
db.close();
}
}
Store Object:
Pilot pilot1 = new Pilot("Michael Schumacher", 100,address,addressMap);
db.store(pilot1);
Display List:
public static void listResult(List<?> result){
}
Retrieve Object:
Pilot proto = new Pilot(null, 0,null,null);
ObjectSet result = db.queryByExample(proto);
OR
ObjectSet result = db.queryByExample(Pilot.class);
OR
Pilot proto = new Pilot("Michael Schumacher", 0,null,null);
ObjectSet result = db.queryByExample(proto);
OR
Pilot proto = new Pilot(null, 100,null,null);
ObjectSet result = db.queryByExample(proto);
Update Object:
Pilot proto = new Pilot("Michael Schumacher", 0,null,null);
ObjectSet result = db.queryByExample(proto);
Pilot found = (Pilot) result.next();
found.addPoints(11);
db.store(found);
Delete Object:
Pilot proto = new Pilot("Michael Schumacher", 0,null,null);
ObjectSet result = db.queryByExample(proto);
Pilot found = (Pilot) result.next();
db.delete(found);
db4o represents an object-oriented database model.
db4o does not require a separate data model creation, the application’s class model defines the structure of the data in db4o database.
Features:
- One-line-of-code database
- Embeddable
- Client-server mode
- Dynamic schema evolution
- Native Queries
Advantages:
- 40% faster to market with your application.
- Full ACID transactional capabilities.
- Slashes 40% of cost to develop persistence.
- Deployable in large volumes without local administration.
- Build asynchronously-distributed, fully synchronized data architectures.
- Fewer errors, better maintainability and software longevity.
Drawbacks:
- Lack of full-text indexing, poor performance on full-text search.
- Lack of Indexing for string types, text based searches can potentially be very slow
- Replication cannot be done administratively—i.e. one needs to program an application to achieve replication.
- Deleted fields are never removed but just hidden until the next Defrag.
- There is no built-in support to import/export data to/from text, XML or JSON files.
- Support of Unique constraints and cascaded operation is partially incomplete and highly immature
Eliminate Mapping Complexity
- Using relational DB, the difficulty comes from the fact that the schema in the database does not match your application schema and you're forced to bridge that gap.
- With an object database like db4o your application schema IS your data schema, no mapping required, no extra work - which translates into ease of use and higher performance!
Java Sample Code:
Model Class:
public class Pilot {
private String name;
private int points;
private List<String> address ;
private Map<String,String> addressMap ;
public Pilot(String name, int points,List<String> address,Map<String,String> addressMap) {
this.name = name;
this.points = points;
this.address = address;
this.addressMap = addressMap;
}//Getter and Setter Methods
}
Access DB4O database:
public static void accessDb4o() {
ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), DB4OFILENAME);
try {// do something with db4o
} finally {
db.close();
}
}
Store Object:
Pilot pilot1 = new Pilot("Michael Schumacher", 100,address,addressMap);
db.store(pilot1);
Display List:
public static void listResult(List<?> result){
System.out.println("Total Records: " + result.size());
for (Object o : result) {
System.out.println("Object: " + o);
}}
Retrieve Object:
Pilot proto = new Pilot(null, 0,null,null);
ObjectSet result = db.queryByExample(proto);
OR
ObjectSet result = db.queryByExample(Pilot.class);
OR
Pilot proto = new Pilot("Michael Schumacher", 0,null,null);
ObjectSet result = db.queryByExample(proto);
OR
Pilot proto = new Pilot(null, 100,null,null);
ObjectSet result = db.queryByExample(proto);
Update Object:
Pilot proto = new Pilot("Michael Schumacher", 0,null,null);
ObjectSet result = db.queryByExample(proto);
Pilot found = (Pilot) result.next();
found.addPoints(11);
db.store(found);
Delete Object:
Pilot proto = new Pilot("Michael Schumacher", 0,null,null);
ObjectSet result = db.queryByExample(proto);
Pilot found = (Pilot) result.next();
db.delete(found);
0 comments:
Post a Comment