The DBBean Framework
Basic DBBean Operations: Insert, Select, Delete

Once you have the DBBean classes for your database, it is easy to manipulate the database through the DBBean framework.

Basic Operations:

  • Insert: Insert a row into a table in the DB
  • Select: Select one or more rows from the DB, matching your search criteria
  • Delete - Delete on or more rows from the DB, matching your search criteria
 
DB mDB = [get the db instance];

// insert a person in to the DB
PersonBean mBean = new Person();
mBean.setValue(PersonBean.FIRST_NAME,"john");
mBean.setValue(PersonBean.LAST_NAME,"smith");
mBean.setValue(PersonBean.AGE,new Integer(25));
mDB.insertBean(mBean);
 
DB mDB = [get the db instance];

// select all people from the db
DBBean mBean = new PersonBean();
DBBean[] mArray = mDB.selectBean(mBean); 

// select all people with first name john
mBean.setValue(PersonBean.FIRST_NAME,"john");
mArray = mDB.selectBean(mBean);

// select all people with first name starting with j
mBean.addSelectLike(PersonBean.FIRST_NAME,"j");
mArray = mDB.selectBean(mBean);

// select the one bean with first name johh
// throws DBSelectSingleException unless exactly one bean is found
mBean = new PersonBean();
mBean.setValue(PersonBean.FIRST_NAME,"john");
mBean = mDB.selectSingleBean(mBean);
 
DB mDB = [get the db instance];

// Delete all of the person beans with first name john
DBBean mBean = new PersonBean();
mBean.setValue(PersonBean.FIRST_NAME,"john");
int mBeansDeleted = mDB.deleteBean(mBean);

// Delete a single bean, with last name smith
// throws DBDeleteSingleException unless a single bean is deleted
mBean = new PersonBean();
mBean.setValue(PersonBean.LAST_NAME,"smith");
mDB.deleteSingleBean(mBean);