Dive into BC4J and ADF

Send me a mail
 Dive into BC4J and ADF    Click to see the XML version of this web page.   (Updated: 6/3/2006; 11:49:53 AM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper 10g

Search blog with Google:
 

Search BC4J JavaDoc:
 

November 2003
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Oct   Dec

Get Firefox!

Thursday, November 13, 2003

As part of the same customer testcase I was just studying to give Worldwide Support some advice about expected framework runtime behavior, I also uncovered another tip that's worthwhile sharing. As I mentioned in this recent posting you can set the jbo.viewlink.consistent property to true in your configuration if you want the framework to make sure that newly added rows made through one view object automatically show up in any other view objects in the current root application module which share the affected entity usage. However, this "magic" can only happen if your view objects attributes are properly mapped to their underlying entity object attributes.

In a regular view object which contains at least one entity usage, the view object to entity object attribute mapping is managed for you. If you create SQL calculated attributes in the view object, then you will see on the "Attribute Mapping" tab of the view object wizard that they are not entity mapped. If you flip the "Expert Mode" switch and override the query with something custom, you need to visit the "Attribute Mappings" tab to make sure that your view object attributes are correctly mapped to your underlying entity attributes. Generally they will be just fine, but it's best to check if you observe entity-related behavior in your view object which doesn't seem to be working as you expected.

In this particular customer's testcase, they added a new row via one view object (let's say, related to an underlying Emp entity object) and then were trying to use a different expert-mode view object (also based on that Emp entity) to find that new row. That's a fine thing to do, and should work fine if your view link consistency setting is set to true, but in their case somehow the attributes in their expert mode view object were all marked as "Calculated" (and not mapped correctly to their underlying entity attribute counterparts. Without this VO-attribute-to-EO-attribute wiring being correct, the feature won't work. Making sure the VO attributes were correctly wired to the underlying EO attributes in the expert mode query made it behave as their were expecting.


6:28:30 PM    



I just spent some time investigating a customer testcase where they were wondering why the following sequence of steps was not working properly:

  1. Get an AppModule instance from the pool
  2. Create a new row in some view object
  3. Call appModule.getTransaction().postChanges()
  4. Release the AppModule to the Pool in "Managed State" mode (known as the Stateful mode)
  5. Reaquire an AppModule instance from the pool
  6. Try to find the newly added row

These steps will work fine if your configuration is not set to use database-level connection pooling. We generally recommend only using Application Module level pooling since there are performance benefits to be gained by allowing the instances of the application modules in the pool to hang onto their JDBC connection object (until, of course, that AM instance in the pool is cleaned up). JDBC prepared statements that we've created can be reused again by the framework if the JDBC connection against which they were initially created is still valid. If you ask us to "unplug" the JDBC connection from the application module each time we check an AM instance back into the pool -- which is what turning on database connection pooling is doing -- then we cannot assume that the next time around we will get the same database connection object from the database connection pool, so we rollback that connection when it's released to the pool so that no database pending state is left "hanging" there. Also, when a postChanges() operation is successful, pending changes are no longer considered pending anymore (since they've been communicated to the database) so the BC4J pending state management facility will no longer consider those entities as things that need tracking.

If you do turn on database connection pooling in your configuration, then...

  • After step 3 above, the pending entities are removed from the list that the pending state management facility will bother storing pending information about.
  • At step 4, upon releasing the AM to the pool, we turn around and release the database connection to the pool and issue a rollback on it just before doing that
  • At step 5 you reacquire an AM instance, but since the newly added entities were successfully posted to the database prior to releasing in "Managed State" mode, they will not be in the state snapshot that we manage. Since we issued a rollback on the database connection, those pending inserts won't be there anymore in whatever database connection your new AM instance gets from the database connection pool
  • At step 6, an attempt to find the newly added row (but never committed, just posted before releasing the AM) will not find it

The solution is to either not use database connection pooling (since our pooling of AppModules effectively accomplishes a nice pooling for you), or else don't try to combine that feature with postChanges().

One situation when database connection pooling may be worthwhile is when you have many application module pools, all using the same underlying database connection. In that case, the savings of database connections in use may be worth the tradeoff of losing the efficiency of reusing existing prepared statements.


6:18:04 PM    


© Copyright 2006 Steve Muench.