You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2016/03/15 09:53:49 UTC

isis git commit: isis-1325: new SessionManageService and impl; also updated docs.

Repository: isis
Updated Branches:
  refs/heads/master 56ccc9c35 -> 871e7b99f


isis-1325: new SessionManageService and impl; also updated docs.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/871e7b99
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/871e7b99
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/871e7b99

Branch: refs/heads/master
Commit: 871e7b99f58764603e0c0af6a1125253c1cca517
Parents: 56ccc9c
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Mar 15 08:53:00 2016 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Mar 15 08:53:00 2016 +0000

----------------------------------------------------------------------
 .../guides/_rgsvc_api_RepositoryService.adoc    |  2 +-
 .../_rgsvc_api_SessionManagementService.adoc    | 56 ++++++++++++++++++++
 .../guides/_rgsvc_api_TransactionService.adoc   |  4 +-
 .../guides/_rgsvc_application-layer-api.adoc    | 13 +++++
 .../sessmgmt/SessionManagementService.java      | 44 +++++++++++++++
 .../SessionManagementServiceDefault.java        | 47 ++++++++++++++++
 6 files changed, 163 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/871e7b99/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_RepositoryService.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_RepositoryService.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_RepositoryService.adoc
index 40c20e4..2e76395 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_RepositoryService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_RepositoryService.adoc
@@ -144,7 +144,7 @@ It is also possible to query using DataNucleus' type-safe query API.  For more d
 
 == Implementation
 
-The core framework provides a default implementation of this service (`o.a.i.core.runtime.services.repository.RepositoryServiceDefault`).
+The core framework provides a default implementation of this service (`o.a.i.core.metamodel.services.repository.RepositoryServiceDefault`).
 
 
 

