How to trigger commit programmaticaly on Spring Webflow 2 with Flow Managed Persistence Context - spring

i have upgraded our application to SWF 2 and have implemented FMPC pattern. majority of our existing flow definitions doesn't have end-state, now using FMPC as described here, you can trigger commit by putting commit=true to your end-state. Example of our flow:
get form object
save details to db (we want to commit here)
fetch the same object with refreshed data
display to view
its currently working with previous SWF and just using Open Session in View pattern. but we imlemented FMPC to avoid any LazyInitializationException. Now what's happening is steps 1-4 is happening except that changes are not committed, so in the view, we don't see any changes. it seems difficult to add end-state at the middle just to commit to DB and also this means we need to add so many end-state, so my question is how to tell (SWF/FMPC) to commit "programmaticaly" without having to add the end-state tag. If you know better approach, please tell also. Thanks!

Spring Web Flows can have inheritance, so you can implement the end-state in your parent flow and then have it as a parent for all your flows.

I resolved my issue. I finally found out that indeed Hibernate is auto-committing all my read-write operations. The problem is when refreshing the object concerned which gave me the impression that there is no read-write done while in fact there is. Doing sessioFactory.refresh(object) instead of plain find() effectively fetched the updated data from the DB. I guess its because the hibernate session is still alive (due to FMPC) that's why doing "find" will retrieve from the hibernate cache while "refresh" means re-reading the data directly from underlying database. Please correct my analysis as necessary.

Related

safeguard hibernate.hbm2ddl.auto with manual confirmation

normally you provide a application-P.properties file with you application and in there set hibernate.hbm2ddl.auto=validate or something that does not delete data. but what if you want to have a further safeguard so that deletion needs a manual confirmation?
there are some google hits that go into the right direction but i haven't found one that clearly sasy that code x is run before spring checks that variable and deletes the db.
where in spring do you run code that is executed before the database tables are created?

How to create a Checkpoint in UFT

Strange enough that I have to ask such a simple question.
I started automating with UFT and I suppose the correct way to check if for instance my login has worked is to add a checkpoint on the next page.
But how do I do that?
All info I get from google is on how to add an already existing checkpoint to may page. But I don't have any.
Here is how I go about automating:
I add manually the relevant objects to the object repository
I create parameters for my action
I create the code that does the steps on the page
one action per page seems to be fine for me
But in the Object Repository of UFT 14.53, there is no button to add a Checkpoint.
A workaround for me would be to just add another Object and check it's existence and forget about checkpoints. Until I hopefully get an answer here, I will try to do just that.
In UFT there are typically two ways to verify that things are working as expected.
Flow (implicit) - In order to verify that progress in the application is successful (e.g. login) one usually just keeps working with the app, assuming that if the previous step failed, the objects needed for the next steps won't exist and the test will fail due to ObjectNotFound errors
State (explicit) - In order to see that objects have a specific state, checkpoints are usually used. Checkpoints are typically added during a record session, I'm not sure if there's a way to add them directly to the repository. An alternative to checkpoints, which works better with keyword driven testing (no recording), is to use the built in CheckProperty method.

Spring Webflow (and Freemarker) - restrict page to one user

I am working on an application with Spring Webflow, Freemarker, Hibernate (JPA) and Oracle.
In the application I've got an Admin page which should be editable to only one user.
Once a user is editing that page, other user accessing should be presented this page as a view only page and they should get a warning when they open the page that 'X is editing this page, thus your access is read only'.
Is this possible to do easily in Webflow or Freemarker?
Any suggestions are welcome.
Thanks
UPDATE 1
I am using JPA (Hibernate) as well.
UPDATE 2
And the application will be deployed in a clustered JBoss.
I would use optimistic locking instead. The following strategy is the one used by JPA.
You add a version field to the table holding the data to edit. Each time you load the data to edit, you also load the version field. Each time the data is modified, you increment this version field by 1. But to be able to save the data, you must have an in-memory version that is equal to the one stored in database:
update data set ..., version = version + 1 where ... and version = :inMemoryVersion
If the above query doesn't update anything, it means the data has been updated by someone else. In this case, you throw an exception and tell the admin to refresh the page and redo his edit.
If you really want pessimistic locking, then you need to maintain some in-memory (in the app is not clustered) or in-database lock, try to lock the lock, and display the page in read-only if it's already locked. Once the update is done, you must release the lock. The problem is if the update is never done. In this case, you need to use an HttpSessionListener, and release the lock when sessionDestroyed() is called, if the lock is held by the session being destroyed.

Tracking Changes Object Changes

I wanted to get your opinions on the easiest way to track changes that users make when they do CRUD events. I am working on a system where the users are less interested on permissions, but really want to have a sophisticated log of what changes a user made. I am using ASP.NET MVC 3, EF, and NLog.
Any advice is greatly appreciated :)
Steve
I use a convention based approach. Each entity has an associated audit entity which includes all properties from the base entity plus information on the change, including whether it was successful or not. I override the SaveChanges method on the DB context. For each entity being changed it creates an audit entity from it holding the new values. It attempts to save the changes, then uses a separate, auditing context to save each of the audited entities with the results of the save operation. I use an injected utility in the data context to get access to the current user (via HttpContext.Current for web, via the Environment.User for non-web) when constructing the audit entities.
I blogged about an earlier version of this for LINQ to SQL at http://farm-fresh-code.blogspot.com/2009/05/auditing-inserts-and-updates-using-linq.html. You should be able to get the basic idea from that.

Subsonic, SharedDbConnectionScope and ApplicationState

I'm looking at using Subsonic with a multi-tenant ASP.net web application. There are multiple DB's (one per client/instance). The user logs in with a domain suffix to their username (e.g. user#tenant1, user#tenant2).
The custom membership provider will then determine which database a user is using, and authenticate against it. All user-initiated calls in the webapp will be wrapped in a SharedDbConnectionScope call, however I have a question regarding caching subsonic items.
Basically each instance will have a few records that rarely change (search options/configurations). I would like to read these in the Application_Start event, and cache them into the ApplicationState.
In the Application_Start event, it would loop over each client database, use a SharedDbConnectionScope to connect to each DB, and create these cached records (e.g. Application('tenant1_search_obj') = subsonic_object
When a user loads the search page, it would then check what domain a user is in, and then retreive that search option from the cache.
Is this feasible? I'm just concerned that if I cache an object, when I retrieve it from the application cache it won't know what connection its using, and might possibly pull in the wrong data.
I'd like to avoid putting this in the session object if possible.
it's possible, but probably not a good idea since it doesn't scale at all - you're going to pop a new connection for every single client whether they show up or not.
Maybe your best bet is to "lazy load" the setting - first hit on the search page loads the config into the cache or Application settings and there it stays.
Other than that - to answer your question it is possible. If you're using SubSonic 3, just create a new provider on the fly using ProviderFactory.GetProvider(connectionString, "System.Data.SqlClient") and then execute your stuff against it.
For SubSonic 2 - SharedConnectionScope is what you want.

Resources