mulax - 2014-04-12

Class requeriments to persist:

class myObject1 {
   @jsndbObjectId
   private long id;

   public long getId() {
    return id;
   }

   public void setId(long id) {
    this.id = id;
   }
}

open database:

 jsndb js = new jsndb(System.getProperty("user.dir")+"database");

save object:

 js.persist(new myObject1()).persist(new myObject2()).commit()

update:

 just save, edit, and save again

retrive object by id:

 myObect1 obj= js.getById(long id, myObject1.class);

Queries:

qwery q=qwery.create(myObject1.class, "cyndi", "name", comparator.equal);
qwery q2=qwery.create(myObject1.class, 12, "age",comparator.egreatter);
q=connectors.and(q,q2);

indexes:

index are created or loaded automatically when querie is analized

select:

ArrayList<myObject1> list=js.select(q, myObject1.class);

use comparator.contains only to search fathers of objects

class hotel {
   String name;
   int stars;
}

class city {
   String name;
   List<hotel> hotels;
}

qwery q1=qwery.create(hotel.class, 4, "stars", comparator.equal);
qwery q2=qwery.create(city.class, q1, "hotels",comparator.contains);
ArrayList<myObject1> list=js.select(q2, city.class);

list must have only city with 4 star hotels

 

Last edit: mulax 2014-04-14