http://git-wip-us.apache.org/repos/asf/isis/blob/871e7b99/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_SessionManagementService.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_SessionManagementService.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_SessionManagementService.adoc
new file mode 100644
index 0000000..0ee4ed6
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_SessionManagementService.adoc
@@ -0,0 +1,56 @@
+[[_rgsvc_api_SessionManagementService]]
+= `SessionManagementService` (`1.12.0-SNAPSHOT`)
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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.
+:_basedir: ../
+:_imagesdir: images/
+
+
+The `SessionManagementService` provides the ability to programmatically manage sessions.  The primary use case is
+for fixture scripts or other routines that are invoked from the UI and which create or modify large amounts of data.
+A classic example is migrating data from one system to another.
+
+
+
+== API
+
+The API of `SessionManagementService` is:
+
+
+[source,java]
+----
+public interface SessionManagementService {
+    void nextSession();
+}
+----
+
+
+Normally, the framework will automatically start a session and then a transaction before each user interaction
+(action invocation or property modification), and wil then commit that transaction and close the session after the
+interaction has completed.  If the interaction throws an exception then the transaction is aborted.
+
+The `nextSession()` method allows a domain object to commit the transaction, close the session, then open a new
+session and start a new transaction.
+
+[IMPORTANT]
+====
+Any domain objects that were created in the "previous" session are no longer usable, and must not be rendered in the UI.
+====
+
+
+
+== Implementation
+
+The core framework provides a default implementation of this service (`o.a.i.core.runtime.services.xactn.SessionManagementServiceDefault`).
+
+
+
+== Registering the Service
+
+Assuming that the `configuration-and-annotation` services installer is configured (implicit if using the
+`AppManifest` to xref:rgcms.adoc#_rgcms_classes_AppManifest-bootstrapping[bootstrap the app]) then Apache Isis' core
+implementation of `SessionManagementService` service is automatically registered and injected (it is annotated with
+`@DomainService`) so no further configuration is required.
+
+To use an alternative implementation, use
+xref:rgant.adoc#_rgant-DomainServiceLayout_menuOrder[`@DomainServiceLayout#menuOrder()`] (as explained
+in the xref:rgsvc.adoc#_rgsvc_intro_overriding-the-services[introduction] to this guide).

http://git-wip-us.apache.org/repos/asf/isis/blob/871e7b99/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_TransactionService.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_TransactionService.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_TransactionService.adoc
index bdf7ee8..f0cfb66 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_TransactionService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_TransactionService.adoc
@@ -50,14 +50,14 @@ end of the transaction, or immediately prior to the next query.
 
 == Implementation
 
-The core framework provides a default implementation of this service (`o.a.i.core.runtime.services.xactn.TransactionServiceDefault`).
+The core framework provides a default implementation of this service (`o.a.i.core.metamodel.services.xactn.TransactionServiceDefault`).
 
 
 == Registering the Service
 
 Assuming that the `configuration-and-annotation` services installer is configured (implicit if using the
 `AppManifest` to xref:rgcms.adoc#_rgcms_classes_AppManifest-bootstrapping[bootstrap the app]) then Apache Isis' core
-implementation of `RepositoryService` service is automatically registered and injected (it is annotated with
+implementation of `TransactionService` service is automatically registered and injected (it is annotated with
 `@DomainService`) so no further configuration is required.
 
 To use an alternative implementation, use

http://git-wip-us.apache.org/repos/asf/isis/blob/871e7b99/adocs/documentation/src/main/asciidoc/guides/_rgsvc_application-layer-api.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_application-layer-api.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_application-layer-api.adoc
index 2013890..432ed67 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_application-layer-api.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_application-layer-api.adoc
@@ -77,6 +77,18 @@ xref:rgsvc.adoc#_rgsvc_spi_CommandService[`CommandService`] for persistent `Comm
 |Supercedes methods in xref:rgsvc.adoc#_rgsvc_api_DomainObjectContainer[`DomainObjectContainer`].
 
 
+|xref:rgsvc.adoc#_rgsvc_api_SessionManagementService[`o.a.i.applib.` +
+`services.sessmgmt` +
+`SessionManagementService`]
+|(`1.12.0-SNAPSHOT`) Methods for batching long-running work (eg data migration) into multiple sessions.
+|`SessionManagementService-` +
+``Default`` +
+``o.a.i.core`` +
+``isis-core-runtime``
+|
+
+
+
 |xref:rgsvc.adoc#_rgsvc_api_TransactionService[`o.a.i.applib.` +
 `services.xactn` +
 `TransactionService`]
@@ -115,5 +127,6 @@ include::_rgsvc_api_ActionInvocationContext.adoc[leveloffset=+1]
 include::_rgsvc_api_BackgroundService.adoc[leveloffset=+1]
 include::_rgsvc_api_CommandContext.adoc[leveloffset=+1]
 include::_rgsvc_api_MessageService.adoc[leveloffset=+1]
+include::_rgsvc_api_SessionManagementService.adoc[leveloffset=+1]
 include::_rgsvc_api_TransactionService.adoc[leveloffset=+1]
 include::_rgsvc_api_WrapperFactory.adoc[leveloffset=+1]

http://git-wip-us.apache.org/repos/asf/isis/blob/871e7b99/core/applib/src/main/java/org/apache/isis/applib/services/sessmgmt/SessionManagementService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/sessmgmt/SessionManagementService.java b/core/applib/src/main/java/org/apache/isis/applib/services/sessmgmt/SessionManagementService.java
new file mode 100644
index 0000000..0450191
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/sessmgmt/SessionManagementService.java
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.isis.applib.services.sessmgmt;
+
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.fixturescripts.FixtureScript;
+
+/**
+ * Intended primarily for {@link org.apache.isis.applib.fixturescripts.FixtureScript}s that define long-running/large
+ * jobs, eg as used for migration; the intention is to allow that work to be broken into separate batches, each in
+ * their own session, but all within a single request.
+ *
+ * <p>
+ *     Care must be taken not to use any objects from one session to the next.  In other words, the service does
+ *     <i>not</i> detach any persistent objects in one session and re-attach them in the next.  Also, any objects
+ *     created in previous sessions cannot be exposed in the UI.  In practical terms this means that
+ *     {@link org.apache.isis.applib.fixturescripts.FixtureScript.ExecutionContext#addResult(FixtureScript, Object)}
+ *     must not be called.
+ * </p>
+ *
+ * @see org.apache.isis.applib.services.xactn.TransactionService
+ */
+public interface SessionManagementService {
+
+    @Programmatic
+    public void nextSession();
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/871e7b99/core/runtime/src/main/java/org/apache/isis/core/runtime/services/sessmgmt/SessionManagementServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/sessmgmt/SessionManagementServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/sessmgmt/SessionManagementServiceDefault.java
new file mode 100644
index 0000000..a389dee
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/sessmgmt/SessionManagementServiceDefault.java
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.isis.core.runtime.services.sessmgmt;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.sessmgmt.SessionManagementService;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+
+@DomainService(
+        nature = NatureOfService.DOMAIN
+)
+public class SessionManagementServiceDefault implements SessionManagementService {
+
+
+    @Programmatic
+    @Override
+    public void nextSession() {
+        final AuthenticationSession authenticationSession = IsisContext.getAuthenticationSession();
+
+        IsisContext.getPersistenceSession().getTransactionManager().endTransaction();
+        IsisContext.closeSession();
+        IsisContext.openSession(authenticationSession);
+        IsisContext.getPersistenceSession().getTransactionManager().startTransaction();
+    }
+
+
+}