Enterprise J2ME Developing Mobile Java Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Enterprise J2ME Developing Mobile Java Applications [Electronic resources] - نسخه متنی

Michael Juntao Yuan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



12.2 The Oracle J2ME SODA SDK


The 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).

Table 12.1. Oracle Simple Object Database Access (SODA) API

Java class

Description

DBSession

It manages the databases and transactions. When you instantiate it, you can specify the maximum number of underlying RMS record stores it uses.

DBClass

It is analogous to a SQL Table in the relational world. It has a name and multiple data fields. DBClass objects can be created using the DBSession.createClass() factory method.

DBAttr

Each data field in the DBClass is represented by a DBAttr object. A DBAttr has a name and a type. The type could be one of the SQL types (e.g., INT, BOOLEAN, STRING) or an array type or a DBObject for a nested Java data object.

DBObject

It is analogous to a row of data in a table in the relational world. The DBObject class defines JDBC style getter and setter methods (e.g., getBoolean(), setString(), etc.) to access its data columns (i.e., DBAttr objects).

DBLoader

It is a helper class that loads data from a text file into DBObjects in a DBClass in a batch.

DBCursor

We can search a DBObject (row) in a DBClass (table) using the DBClass.match() method. Or, we can use the DBClass.createCursor() method to get a set of DBObjects linked to a DBCursor object. We can then navigate through those DBObjects by using methods such as DBCursor.next() and DBCursor.prior().

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 demo



DBSession 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();


/ 204