12.2 The Oracle J2ME SODA SDKThe Oracle9i Lite database does not run on the MIDP platform. Instead, Oracle provides a Java object database for MIDP devices. The Oracle J2ME SDK (beta) supports the Oracle Simple Object Database Access (SODA) data store. Built on top of the standard RMS, SODA allows us to store, search, and retrieve Java data objects directly. The oracle.wireless.me.soda package contains six classes (see descriptions in Table 12.1).
Listing 12.2 demonstrates the use of the SODA. The code is based on the example included in Oracle J2ME SDK. Listing 12.2. The SODA demoDBSession sess = new DBSession(); // Create a new DBClass with an INT field // and a String field. // The name of this DBClass is "dept". You can // get it by its name using findClass() method // in the sess object. DBClass dept = sess.createClass( "dept", new DBAttr[] { new DBAttr("id", DBAttr.C_INT), new DBAttr("name", DBAttr.C_STRING) } ); // Load a comma delimited database file. // It will create a number of DBObjects // under the "dept" DBClass. DBLoader.loadCSV(dept, new InputStreamReader(in), dept.allAttr()); // Now, get all DBObjects (null match condition) // in dept class in a DBCursor DBCursor c = dept.createCursor(null, null); // Iterate and get all field attributes // in the DBClass. DBAttr[] a = dept.getAttrs(); for (int i = 0; i < a.length; i++) System.out.print(a[i].name+", "); System.out.println(); DBObject o; // Iterate through the cursor and get // data in each column (field). while ((o = c.next()) != null) { for (int i = 0; i < a.length; i++) System.out.print(o.getString(i)+","); System.out.println(); } c.close(); } // Remember to release resources. sess.close(); |