Neo wrote:
Quote:
Where can I find simple example that demos db40. |
In our interactive tutorial that comes with the
download. It allows you to run all demo samples
from within the browser, while you read along
the source code.
Quote:
For example, how would
one create 2 persons, each with properites name,
age and gender; |
You would create the respective classes in your
preferred programming language. We support Java
and all .NET languages like C# and VB .NET.
// Let's go for Java
public class Person{
String name;
int age;
Gender gender;
public Person(String name, int age, Gender gender){
this.name = name;
this.age = age;
this.gender = gender;
}
}
public class Gender{
static final Gender MALE = new Gender();
static final Gender FEMALE = new Gender();
}
// To store two person objects
// import the classes from db4o.jar.
import com.db4o.*;
// open a database file
ObjectContainer oc = Db4o.openFile("myDB.yap");
// store two Person objects
oc.set(new Person("Jeff", 32, Gender.MALE));
oc.set(new Person("Sue", 29, Gender.FEMALE));
// closing the database performs an automatic commit
oc.close();
The above is all you need to do. db4o analyses the
classes during runtime.
However there is one specific configuration step that
is necessary to tell db4o to use the Gender class to
supply static constants:
Db4o.configure().objectClass(new Gender())
..persistStaticFieldValues();
Quote:
and how to query for a person by age and gender? |
// simple query by example on an ObjectContainer:
Person example = new Person(null, 32, Gender.MALE);
ObjectSet objectSet = oc.get(emample);
// an alternative using S.O.D.A. notation:
Query q = oc.query();
q.constrain(Person.class);
q.descend("age").constrain(new Integer(32));
q.descend("gender").constrain(Gender.MALE).identit y();
ObjectSet objectSet = q.execute();
Quote:
Also, suppose gender is
used for other things such as animals, how does one
normalize gender values? |
As above.
Best,
Carl
--
Carl Rosenberger
Chief Software Architect
db4objects Inc.
http://www.db4o.com