Remove dependency to JTA
[lgpl/argeo-commons.git] / org.argeo.cms.e4 / src / org / argeo / cms / e4 / users / UserBatchUpdateWizard.java
index 7513102fe8352a664ee00f9163d2c19e1b04231f..4073a209b25c3b7582820731c12da0b5064beae9 100644 (file)
@@ -5,9 +5,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.api.NodeConstants;
@@ -23,6 +20,7 @@ import org.argeo.eclipse.ui.EclipseUiUtils;
 import org.argeo.eclipse.ui.parts.LdifUsersTable;
 import org.argeo.naming.LdapAttrs;
 import org.argeo.naming.LdapObjs;
+import org.argeo.osgi.transaction.WorkTransaction;
 import org.eclipse.jface.dialogs.IPageChangeProvider;
 import org.eclipse.jface.dialogs.IPageChangedListener;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -90,15 +88,10 @@ public class UserBatchUpdateWizard extends Wizard {
        public boolean performFinish() {
                if (!canFinish())
                        return false;
-               UserTransaction ut = userAdminWrapper.getUserTransaction();
-               try {
-                       if (ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION
-                                       && !MessageDialog.openConfirm(getShell(), "Existing Transaction",
-                                                       "A user transaction is already existing, " + "are you sure you want to proceed ?"))
-                               return false;
-               } catch (SystemException e) {
-                       throw new CmsException("Cannot get user transaction state " + "before user batch update", e);
-               }
+               WorkTransaction ut = userAdminWrapper.getUserTransaction();
+               if (!ut.isNoTransactionStatus() && !MessageDialog.openConfirm(getShell(), "Existing Transaction",
+                               "A user transaction is already existing, " + "are you sure you want to proceed ?"))
+                       return false;
 
                // We cannot use jobs, user modifications are still meant to be done in
                // the UIThread
@@ -151,14 +144,9 @@ public class UserBatchUpdateWizard extends Wizard {
                        } catch (Exception e) {
                                throw new CmsException("Cannot perform batch update on users", e);
                        } finally {
-                               UserTransaction ut = userAdminWrapper.getUserTransaction();
-                               try {
-                                       if (ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION)
-                                               ut.rollback();
-                               } catch (IllegalStateException | SecurityException | SystemException e) {
-                                       log.error("Unable to rollback session in 'finally', " + "the system might be in a dirty state");
-                                       e.printStackTrace();
-                               }
+                               WorkTransaction ut = userAdminWrapper.getUserTransaction();
+                               if (!ut.isNoTransactionStatus())
+                                       ut.rollback();
                        }
                }
        }
@@ -190,14 +178,9 @@ public class UserBatchUpdateWizard extends Wizard {
                        } catch (Exception e) {
                                throw new CmsException("Cannot perform batch update on users", e);
                        } finally {
-                               UserTransaction ut = userAdminWrapper.getUserTransaction();
-                               try {
-                                       if (ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION)
-                                               ut.rollback();
-                               } catch (IllegalStateException | SecurityException | SystemException e) {
-                                       log.error("Unable to rollback session in finally block, the system might be in a dirty state");
-                                       e.printStackTrace();
-                               }
+                               WorkTransaction ut = userAdminWrapper.getUserTransaction();
+                               if (!ut.isNoTransactionStatus())
+                                       ut.rollback();
                        }
                }
        }
@@ -457,8 +440,7 @@ public class UserBatchUpdateWizard extends Wizard {
        }
 
        /**
-        * Displays a list of users with a check box to be able to choose some of
-        * them
+        * Displays a list of users with a check box to be able to choose some of them
         */
        private class ChooseUsersWizardPage extends WizardPage implements IPageChangedListener {
                private static final long serialVersionUID = 7651807402211214274L;