001 package com.sptci.echo2;
002
003 import java.io.Serializable;
004
005 import java.lang.reflect.InvocationTargetException;
006 import java.lang.reflect.Method;
007
008 import java.util.ArrayList;
009 import java.util.List;
010 import java.util.Map;
011 import java.util.logging.Logger;
012
013 import nextapp.echo2.app.ListBox;
014 import nextapp.echo2.app.SelectField;
015 import nextapp.echo2.app.button.ToggleButton;
016 import nextapp.echo2.app.list.DefaultListModel;
017
018 import javax.jdo.JDOHelper;
019 import javax.jdo.PersistenceManager;
020
021 import com.sptci.ReflectionUtility;
022 import com.sptci.jdo.PersistenceManagerFactory;
023
024 /**
025 * An <code>updater</code> used to update JavaBean objects from
026 * their associated UI containers. Adds JDO specific
027 * actions such as making modifications within the
028 * bounds of a <code>transaction</code>.
029 *
030 * <p>Copyright 2006 Sans Pareil Technologies, Inc.</p>
031 * @author Rakesh Vidyadharan 2006-02-08
032 * @version $Id: JDOModelUpdater.java,v 1.2 2006/02/13 23:13:49 rakesh Exp $
033 */
034 public class JDOModelUpdater extends ModelUpdater implements Serializable
035 {
036 /**
037 * The logger used to log errors/warnings to.
038 */
039 private static transient final Logger logger =
040 Logger.getLogger( "com.sptci.echo2.JDOModelUpdater" );
041
042 /**
043 * Create a new instance with the specified UI container and java
044 * bean.
045 *
046 * @param uiContainer The {@link #uiContainer} to use.
047 * @param bean The {@link #bean} to use.
048 */
049 public JDOModelUpdater( Object uiContainer, Object bean )
050 {
051 super( uiContainer, bean );
052 }
053
054 /**
055 * Over-ridden to conduct the updates with the bounds of a transaction
056 * as mandated by JDO. Starts a new transaction is necessary and
057 * delegates processing to the super-class method implementation.
058 *
059 * @see ModelUpdater#update
060 * @throws BindingException If errors are encountered while
061 * accessing or setting the fields.
062 */
063 public void update()
064 {
065 PersistenceManager persistenceManager = null;
066 boolean active = false;
067
068 try
069 {
070 persistenceManager = JDOHelper.getPersistenceManager( bean );
071 if ( persistenceManager == null )
072 {
073 persistenceManager =
074 PersistenceManagerFactory.getPersistenceManager();
075 }
076
077 active = persistenceManager.currentTransaction().isActive();
078
079 if ( ! active )
080 {
081 persistenceManager.currentTransaction().begin();
082 }
083
084 super.update();
085
086 if ( ! active )
087 {
088 persistenceManager.currentTransaction().commit();
089 }
090 }
091 catch ( Throwable t )
092 {
093 throw new BindingException( t );
094 }
095 finally
096 {
097 if ( persistenceManager != null && ! active &&
098 persistenceManager.currentTransaction().isActive() )
099 {
100 persistenceManager.currentTransaction().rollback();
101 logger.warning( "Unknown problem. Rollling back transaction." );
102 }
103 }
104 }
105 }