Database concepts enable you to manipulate the database using a rule or rule function. The database concepts feature has an O/R (object to relational) mapping feature that enables you to simply act on the concepts (database concepts are BusinessEvents concepts with database behavior) and delegate the persistence of these objects to the catalog functions. The RDBMS functions catalog allows you to perform basic CRUD operations on database tables using database concepts.
In a rule, use setCurrentConnection() once before performing any database operation. Use
unsetConnection() once after all database operations are performed. You must call
unsetConnection() even in case of a failure within the rule function. If you don’t unset the connection, the connection is not returned to the database connection pool, which amounts to a resource leak.
Use of setCurrentConnection() may result in an exception if the underlying database is disconnected.
By default, all database statements are individually committed. For example, if an insert call results in multiple insert statements, then each one gets committed individually. To ensure that all statements are grouped inside a transaction, call the
beginTransaction() function explicitly.
You have to explicitly commit the transaction using Database.commit() otherwise it results in a rollback.
The insert function Database.insert() inserts an object and its concept properties (if any) recursively into the database. You can insert all related objects at once instead of performing individual inserts. The join keys are internally managed.
If columns in the database are modified by the database during inserts, these changes are also made in the concept instances. This is usually the case when primary keys are automatically generated or when columns have default values.
Create an XML file with an extension .sequences.xml and add it to the project as a shared resource.
The property attribute is the name of the property that holds the primary key.
The unique_identifier attribute holds the name of the Oracle sequence to use.
In order for the database to perform updates or deletes on the BusinessEvents objects, or for BusinessEvents to perform updates or deletes on the database tables, the software must be able to uniquely identify the row. Therefore, you can only perform delete and update operations if the table has at least one primary key.
To find out whether a table has primary keys or not, open the project in TIBCO Designer, and check the
PRIMARY_ KEY_PROPS extended property, which is on the Extended Properties tab for the concept. If this property has no value, no primary keys exist and you can’t perform update or delete operations.
The Database.update() function updates the database with values contained in the concept.
The Database.delete() function deletes a record corresponding to the concept instance in the database. If
cascade is set to
true, it deletes all database records corresponding to the contained concept property references and nulls out foreign key references in database records corresponding to the concepts that refer to the concept being deleted.
Concepts returned by these query operations are not automatically asserted. You must explicitly assert these concepts as required, using the
Database.assertDBInstance(concept, deep) function to assert a database concept.
When a database concept is asserted with the deep parameter set to
true, all the referenced concepts are also asserted.