Posted by guruwons
on July 6, 2007 at 7:39 PM PDT
Recently I've implemented two minor but useful features for TopLink Essentials(TLE) v2 b54(or GlassFish v2 b54). One is the category-specific logging level configuration which is useful for who want to see only SQL logs and the other is the cascade refresh query hintwhich control the cascade scope of the refresh query dynamically.
Recently I've implemented two minor but useful features for TopLink Essentials (TLE) v2 b54(or GlassFish v2 b54). One is the category-specific logging level configuration which is useful for who want to see only SQL logs and the other is the cascade refresh query hint which control the cascade scope of the refresh query dynamically.
Let's see what these are...
Category-specific logging level
Configuring logging level for a PU(Persistence Unit) could be done by "toplink.logging.level" property like below.
<property name="toplink.logging.level" value="FINE"/>
To see SQLs triggerred by TLE the logging level should be FINE. However this will print other many FINE logs which may be of little interest to normal users. This is like all-or-nothing choice.
Fortunately the logging platform of TLE basically supports categories for different types of logs - "sql", "connection", "transaction" and so on.
This enable users to watch interested logs of specific categories. Especially the "sql" category is the most interesting one.
However there had been no easy way to configure the logging level for the specific category. So I've added the following new category logging level property and connected it with logger code.
| Property |
| Description |
| toplink.loging.level.<category> ||Control the log level for a specific category.
Categories(defined in oracle.toplink.essentials.logging.SessionLog):
- sql - SQL logs
- transaction - Transaction related logs
- connection - Session related logs
- query - DatabaseQuery related logs
- cache - shared cache logs
- sequencing - sequencing generator logs
- ejb_or_metadata - metadata processing logs
- weaver - class weaver logs
- properties - deployment time properties handler logs
Valid values are defined in
If there is no category-specific level, the level set with toplink.logging.level(INFO is default) is used.
Example: to see SQL logs
Cascade refresh query hint for refresh query
TLE provides the query hint toplink.refresh to fetch up-to-date entities from database like below.
Query query = em.createQuery("SELECT e FROM Employee e WHERE e.id = :id");The associated entities will be refreshed also if they are specified with cascade=REFRESH. However the cascade metadata is static configuration which can not be changed in runtime and there may be some cases to apply different cascade options - do not cascade or cascade to all associations from time to time regardless of predefined cascade option. That is, more dynamic cascade refresh option can be useful. Hence I added the following query hint.
| Query hint
| Control whether associated entities are refreshed.
The following are the valid values for the
- NoCascading - do not cascade at all
- CascadePrivateParts - cascade to private-owned associations
- CascadeAllParts - cascade to all associations
- CascadeByMapping - cascade by mapping metadata
Default is CascadeByMapping
import oracle.toplink.essentials.config.TopLinkQueryHints; NOTE: This applies only if toplink.refresh is set to TRUE.
At this time CascadePrivateParts option has no difference from CascadeAllParts for Java Persistence Entity, but when using underlying TopLink feature this could behave different in the future.
Other existing properties and query hints are documented in http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html
Have fun with this enhancements and please comment how you feel.
 GlassFish Issue#1338
 GlassFish Issue#3269