persistentBeanTemplate creates Java CRUD (create, read, update, delete) beans.
CRUD beans allow object level persistence to relational databases. It has full support for all JDBC 2.0 datatypes, including BLOB and CLOB.
Each bean has a 1 to 1 correspondence with a sql table, and supports standard CRUD (create, read, update, delete) functionality. In addition, these persistent beans can use optimistic locking in conjunction with a "transaction control number" to ensure data integrity during concurrent updates.
The bean-per-table approach, while not "transparent" in the sense that JDO is transparent (hands off persistence), is transparent in terms of usability. The developer knows exactly what is happening behind the scenes. Traditional object models can still be maintained by extending or aggregating the bean. By placing all business logic in your extended classes, xbeans can be regenerated as the datastore changes, without affecting any of your business logic.
Connection pooling and transaction control is handled by business logic, while concurrency control is transparent and handled by the bean. To use optimistic locking, each table must incorporate a field for a transaction control number.
Here is an example standard bean. and lob bean. See the technical docs for more information.
The persistent beans generated with Xml2Bean should work with any JDBC Type 3-4 driver. The following drivers have been tested:
Database | Driver | Jar |
---|---|---|
MySql | org.gjt.mm.mysql.Driver | mm.mysql-2.0.4-bin.jar |
Oracle | oracle.jdbc.driver.OracleDriver | classes12.jar |
Postgres | org.postgresql.Driver | jdbc7.1-1.2.jar |
MS Sql Server | com.inet.tds.TdsDriver | sprinta2000.jar |
Cloudscape | COM.cloudscape.core.JDBCDriver | cloudscape.jar |
DB2 | COM.ibm.db2.jdbc.app.DB2Driver | db2java.jar |
Insert a new record:
StudentBean student = new StudentBean();
student.setName("Pat");
student.setAge(20);
student.persist(connection);
Update a record:
Vector students = StudentBean.load("where student_id = 111223333");
StudentBean student = (StudentBean)students.firstElement();
student.setName("Pat");
student.setAge(21);
student.persist(connection);
Delete a record:
StudentBean.delete(connection, "where student_id = 111223333");
Select all records:
Vector students = StudentBean.load(connection, "");
Servlet html form support:
StudentBean student = new StudentBean();
student.load(response.getMap());
student.persist(connection);
Managing many to many persistence:
Many students have may classes:
- student table
- course table
- student_course table
student.dropCourse("CS101");
or
course.dropStudent("111223333");
or
String where = "where course_id = '" + courseId + "'" AND student_id = " + studentId
StudentCourseBean.delete(connection,where);