From: Bruno Sinou Date: Mon, 14 Sep 2015 13:42:23 +0000 (+0000) Subject: Introduce commands to manage user transaction X-Git-Tag: argeo-commons-2.1.30~162 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=d4e81d47521226b3b877d4d4682e4837450d8d55;hp=70bf531fd1410ffbaaa4083a4f763b04a7c3f95b;p=lgpl%2Fargeo-commons.git Introduce commands to manage user transaction git-svn-id: https://svn.argeo.org/commons/trunk@8390 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.security.ui.admin/META-INF/spring/commands.xml b/org.argeo.security.ui.admin/META-INF/spring/commands.xml index e83440376..24c0ac274 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/commands.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/commands.xml @@ -4,22 +4,13 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - @@ -29,4 +20,11 @@ /> --> + + + + + diff --git a/org.argeo.security.ui.admin/META-INF/spring/editors.xml b/org.argeo.security.ui.admin/META-INF/spring/editors.xml index 263cfccb4..e9cf5ac8d 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/editors.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/editors.xml @@ -15,7 +15,4 @@ - diff --git a/org.argeo.security.ui.admin/META-INF/spring/osgi.xml b/org.argeo.security.ui.admin/META-INF/spring/osgi.xml index 9d1d4645c..02a63748f 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/osgi.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/osgi.xml @@ -10,9 +10,8 @@ - - + + \ No newline at end of file diff --git a/org.argeo.security.ui.admin/META-INF/spring/views.xml b/org.argeo.security.ui.admin/META-INF/spring/views.xml index 6b0970e41..18a7b8881 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/views.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/views.xml @@ -14,11 +14,4 @@ scope="prototype"> - - - diff --git a/org.argeo.security.ui.admin/icons/begin.gif b/org.argeo.security.ui.admin/icons/begin.gif new file mode 100755 index 000000000..feb8e94a7 Binary files /dev/null and b/org.argeo.security.ui.admin/icons/begin.gif differ diff --git a/org.argeo.security.ui.admin/icons/commit.gif b/org.argeo.security.ui.admin/icons/commit.gif new file mode 100755 index 000000000..876f3eb16 Binary files /dev/null and b/org.argeo.security.ui.admin/icons/commit.gif differ diff --git a/org.argeo.security.ui.admin/icons/rollback.gif b/org.argeo.security.ui.admin/icons/rollback.gif new file mode 100755 index 000000000..c75399599 Binary files /dev/null and b/org.argeo.security.ui.admin/icons/rollback.gif differ diff --git a/org.argeo.security.ui.admin/plugin.xml b/org.argeo.security.ui.admin/plugin.xml index b8ad03000..6bdfd6d8b 100644 --- a/org.argeo.security.ui.admin/plugin.xml +++ b/org.argeo.security.ui.admin/plugin.xml @@ -11,6 +11,7 @@ + - + - - - + - - - + + + - - + - + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + --> + + - - + - - - - - - - - \ No newline at end of file + + + + + + + + \ No newline at end of file diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java new file mode 100644 index 000000000..158fae24d --- /dev/null +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.admin.commands; + +import javax.transaction.Status; +import javax.transaction.UserTransaction; + +import org.argeo.ArgeoException; +import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +/** Manage the transaction that is bound to the current perspective */ +public class UserTransactionHandler extends AbstractHandler { + public final static String ID = SecurityAdminPlugin.PLUGIN_ID + + ".userTransactionHandler"; + + public final static String PARAM_COMMAND_ID = "param.commandId"; + + public final static String TRANSACTION_BEGIN = "transaction.begin"; + public final static String TRANSACTION_COMMIT = "transaction.commit"; + public final static String TRANSACTION_ROLLBACK = "transaction.rollback"; + + private UserTransaction userTransaction; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + String commandId = event.getParameter(PARAM_COMMAND_ID); + try { + if (TRANSACTION_BEGIN.equals(commandId)) { + if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION) + throw new ArgeoException("A transaction already exists"); + else + userTransaction.begin(); + } else if (TRANSACTION_COMMIT.equals(commandId)) { + if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) + throw new ArgeoException("No transaction."); + else + userTransaction.commit(); + } else if (TRANSACTION_ROLLBACK.equals(commandId)) { + if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) + throw new ArgeoException("No transaction to rollback."); + else + userTransaction.rollback(); + } + } catch (ArgeoException e) { + throw e; + } catch (Exception e) { + throw new ArgeoException("Unable to call " + commandId + " on " + + userTransaction, e); + } + // + // IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event); + // if (iww == null) + // return null; + // IWorkbenchPage activePage = iww.getActivePage(); + // IWorkbenchPart part = activePage.getActivePart(); + // if (part instanceof UsersView) + // ((UsersView) part).refresh(); + // else if (part instanceof GroupsView) + // ((GroupsView) part).refresh(); + return null; + } + + public void setUserTransaction(UserTransaction userTransaction) { + this.userTransaction = userTransaction; + } +} \ No newline at end of file diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java index af6f5748e..485956b9a 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java @@ -120,11 +120,11 @@ public class UserEditor extends FormEditor implements UserAdminConstants { commitPages(true); firePropertyChange(PROP_DIRTY); // FIXME transaction should be managed at a higher level - try { - userTransaction.commit(); - } catch (Exception e) { - throw new ArgeoException("Could not save user editor", e); - } + // try { + // userTransaction.commit(); + // } catch (Exception e) { + // throw new ArgeoException("Could not save user editor", e); + // } } @Override diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java index 989b1975e..6604e6106 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java @@ -82,12 +82,12 @@ public class UsersView extends ViewPart implements ArgeoNames { // Really? userTableViewerCmp.refresh(); - try { - if (userTransaction != null) - userTransaction.begin(); - } catch (Exception e) { - throw new ArgeoException("Cannot begin transaction", e); - } +// try { +// if (userTransaction != null) +// userTransaction.begin(); +// } catch (Exception e) { +// throw new ArgeoException("Cannot begin transaction", e); +// } } private class MyUserTableViewer extends UserTableViewer {