1. Soda query Graphs
---- A graph data structure
Find all persons whose names are "Lincoln"
2. Soda keywords
(1) query keywords
(2) Constraint keywords
3. query example
(1) query all
DB = db4o. openfile ("Customer. yap"); Query = dB. Query (); query. constrain (customer.Class); List <customer> rsw.query.exe cute ();For(Customer C: RS) {system. Out. println (C. getname ());}
(2) conditional Query
Query query = dB. Query ();Query. constrain (customer.Class); // Class-level constraintsQuery. Descend ("Name"). Constrain ("Customer2"); // Field-level constraintsList <customer> rsw.query.exe cute ();
(3) Use keywords
DB = db4o. openfile ("Customer. yap"); Query = dB. Query (); query. constrain (customer.Class); Query. Descend ("Name"). Constrain ("Customer2"). Not ();List <customer> rsw.query.exe cute ();
(4) Compound Conditions
And usage:
Query query = dB. Query (); query. constrain (customer.Class);Constraint firstconstr = query. Descend ("Phonenumber"). Constrain ("Phone2"); Query. Descend ("Name"). Constrain ("Customer2"). And (firstconstr );List <customer> rsw.query.exe cute ();
It is equivalent:
Query query = dB. Query (); query. constrain (customer.Class); Query. Descend ("Name"). Constrain ("Customer2"); Query. Descend ("Phonenumber"). Constrain ("Phone2"); List <customer> rsw.query.exe cute ();
Query query = dB. Query ();
Or usage: Query. constrain (customer.Class);Constraint firstconstr = query. Descend ("Phonenumber"). Constrain ("Phone3"); Query. Descend ("Name"). Constrain ("Customer2"). Or (firstconstr );List <customer> rsw.query.exe cute ();
(5) Greater/smaller
Query query = dB. Query (); query. constrain (person.Class); Query. Descend ("_ Age"). Constrain (80). Greater (); objectset resultappsquery.exe cute ();
(6) Range Query
Query query = dB. Query (); query. constrain (person.Class); Constraint firstconstr = query. Descend ("_ Age"). Constrain (60). Greater (); query. Descend ("_ Age"). Constrain (80). Smaller (). And (firstconstr );
(7) fuzzy search
Query query = dB. Query (); query. constrain (person.Class); Query. Descend ("_ Name"). Constrain ("Ma"). Like ();// Also works with "Ma"Objectset result = query.exe cute ();
(8) query null values
Query query = dB. Query (); query. constrain (person.Class); Query. Descend ("Age"). Constrain (0 );// Field has been setObjectset resultappsquery.exe cute ();
(9) sorting results
// JavaQuery query = dB. Query (); query. constrain (person.Class); Query. Descend ("_ Name"). Orderascending ();// The list shocould start with the lowestObjectset resultappsquery.exe cute ();