Click here to view in C++
This is an example on how to use predicate scans. In this example, the database has 4 "Car" objects.
After ingesting some data, the application does a predicate scan on the container that has these four objects for 158*. That is: "VIN=~ \"158.*.\""
Program Output
Car.java
import com.objy.db.app.*;
class Car extends ooObj
{
public String VIN;
public void setVin(String vinNum)
{
markModified(); //to mark object for update
VIN = vinNum;
}
public String returnVin()
{
fetch(); //mark object for read
return VIN;
}
};
createObj.java
import com.objy.db.*;
import com.objy.db.app.*;
public class createObj
{
public static void main(String[] args)
{
String bootfile = "test.boot"; //insert bootfile name here
String dbName = "testDB"; //insert db name here
String contName = "testCont"; //insert cont name here
Connection connection = null;
Session session = null;
try
{
connection = Connection.open(bootfile, oo.openReadWrite);
connection.loadSchemaClasses(true);
session = new Session();
ooFDObj fd = session.getFD();
session.begin();
ooDBObj db = null;
if(fd.hasDB(dbName))
{
db = fd.lookupDB(dbName);
}
else
{
db = fd.newDB(dbName);
}
ooContObj cont = null;
if(db.hasContainer(contName))
{
cont = db.lookupContainer(contName);
}
else
{
cont = new ooContObj();
db.addContainer(cont, 0, contName, 0, 0);
}
Car obj;
obj = new Car();
cont.cluster(obj);
obj.setVin("158L3X");
obj = new Car();
cont.cluster(obj);
obj.setVin("462A2H");
obj = new Car();
cont.cluster(obj);
obj.setVin("158P7D");
obj = new Car();
cont.cluster(obj);
obj.setVin("472G1Q");
session.commit();
session.begin();
Iterator carItr;
carItr = cont.scan("Car", "VIN=~ \"158.*.\"");
System.out.println("Found Cars with VIN starting with 158");
while(carItr.hasNext())
{
System.out.println(((Car)carItr.next()).returnVin());
}
session.commit();
}
catch(Exception e)
{
e.printStackTrace();
session.abort();
}
}
}
|
|||
